diff --git a/Makefile b/Makefile index 9262192682112afaedf11e8ae1ff56db939d860a..96f103ac89ef4b654dc476ab2d6d53bc89569cf4 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif # environment where things likely will work -- as well as anything # works on the bajillion of different Linux environments ifneq (, $(findstring linux, $(SYS))) -LIBS = -lpcap -lm -lrt -ldl -lpthread +LIBS = -lm -lrt -ldl -lpthread INCLUDES = FLAGS2 = endif @@ -23,7 +23,7 @@ endif # my regularly regression-test environment. That means at any point # in time, something might be minorly broken in Mac OS X. ifneq (, $(findstring darwin, $(SYS))) -LIBS = -lpcap -lm +LIBS = -lm INCLUDES = -I. FLAGS2 = INSTALL_DATA = -pm755 @@ -37,7 +37,7 @@ endif # intended environment, so it make break in the future. ifneq (, $(findstring mingw, $(SYS))) INCLUDES = -Ivs10/include -LIBS = -L vs10/lib -lwpcap -lIPHLPAPI -lWs2_32 +LIBS = -L vs10/lib -lIPHLPAPI -lWs2_32 FLAGS2 = -march=i686 endif @@ -47,20 +47,20 @@ endif # head with a hammer and want to feel a different sort of pain. ifneq (, $(findstring cygwin, $(SYS))) INCLUDES = -I. -LIBS = -lwpcap +LIBS = FLAGS2 = endif # OpenBSD ifneq (, $(findstring openbsd, $(SYS))) -LIBS = -lpcap -lm -pthread +LIBS = -lm -pthread INCLUDES = -I. FLAGS2 = endif # FreeBSD ifneq (, $(findstring freebsd, $(SYS))) -LIBS = -lpcap -lm -pthread +LIBS = -lm -pthread INCLUDES = -I. FLAGS2 = endif diff --git a/src/main.c b/src/main.c index caf2745e6c26d64d1b11f8a359ea4d086b040a21..2e5b870156a85fa1ecceb841efbcb1f9e305f368 100644 --- a/src/main.c +++ b/src/main.c @@ -1428,6 +1428,7 @@ main_scan(struct Masscan *masscan) +void pcap_init(void); /*************************************************************************** ***************************************************************************/ @@ -1435,7 +1436,7 @@ int main(int argc, char *argv[]) { struct Masscan masscan[1]; unsigned i; - + usec_start = pixie_gettime(); #if defined(WIN32) {WSADATA x; WSAStartup(0x101, &x);} @@ -1506,6 +1507,7 @@ int main(int argc, char *argv[]) /* We need to do a separate "raw socket" initialization step. This is * for Windows and PF_RING. */ + pcap_init(); rawsock_init(); /* Init some protocol parser data structures */ diff --git a/src/rawsock-pcap.c b/src/rawsock-pcap.c new file mode 100644 index 0000000000000000000000000000000000000000..8909c46b76413f9fc35f1143d6a3c097de247dcc --- /dev/null +++ b/src/rawsock-pcap.c @@ -0,0 +1,416 @@ +/* Copyright (c) 2007 by Errata Security, All Rights Reserved + * Copyright (c) 2017 by Robert David Graham + * Programer(s): Robert David Graham [rdg] + */ +/* + PCAPLIVE + + This code links the 'libpcap' module at RUNTIME rather than LOADTIME. + This allows us to: + (a) run this program on capture files without needing libpcap installed. + (b) give more user friendly diagnostic to the users who don't realize + that they need to install libpcap separately. + + On Windows, this uses the LoadLibrary/GetProcAddress functions to + load the library. + + On Linux, this uses the dlopen/dlsym functions to do essentially + the same thing. + */ +#include "logger.h" + +#if _MSC_VER==1200 +#pragma warning(disable:4115 4201) +#include +#endif +#include "rawsock-pcap.h" + +#ifdef WIN32 +#include +#else +#include +#endif + +#include +#include +#include + +#ifndef UNUSEDPARM +#ifdef __GNUC__ +#define UNUSEDPARM(x) x=(x) +#endif +#endif + +struct pcap_if { + struct pcap_if *next; + char *name; /* name to hand to "pcap_open_live()" */ + char *description; /* textual description of interface, or NULL */ + void *addresses; + unsigned flags; /* PCAP_IF_ interface flags */ +}; + +static void seterr(char *errbuf, const char *msg) +{ + size_t length = strlen(msg); + + if (length > PCAP_ERRBUF_SIZE-1) + length = PCAP_ERRBUF_SIZE-1; + memcpy(errbuf, msg, length); + errbuf[length] = '\0'; +} + +static void null_PCAP_CLOSE(void *hPcap) +{ +#ifdef STATICPCAP + pcap_close(hPcap); + return; +#endif + UNUSEDPARM(hPcap); +} + + +static unsigned null_PCAP_DATALINK(void *hPcap) +{ +#ifdef STATICPCAP + return pcap_datalink(hPcap); +#endif + UNUSEDPARM(hPcap); + return 0; +} + + +static unsigned null_PCAP_DISPATCH(void *hPcap, unsigned how_many_packets, PCAP_HANDLE_PACKET handler, void *handle_data) +{ +#ifdef STATICPCAP + return pcap_dispatch(hPcap, how_many_packets, handler, handle_data); +#endif + UNUSEDPARM(hPcap);UNUSEDPARM(how_many_packets);UNUSEDPARM(handler);UNUSEDPARM(handle_data); + return 0; +} + + +static int null_PCAP_FINDALLDEVS(pcap_if_t **alldevs, char *errbuf) +{ +#ifdef STATICPCAP + return pcap_findalldevs(alldevs, errbuf); +#endif + *alldevs = 0; + seterr(errbuf, "libpcap not loaded"); + return -1; +} + + +static void null_PCAP_FREEALLDEVS(pcap_if_t *alldevs) +{ +#ifdef STATICPCAP + return pcap_freealldevs(alldevs); +#endif + UNUSEDPARM(alldevs); + return; +} + + +static char *null_PCAP_LOOKUPDEV(char *errbuf) +{ +#ifdef STATICPCAP + return pcap_lookupdev(errbuf); +#endif + seterr(errbuf, "libpcap not loaded"); + return ""; +} + + +static void * null_PCAP_OPEN_LIVE(const char *devicename, unsigned snap_length, unsigned is_promiscuous, unsigned read_timeout, char *errbuf) +{ +#ifdef STATICPCAP + return pcap_open_live(devicename, snap_length, is_promiscuous, read_timeout, errbuf); +#endif + seterr(errbuf, "libpcap not loaded"); + UNUSEDPARM(devicename);UNUSEDPARM(snap_length);UNUSEDPARM(is_promiscuous);UNUSEDPARM(read_timeout); + return NULL; +} + +static int null_PCAP_MAJOR_VERSION(void *p) +{ +#ifdef STATICPCAP + return pcap_major_version(p); +#endif + UNUSEDPARM(p); + return 0; +} + + +static int null_PCAP_MINOR_VERSION(void *p) +{ +#ifdef STATICPCAP + return pcap_minor_version(p); +#endif + UNUSEDPARM(p); + return 0; +} + +static const char *null_PCAP_LIB_VERSION(void) +{ +#ifdef STATICPCAP + return pcap_lib_version(); +#endif + + return "stub/0.0"; +} + +#ifdef WIN32 +static void *null_PCAP_GET_AIRPCAP_HANDLE(void *p) +{ + UNUSEDPARM(p); + return NULL; +} +#endif + +#ifdef WIN32 +static unsigned null_AIRPCAP_SET_DEVICE_CHANNEL(void *p, unsigned channel) +{ + UNUSEDPARM(p);UNUSEDPARM(channel); + + return 0; /*0=failure, 1=success*/ +} +#endif + + +static unsigned null_CAN_TRANSMIT(const char *devicename) +{ +#if WIN32 + struct DeviceCapabilities { + unsigned AdapterId; /* An Id that identifies the adapter model.*/ + char AdapterModelName; /* String containing a printable adapter model.*/ + unsigned AdapterBus; /* The type of bus the adapter is plugged to. */ + unsigned CanTransmit; /* TRUE if the adapter is able to perform frame injection.*/ + unsigned CanSetTransmitPower; /* TRUE if the adapter's transmit power is can be specified by the user application.*/ + unsigned ExternalAntennaPlug; /* TRUE if the adapter supports plugging one or more external antennas.*/ + unsigned SupportedMedia; + unsigned SupportedBands; + } caps; + void * (*myopen)(const char *devicename, char *errbuf); + void (*myclose)(void *h); + unsigned (*mycapabilities)(void *h, struct DeviceCapabilities *caps); + + unsigned result = 0; + void *hAirpcap; + + + hAirpcap = LoadLibraryA("airpcap.dll"); + if (hAirpcap == NULL) + return 0; + + + myopen = (void * (*)(const char *, char*))GetProcAddress(hAirpcap, "AirpcapOpen"); + myclose = (void (*)(void*))GetProcAddress(hAirpcap, "AirpcapClose"); + mycapabilities = (unsigned (*)(void*, struct DeviceCapabilities *))GetProcAddress(hAirpcap, "AirpcapGetDeviceCapabilities"); + if (myopen && mycapabilities && myclose ) { + void *h = myopen(devicename, NULL); + if (h) { + if (mycapabilities(h, &caps)) { + result = caps.CanTransmit; + } + myclose(h); + } + } + + FreeLibrary(hAirpcap); + return result; +#elif defined(__linux__) + return 1; +#elif defined(__APPLE__) || defined(__FreeBSD__) + return 1; +#else +#error unknown os +#endif +} + +struct PcapFunctions PCAP = { + 0,0,0,0,0, + null_PCAP_CLOSE, +}; + + +static void *my_null(int x, ...) +{ + return 0; +} +static pcap_t *null_PCAP_OPEN_OFFLINE(const char *fname, char *errbuf) +{ + return my_null(2, fname, errbuf); +} +static int null_PCAP_SENDPACKET(pcap_t *p, const unsigned char *buf, int size) +{ + return (int)my_null(p, buf, size); +} + +static const unsigned char *null_PCAP_NEXT(pcap_t *p, struct pcap_pkthdr *h) +{ + return 0; +} +static int null_PCAP_SETDIRECTION(pcap_t *p, pcap_direction_t d) +{ + return 0; +} +static const char *null_PCAP_DATALINK_VAL_TO_NAME(int dlt) +{ + return 0; +} +static void null_PCAP_PERROR(pcap_t *p, char *prefix) +{ + perror("pcap"); +} +static const char *null_PCAP_DEV_NAME(const pcap_if_t *dev) +{ + return dev->name; +} +static const char *null_PCAP_DEV_DESCRIPTION(const pcap_if_t *dev) +{ + return dev->description; +} +static const pcap_if_t *null_PCAP_DEV_NEXT(const pcap_if_t *dev) +{ + return dev->next; +} + +/** + * Runtime-load the libpcap shared-object or the winpcap DLL. We + * load at runtime rather than loadtime to allow this program to + * be used to process offline content, and to provide more helpful + * messages to people who don't realize they need to install PCAP. + */ +void pcap_init(void) +{ + struct PcapFunctions *pl = &PCAP; +#ifdef WIN32 + HMODULE hPacket; + HMODULE hLibpcap; + HMODULE hAirpcap; + + pl->is_available = 0; + pl->is_printing_debug = 1; + + /* Look for the Packet.dll */ + hPacket = LoadLibraryA("Packet.dll"); + if (hPacket == NULL) { + if (pl->is_printing_debug) + switch (GetLastError()) { + case ERROR_MOD_NOT_FOUND: + fprintf(stderr, "%s: not found\n", "Packet.dll"); + return; + default: + fprintf(stderr, "%s: couldn't load %d\n", "Packet.dll", (int)GetLastError()); + return; + } + } + + /* Look for the Packet.dll */ + hLibpcap = LoadLibraryA("wpcap.dll"); + if (hLibpcap == NULL) { + if (pl->is_printing_debug) + fprintf(stderr, "%s: couldn't load %d\n", "wpcap.dll", (int)GetLastError()); + return; + } + + /* Look for the Packet.dll */ + hAirpcap = LoadLibraryA("airpcap.dll"); + if (hLibpcap == NULL) { + if (pl->is_printing_debug) + fprintf(stderr, "%s: couldn't load %d\n", "airpcap.dll", (int)GetLastError()); + return; + } + +#define DOLINK(PCAP_DATALINK, datalink) \ +pl->datalink = (PCAP_DATALINK)GetProcAddress(hLibpcap, "pcap_"#datalink); \ +if (pl->datalink == NULL) pl->func_err=1, pl->datalink = null_##PCAP_DATALINK; +#endif + + +#ifndef WIN32 +#ifndef STATICPCAP + void *hLibpcap; + + pl->is_available = 0; + pl->is_printing_debug = 1; + + { + static const char *possible_names[] = { + "libpcap.so", + "libpcap.A.dylib", + "libpcap.dylib", + "libpcap.so.0.9.5", + "libpcap.so.0.9.4", + "libpcap.so.0.8", + 0 + }; + unsigned i; + for (i=0; possible_names[i]; i++) { + hLibpcap = dlopen(possible_names[i], RTLD_LAZY); + if (hLibpcap) { + LOG(1, "pcap: found library: %s\n", possible_names[i]); + break; + } else { + LOG(2, "pcap: failed to load: %s\n", possible_names[i]); + } + } + + if (hLibpcap == NULL) + fprintf(stderr, "pcap: failed to load libpcap\n"); + } + +#define DOLINK(PCAP_DATALINK, datalink) \ +pl->datalink = (PCAP_DATALINK)dlsym(hLibpcap, "pcap_"#datalink); \ + if (pl->datalink == NULL) LOG(1, "pcap: pcap_%s: failed\n", #datalink); \ + if (pl->datalink == NULL) pl->func_err=1, pl->datalink = null_##PCAP_DATALINK; +#else +#define DOLINK(PCAP_DATALINK, datalink) \ +pl->func_err=0, pl->datalink = null_##PCAP_DATALINK; +#endif +#endif + +#ifdef WIN32 + DOLINK(PCAP_GET_AIRPCAP_HANDLE, get_airpcap_handle); + if (pl->func_err) { + pl->func_err = 0; + } + if (hAirpcap) { + pl->airpcap_set_device_channel = (AIRPCAP_SET_DEVICE_CHANNEL)GetProcAddress(hAirpcap, "AirpcapSetDeviceChannel"); + if (pl->airpcap_set_device_channel == NULL) + pl->airpcap_set_device_channel = null_AIRPCAP_SET_DEVICE_CHANNEL; + } +#endif + + + + DOLINK(PCAP_CLOSE , close); + DOLINK(PCAP_DATALINK , datalink); + DOLINK(PCAP_DISPATCH , dispatch); + DOLINK(PCAP_FINDALLDEVS , findalldevs); + DOLINK(PCAP_FREEALLDEVS , freealldevs); + DOLINK(PCAP_LIB_VERSION , lib_version); + DOLINK(PCAP_LOOKUPDEV , lookupdev); + DOLINK(PCAP_MAJOR_VERSION , major_version); + DOLINK(PCAP_MINOR_VERSION , minor_version); + DOLINK(PCAP_OPEN_LIVE , open_live); + + DOLINK(PCAP_OPEN_OFFLINE , open_offline); + DOLINK(PCAP_SENDPACKET , sendpacket); + DOLINK(PCAP_NEXT , next); + DOLINK(PCAP_SETDIRECTION , setdirection); + DOLINK(PCAP_DATALINK_VAL_TO_NAME , datalink_val_to_name); + DOLINK(PCAP_PERROR , perror); + + DOLINK(PCAP_DEV_NAME , dev_name); + DOLINK(PCAP_DEV_DESCRIPTION , dev_description); + DOLINK(PCAP_DEV_NEXT , dev_next); + + + pl->can_transmit = null_CAN_TRANSMIT; + + if (!pl->func_err) + pl->is_available = 1; + else + pl->is_available = 0; +} + diff --git a/src/rawsock-pcap.h b/src/rawsock-pcap.h new file mode 100644 index 0000000000000000000000000000000000000000..615cceda9828fc744e99fe38e8b4bafd5d9a27f5 --- /dev/null +++ b/src/rawsock-pcap.h @@ -0,0 +1,96 @@ +#ifndef RAWSOCK_PCAP_H +#define RAWSOCK_PCAP_H +#include + +struct pcap; +typedef struct pcap pcap_t; +typedef struct pcap_if pcap_if_t; + +enum { + PCAP_ERRBUF_SIZE=256, +}; + +typedef enum { + PCAP_D_INOUT = 0, + PCAP_D_IN, + PCAP_D_OUT +} pcap_direction_t; + +struct pcap_pkthdr { + struct timeval ts; + unsigned caplen; + unsigned len; +#ifdef __APPLE__ + char comment[256]; +#endif +}; + +typedef void (*PCAP_HANDLE_PACKET)(unsigned char *v_seap, const struct pcap_pkthdr *framehdr, const unsigned char *buf); + +typedef void (*PCAP_CLOSE)(void *hPcap); +typedef unsigned (*PCAP_DATALINK)(void *hPcap); +typedef unsigned (*PCAP_DISPATCH)(void *hPcap, unsigned how_many_packets, PCAP_HANDLE_PACKET handler, void *handle_data); +typedef int (*PCAP_FINDALLDEVS)(pcap_if_t **alldevs, char *errbuf); +typedef const char *(*PCAP_LIB_VERSION)(void); +typedef char *(*PCAP_LOOKUPDEV)(char *errbuf); +typedef int (*PCAP_MAJOR_VERSION)(void *p); +typedef int (*PCAP_MINOR_VERSION)(void *p); +typedef void * (*PCAP_OPEN_LIVE)(const char *devicename, unsigned snap_length, unsigned is_promiscuous, unsigned read_timeout, char *errbuf); +typedef void (*PCAP_FREEALLDEVS)(pcap_if_t *alldevs); +typedef void * (*PCAP_GET_AIRPCAP_HANDLE)(void *p); +typedef unsigned (*AIRPCAP_SET_DEVICE_CHANNEL)(void *p, unsigned channel); +typedef unsigned (*CAN_TRANSMIT)(const char *devicename); + +typedef pcap_t *(*PCAP_OPEN_OFFLINE)(const char *fname, char *errbuf); +typedef int (*PCAP_SENDPACKET)(pcap_t *p, const unsigned char *buf, int size); +typedef const unsigned char *(*PCAP_NEXT)(pcap_t *p, struct pcap_pkthdr *h); +typedef int (*PCAP_SETDIRECTION)(pcap_t *, pcap_direction_t); +typedef const char *(*PCAP_DATALINK_VAL_TO_NAME)(int dlt); +typedef void (*PCAP_PERROR)(pcap_t *p, char *prefix); +typedef const char *(*PCAP_DEV_NAME)(const pcap_if_t *dev); +typedef const char *(*PCAP_DEV_DESCRIPTION)(const pcap_if_t *dev); +typedef const pcap_if_t *(*PCAP_DEV_NEXT)(const pcap_if_t *dev); + + + +struct PcapFunctions { + unsigned func_err:1; + unsigned is_available:1; + unsigned is_printing_debug:1; + unsigned status; + unsigned errcode; + + PCAP_CLOSE close; + PCAP_DATALINK datalink; + PCAP_DISPATCH dispatch; + PCAP_FINDALLDEVS findalldevs; + PCAP_FREEALLDEVS freealldevs; + PCAP_LOOKUPDEV lookupdev; + PCAP_LIB_VERSION lib_version; + PCAP_MAJOR_VERSION major_version; + PCAP_MINOR_VERSION minor_version; + PCAP_OPEN_LIVE open_live; + PCAP_GET_AIRPCAP_HANDLE get_airpcap_handle; + AIRPCAP_SET_DEVICE_CHANNEL airpcap_set_device_channel; + //AIRPCAP_SET_FCS_PRESENCE airpcap_set_fcs_presence; + //BOOL AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, BOOL IsFcsPresent); + + CAN_TRANSMIT can_transmit; + + PCAP_OPEN_OFFLINE open_offline; + PCAP_SENDPACKET sendpacket; + PCAP_NEXT next; + PCAP_SETDIRECTION setdirection; + PCAP_DATALINK_VAL_TO_NAME datalink_val_to_name; + PCAP_PERROR perror; + + PCAP_DEV_NAME dev_name; + PCAP_DEV_DESCRIPTION dev_description; + PCAP_DEV_NEXT dev_next; + +}; + +extern struct PcapFunctions PCAP; +void pcap_init(void); + +#endif diff --git a/src/rawsock.c b/src/rawsock.c index 888c4695a5618416abc253e36cc7625ff23cf0ad..536f52a973b0e25fa90113bf2878f86c2f7b6317 100644 --- a/src/rawsock.c +++ b/src/rawsock.c @@ -12,8 +12,8 @@ #include "rawsock-pfring.h" #include "pixie-timer.h" #include "main-globals.h" - -#include +#include "rawsock-pcap.h" +//#include #include #include @@ -205,30 +205,33 @@ rawsock_init(void) } /*************************************************************************** + * This function prints to the command line a list of all the network + * intefaces/devices. ***************************************************************************/ void rawsock_list_adapters(void) { pcap_if_t *alldevs; char errbuf[PCAP_ERRBUF_SIZE]; - - if (pcap_findalldevs(&alldevs, errbuf) != -1) { + + if (PCAP.findalldevs(&alldevs, errbuf) != -1) { int i; - pcap_if_t *d; + const pcap_if_t *d; i=0; - + if (alldevs == NULL) { fprintf(stderr, "ERR:libpcap: no adapters found, are you sure you are root?\n"); } /* Print the list */ - for(d=alldevs; d; d=d->next) { - fprintf(stderr, " %d %s \t", i++, d->name); - if (d->description) - fprintf(stderr, "(%s)\n", d->description); + for(d=alldevs; d; d=PCAP.dev_next(d)) { + fprintf(stderr, " %d %s \t", i++, PCAP.dev_name(d)); + if (PCAP.dev_description(d)) + fprintf(stderr, "(%s)\n", PCAP.dev_description(d)); else fprintf(stderr, "(No description available)\n"); } fprintf(stderr,"\n"); + PCAP.freealldevs(alldevs); } else { fprintf(stderr, "%s\n", errbuf); } @@ -236,25 +239,24 @@ rawsock_list_adapters(void) /*************************************************************************** ***************************************************************************/ -static char * +static const char * adapter_from_index(unsigned index) { pcap_if_t *alldevs; char errbuf[PCAP_ERRBUF_SIZE]; int x; - x = pcap_findalldevs(&alldevs, errbuf); + x = PCAP.findalldevs(&alldevs, errbuf); if (x != -1) { - pcap_if_t *d; + const pcap_if_t *d; if (alldevs == NULL) { fprintf(stderr, "ERR:libpcap: no adapters found, are you sure you are root?\n"); } /* Print the list */ - for(d=alldevs; d; d=d->next) - { + for(d=alldevs; d; d=PCAP.dev_next(d)) { if (index-- == 0) - return d->name; + return PCAP.dev_name(d); } return 0; } else { @@ -339,7 +341,7 @@ rawsock_send_packet( /* LIBPCAP */ if (adapter->pcap) - return pcap_sendpacket(adapter->pcap, packet, length); + return PCAP.sendpacket(adapter->pcap, packet, length); return 0; } @@ -377,13 +379,13 @@ int rawsock_recv_packet( return 1; *length = hdr.caplen; - *secs = hdr.ts.tv_sec; - *usecs = hdr.ts.tv_usec; + *secs = (unsigned)hdr.ts.tv_sec; + *usecs = (unsigned)hdr.ts.tv_usec; } else if (adapter->pcap) { struct pcap_pkthdr hdr; - *packet = pcap_next(adapter->pcap, &hdr); + *packet = PCAP.next(adapter->pcap, &hdr); if (*packet == NULL) { if (is_pcap_file) { @@ -395,7 +397,7 @@ int rawsock_recv_packet( } *length = hdr.caplen; - *secs = hdr.ts.tv_sec; + *secs = (unsigned)hdr.ts.tv_sec; *usecs = hdr.ts.tv_usec; } @@ -506,9 +508,9 @@ rawsock_ignore_transmits(struct Adapter *adapter, const unsigned char *adapter_m if (adapter->pcap) { int err; - err = pcap_setdirection(adapter->pcap, PCAP_D_IN); + err = PCAP.setdirection(adapter->pcap, PCAP_D_IN); if (err) { - pcap_perror(adapter->pcap, "pcap_setdirection(IN)"); + PCAP.perror(adapter->pcap, "pcap_setdirection(IN)"); } } #else @@ -554,7 +556,7 @@ rawsock_close_adapter(struct Adapter *adapter) PFRING.close(adapter->ring); } if (adapter->pcap) { - pcap_close(adapter->pcap); + PCAP.close(adapter->pcap); } if (adapter->sendq) { pcap_sendqueue_destroy(adapter->sendq); @@ -739,18 +741,18 @@ rawsock_init_adapter(const char *adapter_name, * This is the stanard that should work everywhere. *----------------------------------------------------------------*/ { - LOG(1, "pcap: %s\n", pcap_lib_version()); + LOG(1, "pcap: %s\n", PCAP.lib_version()); LOG(2, "pcap:'%s': opening...\n", adapter_name); if (memcmp(adapter_name, "file:", 5) == 0) { LOG(1, "pcap: file: %s\n", adapter_name+5); is_pcap_file = 1; - adapter->pcap = pcap_open_offline( + adapter->pcap = PCAP.open_offline( adapter_name+5, /* interface name */ errbuf); } else { - adapter->pcap = pcap_open_live( + adapter->pcap = PCAP.open_live( adapter_name, /* interface name */ 65536, /* max packet size */ 8, /* promiscuous mode */ @@ -778,7 +780,7 @@ rawsock_init_adapter(const char *adapter_name, /* Figure out the link-type. We suport Ethernet and IP */ { - int dl = pcap_datalink(adapter->pcap); + int dl = PCAP.datalink(adapter->pcap); switch (dl) { case 1: /* Ethernet */ adapter->link_type = dl; @@ -788,13 +790,13 @@ rawsock_init_adapter(const char *adapter_name, break; default: LOG(0, "unknown data link type: %u(%s)\n", - dl, pcap_datalink_val_to_name(dl)); + dl, PCAP.datalink_val_to_name(dl)); break; } } - +#if 0 /* Set any BPF filters the user might've set */ if (bpf_filter) { int err; @@ -818,7 +820,7 @@ rawsock_init_adapter(const char *adapter_name, exit(1); } } - +#endif } diff --git a/src/siphash24.c b/src/siphash24.c index 4e7d21c0b492055974dbed2e110da19489653155..83f0c5023ac71f744bc56c3dd5ca395f5fb4c81e 100644 --- a/src/siphash24.c +++ b/src/siphash24.c @@ -72,7 +72,7 @@ static int crypto_auth( unsigned char *out, const unsigned char *in, unsigned lo for ( ; in != end; in += 8 ) { m = U8TO64_LE( in ); -#ifdef DEBUG +#ifdef xxxDEBUG printf( "(%3d) v0 %08x %08x\n", ( int )inlen, ( u32 )( v0 >> 32 ), ( u32 )v0 ); printf( "(%3d) v1 %08x %08x\n", ( int )inlen, ( u32 )( v1 >> 32 ), ( u32 )v1 ); printf( "(%3d) v2 %08x %08x\n", ( int )inlen, ( u32 )( v2 >> 32 ), ( u32 )v2 ); @@ -104,7 +104,7 @@ static int crypto_auth( unsigned char *out, const unsigned char *in, unsigned lo case 0: break; } -#ifdef DEBUG +#ifdef xxxDEBUG printf( "(%3d) v0 %08x %08x\n", ( int )inlen, ( u32 )( v0 >> 32 ), ( u32 )v0 ); printf( "(%3d) v1 %08x %08x\n", ( int )inlen, ( u32 )( v1 >> 32 ), ( u32 )v1 ); printf( "(%3d) v2 %08x %08x\n", ( int )inlen, ( u32 )( v2 >> 32 ), ( u32 )v2 ); @@ -115,7 +115,7 @@ static int crypto_auth( unsigned char *out, const unsigned char *in, unsigned lo SIPROUND; SIPROUND; v0 ^= b; -#ifdef DEBUG +#ifdef xxxDEBUG printf( "(%3d) v0 %08x %08x\n", ( int )inlen, ( u32 )( v0 >> 32 ), ( u32 )v0 ); printf( "(%3d) v1 %08x %08x\n", ( int )inlen, ( u32 )( v1 >> 32 ), ( u32 )v1 ); printf( "(%3d) v2 %08x %08x\n", ( int )inlen, ( u32 )( v2 >> 32 ), ( u32 )v2 ); diff --git a/xcode4/masscan.xcodeproj/project.pbxproj b/xcode4/masscan.xcodeproj/project.pbxproj index c9bc2bdcfdc3632df403ae2bceb70fa9a10e1cd7..17c5c10dbb2908a7301ec7b421e4be07734420f3 100644 --- a/xcode4/masscan.xcodeproj/project.pbxproj +++ b/xcode4/masscan.xcodeproj/project.pbxproj @@ -84,6 +84,9 @@ 11BA2967189055CA0064A759 /* script.c in Sources */ = {isa = PBXBuildFile; fileRef = 11BA2966189055CA0064A759 /* script.c */; }; 11BA29691890560C0064A759 /* script-ntp-monlist.c in Sources */ = {isa = PBXBuildFile; fileRef = 11BA29681890560C0064A759 /* script-ntp-monlist.c */; }; 11BA296B189060220064A759 /* proto-ntp.c in Sources */ = {isa = PBXBuildFile; fileRef = 11BA296A189060220064A759 /* proto-ntp.c */; }; + 11C936C31EDCE77F0023D32E /* in-filter.c in Sources */ = {isa = PBXBuildFile; fileRef = 11C936BF1EDCE77F0023D32E /* in-filter.c */; }; + 11C936C41EDCE77F0023D32E /* in-report.c in Sources */ = {isa = PBXBuildFile; fileRef = 11C936C11EDCE77F0023D32E /* in-report.c */; }; + 11C936C71EDCE8B40023D32E /* rawsock-pcap.c in Sources */ = {isa = PBXBuildFile; fileRef = 11C936C51EDCE8B40023D32E /* rawsock-pcap.c */; }; 11E76DB41889BC5200061F45 /* pixie-backtrace.c in Sources */ = {isa = PBXBuildFile; fileRef = 11E76DB21889BC5200061F45 /* pixie-backtrace.c */; }; 11F9375419F1A54200C1947F /* script-sslv3.c in Sources */ = {isa = PBXBuildFile; fileRef = 11F9375319F1A54200C1947F /* script-sslv3.c */; }; 11F9375719F1AD5000C1947F /* script-heartbleed.c in Sources */ = {isa = PBXBuildFile; fileRef = 11F9375619F1AD5000C1947F /* script-heartbleed.c */; }; @@ -247,6 +250,12 @@ 11BA29681890560C0064A759 /* script-ntp-monlist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "script-ntp-monlist.c"; sourceTree = ""; }; 11BA296A189060220064A759 /* proto-ntp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "proto-ntp.c"; sourceTree = ""; }; 11BA296C189060590064A759 /* proto-ntp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "proto-ntp.h"; sourceTree = ""; }; + 11C936BF1EDCE77F0023D32E /* in-filter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "in-filter.c"; sourceTree = ""; }; + 11C936C01EDCE77F0023D32E /* in-filter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "in-filter.h"; sourceTree = ""; }; + 11C936C11EDCE77F0023D32E /* in-report.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "in-report.c"; sourceTree = ""; }; + 11C936C21EDCE77F0023D32E /* in-report.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "in-report.h"; sourceTree = ""; }; + 11C936C51EDCE8B40023D32E /* rawsock-pcap.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "rawsock-pcap.c"; sourceTree = ""; }; + 11C936C61EDCE8B40023D32E /* rawsock-pcap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "rawsock-pcap.h"; sourceTree = ""; }; 11E76DB21889BC5200061F45 /* pixie-backtrace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "pixie-backtrace.c"; sourceTree = ""; }; 11E76DB31889BC5200061F45 /* pixie-backtrace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "pixie-backtrace.h"; sourceTree = ""; }; 11F9375319F1A54200C1947F /* script-sslv3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "script-sslv3.c"; sourceTree = ""; }; @@ -284,6 +293,12 @@ 11A9219217DBCC7E00DDFD32 /* src */ = { isa = PBXGroup; children = ( + 11C936C51EDCE8B40023D32E /* rawsock-pcap.c */, + 11C936C61EDCE8B40023D32E /* rawsock-pcap.h */, + 11C936BF1EDCE77F0023D32E /* in-filter.c */, + 11C936C01EDCE77F0023D32E /* in-filter.h */, + 11C936C11EDCE77F0023D32E /* in-report.c */, + 11C936C21EDCE77F0023D32E /* in-report.h */, 11126596197A086B00DC5987 /* out-unicornscan.c */, 11A773E91881BFC700B135DE /* crypto-base64.c */, 11A773EA1881BFC700B135DE /* crypto-base64.h */, @@ -514,6 +529,7 @@ 11A921EE17DBCC7E00DDFD32 /* rawsock-getip.c in Sources */, 11A921EF17DBCC7E00DDFD32 /* rawsock-getmac.c in Sources */, 11A921F017DBCC7E00DDFD32 /* rawsock-getroute.c in Sources */, + 11C936C41EDCE77F0023D32E /* in-report.c in Sources */, 11A921F117DBCC7E00DDFD32 /* rawsock-pcapfile.c in Sources */, 11A921F217DBCC7E00DDFD32 /* rawsock-pfring.c in Sources */, 11A921F317DBCC7E00DDFD32 /* rawsock.c in Sources */, @@ -541,6 +557,7 @@ 11A868181816F3A7008E00B8 /* out-redis.c in Sources */, 11A868191816F3A7008E00B8 /* pixie-file.c in Sources */, 11A8681A1816F3A7008E00B8 /* siphash24.c in Sources */, + 11C936C71EDCE8B40023D32E /* rawsock-pcap.c in Sources */, 11A8681E1819A6F7008E00B8 /* proto-zeroaccess.c in Sources */, 11B22ED518641DCC00DA5438 /* proto-banout.c in Sources */, 11B22ED618641DCC00DA5438 /* proto-ssl-test.c in Sources */, @@ -559,6 +576,7 @@ 11623F6A191E0DB00075EEE6 /* out-certs.c in Sources */, 11126597197A086B00DC5987 /* out-unicornscan.c in Sources */, 11420DD319A2D47A00DB5BFE /* proto-vnc.c in Sources */, + 11C936C31EDCE77F0023D32E /* in-filter.c in Sources */, 11420DD819A8160500DB5BFE /* proto-ftp.c in Sources */, 11420DDB19A84A9F00DB5BFE /* proto-smtp.c in Sources */, 11420DDE19A8FDE300DB5BFE /* proto-pop3.c in Sources */, @@ -592,7 +610,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.6; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; }; @@ -612,7 +630,7 @@ GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; + MACOSX_DEPLOYMENT_TARGET = 10.6; SDKROOT = macosx; }; name = Release;