From 45ccb4e4b9552c88a1d6c33d17c81833a2be5035 Mon Sep 17 00:00:00 2001 From: pdw <> Date: Fri, 18 Oct 2002 11:51:47 +0000 Subject: [PATCH] Various changes for portability to FreeBSD. Added "R" to control service resolution. --- Makefile | 2 +- addr_hash.h | 1 + iftop.c | 4 +++- iftop.h | 8 ++++++++ options.c | 1 + options.h | 1 + ui.c | 7 ++++++- 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a4b1c7f..4775fc6 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ MANDIR = man #MANDIR = share/man # FHS-ish # You shouldn't need to change anything below this point. -VERSION = 0.8 +VERSION = 0.9pre1 CFLAGS += -g -Wall "-DIFTOP_VERSION=\"$(VERSION)\"" LDFLAGS += -g LDLIBS += -lpcap -lpthread -lcurses -lm diff --git a/addr_hash.h b/addr_hash.h index 1289790..4593292 100644 --- a/addr_hash.h +++ b/addr_hash.h @@ -6,6 +6,7 @@ #ifndef __ADDR_HASH_H_ /* include guard */ #define __ADDR_HASH_H_ +#include #include #include #include diff --git a/iftop.c b/iftop.c index 6015a0a..24f63ec 100644 --- a/iftop.c +++ b/iftop.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -130,7 +132,7 @@ void assign_addr_pair(addr_pair* ap, struct ip* iptr, int flip) { unsigned short int dst_port = 0; /* Does this protocol use ports? */ - if(iptr->ip_p == SOL_TCP || iptr->ip_p == SOL_UDP) { + if(iptr->ip_p == IPPROTO_TCP || iptr->ip_p == IPPROTO_UDP) { /* We take a slight liberty here by treating UDP the same as TCP */ /* Find the TCP/UDP header */ diff --git a/iftop.h b/iftop.h index 7eda33a..0d01fee 100644 --- a/iftop.h +++ b/iftop.h @@ -33,4 +33,12 @@ void ui_init(void); /* options.c */ void options_read(int argc, char **argv); + +/* Make use of SIOCGIFHWADDR work on FreeBSD */ +#ifdef __BSD__ +#define SIOCGIFHWADDR SIOCGIFADDR +#define ifr_hwaddr ifr_addr +#endif + + #endif /* __IFTOP_H_ */ diff --git a/options.c b/options.c index d9729bf..c9f8a43 100644 --- a/options.c +++ b/options.c @@ -64,6 +64,7 @@ static void set_defaults() { inet_aton("10.0.1.0", &options.netfilternet); inet_aton("255.255.255.0", &options.netfiltermask); options.dnsresolution = 1; + options.portresolution = 1; options.promiscuous = 0; options.showbars = 1; options.showports = OPTION_PORTS_OFF; diff --git a/options.h b/options.h index b7dc81f..329e494 100644 --- a/options.h +++ b/options.h @@ -35,6 +35,7 @@ typedef struct { struct in_addr netfilternet; struct in_addr netfiltermask; int dnsresolution; + int portresolution; int promiscuous; int showbars; option_port_t showports; diff --git a/ui.c b/ui.c index e90b808..1cb268b 100644 --- a/ui.c +++ b/ui.c @@ -328,7 +328,7 @@ void sprint_host(char * line, struct in_addr* addr, unsigned int port, unsigned if(port != 0) { skey.port = port; skey.protocol = protocol; - if(hash_find(service_hash, &skey, (void**)&s_name) == HASH_STATUS_OK) { + if(options.portresolution && hash_find(service_hash, &skey, (void**)&s_name) == HASH_STATUS_OK) { snprintf(service, HOSTNAME_LENGTH, ":%s", s_name); } else { @@ -513,6 +513,11 @@ void ui_loop() { tick(1); break; + case 'R': + options.portresolution = !options.portresolution; + tick(1); + break; + case 'b': options.showbars = !options.showbars; tick(1);