Azinix

pktFile.c File Reference

Routines for reading and writing packets to file, as well as creating packets. More...

#include "pkt.h"

Go to the source code of this file.

Functions

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.


Detailed Description

Routines for reading and writing packets to file, as well as creating packets.

Definition in file pktFile.c.


Function Documentation

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.

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.