From 1ead42b71fc7668ab53ab7e1948b3fb209e497d4 Mon Sep 17 00:00:00 2001 From: Brett Kuskie Date: Mon, 19 Apr 2021 09:44:42 -0600 Subject: [PATCH] Fix #13: multiple definition of variables --- src/nemesis-dns.c | 12 +++++++----- src/nemesis-dns.h | 2 +- src/nemesis-icmp.c | 25 ++++++++++++++----------- src/nemesis-icmp.h | 4 ++-- src/nemesis-ospf.c | 8 +++++--- src/nemesis-ospf.h | 2 +- src/nemesis-proto_dns.c | 10 +++++----- src/nemesis-proto_icmp.c | 6 +++--- 8 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/nemesis-dns.c b/src/nemesis-dns.c index 759c604..68bfac3 100644 --- a/src/nemesis-dns.c +++ b/src/nemesis-dns.c @@ -34,6 +34,8 @@ static void dns_usage(char *); static void dns_validatedata(void); static void dns_verbose(void); +int dns_state = 0; /* default to UDP */ + void nemesis_dns(int argc, char **argv) { const char *module = "DNS Packet Injection"; @@ -65,7 +67,7 @@ void nemesis_dns(int argc, char **argv) dns_verbose(); if (got_payload) { - if (state) { + if (dns_state) { #if defined(WIN32) if (builddatafromfile(DNSTCP_LINKBUFFSIZE, &pd, payloadfile, PAYLOADMODE) < 0) #else @@ -89,7 +91,7 @@ void nemesis_dns(int argc, char **argv) dns_exit(1); } - if (state && got_tcpoptions) { + if (dns_state && got_tcpoptions) { if (builddatafromfile(OPTIONSBUFFSIZE, &tcpod, tcpoptionsfile, OPTIONSMODE) < 0) dns_exit(1); } @@ -145,7 +147,7 @@ static void dns_initdata(void) static void dns_validatedata(void) { - if (state && tcphdr.th_flags == 0) + if (dns_state && tcphdr.th_flags == 0) tcphdr.th_flags |= TH_SYN; } @@ -301,7 +303,7 @@ static void dns_cmdline(int argc, char **argv) case 'k': /* use TCP */ iphdr.ip_tos = 0; iphdr.ip_p = IPPROTO_TCP; - state = 1; + dns_state = 1; break; case 'M': /* Ethernet destination address */ @@ -457,7 +459,7 @@ static void dns_verbose(void) nemesis_printip(&iphdr); - if (state) + if (dns_state) nemesis_printtcp(&tcphdr); else nemesis_printudp(&udphdr); diff --git a/src/nemesis-dns.h b/src/nemesis-dns.h index 117cdb2..8553e58 100644 --- a/src/nemesis-dns.h +++ b/src/nemesis-dns.h @@ -29,7 +29,7 @@ #include "nemesis.h" #include -int state; /* default to UDP */ +extern int dns_state; /* default to UDP */ int builddns(ETHERhdr *, IPhdr *, TCPhdr *, UDPhdr *, DNShdr *, struct file *, struct file *, struct file *, libnet_t *); diff --git a/src/nemesis-icmp.c b/src/nemesis-icmp.c index 3f6d95e..063387a 100644 --- a/src/nemesis-icmp.c +++ b/src/nemesis-icmp.c @@ -35,6 +35,9 @@ static void icmp_usage(char *); static void icmp_validatedata(void); static void icmp_verbose(void); +int icmp_mode; +int got_origoptions; + void nemesis_icmp(int argc, char **argv) { const char *module = "ICMP Packet Injection"; @@ -116,7 +119,7 @@ static void icmp_initdata(void) ipunreach.ip_ttl = 255; /* ICMP unreach IP TTL */ ipunreach.ip_p = 17; /* ICMP unreach IP protocol */ - mode = ICMP_ECHO; /* default to ICMP echo */ + icmp_mode = ICMP_ECHO; /* default to ICMP echo */ icmphdr.icmp_type = 0; /* ICMP type */ icmphdr.icmp_code = 0; /* ICMP code */ icmphdr.hun.echo.id = 0; /* ICMP ID */ @@ -142,12 +145,12 @@ static void icmp_validatedata(void) icmp_exit(1); } - if (got_origoptions && !(mode == ICMP_UNREACH || mode == ICMP_REDIRECT || mode == ICMP_TIMXCEED)) { + if (got_origoptions && !(icmp_mode == ICMP_UNREACH || icmp_mode == ICMP_REDIRECT || icmp_mode == ICMP_TIMXCEED)) { fprintf(stderr, "ERROR: -l is only valid with ICMP redirect, unreach or time exceeded injection.\n"); icmp_exit(1); } - if (pd.file_len == 0 && (mode == ICMP_UNREACH || mode == ICMP_REDIRECT || mode == ICMP_TIMXCEED)) { + if (pd.file_len == 0 && (icmp_mode == ICMP_UNREACH || icmp_mode == ICMP_REDIRECT || icmp_mode == ICMP_TIMXCEED)) { udphdr.uh_sport = libnet_get_prand(PRu16); udphdr.uh_dport = libnet_get_prand(PRu16); udphdr.uh_ulen = htons(20); @@ -161,7 +164,7 @@ static void icmp_validatedata(void) } /* Attempt to send valid packets if the user hasn't decided to craft an anomolous packet */ - switch (mode) { + switch (icmp_mode) { case ICMP_ECHO: /* send an echo request */ if (!got_type) icmphdr.icmp_type = ICMP_ECHO; @@ -445,32 +448,32 @@ static void icmp_cmdline(int argc, char **argv) } switch (cmd_mode) { case 'E': /* ICMP echo injection */ - mode = ICMP_ECHO; + icmp_mode = ICMP_ECHO; got_mode++; break; case 'M': /* ICMP mask injection */ - mode = ICMP_MASKREQ; + icmp_mode = ICMP_MASKREQ; got_mode++; break; case 'U': /* ICMP unreach injection */ - mode = ICMP_UNREACH; + icmp_mode = ICMP_UNREACH; got_mode++; break; case 'X': /* ICMP time exceeded injection */ - mode = ICMP_TIMXCEED; + icmp_mode = ICMP_TIMXCEED; got_mode++; break; case 'R': /* ICMP redirect injection */ - mode = ICMP_REDIRECT; + icmp_mode = ICMP_REDIRECT; got_mode++; break; case 'T': /* ICMP timestamp injection */ - mode = ICMP_TSTAMP; + icmp_mode = ICMP_TSTAMP; got_mode++; break; @@ -567,6 +570,6 @@ static void icmp_verbose(void) nemesis_printeth(ðerhdr); nemesis_printip(&iphdr); - nemesis_printicmp(&icmphdr, mode); + nemesis_printicmp(&icmphdr, icmp_mode); } } diff --git a/src/nemesis-icmp.h b/src/nemesis-icmp.h index 6dda3c1..cc560bc 100644 --- a/src/nemesis-icmp.h +++ b/src/nemesis-icmp.h @@ -39,8 +39,8 @@ #include "nemesis.h" #include -int mode; /* ICMP injection mode */ -int got_origoptions; +extern int icmp_mode; /* ICMP injection mode */ +extern int got_origoptions; int buildicmp(ETHERhdr *, IPhdr *, ICMPhdr *, IPhdr *, struct file *, struct file *, struct file *, libnet_t *); diff --git a/src/nemesis-ospf.c b/src/nemesis-ospf.c index b1c7a78..254a46f 100644 --- a/src/nemesis-ospf.c +++ b/src/nemesis-ospf.c @@ -43,6 +43,8 @@ static void ospf_usage(char *); static void ospf_validatedata(void); static void ospf_verbose(void); +int ospf_mode; /* OSPF injection mode */ + void nemesis_ospf(int argc, char **argv) { const char *module = "OSPF Packet Injection"; @@ -826,9 +828,9 @@ static void ospf_verbose(void) nemesis_printospf(&ospfhdr); - if (mode == 1) { - } else if (mode == 2) { - } else if (mode == 3) { + if (ospf_mode == 1) { + } else if (ospf_mode == 2) { + } else if (ospf_mode == 3) { } } } diff --git a/src/nemesis-ospf.h b/src/nemesis-ospf.h index 8a34312..8c9cab1 100644 --- a/src/nemesis-ospf.h +++ b/src/nemesis-ospf.h @@ -43,7 +43,7 @@ extern DBDhdr dbdhdr; extern NETLSAhdr netlsahdr; extern SUMLSAhdr sumlsahdr; -int mode; /* OSPF injection mode */ +extern int ospf_mode; /* OSPF injection mode */ int buildospf(ETHERhdr *, IPhdr *, struct file *, struct file *, libnet_t *, int); diff --git a/src/nemesis-proto_dns.c b/src/nemesis-proto_dns.c index 254222a..a8a60c0 100644 --- a/src/nemesis-proto_dns.c +++ b/src/nemesis-proto_dns.c @@ -30,7 +30,7 @@ int builddns(ETHERhdr *eth, IPhdr *ip, TCPhdr *tcp, UDPhdr *udp, DNShdr *dns, dns_packetlen = link_offset + LIBNET_IPV4_H + pd->file_len + ipod->file_len; - if (state == 0) + if (dns_state == 0) dns_packetlen += LIBNET_UDP_H + LIBNET_UDP_DNSV4_H; else dns_packetlen += LIBNET_TCP_H + tcpod->file_len + LIBNET_TCP_DNSV4_H; @@ -44,7 +44,7 @@ int builddns(ETHERhdr *eth, IPhdr *ip, TCPhdr *tcp, UDPhdr *udp, DNShdr *dns, printf("DEBUG: DNS payload size %zd.\n", pd->file_len); #endif - libnet_build_dnsv4(((state == 0) + libnet_build_dnsv4(((dns_state == 0) ? LIBNET_UDP_DNSV4_H : LIBNET_TCP_DNSV4_H) + pd->file_len, dns->id, @@ -52,7 +52,7 @@ int builddns(ETHERhdr *eth, IPhdr *ip, TCPhdr *tcp, UDPhdr *udp, DNShdr *dns, dns->num_q, dns->num_answ_rr, dns->num_auth_rr, dns->num_addi_rr, pd->file_buf, pd->file_len, l, 0); - if (state == 0) { + if (dns_state == 0) { libnet_build_udp(udp->uh_sport, udp->uh_dport, LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + pd->file_len, @@ -114,11 +114,11 @@ int builddns(ETHERhdr *eth, IPhdr *ip, TCPhdr *tcp, UDPhdr *udp, DNShdr *dns, if (verbose) { if (got_link) { printf("Wrote %d byte DNS (%s) packet through linktype %s.\n", - n, ((state == 0) ? "UDP" : "TCP"), + n, ((dns_state == 0) ? "UDP" : "TCP"), nemesis_lookup_linktype(l->link_type)); } else { printf("Wrote %d byte DNS (%s) packet\n", - n, ((state == 1) ? "UDP" : "TCP")); + n, ((dns_state == 1) ? "UDP" : "TCP")); } } } diff --git a/src/nemesis-proto_icmp.c b/src/nemesis-proto_icmp.c index 497f830..8d0a4fc 100644 --- a/src/nemesis-proto_icmp.c +++ b/src/nemesis-proto_icmp.c @@ -31,7 +31,7 @@ int buildicmp(ETHERhdr *eth, IPhdr *ip, ICMPhdr *icmp, IPhdr *ipunreach, icmp_packetlen = link_offset + LIBNET_IPV4_H + pd->file_len + ipod->file_len; - switch (mode) { + switch (icmp_mode) { case ICMP_ECHO: icmp_packetlen += LIBNET_ICMPV4_ECHO_H; break; @@ -60,7 +60,7 @@ int buildicmp(ETHERhdr *eth, IPhdr *ip, ICMPhdr *icmp, IPhdr *ipunreach, printf("DEBUG: ICMP payload size %zd.\n", pd->file_len); #endif - switch (mode) { + switch (icmp_mode) { case ICMP_ECHO: libnet_build_icmpv4_echo(icmp->icmp_type, icmp->icmp_code, @@ -123,7 +123,7 @@ int buildicmp(ETHERhdr *eth, IPhdr *ip, ICMPhdr *icmp, IPhdr *ipunreach, break; } - if ((mode == ICMP_UNREACH || mode == ICMP_TIMXCEED || mode == ICMP_REDIRECT) && got_origoptions) { + if ((icmp_mode == ICMP_UNREACH || icmp_mode == ICMP_TIMXCEED || icmp_mode == ICMP_REDIRECT) && got_origoptions) { if (libnet_build_ipv4_options(origod->file_buf, origod->file_len, l, 0) == -1) fprintf(stderr, "ERROR: Unable to add original IP options, discarding them.\n"); }