Azinix

pkt.h File Reference

Packet data structures. More...

#include "nm.h"

Go to the source code of this file.

Data Structures

struct  Pkt_EthernetHdr_t
 Ethernet Packet Header. More...
struct  Pkt_WifiHdr_t
 use for wlan detection More...
struct  Pkt_IpHdr_t
 IP Packet header. More...
struct  Pkt_TcpHdr_t
 TCP Packet header. More...
struct  Pkt_UdpHdr_t
 UDP Packet header. More...
struct  Pkt_IcmpHdr_t
 ICMP packet header. More...
struct  Pkt_IpFlags_t
 Packed bit-fields for ip frag flags, offset. More...
struct  Pkt_TcpResDoffFlags_t
 Packed bit-fields for tcp flags, offset, etc. More...
struct  Pkt_L4Flow_t
 Layer 4 flow captured by 4 fields - source/dest IP, source/dest TCP ports. More...
struct  Pkt_LibNet_t
 An encapsulation of the libnet_t structure. More...
struct  Pkt_LibPcap_t
 An encapsulation of the libpcap_t structure. More...
struct  Pkt_VectorBuff_t
 Useful for passing sets of packets around. More...
struct  Pkt_ProcessPkt_t
 Packet and rules that are to be applied. More...
struct  Pkt_TfcMode_t
 Structure encapsulating settings for Pkt_CreateRandEthPktArray. More...

Typedefs

typedef Pkt_EthernetHdr_t Pkt_EthernetHdr_t
typedef Pkt_WifiHdr_t Pkt_WifiHdr_t
typedef Pkt_IpHdr_t Pkt_IpHdr_t
typedef Pkt_TcpHdr_t Pkt_TcpHdr_t
typedef Pkt_UdpHdr_t Pkt_UdpHdr_t
typedef Pkt_IcmpHdr_t Pkt_IcmpHdr_t
typedef Pkt_L4Flow_t Pkt_L4Flow_t
typedef Pkt_LibNet_t Pkt_LibNet_t
typedef Pkt_LibPcap_t Pkt_LibPcap_t
typedef Pkt_VectorBuff_t Pkt_VectorBuff_t
typedef Pkt_ProcessPkt_t Pkt_ProcessPkt_t
typedef Pkt_TfcMode_t Pkt_TfcMode_t

Enumerations

enum  Pkt_L3ProtType_t {
  Pkt_L3ProtIp_c = 0x0008, Pkt_L3ProtComp_c = 0x0009, Pkt_L3ProtArp_c = 0x0608, Pkt_L3ProtRarp_c = 0x3580,
  Pkt_L3ProtUndef_c = 0x0000
}
 Types of layer 3 protocols in host order. More...
enum  Pkt_L4ProtType_t {
  Pkt_L4ProtTcp_c = 6, Pkt_L4ProtUdp_c = 17, Pkt_L4ProtIcmp_c = 1, Pkt_L4ProtIgmp_c = 2,
  Pkt_L4ProtRsvp_c = 46, Pkt_L4ProtIPv6_c = 41, Pkt_L4ProtPIM_c = 103, Pkt_L4ProtRaw_c = 255,
  Pkt_L4ProtUndef_c = 0
}
 Types of layer 4 protocols. More...
enum  Pkt_FlowType_t {
  Pkt_SrcIpFlow_c, Pkt_DestIpFlow_c, Pkt_SrcDestIpFlow_c, Pkt_SrcDestTcpIpFlow_c,
  Pkt_DestTcpIpFlow_c
}
 Types of flows. More...
enum  Pkt_ByteOrder_t { Pkt_HostByteOrder_c, Pkt_NetworkByteOrder_c }
 Types of byte-orders. More...
enum  Pkt_TcpFlags_t {
  Pkt_TcpFin_c, Pkt_TcpSyn_c, Pkt_TcpRst_c, Pkt_TcpPsh_c,
  Pkt_TcpAck_c, Pkt_TcpUrg_c, Pkt_TcpEce_c, Pkt_TcpCwr_c
}
 Types of TCP flags. More...

Functions

Pkt_IpHdr_tPkt_EthernetExtractIp (Pkt_EthernetHdr_t *ethPkt)
 Extract the Ip component from an Ethernet packet.
int Pkt_EthernetPktHdrReadLengthNetworkOrder (Pkt_EthernetHdr_t *pkt)
 Return the length of the Ethernet packet, including header.
int Pkt_EthernetPktHdrReadLength (Pkt_EthernetHdr_t *pkt)
 Return the length of the Ethernet packet, including header.
int Pkt_EthernetHdrFree (Pkt_EthernetHdr_t *pkt)
 Free an Ethernet packet.
int Pkt_ProcessPktFree (Pkt_ProcessPkt_t *pp)
 Free an ProcessPkt structure.
Pkt_IcmpHdr_tPkt_IpExtractIcmp (Pkt_IpHdr_t *anIpPkt)
 Extract the Icmp component from an Ip packet.
Pkt_UdpHdr_tPkt_IpExtractUdp (Pkt_IpHdr_t *anIpPkt)
 Extract the Udp component from an Ip packet.
Pkt_TcpHdr_tPkt_IpExtractTcp (Pkt_IpHdr_t *anIpPkt)
 Extract the Tcp component from an Ip packet.
char * Pkt_IpExtractPayload (Pkt_IpHdr_t *anIpPkt)
 Extract the payload component from an Ip packet.
Pkt_UdpHdr_tPkt_EthernetExtractUdp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Tcp component from an Ethernet packet.
Pkt_TcpHdr_tPkt_EthernetExtractTcp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Tcp component from an Ethernet packet.
Pkt_IcmpHdr_tPkt_EthernetExtractIcmp (Pkt_EthernetHdr_t *aEthernetPkt)
 Extract the Icmp component from an Ethernet packet.
char * Pkt_UdpHdrReadPayload (Pkt_UdpHdr_t *aUdpPkt)
 Returns a pointer to the payload of a UDP packet.
char * Pkt_TcpHdrReadPayload (Pkt_TcpHdr_t *aTcpPkt)
 Returns a pointer to the payload of a TCP packet.
int Pkt_SrcIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two src ip flows Returns -1, 0, 1 a la strcmp.
int Pkt_DestIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two dest ip flows Returns -1, 0 , 1.
int Pkt_SrcDestIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two src-dest ip flows Returns -1,0,1 a la strcmp.
int Pkt_DestTcpIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two dest tcp-Ip flows. Returns -1, 0, 1 a la strcmp.
int Pkt_SrcIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a src-ip flow.
int Pkt_DestIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a dest-ip.
int Pkt_SrcDestIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a src-dest ip flow.
int Pkt_DestTcpIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a dest tcp-Ip flow.
int Pkt_SrcDestTcpIpFlowHash (Pkt_EthernetHdr_t *pkt1, int modulus)
 Hash a tcp-Ip flow.
int Pkt_SrcDestTcpIpFlowCmp (Pkt_EthernetHdr_t *pkt1, Pkt_EthernetHdr_t *pkt2)
 Compare two Tcp-Ip flows. Returns -1, 0, 1 a la strcmp.
int Pkt_L4FlowCompareForSt (Pkt_L4Flow_t *foo, Pkt_L4Flow_t *bar)
 Compare function for an L4 flow struct for the st package, returns 0 for equal, 1 for unequal.
int Pkt_L4FlowCompare (Pkt_L4Flow_t *foo, Pkt_L4Flow_t *bar)
 Compare function for an L4 flow struct - 1 for equal, 0 for unequal.
int Pkt_L4FlowHashForSt (Pkt_L4Flow_t *anL4Flow_t, int modulus)
 Hash function for an L4 flow struct with modulus argument.
unsigned int Pkt_L4FlowHash (Pkt_L4Flow_t *anL4Flow_t)
 Hash function for an L4 flow struct.
Pkt_L4Flow_tPkt_EthPktToL4Flow (Pkt_EthernetHdr_t *anEthPkt)
 Create a L4 flow structure from an Ethernet packet.
Pkt_L4Flow_tPkt_IpPktToL4Flow (Pkt_IpHdr_t *anIpPkt)
 Create a L4 flow structure from an Ip packet.
int Pkt_EthernetReadL3Type (Pkt_EthernetHdr_t *anEth)
 Return the L3 type of an ethernet packet.
int Pkt_PrintEthernet (Pkt_EthernetHdr_t *anEthPkt, int length)
 Print an Ethernet packet.
int Pkt_PrintWifi (Pkt_WifiHdr_t *aWifiPkt)
 Print a Wifi packet.
int Pkt_PrintIp (Pkt_IpHdr_t *anIpPkt)
 Print an Ip Pkt, given in network order.
void Pkt_PrintIpAddressDotted (u_int32_t aNumIp)
 Print an Ip address in 1.2.3.4 format.
void Pkt_PrintIpAddressDottedGeneral (char *, u_int32_t aNumIp)
 Print an Ip address in 1.2.3.4 format.
Pkt_ProcessPkt_tPkt_AllocateProcessPacket (Pkt_EthernetHdr_t *pkt, array_t *applicableRules)
 Allocate a process-packet structure.
int Pkt_DeviceSkb ()
Pkt_VectorBuff_tPkt_SocketVectorWrite (int count)
int Pkt_EthPacketWriteToFile (int fd, Pkt_EthernetHdr_t *anEthPkt, unsigned int length)
 Write an ethernet frame to file. File is assumed to be open and writable. Format: length followed by sequence of bytes.
int Pkt_EthPacketReadFromFile (int fd, Pkt_EthernetHdr_t **anEthPktPtr)
 Read an Ethernet frame from a file Returns NIL if the file is empty, and otherwise a pointer to the frame. Caller is responsible for freeing the memory allocated for the frame.
array_tPkt_CreatePktsFromString (char *pktFile)
 Create a packets from a textual description.
Pkt_EthernetHdr_tPkt_CreatePktFromString (char *pktString)
 Create single packet from string.
int Pkt_Init (char *ifName, int numRounds, int markPoint)
Pkt_LibNet_tPkt_InitLibNet (char *interfaceName)
 Routine for creating an encapsulation of the libnet data structures.
int Pkt_LibNetFinish (Pkt_LibNet_t *obj)
 Finish using a Pkt_LibNet_t struct.
int Pkt_EthPktWrite (Pkt_EthernetHdr_t *anEth, int anEthLength, Pkt_LibNet_t *aNetObj)
 Transmit a raw ethernet frame.
array_tPkt_InitLibPcapArray (array_t *inArray)
 Initialize an array of pcap objects, one per array entry.
array_tPkt_InitLibNetArray (array_t *outArray)
 Initialize an array of libnet objects, one per array entry.
Pkt_LibPcap_tPkt_InitLibPcap (char *interfaceName)
 Initialize our encapsulation of a pcap_t.
int Pkt_LibPcapFinish (Pkt_LibPcap_t *obj)
 Finish using a Pkt_LibPcap_t struct.
util_byte_array_tPkt_CreateIcmpPkt (array_t *typeArray, array_t *codeArray, array_t *idArray, array_t *seqArray)
 Create an ICMP packet.
util_byte_array_tPkt_CreateUdpPkt (array_t *srcPorts, array_t *destPorts, array_t *sizes, array_t *byteStrings)
 Create a UDP packet.
util_byte_array_tPkt_CreateTcpPkt (array_t *srcPorts, array_t *destPorts, array_t *seqNums, array_t *ackNums, st_table *flags, array_t *sizes, array_t *byteStrings)
 Create a TCP packet.
util_byte_array_tPkt_CreateIpPkt (array_t *srcIps, array_t *destIps, st_table *ipFlagsTable, array_t *offsets, array_t *ids, st_table *ipOptions, array_t *ttls, util_byte_array_t *l4Payload, int l4Protocol)
 Create a IP packet.
Pkt_EthernetHdr_tPkt_CreateEthPkt (char *srcMac, char *destMac, util_byte_array_t *l3Payload, u_int16_t l3Protocol)
 Create Ethernet packet with given params.
Pkt_EthernetHdr_tPkt_CreateRandEthPkt (array_t *tmpArray)
 Create a random ethernet packet.
array_tPkt_SeedRandEthPktArray (Pkt_ByteOrder_t byteOrder, int numSeeds, Pkt_TfcMode_t *tfcMode)
 Create a random ethernet packet; only tcp for now.
void Pkt_HTON (Pkt_EthernetHdr_t *anEth)
 Take an ethernet packet and convert it to network order.
void Pkt_NTOH (Pkt_EthernetHdr_t *anEth)
 Take an ethernet packet and convert it to host order.
int Rlp_UpdateDefineTable (st_table *aTable, char *anEntry)
 Adds a mapping from a macro name to definition.
array_tRlp_L7StringParse (char *l7Rule)
 Parse a string encoding a Layer 7 formula.
u_int32_t Rlp_DotToInt (char *)
 Convert a string in dotted decimal notation to an unsigned 32 bit int.


Detailed Description

Packet data structures.

Definition in file pkt.h.


Typedef Documentation

typedef struct Pkt_EthernetHdr_t Pkt_EthernetHdr_t

Definition at line 79 of file pkt.h.

typedef struct Pkt_IcmpHdr_t Pkt_IcmpHdr_t

Definition at line 354 of file pkt.h.

typedef struct Pkt_IpHdr_t Pkt_IpHdr_t

Definition at line 208 of file pkt.h.

typedef struct Pkt_L4Flow_t Pkt_L4Flow_t

Definition at line 405 of file pkt.h.

typedef struct Pkt_LibNet_t Pkt_LibNet_t

Definition at line 419 of file pkt.h.

typedef struct Pkt_LibPcap_t Pkt_LibPcap_t

Definition at line 437 of file pkt.h.

typedef struct Pkt_ProcessPkt_t Pkt_ProcessPkt_t

Definition at line 472 of file pkt.h.

typedef struct Pkt_TcpHdr_t Pkt_TcpHdr_t

Definition at line 302 of file pkt.h.

typedef struct Pkt_TfcMode_t Pkt_TfcMode_t

Definition at line 488 of file pkt.h.

typedef struct Pkt_UdpHdr_t Pkt_UdpHdr_t

Definition at line 323 of file pkt.h.

typedef struct Pkt_VectorBuff_t Pkt_VectorBuff_t

Definition at line 451 of file pkt.h.

typedef struct Pkt_WifiHdr_t Pkt_WifiHdr_t

Definition at line 97 of file pkt.h.


Enumeration Type Documentation

enum Pkt_ByteOrder_t

Types of byte-orders.

Only two possibilities: host or network.

Enumerator:
Pkt_HostByteOrder_c 
Pkt_NetworkByteOrder_c 

Definition at line 233 of file pkt.h.

enum Pkt_FlowType_t

Types of flows.

Missing a number of cases - e.g., udp, icmp.

Enumerator:
Pkt_SrcIpFlow_c 
Pkt_DestIpFlow_c 
Pkt_SrcDestIpFlow_c 
Pkt_SrcDestTcpIpFlow_c 
Pkt_DestTcpIpFlow_c 

Definition at line 217 of file pkt.h.

enum Pkt_L3ProtType_t

Types of layer 3 protocols in host order.

See also:
/usr/include/linux/if_eth.h
Enumerator:
Pkt_L3ProtIp_c 
Pkt_L3ProtComp_c 
Pkt_L3ProtArp_c 
Pkt_L3ProtRarp_c 
Pkt_L3ProtUndef_c 

Definition at line 22 of file pkt.h.

enum Pkt_L4ProtType_t

Types of layer 4 protocols.

See also:
/usr/include/linux/in.h
Enumerator:
Pkt_L4ProtTcp_c 
Pkt_L4ProtUdp_c 
Pkt_L4ProtIcmp_c 
Pkt_L4ProtIgmp_c 
Pkt_L4ProtRsvp_c 
Pkt_L4ProtIPv6_c 
Pkt_L4ProtPIM_c 
Pkt_L4ProtRaw_c 
Pkt_L4ProtUndef_c 

Definition at line 38 of file pkt.h.

enum Pkt_TcpFlags_t

Types of TCP flags.

Their numbering is in the order they appear in the header.

Enumerator:
Pkt_TcpFin_c 
Pkt_TcpSyn_c 
Pkt_TcpRst_c 
Pkt_TcpPsh_c 
Pkt_TcpAck_c 
Pkt_TcpUrg_c 
Pkt_TcpEce_c 
Pkt_TcpCwr_c 

Definition at line 246 of file pkt.h.


Function Documentation

Pkt_ProcessPkt_t* Pkt_AllocateProcessPacket ( Pkt_EthernetHdr_t pkt,
array_t applicableRules 
)

Allocate a process-packet structure.

Definition at line 790 of file pkt.c.

Pkt_EthernetHdr_t* Pkt_CreateEthPkt ( char *  srcMac,
char *  destMac,
util_byte_array_t l3Payload,
u_int16_t  l3Protocol 
)

Create Ethernet packet with given params.

Definition at line 604 of file pktTfc.c.

util_byte_array_t* Pkt_CreateIcmpPkt ( array_t typeArray,
array_t codeArray,
array_t idArray,
array_t seqArray 
)

Create an ICMP packet.

See also:
Pkt_CreateTcpPkt

Definition at line 44 of file pktTfc.c.

util_byte_array_t* Pkt_CreateIpPkt ( array_t srcIps,
array_t destIps,
st_table ipFlagsTable,
array_t offsets,
array_t ids,
st_table ipOptions,
array_t ttls,
util_byte_array_t l4Payload,
int  l4Protocol 
)

Create a IP packet.

User defines the "interesting" source and dest IP addresses. If any of these arrays are empty, we take the corresponding field to be unconstrained.

Payload is constructed by calling function, which is responsible for freeing it.

Definition at line 476 of file pktTfc.c.

Pkt_EthernetHdr_t* Pkt_CreatePktFromString ( char *  pktString  ) 

Create single packet from string.

Just calls Pkt_CreatePktsFromString and makes sure there is just one entry in the returned array, and returns that entry.

Definition at line 175 of file pktFile.c.

array_t* Pkt_CreatePktsFromString ( char *  pktFile  ) 

Create a packets from a textual description.

See also:
Pkt_CreateRandIpPkt
Format
  protocol: ip, udp, tcp, icmp
  offset is from 0 to 2^13 - 1
  ttl is from 0 to 255
  ipflag:RB,DF,MF (one of)
  tcpflag:fin,syn,rst,psh,ack,urg,ece,cwr  (one of)
  ipoptions:EOOL,NOP,SEC,LSR,TS,E-SEC,CIPSO,RR,SID,SSR,ZSU,
  		MTUP,MTUR,FINN,VISA,ENCODE,IMITD,EIP,TR,ADDEXT,RTRALT,SDB,NSAPA,DPS,UMP 
  size is size of ENTIRE packet, including header (but not ethernet part)
  content:"foo"  --- use escapes, etc. appropriately

  Ex. 
  srcip:192.168.1.1; destip:1.2.3.4; ipflags:MF; ipoptions:EOOL; offset:1234; id:100; ttl:255; protocol:tcp; srcport:80; 
  destport:80; seq:100; ack:100; tcpflag:fin; size:100; content:"foo"; 

Definition at line 134 of file pktFile.c.

Pkt_EthernetHdr_t* Pkt_CreateRandEthPkt ( array_t tmpArray  ) 

Create a random ethernet packet.

For other systems, use Pkt_NetworkByteOrder_c for packet For narya, use Pkt_HostByteOrder_c for packet

numSeeds is the number of packets that the routine uses for seeding the array.

Definition at line 739 of file pktTfc.c.

util_byte_array_t* Pkt_CreateTcpPkt ( array_t srcPorts,
array_t destPorts,
array_t seqNums,
array_t ackNums,
st_table flags,
array_t sizes,
array_t byteStrings 
)

Create a TCP packet.

User defines the "interesting" source and dest ports, seq numbers, ack numbers, sizes, and byteStrings to be inserted in the packet. If any of these arrays are empty, we take the corresponding field to be un-constrained. Otherwise, the field takes a value with equal likelihood from the correp array. (The array can be of length 1, which is useful for directed testing.)

User also define flags to be set by a st_table containing strings "fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr" - default is set with prob 0.5. If the st_table is NIL, flags are set at random.

Since there is no length field in the tcp header, we return a util_byte_array_t *, with the bytes entry being the actual packet, and the length entry being the length of the packet.

Definition at line 242 of file pktTfc.c.

util_byte_array_t* Pkt_CreateUdpPkt ( array_t srcPorts,
array_t destPorts,
array_t sizes,
array_t byteStrings 
)

Create a UDP packet.

User defines the "interesting" source and dest ports, and byteStrings to be inserted in the packet.

See also:
Pkt_CreateTcpPkt

Definition at line 126 of file pktTfc.c.

int Pkt_DestIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two dest ip flows Returns -1, 0 , 1.

Definition at line 280 of file pkt.c.

int Pkt_DestIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a dest-ip.

Definition at line 392 of file pkt.c.

int Pkt_DestTcpIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two dest tcp-Ip flows. Returns -1, 0, 1 a la strcmp.

Definition at line 335 of file pkt.c.

int Pkt_DestTcpIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a dest tcp-Ip flow.

Definition at line 431 of file pkt.c.

int Pkt_DeviceSkb (  ) 

Pkt_IcmpHdr_t* Pkt_EthernetExtractIcmp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Icmp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 215 of file pkt.c.

Pkt_IpHdr_t* Pkt_EthernetExtractIp ( Pkt_EthernetHdr_t ethPkt  ) 

Extract the Ip component from an Ethernet packet.

No new memory is allocated, simply returning a pointer. Note that we're being careless with the difference between an actual packet, and just the header.

Definition at line 27 of file pkt.c.

Pkt_TcpHdr_t* Pkt_EthernetExtractTcp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Tcp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 200 of file pkt.c.

Pkt_UdpHdr_t* Pkt_EthernetExtractUdp ( Pkt_EthernetHdr_t aEthernetPkt  ) 

Extract the Tcp component from an Ethernet packet.

No new memory is allocated, simply returning a pointer.

Definition at line 185 of file pkt.c.

int Pkt_EthernetHdrFree ( Pkt_EthernetHdr_t pkt  ) 

Free an Ethernet packet.

Assumes packet was allocated by malloc

Definition at line 82 of file pkt.c.

int Pkt_EthernetPktHdrReadLength ( Pkt_EthernetHdr_t pkt  ) 

Return the length of the Ethernet packet, including header.

Only IP suppored for now

Definition at line 62 of file pkt.c.

int Pkt_EthernetPktHdrReadLengthNetworkOrder ( Pkt_EthernetHdr_t pkt  ) 

Return the length of the Ethernet packet, including header.

Only IP suppored for now. Packet is assumed to be in network order.

Definition at line 41 of file pkt.c.

int Pkt_EthernetReadL3Type ( Pkt_EthernetHdr_t anEth  ) 

Return the L3 type of an ethernet packet.

Promotes a short to an int in the process.

Definition at line 637 of file pkt.c.

int Pkt_EthPacketReadFromFile ( int  fd,
Pkt_EthernetHdr_t **  anEthPktPtr 
)

Read an Ethernet frame from a file Returns NIL if the file is empty, and otherwise a pointer to the frame. Caller is responsible for freeing the memory allocated for the frame.

Definition at line 81 of file pktFile.c.

int Pkt_EthPacketWriteToFile ( int  fd,
Pkt_EthernetHdr_t anEthPkt,
unsigned int  length 
)

Write an ethernet frame to file. File is assumed to be open and writable. Format: length followed by sequence of bytes.

If we used fprintf, we would need both the FILE * fp AND the int fd as there's no simple way to go from one to the other. (We don't wan't to pass in the file name as the we'd have to keep opening and closing the file.)

The alternative is to write the length using write itself, but then we need to worry about the byte order. (Or perhaps not, as we can just read back without worrying about the order, its the same in both cases.

Definition at line 56 of file pktFile.c.

Pkt_L4Flow_t* Pkt_EthPktToL4Flow ( Pkt_EthernetHdr_t anEthPkt  ) 

Create a L4 flow structure from an Ethernet packet.

Definition at line 599 of file pkt.c.

int Pkt_EthPktWrite ( Pkt_EthernetHdr_t anEth,
int  anEthLength,
Pkt_LibNet_t aNetObj 
)

Transmit a raw ethernet frame.

Exits on fail, returns number of bytes written on success.

Definition at line 72 of file pktNet.c.

void Pkt_HTON ( Pkt_EthernetHdr_t anEth  ) 

Take an ethernet packet and convert it to network order.

Definition at line 859 of file pktTfc.c.

int Pkt_Init ( char *  ifName,
int  numRounds,
int  markPoint 
)

Pkt_LibNet_t* Pkt_InitLibNet ( char *  interfaceName  ) 

Routine for creating an encapsulation of the libnet data structures.

If the interface name passed in is null, default to "eth0".

Definition at line 27 of file pktNet.c.

array_t* Pkt_InitLibNetArray ( array_t outArray  ) 

Initialize an array of libnet objects, one per array entry.

Definition at line 117 of file pktNet.c.

Pkt_LibPcap_t* Pkt_InitLibPcap ( char *  interfaceName  ) 

Initialize our encapsulation of a pcap_t.

Definition at line 136 of file pktNet.c.

array_t* Pkt_InitLibPcapArray ( array_t inArray  ) 

Initialize an array of pcap objects, one per array entry.

Definition at line 98 of file pktNet.c.

Pkt_IcmpHdr_t* Pkt_IpExtractIcmp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Icmp component from an Ip packet.

No new memory is allocated, simply returning a pointer. Note that we're being careless with the difference between an actual packet, and just the header. If the encapsulated packet is not ip encapsualting icmp we return NIL.

Definition at line 114 of file pkt.c.

char* Pkt_IpExtractPayload ( Pkt_IpHdr_t anIpPkt  ) 

Extract the payload component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 169 of file pkt.c.

Pkt_TcpHdr_t* Pkt_IpExtractTcp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Tcp component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 154 of file pkt.c.

Pkt_UdpHdr_t* Pkt_IpExtractUdp ( Pkt_IpHdr_t anIpPkt  ) 

Extract the Udp component from an Ip packet.

No new memory is allocated, simply returning a pointer.

Definition at line 134 of file pkt.c.

Pkt_L4Flow_t* Pkt_IpPktToL4Flow ( Pkt_IpHdr_t anIpPkt  ) 

Create a L4 flow structure from an Ip packet.

Definition at line 613 of file pkt.c.

int Pkt_L4FlowCompare ( Pkt_L4Flow_t foo,
Pkt_L4Flow_t bar 
)

Compare function for an L4 flow struct - 1 for equal, 0 for unequal.

Definition at line 545 of file pkt.c.

int Pkt_L4FlowCompareForSt ( Pkt_L4Flow_t foo,
Pkt_L4Flow_t bar 
)

Compare function for an L4 flow struct for the st package, returns 0 for equal, 1 for unequal.

Definition at line 529 of file pkt.c.

unsigned int Pkt_L4FlowHash ( Pkt_L4Flow_t anL4FlowStruct  ) 

Hash function for an L4 flow struct.

See also:
st_strhash

Definition at line 580 of file pkt.c.

int Pkt_L4FlowHashForSt ( Pkt_L4Flow_t anL4Flow_t,
int  modulus 
)

Hash function for an L4 flow struct with modulus argument.

Definition at line 561 of file pkt.c.

int Pkt_LibNetFinish ( Pkt_LibNet_t obj  ) 

Finish using a Pkt_LibNet_t struct.

Definition at line 56 of file pktNet.c.

int Pkt_LibPcapFinish ( Pkt_LibPcap_t obj  ) 

Finish using a Pkt_LibPcap_t struct.

Definition at line 255 of file pktNet.c.

void Pkt_NTOH ( Pkt_EthernetHdr_t anEth  ) 

Take an ethernet packet and convert it to host order.

Definition at line 918 of file pktTfc.c.

int Pkt_PrintEthernet ( Pkt_EthernetHdr_t anEthPkt,
int  length 
)

Print an Ethernet packet.

Packet is assumed to be in network format.

Definition at line 650 of file pkt.c.

int Pkt_PrintIp ( Pkt_IpHdr_t anIpPkt  ) 

Print an Ip Pkt, given in network order.

Definition at line 727 of file pkt.c.

void Pkt_PrintIpAddressDotted ( u_int32_t  aNumIp  ) 

Print an Ip address in 1.2.3.4 format.

Definition at line 754 of file pkt.c.

void Pkt_PrintIpAddressDottedGeneral ( char *  ,
u_int32_t  aNumIp 
)

Print an Ip address in 1.2.3.4 format.

Definition at line 764 of file pkt.c.

int Pkt_PrintWifi ( Pkt_WifiHdr_t aWifiPkt  ) 

Print a Wifi packet.

Definition at line 694 of file pkt.c.

int Pkt_ProcessPktFree ( Pkt_ProcessPkt_t pp  ) 

Free an ProcessPkt structure.

Does not free the packet, but does free applicable rules.

Definition at line 96 of file pkt.c.

array_t* Pkt_SeedRandEthPktArray ( Pkt_ByteOrder_t  byteOrder,
int  numSeeds,
Pkt_TfcMode_t tfcMode 
)

Create a random ethernet packet; only tcp for now.

Definition at line 754 of file pktTfc.c.

Pkt_VectorBuff_t* Pkt_SocketVectorWrite ( int  count  ) 

int Pkt_SrcDestIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two src-dest ip flows Returns -1,0,1 a la strcmp.

Definition at line 303 of file pkt.c.

int Pkt_SrcDestIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a src-dest ip flow.

Definition at line 411 of file pkt.c.

int Pkt_SrcDestTcpIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two Tcp-Ip flows. Returns -1, 0, 1 a la strcmp.

Definition at line 478 of file pkt.c.

int Pkt_SrcDestTcpIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a tcp-Ip flow.

Definition at line 453 of file pkt.c.

int Pkt_SrcIpFlowCmp ( Pkt_EthernetHdr_t pkt1,
Pkt_EthernetHdr_t pkt2 
)

Compare two src ip flows Returns -1, 0, 1 a la strcmp.

See also:
st_init_table

Definition at line 256 of file pkt.c.

int Pkt_SrcIpFlowHash ( Pkt_EthernetHdr_t pkt1,
int  modulus 
)

Hash a src-ip flow.

Definition at line 372 of file pkt.c.

char* Pkt_TcpHdrReadPayload ( Pkt_TcpHdr_t aTcpPkt  ) 

Returns a pointer to the payload of a TCP packet.

Definition at line 241 of file pkt.c.

char* Pkt_UdpHdrReadPayload ( Pkt_UdpHdr_t aUdpPkt  ) 

Returns a pointer to the payload of a UDP packet.

Definition at line 229 of file pkt.c.

u_int32_t Rlp_DotToInt ( char *   ) 

Convert a string in dotted decimal notation to an unsigned 32 bit int.

Definition at line 414 of file rlpL4.c.

array_t* Rlp_L7StringParse ( char *  l7Rule  ) 

Parse a string encoding a Layer 7 formula.

String is assumed to be well-formed. Returns an array_t of rule components, which are attibute-value pairs.

Definition at line 29 of file rlpParse.c.

int Rlp_UpdateDefineTable ( st_table aTable,
char *  anEntry 
)

Adds a mapping from a macro name to definition.

Typically anEntry will be "var foo 192.168.1.1" We will add "foo" to the table, and map it to "192.168.1.1"

Definition at line 2116 of file rlpUtil.c.