1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-12 02:39:03 +00:00

Allow use of Windows' own inet_pton and inet_ntop functions

This commit is contained in:
dmiller
2016-06-04 02:46:12 +00:00
parent 50054e6ed7
commit 855ec33fc0
5 changed files with 21 additions and 7 deletions

View File

@@ -2294,9 +2294,9 @@ const char *ippackethdrinfo(const u8 *packet, u32 len, int detail) {
/* Obtain IP source and destination info */ /* Obtain IP source and destination info */
sin = (struct sockaddr_in *) &hdr.src; sin = (struct sockaddr_in *) &hdr.src;
inet_ntop(AF_INET, &sin->sin_addr.s_addr, srchost, sizeof(srchost)); inet_ntop(AF_INET, (void *)&sin->sin_addr.s_addr, srchost, sizeof(srchost));
sin = (struct sockaddr_in *) &hdr.dst; sin = (struct sockaddr_in *) &hdr.dst;
inet_ntop(AF_INET, &sin->sin_addr.s_addr, dsthost, sizeof(dsthost)); inet_ntop(AF_INET, (void *)&sin->sin_addr.s_addr, dsthost, sizeof(dsthost));
/* Compute fragment offset and check if flags are set */ /* Compute fragment offset and check if flags are set */
frag_off = 8 * (ntohs(ip->ip_off) & 8191) /* 2^13 - 1 */; frag_off = 8 * (ntohs(ip->ip_off) & 8191) /* 2^13 - 1 */;
@@ -2348,9 +2348,9 @@ const char *ippackethdrinfo(const u8 *packet, u32 len, int detail) {
/* Obtain IP source and destination info */ /* Obtain IP source and destination info */
sin6 = (struct sockaddr_in6 *) &hdr.src; sin6 = (struct sockaddr_in6 *) &hdr.src;
inet_ntop(AF_INET6, sin6->sin6_addr.s6_addr, srchost, sizeof(srchost)); inet_ntop(AF_INET6, (void *)sin6->sin6_addr.s6_addr, srchost, sizeof(srchost));
sin6 = (struct sockaddr_in6 *) &hdr.dst; sin6 = (struct sockaddr_in6 *) &hdr.dst;
inet_ntop(AF_INET6, sin6->sin6_addr.s6_addr, dsthost, sizeof(dsthost)); inet_ntop(AF_INET6, (void *)sin6->sin6_addr.s6_addr, dsthost, sizeof(dsthost));
/* Obtain flow label and traffic class */ /* Obtain flow label and traffic class */
u32 flow = ntohl(ip6->ip6_flow); u32 flow = ntohl(ip6->ip6_flow);

View File

@@ -22,6 +22,8 @@
#include "nbase.h" #include "nbase.h"
#ifndef HAVE_INET_NTOP
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
@@ -249,3 +251,5 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
return (dst); return (dst);
} }
#endif #endif
#endif /* ifndef HAVE_INET_NTOP */

View File

@@ -22,6 +22,8 @@
#include "nbase.h" #include "nbase.h"
#ifndef HAVE_INET_PTON
#if HAVE_SYS_TYPES_H #if HAVE_SYS_TYPES_H
#include <sys/types.h> #include <sys/types.h>
#endif #endif
@@ -243,3 +245,5 @@ inet_pton6(const char *src, unsigned char *dst)
return (1); return (1);
} }
#endif #endif
#endif /* ifndef HAVE_INET_PTON */

View File

@@ -152,6 +152,12 @@
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
/* #define HAVE_INTTYPES_H */ /* #define HAVE_INTTYPES_H */
/* These functions are available on Vista and later */
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= _WIN32_WINNT_WIN6
#define HAVE_INET_PTON 1
#define HAVE_INET_NTOP 1
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
/* <wspiapi.h> only comes with Visual Studio. */ /* <wspiapi.h> only comes with Visual Studio. */
#define HAVE_WSPIAPI_H 1 #define HAVE_WSPIAPI_H 1

View File

@@ -235,11 +235,11 @@ void PacketTrace::traceArp(pdirection pdir, const u8 *frame, u32 len,
} }
if (frame[7] == 1) { /* arp REQUEST */ if (frame[7] == 1) { /* arp REQUEST */
inet_ntop(AF_INET, frame + 24, who_has, sizeof(who_has)); inet_ntop(AF_INET, (void *)(frame + 24), who_has, sizeof(who_has));
inet_ntop(AF_INET, frame + 14, tell, sizeof(tell)); inet_ntop(AF_INET, (void *)(frame + 14), tell, sizeof(tell));
Snprintf(arpdesc, sizeof(arpdesc), "who-has %s tell %s", who_has, tell); Snprintf(arpdesc, sizeof(arpdesc), "who-has %s tell %s", who_has, tell);
} else { /* ARP REPLY */ } else { /* ARP REPLY */
inet_ntop(AF_INET, frame + 14, who_has, sizeof(who_has)); inet_ntop(AF_INET, (void *)(frame + 14), who_has, sizeof(who_has));
Snprintf(arpdesc, sizeof(arpdesc), Snprintf(arpdesc, sizeof(arpdesc),
"reply %s is-at %02X:%02X:%02X:%02X:%02X:%02X", who_has, "reply %s is-at %02X:%02X:%02X:%02X:%02X:%02X", who_has,
frame[8], frame[9], frame[10], frame[11], frame[12], frame[8], frame[9], frame[10], frame[11], frame[12],