Skip to content

Commit

Permalink
Merge pull request #5 from yalla/master
Browse files Browse the repository at this point in the history
Added OSX support
  • Loading branch information
caesar0301 committed Mar 1, 2014
2 parents 846a402 + bbe565e commit 60e0bc0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
18 changes: 2 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# Object files
.sconsign.dblite
pkt2flow
*.o

# Libraries
*.lib
*.a

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ You can follow simple steps to make a compile:
$ scons


How to install (optional)
----------

You can optionally let scons automatically handle the installation for you by
providing an installation prefix, e.g.:

$ PREFIX=/usr/local
$ scons --prefix=$PREFIX install

This will build pkt2flow and install the binary to /usr/local/bin/pkt2flow.
Depending on where you want to install it, you might need to use sudo or
become the appropriate user.

Usage
--------

Expand Down
30 changes: 28 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
#!/usr/bin/evn python
#!/usr/bin/env python

import sys
env = Environment(CCFLAGS='-Wall -g', CPPFLAGS='-D_GNU_SOURCE')

AddOption('--prefix',
dest='prefix',
nargs=1, type='string',
action='store',
metavar='DIR',
help='installation prefix')
env = Environment(PREFIX = GetOption('prefix'))

idir_prefix = '$PREFIX'
idir_bin = '$PREFIX/bin'

Export('env idir_prefix idir_bin')

platform = sys.platform
lib_path = ['/usr/local/lib', '/usr/lib']
libs = Glob('./*.a') + ['pcap']
cpp_path=['.']

if platform == 'darwin':
env.Append(CPPFLAGS=['-Ddarwin'])

# Compile the programs
env.Program(target = './pkt2flow',
pkt2flow = env.Program(target = './pkt2flow',
source = Glob('./*.c'),
LIBPATH = lib_path,
LIBS = libs,
CPPPATH = cpp_path)

# install the program
env.Install(dir = idir_bin, source = pkt2flow)

# create an install alias
env.Alias('install', idir_prefix)
14 changes: 14 additions & 0 deletions pkt2flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,33 @@ static int pcap_handle_layer4(struct af_6tuple *af_6tuple, const u_char *bytes,

udphdr = (struct udphdr *)bytes;
af_6tuple->protocol = IPPROTO_UDP;
#ifdef darwin
af_6tuple->port1 = ntohs(udphdr->uh_sport);
af_6tuple->port2 = ntohs(udphdr->uh_dport);
#else
af_6tuple->port1 = ntohs(udphdr->source);
af_6tuple->port2 = ntohs(udphdr->dest);
#endif
return 0;
case IPPROTO_TCP:
if (len < sizeof(*tcphdr))
return -1;

tcphdr = (struct tcphdr *)bytes;
af_6tuple->protocol = IPPROTO_TCP;
#ifdef darwin
af_6tuple->port1 = ntohs(tcphdr->th_sport);
af_6tuple->port2 = ntohs(tcphdr->th_dport);
#else
af_6tuple->port1 = ntohs(tcphdr->source);
af_6tuple->port2 = ntohs(tcphdr->dest);
#endif

#ifdef darwin
if (tcphdr->th_flags == TH_SYN)
#else
if (tcphdr->syn)
#endif
return 1;
else
return 0;
Expand Down

0 comments on commit 60e0bc0

Please sign in to comment.