commit f4067f882008c1204974b15f8deb44ffc41523fe
parent 31abb1aea1e53b2b0066cbf3a53ff5e24569222d
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date: Sun, 14 Jun 2020 16:55:00 +1000
Remove portability parts for initial build.
Also makes privdropping a no-op to get it building now, wil re-enable
later.
Diffstat:
10 files changed, 23 insertions(+), 1097 deletions(-)
diff --git a/ngrep.c b/ngrep.c
@@ -5,114 +5,45 @@
* Please refer to the LICENSE file for more information.
*
*/
-
-#if defined(BSD) || defined(SOLARIS) || defined(MACOSX)
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <net/if.h>
-#include <arpa/inet.h>
#include <sys/tty.h>
-#include <pwd.h>
-#endif
-
-#if defined(OSF1)
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <net/route.h>
-#include <sys/mbuf.h>
-#include <arpa/inet.h>
-#include <unistd>
-#include <pwd.h>
-#endif
-#if defined(LINUX) || defined(__GLIBC__) || defined(__GNU__)
-#include <getopt.h>
-#include <arpa/inet.h>
-#include <ctype.h>
-#include <time.h>
-#include <unistd.h>
-#include <pwd.h>
-#include <grp.h>
-#endif
-
-#if defined(AIX)
-#include <sys/machine.h>
-#include <sys/types.h>
+#include <net/if.h>
#include <netinet/in.h>
-#include <time.h>
-#include <unistd.h>
-#include <pwd.h>
-#endif
-
-#if defined(_WIN32)
-#include <io.h>
-#include <getopt.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <types.h>
-#include <config.h>
-
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-
-#else
-
+#include <net/ethertypes.h>
+#include <netinet/icmp6.h>
+#include <netinet/igmp.h>
+#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
-#include <netinet/ip_icmp.h>
-#include <netinet/igmp.h>
-
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <locale.h>
+#include <arpa/inet.h>
-#if !defined(_WIN32)
+#include <ctype.h>
#include <errno.h>
-#include <sys/ioctl.h>
-#endif
-
+#include <locale.h>
#include <pcap.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#if USE_IPv6 && !defined(_WIN32)
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-#endif
-
-#if USE_PCRE
+#include <pwd.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <pcre.h>
-#else
-#include <regex.h>
-#endif
#include "ngrep.h"
-
/*
* Configuration Options
*/
-
uint32_t snaplen = 65535, limitlen = 65535, promisc = 1, to = 100;
uint32_t match_after = 0, keep_matching = 0, matches = 0, max_matches = 0;
uint32_t seen_frames = 0;
-#if USE_TCPKILL
-uint32_t tcpkill_active = 0;
-#endif
-
uint8_t re_match_word = 0, re_ignore_case = 0, re_multiline_match = 1;
uint8_t show_empty = 0, show_hex = 0, show_proto = 0, quiet = 0;
uint8_t invert_match = 0, bin_match = 0;
@@ -129,17 +60,11 @@ char nonprint_char = '.';
* GNU Regex/PCRE
*/
-#if USE_PCRE
int32_t err_offset;
char *re_err = NULL;
pcre *pattern = NULL;
pcre_extra *pattern_extra = NULL;
-#else
-const char *re_err = NULL;
-
-struct re_pattern_buffer pattern;
-#endif
/*
* Matching
@@ -160,7 +85,7 @@ char *filter = NULL, *filter_file = NULL;
char pc_err[PCAP_ERRBUF_SIZE];
uint8_t link_offset;
uint8_t radiotap_present = 0;
-uint8_t include_vlan = USE_VLAN_HACK;
+uint8_t include_vlan = 1;
pcap_t *pd = NULL, *pd_dumppcap = NULL;
pcap_dumper_t *pd_dump = NULL;
@@ -172,12 +97,6 @@ struct in_addr net, mask;
*/
struct timeval prev_ts = {0, 0}, prev_delay_ts = {0,0};
-#if defined(_WIN32)
-struct timeval delay_tv;
-FD_SET delay_fds;
-SOCKET delay_socket = 0;
-#endif
-
void (*print_time)() = NULL, (*dump_delay)() = dump_delay_proc_init;
@@ -193,16 +112,12 @@ int main(int argc, char **argv) {
signal(SIGINT, clean_exit);
signal(SIGABRT, clean_exit);
-
-#if !defined(_WIN32)
signal(SIGQUIT, clean_exit);
signal(SIGPIPE, clean_exit);
signal(SIGWINCH, update_windowsize);
-#endif
setlocale(LC_ALL, "");
-#if !defined(_WIN32)
{
char const *locale = getenv("LANG");
if (locale == NULL)
@@ -210,9 +125,8 @@ int main(int argc, char **argv) {
setlocale(LC_CTYPE, locale);
}
-#endif
- while ((c = getopt(argc, argv, "LNhXViwqpevxlDtTRMK:Cs:n:c:d:A:I:O:S:P:F:W:")) != EOF) {
+ while ((c = getopt(argc, argv, "NhXViwqpevxlDtTRMCs:n:c:d:A:I:O:S:P:F:W:")) != EOF) {
switch (c) {
case 'W': {
if (!strcasecmp(optarg, "normal"))
@@ -229,7 +143,6 @@ int main(int argc, char **argv) {
usage();
}
} break;
-
case 'F':
filter_file = optarg;
break;
@@ -251,24 +164,9 @@ int main(int argc, char **argv) {
if (match_after < UINT32_MAX)
match_after++;
break;
-#if defined(_WIN32)
- case 'L':
- win32_listdevices();
- clean_exit(2);
- case 'd':
- usedev = win32_usedevice(optarg);
- break;
-#else
- case 'L':
- perror("-L is a Win32-only option");
- clean_exit(2);
case 'd':
usedev = optarg;
- /* Linux: any = DLT_LINUX_SLL, pcap says incompatible with VLAN */
- if (!strncasecmp(usedev, "any", 3))
- include_vlan = 0;
break;
-#endif
case 'c':
ws_col_forced = atoi(optarg);
break;
@@ -295,12 +193,7 @@ int main(int argc, char **argv) {
memset(&prev_ts, 0, sizeof(prev_ts));
} else {
print_time = &print_time_diff;
-#if defined(_WIN32)
- prev_ts.tv_sec = (uint32_t)time(NULL);
- prev_ts.tv_usec = 0;
-#else
gettimeofday(&prev_ts, NULL);
-#endif
}
break;
case 't':
@@ -341,11 +234,6 @@ int main(int argc, char **argv) {
case 'N':
show_proto++;
break;
-#if USE_TCPKILL
- case 'K':
- tcpkill_active = _atoui32(optarg);
- break;
-#endif
case 'h':
usage();
default:
@@ -361,11 +249,6 @@ int main(int argc, char **argv) {
if (argv[optind])
match_data = argv[optind++];
-#if USE_TCPKILL
- if (tcpkill_active)
- tcpkill_init();
-#endif
-
/* Setup PCAP input */
if (setup_pcap_source())
@@ -414,13 +297,7 @@ int main(int argc, char **argv) {
update_windowsize(0);
-#if defined(_WIN32)
- win32_initwinsock();
-#endif
-
-#if !defined(_WIN32) && USE_DROPPRIVS
drop_privs();
-#endif
while (pcap_loop(pd, -1, (pcap_handler)process, 0));
@@ -443,12 +320,7 @@ int setup_pcap_source(void) {
} else {
- char *dev = usedev ? usedev :
-#if defined(_WIN32)
- win32_choosedevice();
-#else
- pcap_lookupdev(pc_err);
-#endif
+ char *dev = usedev ? usedev : pcap_lookupdev(pc_err);
if (!dev) {
perror(pc_err);
@@ -496,51 +368,21 @@ int setup_pcap_source(void) {
case DLT_PPP:
link_offset = PPPHDR_SIZE;
break;
-
-#if HAVE_DLT_LOOP
case DLT_LOOP:
-#endif
case DLT_NULL:
link_offset = LOOPHDR_SIZE;
break;
-
-#if HAVE_DLT_RAW
case DLT_RAW:
link_offset = RAWHDR_SIZE;
break;
-#endif
-
-#if HAVE_DLT_LINUX_SLL
- case DLT_LINUX_SLL:
- link_offset = ISDNHDR_SIZE;
- include_vlan = 0;
- break;
-#endif
-
-#if HAVE_DLT_IEEE802_11_RADIO
case DLT_IEEE802_11_RADIO:
radiotap_present = 1;
-#endif
-
-#if HAVE_DLT_IEEE802_11
case DLT_IEEE802_11:
link_offset = IEEE80211HDR_SIZE;
break;
-#endif
-
-#if HAVE_DLT_PFLOG
case DLT_PFLOG:
link_offset = PFLOGHDR_SIZE;
break;
-#endif
-
-#if HAVE_DLT_IPNET
- case DLT_IPNET:
- link_offset = IPNETHDR_SIZE;
- include_vlan = 0;
- break;
-#endif
-
default:
fprintf(stderr, "fatal: unsupported interface type %u\n", pcap_datalink(pd));
return 1;
@@ -573,10 +415,6 @@ int setup_bpf_filter(char **argv) {
free(filter);
filter = get_filter_from_argv(&argv[optind-1]);
-#if USE_PCAP_RESTART
- PCAP_RESTART_FUNC();
-#endif
-
if (pcap_compile(pd, &pcapfilter, filter, 0, mask.s_addr))
return 1;
@@ -632,7 +470,6 @@ int setup_matcher(void) {
} else {
-#if USE_PCRE
uint32_t pcre_options = PCRE_UNGREEDY;
if (re_ignore_case)
@@ -640,33 +477,6 @@ int setup_matcher(void) {
if (re_multiline_match)
pcre_options |= PCRE_DOTALL;
-#else
- re_syntax_options = RE_CHAR_CLASSES | RE_NO_BK_PARENS | RE_NO_BK_VBAR |
- RE_CONTEXT_INDEP_ANCHORS | RE_CONTEXT_INDEP_OPS;
-
- if (re_multiline_match)
- re_syntax_options |= RE_DOT_NEWLINE;
-
- if (re_ignore_case) {
- uint32_t i;
- char *s;
-
- pattern.translate = (char*)malloc(256);
- s = pattern.translate;
-
- for (i = 0; i < 256; i++)
- s[i] = i;
- for (i = 'A'; i <= 'Z'; i++)
- s[i] = i + 32;
-
- s = match_data;
- while (*s) {
- *s = tolower(*s);
- s++;
- }
-
- } else pattern.translate = NULL;
-#endif
if (re_match_word) {
char *word_regex = (char*)malloc(strlen(match_data) * 3 + strlen(WORD_REGEX));
@@ -674,7 +484,6 @@ int setup_matcher(void) {
match_data = word_regex;
}
-#if USE_PCRE
pattern = pcre_compile(match_data, pcre_options, (const char **)&re_err, &err_offset, 0);
if (!pattern) {
@@ -683,20 +492,6 @@ int setup_matcher(void) {
}
pattern_extra = pcre_study(pattern, 0, (const char **)&re_err);
-#else
- re_err = re_compile_pattern(match_data, strlen(match_data), &pattern);
- if (re_err) {
- fprintf(stderr, "regex compile: %s\n", re_err);
- return 1;
- }
-
- pattern.fastmap = (char*)malloc(256);
- if (re_compile_fastmap(&pattern)) {
- perror("fastmap compile failed");
- return 1;
- }
-#endif
-
match_func = &re_match_func;
}
@@ -723,9 +518,7 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
uint8_t vlan_offset = include_vlan ? vlan_frame_count(p, h->caplen) * VLANHDR_SIZE : 0;
struct ip *ip4_pkt = (struct ip *) (p + link_offset + vlan_offset);
-#if USE_IPv6
struct ip6_hdr *ip6_pkt = (struct ip6_hdr*)(p + link_offset + vlan_offset);
-#endif
uint32_t ip_ver;
@@ -745,25 +538,18 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
seen_frames++;
-#if HAVE_DLT_IEEE802_11_RADIO
if (radiotap_present) {
uint16_t radio_len = ((struct NGREP_rtaphdr_t *)(p))->it_len;
ip4_pkt = (struct ip *)(p + link_offset + radio_len);
len -= radio_len;
}
-#endif
ip_ver = ip4_pkt->ip_v;
switch (ip_ver) {
case 4: {
-#if defined(AIX)
-#undef ip_hl
- ip_hl = ip4_pkt->ip_ff.ip_fhl * 4;
-#else
ip_hl = ip4_pkt->ip_hl * 4;
-#endif
ip_proto = ip4_pkt->ip_p;
ip_off = ntohs(ip4_pkt->ip_off);
@@ -774,8 +560,6 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
inet_ntop(AF_INET, (const void *)&ip4_pkt->ip_src, ip_src, sizeof(ip_src));
inet_ntop(AF_INET, (const void *)&ip4_pkt->ip_dst, ip_dst, sizeof(ip_dst));
} break;
-
-#if USE_IPv6
case 6: {
ip_hl = sizeof(struct ip6_hdr);
ip_proto = ip6_pkt->ip6_nxt;
@@ -795,7 +579,6 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
inet_ntop(AF_INET6, (const void *)&ip6_pkt->ip6_src, ip_src, sizeof(ip_src));
inet_ntop(AF_INET6, (const void *)&ip6_pkt->ip6_dst, ip_dst, sizeof(ip_dst));
} break;
-#endif
}
if (quiet < 1) {
@@ -848,8 +631,6 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
ip_src, ip_dst, icmp4_pkt->icmp_type, icmp4_pkt->icmp_code, 0,
icmp4hdr_offset, fragmented, frag_offset, frag_id);
} break;
-
-#if USE_IPv6
case IPPROTO_ICMPV6: {
struct icmp6_hdr *icmp6_pkt = (struct icmp6_hdr *)((unsigned char *)(ip6_pkt) + ip_hl);
uint16_t icmp6hdr_offset = (frag_offset) ? 0 : 4;
@@ -864,8 +645,6 @@ void process(u_char *d, struct pcap_pkthdr *h, u_char *p) {
ip_src, ip_dst, icmp6_pkt->icmp6_type, icmp6_pkt->icmp6_code, 0,
icmp6hdr_offset, fragmented, frag_offset, frag_id);
} break;
-#endif
-
case IPPROTO_IGMP: {
struct igmp *igmp_pkt = (struct igmp *)((unsigned char *)(ip4_pkt) + ip_hl);
uint16_t igmphdr_offset = (frag_offset) ? 0 : 4;
@@ -983,16 +762,9 @@ void dump_packet(struct pcap_pkthdr *h, u_char *p, uint8_t proto, unsigned char
if (pd_dump)
pcap_dump((u_char*)pd_dump, h, p);
-
-#if USE_TCPKILL
- if (tcpkill_active)
- tcpkill_kill(h, p, link_offset, tcpkill_active);
-#endif
}
int8_t re_match_func(unsigned char *data, uint32_t len, uint16_t *mindex, uint16_t *msize) {
-#if USE_PCRE
-
static int sub[2];
switch(pcre_exec(pattern, 0, (char const *)data, (int32_t)len, 0, 0, 0, 0)) {
case PCRE_ERROR_NULL:
@@ -1010,23 +782,6 @@ int8_t re_match_func(unsigned char *data, uint32_t len, uint16_t *mindex, uint16
*mindex = sub[0];
*msize = sub[1] - sub[0];
}
-#else
-
- static struct re_registers regs;
- switch (re_search(&pattern, (char const *)data, (int32_t)len, 0, len, ®s)) {
- case -2:
- perror("she's dead, jim\n");
- clean_exit(2);
-
- case -1:
- return 0;
-
- default:
- *mindex = regs.start[0];
- *msize = regs.end[0] - regs.start[0];
- }
-#endif
-
matches++;
if (match_after && keep_matching != match_after)
@@ -1308,32 +1063,8 @@ void dump_delay_proc(struct pcap_pkthdr *h) {
usecs = 1000000 - (prev_delay_ts.tv_usec - h->ts.tv_usec);
}
-#ifdef _WIN32
- {
- // grevious hack, yes, but windows sucks. sorry. :( --jordan
- if ((delay_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
- perror("delay socket creation failed, disabling -D");
- Sleep(3000); // give them time to read the message
- want_delay = 0;
- return;
- }
-
- FD_ZERO(&delay_fds);
- FD_SET(delay_socket, &delay_fds);
-
- delay_tv.tv_sec = secs;
- delay_tv.tv_usec = usecs;
-
- if (select(0, &delay_fds, 0, 0, &delay_tv) == -1)
- fprintf(stderr, "WSAGetLastError = %u\n", WSAGetLastError());
-
- closesocket(delay_socket);
- delay_socket = 0; // in case someone ^C's out of me
- }
-#else
sleep(secs);
usleep(usecs);
-#endif
prev_delay_ts.tv_sec = h->ts.tv_sec;
prev_delay_ts.tv_usec = h->ts.tv_usec;
@@ -1345,21 +1076,12 @@ void update_windowsize(int32_t e) {
ws_col = ws_col_forced;
else if (!ws_col_forced) {
-
-#if !defined(_WIN32)
const struct winsize ws;
if (!ioctl(0, TIOCGWINSZ, &ws)) {
ws_row = ws.ws_row;
ws_col = ws.ws_col;
}
-#else
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
- ws_row = csbi.dwSize.Y;
- ws_col = csbi.dwSize.X;
- }
-#endif
else {
ws_row = 24;
ws_col = 80;
@@ -1368,8 +1090,8 @@ void update_windowsize(int32_t e) {
}
}
-#if !defined(_WIN32) && USE_DROPPRIVS
void drop_privs(void) {
+#if 0
struct passwd *pw;
uid_t newuid;
gid_t newgid;
@@ -1377,7 +1099,7 @@ void drop_privs(void) {
if ((getuid() || geteuid()) || dont_dropprivs)
return;
- pw = getpwnam(DROPPRIVS_USER);
+ pw = getpwnam("_ngrep");
if (!pw) {
perror("attempt to drop privileges failed: getpwnam failed");
clean_exit(2);
@@ -1400,21 +1122,14 @@ void drop_privs(void) {
perror("attempt to drop privileges failed");
clean_exit(2);
}
-}
-
#endif
+}
void usage(void) {
printf("usage: ngrep <-"
-#if defined(_WIN32)
- "L"
-#endif
"hNXViwqpevxlDtTRM> <-IO pcap_dump> <-n num> <-d dev> <-A num>\n"
" <-s snaplen> <-S limitlen> <-W normal|byline|single|none> <-c cols>\n"
" <-P char> <-F file>"
-#if USE_TCPKILL
- " <-K count>"
-#endif
"\n"
" <match expression> <bpf filter>\n"
" -h is help/usage\n"
@@ -1445,15 +1160,7 @@ void usage(void) {
" -P is set the non-printable display char to what is specified\n"
" -F is read the bpf filter from the specified file\n"
" -N is show sub protocol number\n"
-#if defined(_WIN32)
- " -d is use specified device (index) instead of the pcap default\n"
- " -L is show the winpcap device list index\n"
-#else
" -d is use specified device instead of the pcap default\n"
-#endif
-#if USE_TCPKILL
- " -K is send N packets to kill observed connections\n"
-#endif
"");
exit(2);
@@ -1471,23 +1178,15 @@ void clean_exit(int32_t sig) {
signal(SIGINT, SIG_IGN);
signal(SIGABRT, SIG_IGN);
-#if !defined(_WIN32)
signal(SIGQUIT, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
signal(SIGWINCH, SIG_IGN);
-#endif
if (quiet < 1 && sig >= 0)
printf("exit\n");
-#if USE_PCRE
if (pattern) pcre_free(pattern);
if (pattern_extra) pcre_free(pattern_extra);
-#else
- if (pattern.translate) free(pattern.translate);
- if (pattern.fastmap) free(pattern.fastmap);
-#endif
-
if (bin_data) free(bin_data);
/* We used to report pcap_stats; but PCAP manpage says pcap_stats "may or
@@ -1500,113 +1199,5 @@ void clean_exit(int32_t sig) {
if (pd_dumppcap) pcap_close(pd_dumppcap);
if (pd_dump) pcap_dump_close(pd_dump);
-#if defined(_WIN32)
- if (delay_socket) closesocket(delay_socket);
- if (want_delay) WSACleanup();
- if (usedev) free(usedev);
-#endif
-
exit(matches ? 0 : 1);
}
-
-#if defined(_WIN32)
-int8_t win32_initwinsock(void) {
- WORD wVersionRequested = MAKEWORD(2, 0);
- WSADATA wsaData;
-
- if (WSAStartup(wVersionRequested, &wsaData)) {
- perror("unable to initialize winsock");
- return 0;
- }
-
- // we want at least major version 2
- if (LOBYTE(wsaData.wVersion) < 2) {
- fprintf(stderr, "unable to find winsock 2.0 or greater (found %u.%u)\n",
- LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
- WSACleanup();
- return 0;
- }
-
- return 1;
-}
-
-void win32_listdevices(void) {
- uint32_t i = 0;
- pcap_if_t *alldevs, *d;
- char errbuf[PCAP_ERRBUF_SIZE];
-
- if (pcap_findalldevs(&alldevs, errbuf) == -1) {
- perror("unable to enumerate device list");
- clean_exit(2);
- }
-
- printf("idx\tdev\n");
- printf("---\t---\n");
-
- for (d = alldevs; d != NULL; d = d->next) {
- printf("%2u:\t%s", ++i, d->name);
-
- if (d->description)
- printf(" (%s)\n", d->description);
- }
-
- pcap_freealldevs(alldevs);
-}
-
-char *win32_usedevice(const char *index) {
- int32_t idx = atoi(index), i = 0;
- pcap_if_t *alldevs, *d;
- char errbuf[PCAP_ERRBUF_SIZE];
- char *dev = NULL;
-
- if (idx <= 0) {
- perror("invalid device index");
- clean_exit(2);
- }
-
- if (pcap_findalldevs(&alldevs, errbuf) == -1) {
- perror("unable to enumerate devices");
- clean_exit(2);
- }
-
- for (d = alldevs; d != NULL && i != idx; d = d->next)
- if (++i == idx)
- dev = _strdup(d->name);
-
- if (i <= 0) {
- perror("no known devices");
- clean_exit(2);
- }
-
- if (i != idx) {
- perror("unknown device specified");
- clean_exit(2);
- }
-
- pcap_freealldevs(alldevs);
-
- return dev;
-}
-
-char *win32_choosedevice(void) {
- pcap_if_t *alldevs, *d;
- char errbuf[PCAP_ERRBUF_SIZE];
- char *dev = NULL;
-
- if (pcap_findalldevs(&alldevs, errbuf) == -1) {
- perror("unable to enumerate devices");
- clean_exit(2);
- }
-
- for (d = alldevs; d != NULL; d = d->next)
- if ((d->addresses) && (d->addresses->addr))
- dev = _strdup(d->name);
-
- pcap_freealldevs(alldevs);
-
- if (!dev)
- dev = pcap_lookupdev(errbuf);
-
- return dev;
-}
-#endif
diff --git a/ngrep.h b/ngrep.h
@@ -26,13 +26,6 @@
#define VLANHDR_SIZE 4
#define IPNETHDR_SIZE 24
-#ifndef ETHERTYPE_IP
-#define ETHERTYPE_IP 0x0800
-#endif
-#ifndef ETHERTYPE_IPV6
-#define ETHERTYPE_IPV6 0x86dd
-#endif
-
#define EXTRACT_16BITS(p) \
((uint16_t)((uint16_t)*((const uint8_t *)(p) + 0) << 8 | \
(uint16_t)*((const uint8_t *)(p) + 1)))
@@ -62,11 +55,7 @@
* decoder.
*/
-#if USE_IPv6
#define BPF_FILTER_IP_TYPE "(ip || ip6)"
-#else
-#define BPF_FILTER_IP_TYPE "(ip)"
-#endif
#define BPF_TEMPLATE_IP BPF_FILTER_IP_TYPE
#define BPF_TEMPLATE_IP_VLAN "(" BPF_FILTER_IP_TYPE " || (vlan && " BPF_FILTER_IP_TYPE "))"
@@ -76,31 +65,8 @@
#define WORD_REGEX "((^%s\\W)|(\\W%s$)|(\\W%s\\W))"
/*
- * For retarded operating systems like Solaris that don't have this,
- * when everyone else does. Good job, Sun!
- */
-
-#ifndef IP_OFFMASK
-#define IP_OFFMASK 0x1fff
-#endif
-
-/*
- * "Newer" flags that older operating systems don't yet recognize.
- */
-
-#ifndef TH_ECE
-#define TH_ECE 0x40
-#endif
-
-#ifndef TH_CWR
-#define TH_CWR 0x80
-#endif
-
-
-/*
* Single-char packet "ident" flags.
*/
-
typedef enum {
TCP = 'T', UDP = 'U', ICMP = 'I', ICMPv6 = 'I', IGMP = 'G', UNKNOWN = '?'
} netident_t;
@@ -108,7 +74,6 @@ typedef enum {
/*
* Prototypes function signatures.
*/
-
int setup_pcap_source(void);
int setup_bpf_filter(char **);
int setup_matcher(void);
@@ -144,17 +109,7 @@ char *get_filter_from_argv (char **);
uint8_t strishex(char *);
-#if !defined(_WIN32)
void drop_privs(void);
-#endif
-
-#if defined(_WIN32)
-int8_t win32_initwinsock(void);
-void win32_listdevices(void);
-char *win32_usedevice(const char *);
-char *win32_choosedevice(void);
-#endif
-
struct NGREP_rtaphdr_t {
uint8_t it_version;
diff --git a/win32/.gitignore b/win32/.gitignore
@@ -1,6 +0,0 @@
-*.sdf
-*.opensdf
-*.suo
-*.vcxproj.*
-Debug/
-Release/
diff --git a/win32/ngrep.sln b/win32/ngrep.sln
@@ -1,19 +0,0 @@
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ngrep", "ngrep.vcxproj", "{CC0C01CE-0AC3-4F93-9DC8-792862344DBA}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Win32 = Debug|Win32
- Release|Win32 = Release|Win32
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {CC0C01CE-0AC3-4F93-9DC8-792862344DBA}.Debug|Win32.ActiveCfg = Debug|Win32
- {CC0C01CE-0AC3-4F93-9DC8-792862344DBA}.Debug|Win32.Build.0 = Debug|Win32
- {CC0C01CE-0AC3-4F93-9DC8-792862344DBA}.Release|Win32.ActiveCfg = Release|Win32
- {CC0C01CE-0AC3-4F93-9DC8-792862344DBA}.Release|Win32.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/win32/ngrep.vcproj b/win32/ngrep.vcproj
@@ -1,168 +0,0 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="7.00"
- Name="ngrep"
- ProjectGUID="{CC0C01CE-0AC3-4F93-9DC8-792862344DBA}"
- Keyword="Win32Proj">
- <Platforms>
- <Platform
- Name="Win32"/>
- </Platforms>
- <Configurations>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="Debug"
- IntermediateDirectory="Debug"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- AdditionalIncludeDirectories="support;..\..\WpdPack\include"
- PreprocessorDefinitions="STDC_HEADERS;WPCAP"
- MinimalRebuild="TRUE"
- BasicRuntimeChecks="3"
- RuntimeLibrary="5"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="4"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="wsock32.lib wpcap.lib"
- OutputFile="$(OutDir)/ngrep.exe"
- LinkIncremental="2"
- AdditionalLibraryDirectories="..\..\WpdPack\Lib"
- GenerateDebugInformation="TRUE"
- ProgramDatabaseFile="$(OutDir)/ngrep.pdb"
- SubSystem="1"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="Release"
- IntermediateDirectory="Release"
- ConfigurationType="1"
- CharacterSet="2">
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- OmitFramePointers="TRUE"
- AdditionalIncludeDirectories="support;..\..\WpdPack\include"
- PreprocessorDefinitions="STDC_HEADERS;WPCAP"
- StringPooling="TRUE"
- RuntimeLibrary="4"
- EnableFunctionLevelLinking="TRUE"
- UsePrecompiledHeader="0"
- WarningLevel="3"
- Detect64BitPortabilityProblems="TRUE"
- DebugInformationFormat="3"/>
- <Tool
- Name="VCCustomBuildTool"/>
- <Tool
- Name="VCLinkerTool"
- AdditionalDependencies="wsock32.lib wpcap.lib"
- OutputFile="$(OutDir)/ngrep.exe"
- LinkIncremental="1"
- AdditionalLibraryDirectories="..\..\WpdPack\Lib"
- GenerateDebugInformation="TRUE"
- SubSystem="1"
- OptimizeReferences="2"
- EnableCOMDATFolding="2"
- TargetMachine="1"/>
- <Tool
- Name="VCMIDLTool"/>
- <Tool
- Name="VCPostBuildEventTool"/>
- <Tool
- Name="VCPreBuildEventTool"/>
- <Tool
- Name="VCPreLinkEventTool"/>
- <Tool
- Name="VCResourceCompilerTool"/>
- <Tool
- Name="VCWebServiceProxyGeneratorTool"/>
- <Tool
- Name="VCWebDeploymentTool"/>
- </Configuration>
- </Configurations>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
- <File
- RelativePath="support\getopt.c">
- </File>
- <File
- RelativePath="support\inet_ntop.c">
- </File>
- <File
- RelativePath="..\ngrep.c">
- </File>
- <File
- RelativePath="..\regex-0.12\regex.c">
- <FileConfiguration
- Name="Debug|Win32">
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions="REGEX_MALLOC"/>
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32">
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions="REGEX_MALLOC"/>
- </FileConfiguration>
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl;inc">
- <File
- RelativePath="support\config.h">
- </File>
- <File
- RelativePath="support\getopt.h">
- </File>
- <File
- RelativePath="support\inet_ntop.h">
- </File>
- <File
- RelativePath="..\ngrep.h">
- </File>
- <File
- RelativePath="..\..\WpdPack\Include\pcap.h">
- </File>
- <File
- RelativePath="..\regex-0.12\regex.h">
- </File>
- <File
- RelativePath="support\types.h">
- </File>
- </Filter>
- <Filter
- Name="Resource Files"
- Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/win32/ngrep.vcxproj b/win32/ngrep.vcxproj
@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{CC0C01CE-0AC3-4F93-9DC8-792862344DBA}</ProjectGuid>
- <Keyword>Win32Proj</Keyword>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <PlatformToolset>v110</PlatformToolset>
- <CharacterSet>MultiByte</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
- <PlatformToolset>v110</PlatformToolset>
- <CharacterSet>MultiByte</CharacterSet>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup>
- <_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <OutDir>Debug\</OutDir>
- <IntDir>Debug\</IntDir>
- <LinkIncremental>true</LinkIncremental>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <OutDir>Release\</OutDir>
- <IntDir>Release\</IntDir>
- <LinkIncremental>false</LinkIncremental>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>support;..\regex-0.12;..\..\WpdPack\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>STDC_HEADERS;WPCAP;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MinimalRebuild>true</MinimalRebuild>
- <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
- <PrecompiledHeader />
- <WarningLevel>Level3</WarningLevel>
- <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
- </ClCompile>
- <Link>
- <AdditionalDependencies>ws2_32.lib;wpcap.lib;packet.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <OutputFile>$(OutDir)ngrep.exe</OutputFile>
- <AdditionalLibraryDirectories>..\..\WpdPack\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <ProgramDatabaseFile>$(OutDir)ngrep.pdb</ProgramDatabaseFile>
- <SubSystem>Console</SubSystem>
- <TargetMachine>MachineX86</TargetMachine>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <Optimization>MaxSpeed</Optimization>
- <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
- <OmitFramePointers>true</OmitFramePointers>
- <AdditionalIncludeDirectories>support;..\regex-0.12;..\..\WpdPack\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>STDC_HEADERS;_CRT_SECURE_NO_WARNINGS;WPCAP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <StringPooling>true</StringPooling>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <PrecompiledHeader />
- <WarningLevel>Level3</WarningLevel>
- <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
- </ClCompile>
- <Link>
- <AdditionalDependencies>ws2_32.lib;wpcap.lib;packet.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <OutputFile>$(OutDir)ngrep.exe</OutputFile>
- <AdditionalLibraryDirectories>..\..\WpdPack\Lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Console</SubSystem>
- <OptimizeReferences>true</OptimizeReferences>
- <EnableCOMDATFolding>true</EnableCOMDATFolding>
- <TargetMachine>MachineX86</TargetMachine>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ClCompile Include="support\getopt.c" />
- <ClCompile Include="..\ngrep.c" />
- <ClCompile Include="..\regex-0.12\regex.c">
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">REGEX_MALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">REGEX_MALLOC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="support\config.h" />
- <ClInclude Include="support\getopt.h" />
- <ClInclude Include="..\ngrep.h" />
- <ClInclude Include="..\..\WpdPack\Include\pcap.h" />
- <ClInclude Include="..\regex-0.12\regex.h" />
- <ClInclude Include="support\types.h" />
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>-
\ No newline at end of file
diff --git a/win32/support/config.h b/win32/support/config.h
@@ -1,21 +0,0 @@
-/*
- * Win32-specific version for manual manipulation.
- */
-
-#define USE_PCRE 0
-#define USE_IPv6 1
-
-#define HAVE_DLT_RAW 1
-#define HAVE_DLT_LOOP 1
-#define HAVE_DLT_LINUX_SLL 1
-#define HAVE_DLT_IEEE802_11 1
-#define HAVE_DLT_IEEE802_11_RADIO 1
-
-#define HAVE_DUMB_UDPHDR 0
-
-#define USE_PCAP_RESTART 0
-#define PCAP_RESTART_FUNC 0
-
-#define USE_DROPPRIVS 0
-#define DROPPRIVS_USER "notused"
-
diff --git a/win32/support/getopt.c b/win32/support/getopt.c
@@ -1,101 +0,0 @@
-
-#include <stdio.h> /* for EOF */
-#include <string.h> /* for strchr() */
-
-#include <getopt.h>
-
-/* static (global) variables that are specified as exported by getopt() */
-char *optarg = NULL; /* pointer to the start of the option argument */
-int optind = 1; /* number of the next argv[] to be evaluated */
-int opterr = 1; /* non-zero if a question mark should be returned
- when a non-valid option character is detected */
-
-int getopt(int argc, char *argv[], char *opstring) {
- static char *pIndexPosition = NULL; /* place inside current argv string */
- char *pArgString = NULL; /* where to start from next */
- char *pOptString; /* the string in our program */
-
- if (pIndexPosition != NULL) {
- /* we last left off inside an argv string */
- if (*(++pIndexPosition)) {
- /* there is more to come in the most recent argv */
- pArgString = pIndexPosition;
- }
- }
-
- if (pArgString == NULL) {
- /* we didn't leave off in the middle of an argv string */
- if (optind >= argc) {
- /* more command-line arguments than the argument count */
- pIndexPosition = NULL; /* not in the middle of anything */
- return EOF; /* used up all command-line arguments */
- }
-
- /*---------------------------------------------------------------------
- * If the next argv[] is not an option, there can be no more options.
- *-------------------------------------------------------------------*/
- pArgString = argv[optind++]; /* set this to the next argument ptr */
-
- if (('/' != *pArgString) && /* doesn't start with a slash or a dash? */
- ('-' != *pArgString)) {
- --optind; /* point to current arg once we're done */
- optarg = NULL; /* no argument follows the option */
- pIndexPosition = NULL; /* not in the middle of anything */
- return EOF; /* used up all the command-line flags */
- }
-
- /* check for special end-of-flags markers */
- if ((strcmp(pArgString, "-") == 0) ||
- (strcmp(pArgString, "--") == 0)) {
- optarg = NULL; /* no argument follows the option */
- pIndexPosition = NULL; /* not in the middle of anything */
- return EOF; /* encountered the special flag */
- }
-
- pArgString++; /* look past the / or - */
- }
-
- if (':' == *pArgString) { /* is it a colon? */
- /*---------------------------------------------------------------------
- * Rare case: if opterr is non-zero, return a question mark;
- * otherwise, just return the colon we're on.
- *-------------------------------------------------------------------*/
- return (opterr ? (int)'?' : (int)':');
- } else if ((pOptString = strchr(opstring, *pArgString)) == 0) {
- /*---------------------------------------------------------------------
- * The letter on the command-line wasn't any good.
- *-------------------------------------------------------------------*/
- optarg = NULL; /* no argument follows the option */
- pIndexPosition = NULL; /* not in the middle of anything */
- return (opterr ? (int)'?' : (int)*pArgString);
- } else {
- /*---------------------------------------------------------------------
- * The letter on the command-line matches one we expect to see
- *-------------------------------------------------------------------*/
- if (':' == _next_char(pOptString)) { /* is the next letter a colon? */
- /* It is a colon. Look for an argument string. */
- if ('\0' != _next_char(pArgString)) /* argument in this argv? */
- optarg = &pArgString[1]; /* Yes, it is */
- else {
- /*-------------------------------------------------------------
- * The argument string must be in the next argv.
- * But, what if there is none (bad input from the user)?
- * In that case, return the letter, and optarg as NULL.
- *-----------------------------------------------------------*/
- if (optind < argc)
- optarg = argv[optind++];
- else {
- optarg = NULL;
- return (opterr ? (int)'?' : (int)*pArgString);
- }
- }
-
- pIndexPosition = NULL; /* not in the middle of anything */
- } else {
- /* it's not a colon, so just return the letter */
- optarg = NULL; /* no argument follows the option */
- pIndexPosition = pArgString; /* point to the letter we're on */
- }
- return (int)*pArgString; /* return the letter that matched */
- }
-}
diff --git a/win32/support/getopt.h b/win32/support/getopt.h
@@ -1,8 +0,0 @@
-
-#define _next_char(string) (char)(*(string+1))
-
-extern char * optarg;
-extern int optind;
-
-int getopt(int, char**, char*);
-
diff --git a/win32/support/types.h b/win32/support/types.h
@@ -1,179 +0,0 @@
-/*
- * Because Windows standard headers are woefully inadequate for (real)
- * network application development, and because I'm basically lazy, I
- * created this header as a container for the types ngrep needs.
- *
- * These include standard types like u*int*_t's, as well as network
- * protocol-specific structures and types.
- */
-
-typedef unsigned char u_int8_t;
-typedef unsigned short int u_int16_t;
-typedef unsigned int u_int32_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-
-typedef signed char int8_t;
-typedef signed short int int16_t;
-typedef signed int int32_t;
-
-
-
-#define IP_RF 0x8000 /* reserved fragment flag */
-#define IP_DF 0x4000 /* dont fragment flag */
-#define IP_MF 0x2000 /* more fragments flag */
-#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
-
-struct ip {
- u_int8_t ip_hl:4; /* header length */
- u_int8_t ip_v:4; /* version */
- u_int8_t ip_tos; /* type of service */
- u_int16_t ip_len; /* total length */
- u_int16_t ip_id; /* identification */
- u_int16_t ip_off; /* fragment offset field */
- u_int8_t ip_ttl; /* time to live */
- u_int8_t ip_p; /* protocol */
- u_int16_t ip_sum; /* checksum */
- struct in_addr ip_src, ip_dst; /* source and dest address */
-};
-
-#define TH_FIN 0x01
-#define TH_SYN 0x02
-#define TH_RST 0x04
-#define TH_PUSH 0x08
-#define TH_ACK 0x10
-#define TH_URG 0x20
-
-typedef u_int32_t tcp_seq;
-
-struct tcphdr {
- u_int16_t th_sport; /* source port */
- u_int16_t th_dport; /* destination port */
- tcp_seq th_seq; /* sequence number */
- tcp_seq th_ack; /* acknowledgement number */
- u_int8_t th_x2:4; /* (unused) */
- u_int8_t th_off:4; /* data offset */
- u_int8_t th_flags;
- u_int16_t th_win; /* window */
- u_int16_t th_sum; /* checksum */
- u_int16_t th_urp; /* urgent pointer */
-};
-
-struct udphdr {
- u_int16_t uh_sport; /* source port */
- u_int16_t uh_dport; /* destination port */
- u_int16_t uh_ulen; /* udp length */
- u_int16_t uh_sum; /* udp checksum */
-};
-
-
-struct icmp {
- u_int8_t icmp_type;
- u_int8_t icmp_code;
- u_int16_t icmp_cksum;
-
- union {
- u_int8_t ih_pptr;
- struct in_addr ih_gwaddr;
- struct ih_idseq {
- u_int16_t icd_id;
- u_int16_t icd_seq;
- } ih_idseq;
- u_int32_t ih_void;
-
- struct ih_pmtu {
- u_int16_t ipm_void;
- u_int16_t ipm_nextmtu;
- } ih_pmtu;
-
- struct ih_rtradv {
- u_int8_t irt_num_addrs;
- u_int8_t irt_wpa;
- u_int16_t irt_lifetime;
- } ih_rtradv;
- } icmp_hun;
-};
-
-struct igmp {
- u_int8_t igmp_type; /* IGMP type */
- u_int8_t igmp_code; /* routing code */
- u_int16_t igmp_cksum; /* checksum */
- struct in_addr igmp_group; /* group address */
-};
-
-/*
- * Taken from arpa/namser.h, used by inet_?to?() (Win32 support).
- */
-
-#define NS_INADDRSZ 4
-#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */
-#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */
-
-/*
- * IPv6 and ICMPv6 declarations.
- */
-
-/* IPv6 address */
-struct UNIX_in6_addr {
- union {
- uint8_t u6_addr8[16];
- uint16_t u6_addr16[8];
- uint32_t u6_addr32[4];
- } in6_u;
-};
-
-struct ip6_hdr {
- union {
- struct ip6_hdrctl {
- uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC,
- 20 bits flow-ID */
- uint16_t ip6_un1_plen; /* payload length */
- uint8_t ip6_un1_nxt; /* next header */
- uint8_t ip6_un1_hlim; /* hop limit */
- } ip6_un1;
-
- uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits tclass */
-
- } ip6_ctlun;
-
- struct UNIX_in6_addr ip6_src; /* source address */
- struct UNIX_in6_addr ip6_dst; /* destination address */
-};
-
-#define ip6_vfc ip6_ctlun.ip6_un2_vfc
-#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
-#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
-#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
-#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
-#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
-
-/* Fragment header */
-struct ip6_frag {
- uint8_t ip6f_nxt; /* next header */
- uint8_t ip6f_reserved; /* reserved field */
- uint16_t ip6f_offlg; /* offset, reserved, and flag */
- uint32_t ip6f_ident; /* identification */
-};
-
-#if BYTE_ORDER == BIG_ENDIAN
-#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
-#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
-#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
-#else /* BYTE_ORDER == LITTLE_ENDIAN */
-#define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
-#define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
-#define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
-#endif
-
-struct icmp6_hdr {
- uint8_t icmp6_type; /* type field */
- uint8_t icmp6_code; /* code field */
- uint16_t icmp6_cksum; /* checksum field */
- union {
- uint32_t icmp6_un_data32[1]; /* type-specific field */
- uint16_t icmp6_un_data16[2]; /* type-specific field */
- uint8_t icmp6_un_data8[4]; /* type-specific field */
- } icmp6_dataun;
-};