From 2f22281c648aa65fe9550ba48978a583dc49b758 Mon Sep 17 00:00:00 2001 From: "Alexander W. Janssen" Date: Thu, 27 Feb 2014 11:14:12 +0100 Subject: [PATCH 1/8] Added OSX support; uses different tcphdr/udphdt structs --- SConstruct | 5 +++++ pkt2flow.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/SConstruct b/SConstruct index 1280c63..54309b2 100755 --- a/SConstruct +++ b/SConstruct @@ -1,9 +1,14 @@ #!/usr/bin/evn python +import sys env = Environment(CCFLAGS='-Wall -g', CPPFLAGS='-D_GNU_SOURCE') +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', source = Glob('./*.c'), diff --git a/pkt2flow.c b/pkt2flow.c index 27775d8..dbe4655 100644 --- a/pkt2flow.c +++ b/pkt2flow.c @@ -199,8 +199,13 @@ 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)) @@ -208,10 +213,19 @@ static int pcap_handle_layer4(struct af_6tuple *af_6tuple, const u_char *bytes, 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; From a55b934f4546801a1baf217e173a14070a977507 Mon Sep 17 00:00:00 2001 From: "Alexander W. Janssen" Date: Thu, 27 Feb 2014 11:18:58 +0100 Subject: [PATCH 2/8] Added OSX support; uses different tcphdr/udphdt structs, removed .gitignore from push --- .gitignore | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0331bbb..0000000 --- a/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -# Object files -*.o - -# Libraries -*.lib -*.a - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app From 019c0ad899c88a3ed2bdf0d72c578e680f66f82f Mon Sep 17 00:00:00 2001 From: Kristian Koehntopp Date: Thu, 27 Feb 2014 14:06:00 +0100 Subject: [PATCH 3/8] added install target --- SConstruct | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 54309b2..4ea7183 100755 --- a/SConstruct +++ b/SConstruct @@ -10,8 +10,14 @@ 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 = "/usr/local/bin", source = pkt2flow) + +# create an install alias +env.Alias('install', ['/usr/local/bin']) From 2b5192923cc03ff884b4c30376041787cac93419 Mon Sep 17 00:00:00 2001 From: Kristian Koehntopp Date: Thu, 27 Feb 2014 14:06:09 +0100 Subject: [PATCH 4/8] added .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b2d462 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.sconsign.dblite From 926f6cebe42dab6237aaa66309ddf1b5578c0fda Mon Sep 17 00:00:00 2001 From: Kristian Koehntopp Date: Thu, 27 Feb 2014 14:51:59 +0100 Subject: [PATCH 5/8] build with install prefix dir --- SConstruct | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 4ea7183..5ee7dec 100755 --- a/SConstruct +++ b/SConstruct @@ -1,6 +1,20 @@ -#!/usr/bin/evn python +#!/usr/bin/env python + import sys env = Environment(CCFLAGS='-Wall -g', CPPFLAGS='-D_GNU_SOURCE') + +opts = Variables('pkt2flow.conf') +opts.Add(PathVariable('PREFIX', 'Directory to install under', '/usr/local', PathVariable.PathIsDir)) +opts.Update(env) +opts.Save('pkt2flow.conf', env) + +Help(opts.GenerateHelpText(env)) + +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'] @@ -17,7 +31,7 @@ pkt2flow = env.Program(target = './pkt2flow', CPPPATH = cpp_path) # install the program -env.Install(dir = "/usr/local/bin", source = pkt2flow) +env.Install(dir = idir_bin, source = pkt2flow) # create an install alias -env.Alias('install', ['/usr/local/bin']) +env.Alias('install', idir_prefix) From 5d49a20b492441a9ed40190c58d5361a686cdce8 Mon Sep 17 00:00:00 2001 From: Kristian Koehntopp Date: Thu, 27 Feb 2014 14:58:43 +0100 Subject: [PATCH 6/8] add --prefix build option as required for homebrew --- SConstruct | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 5ee7dec..80744aa 100755 --- a/SConstruct +++ b/SConstruct @@ -3,12 +3,13 @@ import sys env = Environment(CCFLAGS='-Wall -g', CPPFLAGS='-D_GNU_SOURCE') -opts = Variables('pkt2flow.conf') -opts.Add(PathVariable('PREFIX', 'Directory to install under', '/usr/local', PathVariable.PathIsDir)) -opts.Update(env) -opts.Save('pkt2flow.conf', env) - -Help(opts.GenerateHelpText(env)) +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' From 077f27831985f67a768e5ffcab046c20b17c2769 Mon Sep 17 00:00:00 2001 From: Kristian Koehntopp Date: Thu, 27 Feb 2014 14:59:02 +0100 Subject: [PATCH 7/8] ignore build products in git status --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5b2d462..64226fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .sconsign.dblite +pkt2flow +*.o From bbe565efbe2c267b3f0ea34622d8156ba8383c83 Mon Sep 17 00:00:00 2001 From: "Alexander W. Janssen" Date: Sat, 1 Mar 2014 08:27:12 +0100 Subject: [PATCH 8/8] Merged scons installation target from isotopp/pkt2flow; added installation notes to README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 337e32a..8c2d2ac 100644 --- a/README.md +++ b/README.md @@ -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 --------