Skip to content

Commit

Permalink
Fix #13: multiple definition of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Fullaxx committed Apr 19, 2021
1 parent 33a78a8 commit 1ead42b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 31 deletions.
12 changes: 7 additions & 5 deletions src/nemesis-dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -457,7 +459,7 @@ static void dns_verbose(void)

nemesis_printip(&iphdr);

if (state)
if (dns_state)
nemesis_printtcp(&tcphdr);
else
nemesis_printudp(&udphdr);
Expand Down
2 changes: 1 addition & 1 deletion src/nemesis-dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "nemesis.h"
#include <libnet.h>

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 *);

Expand Down
25 changes: 14 additions & 11 deletions src/nemesis-icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -567,6 +570,6 @@ static void icmp_verbose(void)
nemesis_printeth(&etherhdr);

nemesis_printip(&iphdr);
nemesis_printicmp(&icmphdr, mode);
nemesis_printicmp(&icmphdr, icmp_mode);
}
}
4 changes: 2 additions & 2 deletions src/nemesis-icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#include "nemesis.h"
#include <libnet.h>

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 *);

Expand Down
8 changes: 5 additions & 3 deletions src/nemesis-ospf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
}
}
}
2 changes: 1 addition & 1 deletion src/nemesis-ospf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/nemesis-proto_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,15 +44,15 @@ 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,
dns->flags,
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,
Expand Down Expand Up @@ -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"));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/nemesis-proto_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 1ead42b

Please sign in to comment.