1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include "record.ih"
Record::Record(Type type, size_t seconds, size_t muSeconds,
u_char const *packet)
:
d_protocol(static_cast<Protocol>(get<IP_Header>(packet).protocol)),
d_type(type),
d_seconds(seconds),
d_microSeconds(muSeconds),
d_inSeconds(seconds),
d_inMicroSeconds(muSeconds),
d_sourceIP(get<IP_Header>(packet).sourceAddr.s_addr),
d_destIP(get<IP_Header>(packet).destAddr.s_addr),
d_lastUsed(::time(0))
{
++s_count;
size_t headerLength = size_t(get<IP_Header>(packet).hdrLength << 2);
size_t ipLength = ntohs(get<IP_Header>(packet).length);
// 4 most significant bits: # 32 bit words
// so: shr 4 to het the # 32 bit words, and
// << 2 to multiply by 4 to get the #bytes before the data
size_t dataOffset = size_t(get<TCP_Header>(packet).dataOffset >> 4 << 2);
switch (protocol())
{
case ICMP:
setIDKey(ntohs(get<ICMP_Header>(packet).ident),
ntohs(get<ICMP_Header>(packet).seqnum));
d_payload = ipLength - headerLength;
break;
case UDP:
{
setPorts(
ntohs(get<UDP_Header>(packet).sourcePort),
ntohs(get<UDP_Header>(packet).destPort)
);
d_id = ntohs(get<IP_Header>(packet).identification);
d_payload = ntohs(get<UDP_Header>(packet).length)
- sizeof(UDP_Header);
}
break;
case TCP:
setPorts(
ntohs(get<UDP_Header>(packet).sourcePort),
ntohs(get<UDP_Header>(packet).destPort)
);
d_id = get<TCP_Header>(packet).sequenceNr;
d_flags = get<TCP_Header>(packet).flags;
d_payload = ipLength - headerLength - dataOffset;
break;
}
}
|