From 54c5148e87867214768255182329bf47d0103985 Mon Sep 17 00:00:00 2001 From: Ron Dilley Date: Wed, 10 Jan 2018 17:15:30 -0800 Subject: [PATCH] minor autoconf changes to port to openbsd --- bootstrap | 19 +++++++++++++++++++ configure.ac | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/dns.c | 12 ++++++------ src/passivedns.c | 14 +++++++++++++- src/passivedns.h | 8 ++++---- 5 files changed, 88 insertions(+), 11 deletions(-) create mode 100755 bootstrap diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..e2dfe88 --- /dev/null +++ b/bootstrap @@ -0,0 +1,19 @@ +#!/bin/sh +# +# desc: simple script to run all auto commands +# +#### + +# defines needed for OpenBSD +AUTOMAKE_VERSION=1.15;export AUTOMAKE_VERSION +AUTOCONF_VERSION=2.69;export AUTOCONF_VERSION + +if [ ! -d config ]; then + mkdir config +fi + +aclocal +automake --gnu --add-missing +autoconf +autoheader + diff --git a/configure.ac b/configure.ac index 4fd762f..173c41c 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,52 @@ AC_CONFIG_HEADERS([src/config.h]) # Checks for programs. AC_PROG_CC +AC_CANONICAL_HOST + +dnl Checks for OS type. +case "$host" in + *-freebsd*) + AC_DEFINE([BSD_DERIVED],1,BSD_DERIVED) + AC_DEFINE([FREEBSD],1,FREEBSD) + LDFLAGS="${LDFLAGS}" + ;; + *-netbsd*) + AC_DEFINE([BSD_DERIVED],1,BSD_DERIVED) + AC_DEFINE([NETBSD],1,NETBSD) + ;; + *-openbsd*) + AC_DEFINE([BSD_DERIVED],1,BSD_DERIVED) + AC_DEFINE([OPENBSD],1,OPENBSD) + CFLAGS="${CFLAGS} -Wbounded" + LDFLAGS="${LDFLAGS}" + ;; + *-apple*) + AC_DEFINE([BSD_DERIVED],1,BSD_DERIVED) + AC_DEFINE([MACOS],1,MACOS) + LDFLAGS="${LDFLAGS} -L/sw/lib" + AC_SUBST(more_incl) + more_incl=-I/sw/include + ;; + *-linux*) + AC_DEFINE([SYSV_DERIVED],1,SYSV_DERIVED) + AC_DEFINE([LINUX],1,LINUX) + LDFLAGS="${LDFLAGS}" + ;; + *-solaris*) + AC_DEFINE([SYSV_DERIVED],1,SYSV_DERIVED) + AC_DEFINE([SOLARIS],1,SOLARIS) + LDFLAGS="${LDFLAGS}" + ;; + *-aix*) + AC_DEFINE([SYSV_DERIVED],1,SYSV_DERIVED) + AC_DEFINE([AIX],1,AIX) + ;; + *-hpux*) + AC_DEFINE([SYSV_DERIVED],1,SYSV_DERIVED) + AC_DEFINE([HPUX],1,HPUX) + ;; +esac + # Enable debug output. AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [Enable debug output])) diff --git a/src/dns.c b/src/dns.c index 6f9ee52..1471506 100644 --- a/src/dns.c +++ b/src/dns.c @@ -563,7 +563,7 @@ void update_pdns_record_asset(packetinfo *pi, pdns_record *pr, /* We have this, update and if its over 24h since last print - print it, then return */ passet->seen++; - passet->last_seen = pi->pheader->ts; + memcpy( &passet->last_seen, &pi->pheader->ts, sizeof( struct timeval ) ); passet->af = pi->cxt->af; passet->cip = pi->cxt->s_ip; /* This should always be the client IP */ passet->sip = pi->cxt->d_ip; /* This should always be the server IP */ @@ -606,8 +606,8 @@ void update_pdns_record_asset(packetinfo *pi, pdns_record *pr, passet->next = NULL; /* Populate new values */ - passet->first_seen = pi->pheader->ts; - passet->last_seen = pi->pheader->ts; + memcpy( &passet->first_seen, &pi->pheader->ts, sizeof( struct timeval ) ); + memcpy( &passet->last_seen, &pi->pheader->ts, sizeof( struct timeval ) ); passet->af = pi->cxt->af; passet->cip = pi->cxt->s_ip; /* This should always be the client IP */ passet->sip = pi->cxt->d_ip; /* This should always be the server IP */ @@ -1193,7 +1193,7 @@ pdns_record *get_pdns_record(uint64_t dnshash, packetinfo *pi, if (strcmp((const char *)domain_name, (const char *)pdnsr->qname) == 0) { /* match :) */ - pdnsr->last_seen = pi->pheader->ts; + memcpy( &pdnsr->last_seen, &pi->pheader->ts, sizeof( struct timeval ) ); pdnsr->af = pi->cxt->af; pdnsr->cip = pi->cxt->s_ip; /* This should always be the client IP */ pdnsr->sip = pi->cxt->d_ip; /* This should always be the server IP */ @@ -1213,8 +1213,8 @@ pdns_record *get_pdns_record(uint64_t dnshash, packetinfo *pi, head->prev = pdnsr; /* Populate new values */ - pdnsr->first_seen = pi->pheader->ts; - pdnsr->last_seen = pi->pheader->ts; + memcpy( &pdnsr->first_seen, &pi->pheader->ts, sizeof( struct timeval ) ); + memcpy( &pdnsr->last_seen, &pi->pheader->ts, sizeof( struct timeval ) ); pdnsr->af = pi->cxt->af; pdnsr->nxflag = 0; pdnsr->cip = pi->cxt->s_ip; /* This should always be the client IP */ diff --git a/src/passivedns.c b/src/passivedns.c index f10d1cc..2ebdae6 100644 --- a/src/passivedns.c +++ b/src/passivedns.c @@ -130,7 +130,7 @@ void got_packet(u_char *useless, const struct pcap_pkthdr *pheader, pi->packet = packet; pi->pheader = pheader; set_pkt_end_ptr (pi); - config.tstamp = pi->pheader->ts; /* Global */ + memcpy( &config.tstamp, &pi->pheader->ts, sizeof( struct timeval ) ); /* Global */ if (signal_reopen_log_files) reopen_log_files(); @@ -144,9 +144,11 @@ void got_packet(u_char *useless, const struct pcap_pkthdr *pheader, case DLT_RAW: prepare_raw(pi); break; +#ifdef DLT_LINUX_SSL case DLT_LINUX_SLL: prepare_sll(pi); break; +#endif default: prepare_eth(pi); check_vlan(pi); @@ -431,8 +433,13 @@ int connection_tracking(packetinfo *pi) ip_dst = &PI_IP6DST(pi); } else { +#ifdef BSD_DERIVED + ips.__u6_addr.__u6_addr32[0] = pi->ip4->ip_src; + ipd.__u6_addr.__u6_addr32[0] = pi->ip4->ip_dst; +#else ips.s6_addr32[0] = pi->ip4->ip_src; ipd.s6_addr32[0] = pi->ip4->ip_dst; +#endif ip_src = &ips; ip_dst = &ipd; } @@ -524,8 +531,13 @@ connection *cxt_new(packetinfo *pi) cxt->d_ip = PI_IP6DST(pi); } else { +#ifdef BSD_DERIVED + ips.__u6_addr.__u6_addr32[0] = pi->ip4->ip_src; + ipd.__u6_addr.__u6_addr32[0] = pi->ip4->ip_dst; +#else ips.s6_addr32[0] = pi->ip4->ip_src; ipd.s6_addr32[0] = pi->ip4->ip_dst; +#endif cxt->s_ip = ips; cxt->d_ip = ipd; } diff --git a/src/passivedns.h b/src/passivedns.h index 7efa5d8..024765f 100644 --- a/src/passivedns.h +++ b/src/passivedns.h @@ -269,7 +269,7 @@ typedef struct _connection { #define ISSET_SERVICE_UNKNOWN(pi) (pi->cxt->check & CXT_SERVICE_UNKNOWN_SET) #define ISSET_CLIENT_UNKNOWN(pi) (pi->cxt->check & CXT_CLIENT_UNKNOWN_SET) -#ifdef OSX +#ifdef BSD_DERIVED // sidds darwin ports #define IP4ADDR(ip) (ip)->__u6_addr.__u6_addr32[0] @@ -330,7 +330,7 @@ typedef struct _connection { CMP_PORT((cxt1)->s_port, (sp)) && CMP_PORT((cxt1)->d_port, (dp)))) /* clear the address structure by setting all fields to 0 */ -#ifdef OSX +#ifdef BSD_DERIVED #define CLEAR_ADDR(a) { \ (a)->__u6_addr.__u6_addr32[0] = 0; \ (a)->__u6_addr.__u6_addr32[1] = 0; \ @@ -349,7 +349,7 @@ typedef struct _connection { #define CXT_HASH4(src,dst,sp,dp,pr) \ ((src + dst + sp + dp + pr) % BUCKET_SIZE) -#ifndef OSX +#ifndef BSD_DERIVED #define CXT_HASH6(src,dst,sp,dp,pr) \ (( \ (src)->s6_addr32[0] + (src)->s6_addr32[1] + \ @@ -358,7 +358,7 @@ typedef struct _connection { (dst)->s6_addr32[2] + (dst)->s6_addr32[3] + \ sp + dp + pr ) % BUCKET_SIZE) #else -#define CXT_HASH6(src,dest,sp,dp,pr) \ +#define CXT_HASH6(src,dst,sp,dp,pr) \ (( \ (src)->__u6_addr.__u6_addr32[0] + (src)->__u6_addr.__u6_addr32[1] + \ (src)->__u6_addr.__u6_addr32[2] + (src)->__u6_addr.__u6_addr32[3] + \