Skip to content

Commit

Permalink
API change: return {pkthdr, list()}
Browse files Browse the repository at this point in the history
Somehow the second element of the tagged pkthdr tuple was a tuple rather
than a proplist. I blame my keyboard: must've typed a { instead of a [ ...
and a ei_x_encode_tuple_header instead of ei_x_encode_list_header() <.<

This is a backwards incompatible change. The idea was that the tuple was
like the pkthdr struct and so was ordered and tagged with the field name.
The list is still ordered but can be used as a proplist.
  • Loading branch information
msantos committed Mar 9, 2011
1 parent 3d82ba6 commit 89c2264
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions c_src/epcap.c
Expand Up @@ -228,12 +228,12 @@ epcap_response(struct pcap_pkthdr *hdr, const u_char *pkt, unsigned int datalink
IS_FALSE(ei_x_new_with_version(&msg));
IS_FALSE(ei_x_encode_list_header(&msg, 2));

/* {pkthdr, {{time, Time}, {caplen, CapLength}, {len, ActualLength}}} */
/* {pkthdr, [{time, Time}, {caplen, CapLength}, {len, ActualLength}]} */
IS_FALSE(ei_x_encode_tuple_header(&msg, 2));
IS_FALSE(ei_x_encode_atom(&msg, "pkthdr"));

/* { */
IS_FALSE(ei_x_encode_tuple_header(&msg, 4));
/* [ */
IS_FALSE(ei_x_encode_list_header(&msg, 4));

/* {time, {MegaSec, Sec, MicroSec}} */
IS_FALSE(ei_x_encode_tuple_header(&msg, 2));
Expand All @@ -259,6 +259,9 @@ epcap_response(struct pcap_pkthdr *hdr, const u_char *pkt, unsigned int datalink
IS_FALSE(ei_x_encode_atom(&msg, "datalink"));
IS_FALSE(ei_x_encode_long(&msg, datalink));

/* ] */
IS_FALSE(ei_x_encode_empty_list(&msg));

/* } */

/* {packet, Packet} */
Expand Down
7 changes: 4 additions & 3 deletions src/sniff.erl
Expand Up @@ -81,14 +81,15 @@ handle_sync_event(_Event, _From, StateName, State) ->
%% State: sniffing
%%
handle_info([
{pkthdr, {{time, Time}, {caplen, CapLen}, {len, Len}}},
{pkthdr, [{time, Time}, {caplen, CapLen}, {len, Len}, {datalink, DLT}]},
{packet, Packet}
], sniffing, _) ->
[Ether, IP, Hdr, Payload] = pkt:decapsulate(Packet),
error_logger:info_report([
{time, timestamp(Time)},
{caplen,CapLen},
{len,Len},
{caplen, CapLen},
{len, Len},
{datalink, DLT},

% Source
{source_macaddr, string:join(ether_addr(Ether#ether.shost), ":")},
Expand Down

0 comments on commit 89c2264

Please sign in to comment.