[Javanetsim-cvs] IceScan/icesockets sock_pcap.h, 1.7, 1.8 sock_name.h, 1.12, 1.13
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-12-19 21:09:07
|
Update of /cvsroot/javanetsim/IceScan/icesockets In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19404/icesockets Modified Files: sock_pcap.h sock_name.h Log Message: no message Index: sock_pcap.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/sock_pcap.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** sock_pcap.h 19 Dec 2006 18:59:16 -0000 1.7 --- sock_pcap.h 19 Dec 2006 21:09:04 -0000 1.8 *************** *** 29,32 **** --- 29,36 ---- } + int getdev_pcap(icestring &dev){ + return 0; + } + int pcap_block(pcap_t *p, bool block){ } *************** *** 113,116 **** --- 117,146 ---- } + int getdev_pcap(icestring &dev){ + pcap_if_t *alldevs; + pcap_if_t *d; + int i=1; + char errbuf[PCAP_ERRBUF_SIZE]; + + if(pcap_findalldevs(&alldevs, errbuf) == -1) + { + printf("Error in pcap_findalldevs: %s\n", errbuf); + exit(1); + } + + for(d=alldevs; d; d=d->next, i++) + { + if(!strcmp(d->name, dev.c_str())) break; + } + + if(!d) (i = 0); + + pcap_freealldevs(alldevs); + + if(i==0) + printf("\nNo interfaces found! Make sure WinPcap is installed.\n"); + + return i; + } char* readip_pcap(pcap_t* pd, unsigned int *len, struct timeval *rcvd_time){ Index: sock_name.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/sock_name.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** sock_name.h 17 Dec 2006 21:03:17 -0000 1.12 --- sock_name.h 19 Dec 2006 21:09:04 -0000 1.13 *************** *** 12,15 **** --- 12,16 ---- #include "sock_types.h" + #include "sock_eth.h" #include "iceregex.h" *************** *** 116,118 **** --- 117,167 ---- } + icestring get_source_ip(const icestring &destip, icestring &sourceint){ + #ifdef __CYGWIN__ + char local_hostname[80]; + if(gethostname(local_hostname, 80)) exit(-1); + + sourceint.assign("null"); //unfortunately, no pcap in cygwin + + icestring ret(local_hostname); + + return ret; + #else + #ifdef __linux__ + if(!strcmp(destip.c_str(), "127.0.0.1")){ + sourceint.assign("lo"); + return "127.0.0.1"; + } + #elif + //Need to add some code here... + #endif + + struct ip_intf *ipi; + + ip_t *ip = i_ip_open(); + + if ((ipi = i_lookup_ip_intf(ip, inet_addr(destip.c_str()))) == NULL) { + errno = EHOSTUNREACH; + DBGOUTPUT("HOST UNREACH!!!"); + return ""; + } + + + struct sockaddr sa; + + addr_ntos(&(ipi->pa), &sa); + + struct sockaddr_in *sai = (sockaddr_in *) &sa; + + sourceint.assign(ipi->name); + icestring addr(inet_ntoa(sai->sin_addr)); + + #ifdef __linux__ //add more platforms here + if(! strcmp(addr.c_str(), destip.c_str())) sourceint.assign("lo"); + #endif + + return addr; + #endif + } + #endif |