Merge pull request #87 from h-ume/freebsd

Support for FreeBSD
This commit is contained in:
Arnout Engelen
2016-05-16 20:29:25 +02:00
11 changed files with 28 additions and 10 deletions

View File

@@ -11,7 +11,7 @@ NetHogs is a small 'net top' tool. Instead of breaking the traffic down per prot
NetHogs does not rely on a special kernel module to be loaded. If there's suddenly a lot of network traffic, you can fire up NetHogs and immediately see which PID is causing this. This makes it easy to identify programs that have gone wild and are suddenly taking up your bandwidth.
Since NetHogs heavily relies on `/proc`, most features are only available on Linux.
NetHogs can be built on Mac OS X, but it will only show connections, not processes.
NetHogs can be built on Mac OS X and FreeBSD, but it will only show connections, not processes.
Status
------

View File

@@ -1,6 +1,15 @@
all:
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),FreeBSD)
ifeq ($(PREFIX),/usr/local)
man8 := $(PREFIX)/man/man8
else
man8 := $(PREFIX)/share/man/man8
endif
else
man8 := $(PREFIX)/share/man/man8
endif
install: nethogs.8
install -d -m 755 $(DESTDIR)$(man8)

View File

@@ -10,6 +10,8 @@ all: $(LIBNAME) libnethogs.a
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDFLAGS:= -shared -Wl,-soname,$(SO_NAME)
else ifeq ($(UNAME_S),FreeBSD)
LDFLAGS:= -shared -Wl,-soname,$(SO_NAME)
else
LDFLAGS:= -shared -Wl,-install_name,$(SO_NAME)
endif

View File

@@ -24,6 +24,8 @@
#include <cassert>
#ifdef __APPLE__
#include <sys/malloc.h>
#elif __FreeBSD__
#include <stdlib.h>
#else
#include <malloc.h>
#endif

View File

@@ -28,7 +28,7 @@
#include "nethogs.h"
#include "conninode.h"
#if defined __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
#ifndef s6_addr32
#define s6_addr32 __u6_addr.__u6_addr32
#endif
@@ -183,7 +183,7 @@ void refreshconninode() {
// delete conninode;
// conninode = new HashTable (256);
#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__FreeBSD__)
addprocinfo("net.inet.tcp.pcblist");
#else
if (!addprocinfo("/proc/net/tcp")) {

View File

@@ -13,7 +13,7 @@ int main() {
return 2;
}
#if not defined(__APPLE__)
#if !defined(__APPLE__) && !defined(__FreeBSD__)
if (!addprocinfo("/proc/net/tcp")) {
std::cerr << "Failed to load /proc/net/tcp" << std::endl;
return 3;

View File

@@ -20,6 +20,7 @@
*
*/
#include <sys/types.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <netinet/in.h>

View File

@@ -119,7 +119,7 @@ int process_tcp(u_char *userdata, const dp_header *header,
Packet *packet;
switch (args->sa_family) {
case AF_INET:
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
packet = new Packet(args->ip_src, ntohs(tcp->th_sport), args->ip_dst,
ntohs(tcp->th_dport), header->len, header->ts);
#else
@@ -128,7 +128,7 @@ int process_tcp(u_char *userdata, const dp_header *header,
#endif
break;
case AF_INET6:
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
packet = new Packet(args->ip6_src, ntohs(tcp->th_sport), args->ip6_dst,
ntohs(tcp->th_dport), header->len, header->ts);
#else
@@ -168,7 +168,7 @@ int process_udp(u_char *userdata, const dp_header *header,
Packet *packet;
switch (args->sa_family) {
case AF_INET:
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
packet = new Packet(args->ip_src, ntohs(udp->uh_sport), args->ip_dst,
ntohs(udp->uh_dport), header->len, header->ts);
#else
@@ -177,7 +177,7 @@ int process_udp(u_char *userdata, const dp_header *header,
#endif
break;
case AF_INET6:
#ifdef __APPLE__
#if defined(__APPLE__) || defined(__FreeBSD__)
packet = new Packet(args->ip6_src, ntohs(udp->uh_sport), args->ip6_dst,
ntohs(udp->uh_dport), header->len, header->ts);
#else

View File

@@ -31,6 +31,8 @@
#include <cstring>
#ifdef __APPLE__
#include <sys/malloc.h>
#elif __FreeBSD__
#include <stdlib.h>
#else
#include <malloc.h>
#endif

View File

@@ -28,6 +28,8 @@
#include <netinet/in.h>
#ifdef __APPLE__
#include <sys/malloc.h>
#elif __FreeBSD__
#include <stdlib.h>
#else
#include <malloc.h>
#endif

View File

@@ -24,7 +24,7 @@
#include <strings.h>
#include <string>
#include <ncurses.h>
#ifndef __APPLE__
#if !defined(__APPLE__) && !defined(__FreeBSD__)
#include <asm/types.h>
#endif
#include <sys/types.h>