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;