version 1.1.1.2, 2013/07/22 11:54:42
|
version 1.1.1.3, 2023/09/27 11:11:38
|
Line 1
|
Line 1
|
/* |
/* |
* $Id$ |
|
* |
|
* libnet |
* libnet |
* libnet_resolve.c - various name resolution type routines |
* libnet_resolve.c - various name resolution type routines |
* |
* |
Line 30
|
Line 28
|
* |
* |
*/ |
*/ |
|
|
#if (HAVE_CONFIG_H) | #include "common.h" |
#include "../include/config.h" | |
#endif | |
#if (!(_WIN32) || (__CYGWIN__)) | |
#include "../include/libnet.h" | |
#else | |
#include "../include/win32/libnet.h" | |
#endif | |
|
|
#ifndef HAVE_GETHOSTBYNAME2 |
#ifndef HAVE_GETHOSTBYNAME2 |
struct hostent * |
struct hostent * |
Line 119 libnet_addr2name4_r(uint32_t in, uint8_t use_name, cha
|
Line 110 libnet_addr2name4_r(uint32_t in, uint8_t use_name, cha
|
} |
} |
|
|
uint32_t |
uint32_t |
libnet_name2addr4(libnet_t *l, char *host_name, uint8_t use_name) | libnet_name2addr4(libnet_t *l, const char *host_name, uint8_t use_name) |
{ |
{ |
struct in_addr addr; |
struct in_addr addr; |
struct hostent *host_ent; |
struct hostent *host_ent; |
uint32_t m; |
uint32_t m; |
uint val; | uint32_t val; |
int i; |
int i; |
|
|
if (use_name == LIBNET_RESOLVE) |
if (use_name == LIBNET_RESOLVE) |
Line 134 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
Line 125 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
if (!(host_ent = gethostbyname(host_name))) |
if (!(host_ent = gethostbyname(host_name))) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): %s\n", __func__, hstrerror(h_errno)); | "%s(): %s", __func__, |
| #if (_WIN32) |
| "gethostbyname failure" |
| #else |
| /* FIXME doesn't exist on windows, needs WSAGetLastError()/FormatMessage */ |
| hstrerror(h_errno) |
| #endif |
| ); |
/* XXX - this is actually 255.255.255.255 */ |
/* XXX - this is actually 255.255.255.255 */ |
return (-1); |
return (-1); |
} |
} |
Line 153 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
Line 151 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
if (l) |
if (l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): expecting dots and decimals\n", __func__); | "%s(): expecting dots and decimals", __func__); |
} |
} |
/* XXX - this is actually 255.255.255.255 */ |
/* XXX - this is actually 255.255.255.255 */ |
return (-1); |
return (-1); |
Line 175 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
Line 173 libnet_name2addr4(libnet_t *l, char *host_name, uint8_
|
if (l) |
if (l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): value greater than 255\n", __func__); | "%s(): value greater than 255", __func__); |
} |
} |
/* XXX - this is actually 255.255.255.255 */ |
/* XXX - this is actually 255.255.255.255 */ |
return (-1); |
return (-1); |
Line 251 libnet_name2addr6(libnet_t *l, const char *host_name,
|
Line 249 libnet_name2addr6(libnet_t *l, const char *host_name,
|
if (l) |
if (l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't resolve IPv6 addresses\n", __func__); | "%s(): can't resolve IPv6 addresses", __func__); |
} |
} |
return (in6addr_error); |
return (in6addr_error); |
#else |
#else |
Line 261 libnet_name2addr6(libnet_t *l, const char *host_name,
|
Line 259 libnet_name2addr6(libnet_t *l, const char *host_name,
|
sizeof(struct in_addr), AF_INET6, NULL))) |
sizeof(struct in_addr), AF_INET6, NULL))) |
#else |
#else |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): %s\n", __func__, strerror(errno)); | "%s(): %s", __func__, strerror(errno)); |
return (in6addr_error); |
return (in6addr_error); |
#endif |
#endif |
#else |
#else |
Line 282 libnet_name2addr6(libnet_t *l, const char *host_name,
|
Line 280 libnet_name2addr6(libnet_t *l, const char *host_name,
|
if (l) |
if (l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't resolve IPv6 addresses.\n", __func__); | "%s(): can't resolve IPv6 addresses.", __func__); |
} |
} |
return (in6addr_error); |
return (in6addr_error); |
#else |
#else |
Line 291 libnet_name2addr6(libnet_t *l, const char *host_name,
|
Line 289 libnet_name2addr6(libnet_t *l, const char *host_name,
|
if (l) |
if (l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): invalid IPv6 address\n", __func__); | "%s(): invalid IPv6 address", __func__); |
} |
} |
return (in6addr_error); |
return (in6addr_error); |
} |
} |
Line 318 libnet_get_ipaddr6(libnet_t *l)
|
Line 316 libnet_get_ipaddr6(libnet_t *l)
|
if (getifaddrs(&ifaddr) != 0) |
if (getifaddrs(&ifaddr) != 0) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): getifaddrs(): %s\n", __func__, strerror(errno)); | "%s(): getifaddrs(): %s", __func__, strerror(errno)); |
return (in6addr_error); |
return (in6addr_error); |
} |
} |
|
|
Line 351 struct libnet_in6_addr
|
Line 349 struct libnet_in6_addr
|
libnet_get_ipaddr6(libnet_t *l) |
libnet_get_ipaddr6(libnet_t *l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): not yet Implemented\n", __func__); | "%s(): not yet Implemented", __func__); |
return (in6addr_error); |
return (in6addr_error); |
} |
} |
#endif /* WIN32 */ |
#endif /* WIN32 */ |
Line 374 libnet_get_ipaddr4(libnet_t *l)
|
Line 372 libnet_get_ipaddr4(libnet_t *l)
|
if (fd == -1) |
if (fd == -1) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): socket(): %s\n", __func__, strerror(errno)); | "%s(): socket(): %s", __func__, strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
|
|
Line 397 libnet_get_ipaddr4(libnet_t *l)
|
Line 395 libnet_get_ipaddr4(libnet_t *l)
|
if (ioctl(fd, SIOCGIFADDR, (int8_t*) &ifr) < 0) |
if (ioctl(fd, SIOCGIFADDR, (int8_t*) &ifr) < 0) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): ioctl(): %s\n", __func__, strerror(errno)); | "%s(): ioctl(): %s", __func__, strerror(errno)); |
close(fd); |
close(fd); |
return (-1); |
return (-1); |
} |
} |
Line 409 libnet_get_ipaddr4(libnet_t *l)
|
Line 407 libnet_get_ipaddr4(libnet_t *l)
|
uint32_t |
uint32_t |
libnet_get_ipaddr4(libnet_t *l) |
libnet_get_ipaddr4(libnet_t *l) |
{ |
{ |
long npflen = 0; | long npflen = 1; |
struct sockaddr_in sin; |
struct sockaddr_in sin; |
struct npf_if_addr ipbuff; |
struct npf_if_addr ipbuff; |
|
|
memset(&sin,0,sizeof(sin)); |
memset(&sin,0,sizeof(sin)); |
memset(&ipbuff,0,sizeof(ipbuff)); |
memset(&ipbuff,0,sizeof(ipbuff)); |
|
|
npflen = sizeof(ipbuff); |
|
if (PacketGetNetInfoEx(l->device, &ipbuff, &npflen)) |
if (PacketGetNetInfoEx(l->device, &ipbuff, &npflen)) |
{ |
{ |
sin = *(struct sockaddr_in *)&ipbuff.IPAddress; |
sin = *(struct sockaddr_in *)&ipbuff.IPAddress; |
Line 473 libnet_hex_aton(const char *s, int *len)
|
Line 470 libnet_hex_aton(const char *s, int *len)
|
return (buf); |
return (buf); |
} |
} |
|
|
/* EOF */ | /** |
| * Local Variables: |
| * indent-tabs-mode: nil |
| * c-file-style: "stroustrup" |
| * End: |
| */ |