Skip to content

Commit

Permalink
Added OSX support; uses different tcphdr/udphdt structs
Browse files Browse the repository at this point in the history
  • Loading branch information
yalla committed Feb 27, 2014
1 parent 846a402 commit 2f22281
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
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 2f22281

Please sign in to comment.