Skip to content

Commit

Permalink
Make it compilable under modern Linuxes
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Nov 20, 2016
1 parent ba517f7 commit 752a5c8
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 72 deletions.
28 changes: 16 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,36 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307

CC = gcc
CFLAGS = -fPIC -O3 -g -ggdb -c -std=gnu99 -I. -pedantic \
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
-Wall -Werror -Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \
-Wreturn-type -Wpointer-arith -Wbad-function-cast -Wno-cast-align
CC ?= gcc
COMMON_CFLAGS = -fPIC -O3 -g -c -std=gnu11 -I. \
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE \
-Wall -Werror -Wextra

LD = gcc
LDFLAGS = -fPIC -lpthread
COMMON_LDFLAGS = -fPIE -lpthread

CFLAGS += $(COMMON_CFLAGS)

LD ?= $(CC)
LDFLAGS += $(COMMON_LDFLAGS)

SRCS = debug.c intrace.c threads.c listener.c \
sender.c display.c ipv4.c ipv6.c
sender.c display.c ipv4.c ipv6.c

OBJS = $(SRCS:.c=.o)
BIN = intrace

all: $(BIN)

.c.o: %.c
@(echo CC $<; $(CC) $(CFLAGS) $<)
$(CC) $(CFLAGS) $<

$(BIN): $(OBJS)
@(echo LD $@; $(CC) -o $(BIN) $(OBJS) $(LDFLAGS))
$(CC) -o $(BIN) $(OBJS) $(LDFLAGS)

clean:
@(echo CLEAN; rm -f core $(OBJS) $(BIN))
rm -f core $(OBJS) $(BIN)

indent:
@(echo INDENT; indent -linux -l100 -lc100 -sob -c33 -cp33 *.c *.h; rm -f *~)
indent -linux -l100 -lc100 *.c *.h; rm -f *~

# DO NOT DELETE
11 changes: 4 additions & 7 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
#define _CONFIG_H_

#define INTRACE_NAME "InTrace"
#define INTRACE_VERSION "1.5"
#define INTRACE_AUTHORS "(C)2007-2011 Robert Swiecki <[email protected]>"

/* struct tcphdr incompabilities */
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
#define INTRACE_VERSION "1.6rc1"
#define INTRACE_AUTHORS "(C)2007-2016 Robert Swiecki <[email protected]>"

#define MAX_HOPS 32

#define UNUSED __attribute__((unused))

#endif
4 changes: 2 additions & 2 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <sys/time.h>
#include <time.h>

#include <intrace.h>
#include "intrace.h"

struct {
pthread_mutex_t mutex;
Expand Down Expand Up @@ -105,7 +105,7 @@ int _debug_printf(debug_level_t dl, const char *file, const char *func, int line
}

/* Function initializes debug */
int _debug_init(debug_level_t dl, char *l)
int _debug_init(debug_level_t dl)
{
debug.dl = dl;
debug.f = stdout;
Expand Down
2 changes: 1 addition & 1 deletion debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ extern int _debug_printf(debug_level_t dl, const char *file, const char *func, i
#define debug_printf(dl, ...) _debug_printf(dl, __FILE__, __func__, __LINE__, __VA_ARGS__);

/* Function initializes debug */
extern int _debug_init(debug_level_t dl, char *l);
extern int _debug_init(debug_level_t dl);

#endif
12 changes: 6 additions & 6 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <unistd.h>
#include <stdio.h>
Expand All @@ -36,7 +36,7 @@
#include <sys/time.h>
#include <sys/types.h>

#include <intrace.h>
#include "intrace.h"

static inline int display_selectInput(void)
{
Expand Down Expand Up @@ -92,11 +92,11 @@ int display_process(intrace_t * intrace)
inet_ntop(_IT_AF(intrace), _IT_LIP(intrace), locAddr, sizeof(locAddr));
inet_ntop(_IT_AF(intrace), _IT_RIP(intrace), rmtAddr, sizeof(rmtAddr));

printf("%s %s -- R: %s/%d (%d) L: %s/%d\n", INTRACE_NAME,
INTRACE_VERSION, rmtAddr, intrace->rport, intrace->port ? intrace->port : 0,
locAddr, intrace->lport);
printf("=========================[ %s %s ]========================\n", INTRACE_NAME, INTRACE_VERSION);

printf("Payload Size: %u bytes, Seq: 0x%08x, Ack: 0x%08x\n", intrace->paylSz,
printf("Remote: %s/%d (%d)\n", rmtAddr, intrace->rport, intrace->port ? intrace->port : 0);
printf("Local: %s/%d\n", locAddr, intrace->lport);
printf("Payload Size: %zu bytes, Seq: 0x%08x, Ack: 0x%08x\n", intrace->paylSz,
intrace->seq, intrace->ack);

if (intrace->cnt >= MAX_HOPS)
Expand Down
13 changes: 4 additions & 9 deletions intrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -31,7 +31,7 @@
#include <time.h>
#include <string.h>

#include <intrace.h>
#include "intrace.h"

extern char *optarg;

Expand Down Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv)
dl = atoi(optarg);
break;
case 's':
intrace.paylSz = atoi(optarg);
intrace.paylSz = strtoul(optarg, NULL, 10);
break;
case '4':
intrace.familyMode = IPV4;
Expand All @@ -77,7 +77,7 @@ int main(int argc, char **argv)
}

/* Initialize subsystems */
if ((err = _debug_init(dl, NULL)) < 0) {
if ((err = _debug_init(dl)) < 0) {
fprintf(stderr, "Can't initialize debug, err=%d!\n", err);
return err;
}
Expand All @@ -89,11 +89,6 @@ int main(int argc, char **argv)
return errArg;
}

if (intrace.paylSz < 0) {
debug_printf(dlWarn, "Payload size set to 0\n");
intrace.paylSz = 0;
}

if (intrace.paylSz > MAX_PAYL_SZ) {
debug_printf(dlWarn, "Payload size set to %d\n", MAX_PAYL_SZ);
intrace.paylSz = MAX_PAYL_SZ;
Expand Down
2 changes: 1 addition & 1 deletion intrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct {

char *hostname;
uint16_t port;
unsigned int paylSz;
size_t paylSz;

struct in_addr rip;
struct in_addr lip;
Expand Down
6 changes: 3 additions & 3 deletions ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <errno.h>
#include <string.h>
Expand All @@ -40,7 +40,7 @@
#include <netinet/tcp.h>
#include <net/if.h>

#include <intrace.h>
#include "intrace.h"

static inline unsigned short ipv4_cksum_tcp(u_int16_t * h, u_int16_t * d, int dlen)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ void ipv4_sendpkt(intrace_t * intrace, int seqSkew, int ackSkew)
sizeof(struct sockaddr));
}

static inline int ipv4_checkTcp(intrace_t * intrace, ip4pkt_t * pkt, uint32_t pktlen)
static inline int ipv4_checkTcp(intrace_t * intrace UNUSED, ip4pkt_t * pkt, uint32_t pktlen)
{
if (pktlen < sizeof(struct ip))
return errPkt;
Expand Down
14 changes: 4 additions & 10 deletions ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <assert.h>
#include <errno.h>
Expand All @@ -43,16 +43,9 @@
#include <net/if.h>
#include <arpa/inet.h>
#include <stdio.h>

#include <stdlib.h>

#include <intrace.h>

#undef in6_pktinfo
struct in6_pktinfo {
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
unsigned int ipi6_ifindex; /* send/recv interface index */
};
#include "intrace.h"

static uint16_t in_cksum(const uint16_t * addr, uint32_t len, uint32_t csum)
{
Expand Down Expand Up @@ -186,7 +179,8 @@ static bool ipv6_extract_srcdst(intrace_t * intrace, struct msghdr *msg, struct
return false;
}

static inline int ipv6_checkTcp(intrace_t * intrace, struct tcphdr *pkt, uint32_t pktlen)
static inline int ipv6_checkTcp(intrace_t * intrace UNUSED, struct tcphdr *pkt UNUSED,
uint32_t pktlen)
{
if (pktlen < sizeof(struct tcphdr))
return errPkt;
Expand Down
24 changes: 10 additions & 14 deletions listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <unistd.h>
#include <stdlib.h>
Expand All @@ -34,10 +34,10 @@
#include <errno.h>
#include <stdio.h>

#include <intrace.h>
#include "intrace.h"

static uint32_t listener_get_packet(intrace_t * intrace, int sock, uint8_t * buf, uint32_t buflen,
struct msghdr *msg)
static uint32_t listener_get_packet(intrace_t * intrace UNUSED, int sock, uint8_t * buf,
uint32_t buflen, struct msghdr *msg)
{
bzero(msg, sizeof(struct msghdr));

Expand Down Expand Up @@ -115,38 +115,34 @@ static void listener_process(intrace_t * intrace)

int listener_init(intrace_t * intrace)
{
char errbuf[512];

intrace->listener.rcvSocketTCP = socket(_IT_AF(intrace), SOCK_RAW, IPPROTO_TCP);
if (intrace->listener.rcvSocketTCP < 0) {
strerror_r(errno, errbuf, sizeof(errbuf) - 1);
debug_printf(dlError, "listener: Cannot open raw TCP socket, '%s'\n", errbuf);
debug_printf(dlError, "listener: Cannot open raw TCP socket, '%s'\n",
strerror(errno));
return errSocket;
}

intrace->listener.rcvSocketICMP = socket(_IT_AF(intrace), SOCK_RAW, _IT_ICMPPROTO(intrace));
if (intrace->listener.rcvSocketTCP < 0) {
strerror_r(errno, errbuf, sizeof(errbuf) - 1);
debug_printf(dlError, "listener: Cannot open raw ICMPv6 socket, '%s'\n", errbuf);
debug_printf(dlError, "listener: Cannot open raw ICMPv6 socket, '%s'\n",
strerror(errno));
return errSocket;
}

int on = 1;
if (setsockopt
(intrace->listener.rcvSocketTCP, _IT_IPPROTO(intrace), _IT_PKTINFO(intrace), &on,
sizeof(on)) == -1) {
strerror_r(errno, errbuf, sizeof(errbuf) - 1);
debug_printf(dlError, "listener: Cannot set IPV6_RECVPKTINFO on TCP socket, '%s'\n",
errbuf);
strerror(errno));
return errSocket;
}
if (setsockopt
(intrace->listener.rcvSocketICMP, _IT_IPPROTO(intrace), _IT_PKTINFO(intrace), &on,
sizeof(on)) == -1) {
strerror_r(errno, errbuf, sizeof(errbuf) - 1);
debug_printf(dlError,
"listener: Cannot set IPV6_RECVPKTINFO on ICMP socket, '%s'\n",
errbuf);
strerror(errno));
return errSocket;
}

Expand Down
8 changes: 3 additions & 5 deletions sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <errno.h>
#include <string.h>
Expand All @@ -41,7 +41,7 @@
#include <net/if.h>
#include <sys/ioctl.h>

#include <intrace.h>
#include "intrace.h"

static void sender_process(intrace_t * intrace)
{
Expand Down Expand Up @@ -72,13 +72,11 @@ static void sender_process(intrace_t * intrace)

int sender_init(intrace_t * intrace)
{
char errbuf[256];
int tmp = 1;

intrace->sender.sndSocket = socket(_IT_AF(intrace), SOCK_RAW, IPPROTO_RAW);
if (intrace->sender.sndSocket < 0) {
strerror_r(errno, errbuf, sizeof(errbuf) - 1);
debug_printf(dlError, "sender: Cannot open raw socket, %s\n", errbuf);
debug_printf(dlError, "sender: Cannot open raw socket, %s\n", strerror(errno));
return errSocket;
}

Expand Down
4 changes: 2 additions & 2 deletions threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
*/

#include <config.h>
#include "config.h"

#include <pthread.h>
#include <netdb.h>
Expand All @@ -33,7 +33,7 @@
#include <unistd.h>
#include <sys/types.h>

#include <intrace.h>
#include "intrace.h"

// For setuid case only
static int threads_dropPrivs(void)
Expand Down

0 comments on commit 752a5c8

Please sign in to comment.