version 1.1.1.1, 2012/02/21 22:14:23
|
version 1.1.1.2, 2013/07/22 11:54:42
|
Line 109 libnet_check_iface(libnet_t *l)
|
Line 109 libnet_check_iface(libnet_t *l)
|
#endif |
#endif |
|
|
int |
int |
libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, int8_t *dev, | libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, |
register int8_t *errbuf) | register char *errbuf) |
{ |
{ |
register struct libnet_ifaddr_list *al; |
register struct libnet_ifaddr_list *al; |
struct ifreq *ifr, *lifr, *pifr, nifr; |
struct ifreq *ifr, *lifr, *pifr, nifr; |
int8_t device[sizeof(nifr.ifr_name)]; | char device[sizeof(nifr.ifr_name)]; |
static struct libnet_ifaddr_list ifaddrlist[MAX_IPADDR]; |
static struct libnet_ifaddr_list ifaddrlist[MAX_IPADDR]; |
|
|
char *p; |
char *p; |
Line 154 register int8_t *errbuf)
|
Line 154 register int8_t *errbuf)
|
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
"%s(): ioctl(SIOCGIFCONF) error: %s\n", |
"%s(): ioctl(SIOCGIFCONF) error: %s\n", |
__func__, strerror(errno)); |
__func__, strerror(errno)); |
|
#ifdef HAVE_LINUX_PROCFS |
|
fclose(fp); |
|
#endif |
return(-1); |
return(-1); |
} |
} |
|
|
Line 224 register int8_t *errbuf)
|
Line 227 register int8_t *errbuf)
|
"%s(): SIOCGIFADDR: dev=%s: %s\n", __func__, device, |
"%s(): SIOCGIFADDR: dev=%s: %s\n", __func__, device, |
strerror(errno)); |
strerror(errno)); |
close(fd); |
close(fd); |
|
#ifdef HAVE_LINUX_PROCFS |
|
fclose(fp); |
|
#endif |
return (-1); |
return (-1); |
} |
} |
else /* device has no IP address => set to 0 */ |
else /* device has no IP address => set to 0 */ |
Line 235 register int8_t *errbuf)
|
Line 241 register int8_t *errbuf)
|
{ |
{ |
al->addr = ((struct sockaddr_in *)&nifr.ifr_addr)->sin_addr.s_addr; |
al->addr = ((struct sockaddr_in *)&nifr.ifr_addr)->sin_addr.s_addr; |
} |
} |
|
|
|
free(al->device); |
|
al->device = NULL; |
|
|
if ((al->device = strdup(device)) == NULL) |
if ((al->device = strdup(device)) == NULL) |
{ |
{ |
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
"%s(): strdup not enough memory\n", __func__); |
"%s(): strdup not enough memory\n", __func__); |
|
#ifdef HAVE_LINUX_PROCFS |
|
fclose(fp); |
|
#endif |
return(-1); |
return(-1); |
} |
} |
|
|
Line 257 register int8_t *errbuf)
|
Line 269 register int8_t *errbuf)
|
{ |
{ |
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
snprintf(errbuf, LIBNET_ERRBUF_SIZE, |
"%s(): ferror: %s\n", __func__, strerror(errno)); |
"%s(): ferror: %s\n", __func__, strerror(errno)); |
|
fclose(fp); |
return (-1); |
return (-1); |
} |
} |
fclose(fp); |
fclose(fp); |
Line 268 register int8_t *errbuf)
|
Line 281 register int8_t *errbuf)
|
#else |
#else |
/* From tcptraceroute, convert a numeric IP address to a string */ |
/* From tcptraceroute, convert a numeric IP address to a string */ |
#define IPTOSBUFFERS 12 |
#define IPTOSBUFFERS 12 |
static int8_t *iptos(u_int32_t in) | static int8_t *iptos(uint32_t in) |
{ |
{ |
static int8_t output[IPTOSBUFFERS][ 3 * 4 + 3 + 1]; |
static int8_t output[IPTOSBUFFERS][ 3 * 4 + 3 + 1]; |
static int16_t which; |
static int16_t which; |
u_int8_t *p; | uint8_t *p; |
|
|
p = (u_int8_t *)∈ | p = (uint8_t *)∈ |
which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1); |
which = (which + 1 == IPTOSBUFFERS ? 0 : which + 1); |
snprintf(output[which], IPTOSBUFFERS, "%d.%d.%d.%d", |
snprintf(output[which], IPTOSBUFFERS, "%d.%d.%d.%d", |
p[0], p[1], p[2], p[3]); |
p[0], p[1], p[2], p[3]); |
Line 282 static int8_t *iptos(u_int32_t in)
|
Line 295 static int8_t *iptos(u_int32_t in)
|
} |
} |
|
|
int |
int |
libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, int8_t *dev, | libnet_ifaddrlist(register struct libnet_ifaddr_list **ipaddrp, char *dev, |
register int8_t *errbuf) | register char *errbuf) |
{ |
{ |
int nipaddr = 0; int i = 0; |
int nipaddr = 0; int i = 0; |
|
|
Line 310 register int8_t *errbuf)
|
Line 323 register int8_t *errbuf)
|
|
|
/* XXX - strdup */ |
/* XXX - strdup */ |
ifaddrlist[i].device = strdup(d->name); |
ifaddrlist[i].device = strdup(d->name); |
ifaddrlist[i].addr = (u_int32_t) | ifaddrlist[i].addr = (uint32_t) |
strdup(iptos(((struct sockaddr_in *) |
strdup(iptos(((struct sockaddr_in *) |
d->addresses->addr)->sin_addr.s_addr)); |
d->addresses->addr)->sin_addr.s_addr)); |
++i; |
++i; |
Line 326 int
|
Line 339 int
|
libnet_select_device(libnet_t *l) |
libnet_select_device(libnet_t *l) |
{ |
{ |
int c, i; |
int c, i; |
int8_t err_buf[LIBNET_ERRBUF_SIZE]; | char err_buf[LIBNET_ERRBUF_SIZE]; |
struct libnet_ifaddr_list *address_list, *al; |
struct libnet_ifaddr_list *address_list, *al; |
u_int32_t addr; | uint32_t addr; |
|
|
|
|
if (l == NULL) |
if (l == NULL) |
Line 401 good:
|
Line 414 good:
|
for (i = 0; i < c; i++) |
for (i = 0; i < c; i++) |
{ |
{ |
free(al[i].device); |
free(al[i].device); |
|
al[i].device = NULL; |
} |
} |
return (1); |
return (1); |
|
|
Line 408 bad:
|
Line 422 bad:
|
for (i = 0; i < c; i++) |
for (i = 0; i < c; i++) |
{ |
{ |
free(al[i].device); |
free(al[i].device); |
|
al[i].device = NULL; |
} |
} |
return (-1); |
return (-1); |
} |
} |