Main Page | Class List | File List | Class Members | File Members

packetHeader.c File Reference

#include "packetHeader.h"

Defines

#define CKSUM_CARRY(x)   (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))

Functions

void rst_initEth (struct ethhdr *ethhdr, unsigned char *dst, unsigned char *src, unsigned short proto)
 Initialize an Ethernet header.

void rst_initARPrequest (struct rst_arphdr *arphdr, unsigned char *senderMAC, unsigned int senderIP, unsigned int targetIP)
 Initialize an ARP request header.

void rst_initARPreply (struct rst_arphdr *arphdr, unsigned char *senderMAC, unsigned int senderIP, unsigned char *targetMAC, unsigned int targetIP)
 Initialize an ARP reply header.

void rst_initIP (struct iphdr *iphdr, unsigned short totalLen, unsigned char protocol, unsigned int srcAddr, unsigned int dstAddr)
 Initialize an IP header.

void rst_initICMP (struct icmphdr *icmphdr, unsigned char type)
 Initialize an ICMP header.

void rst_initTCP (struct tcphdr *tcphdr, unsigned short srcPort, unsigned short dstPort)
 Initialize a TCP header.

void rst_initUDP (struct udphdr *udphdr, unsigned short srcPort, unsigned short dstPort, unsigned short len)
 Initialize a UDP header.

void rst_initRbuf (struct rst_buf *rBuf, unsigned char *buf, int bufLen, unsigned int mask)
 Initialize an rst_buf.

int rst_verifyRbuf (struct rst_buf *rBuf)
 Check that an rst_buf is safe, in the sense that a call to rst_htonp will not abort.

void rst_htonp (struct rst_buf *rBuf)
 Do host-to-network byte swapping and checksum calculation.

void rst_ntohp (struct rst_buf *rBuf)
 Parse an incoming packet and do network-to-host byte swapping.

unsigned char * rst_ethData (struct rst_buf *rBuf)
 Get the address of the Ethernet header in rBuf.

unsigned char * rst_ipData (struct rst_buf *rBuf)
 Get the address of the IP header in rBuf.

unsigned char * rst_icmpData (struct rst_buf *rBuf)
 Get the address of the ICMP header in rBuf.

unsigned char * rst_tcpData (struct rst_buf *rBuf)
 Get the address of the TCP header in rBuf.

unsigned char * rst_udpData (struct rst_buf *rBuf)
 Get the address of the UDP header in rBuf.

unsigned short checksumCC (unsigned long sum)
long inChecksum (unsigned short *buf, int len)
unsigned short rst_getIPchecksum (struct iphdr *ip)
 Compute an IP checksum.

unsigned short rst_getICMPchecksum (struct icmphdr *icmp, unsigned short icmpLen)
 Compute an ICMP checksum.

unsigned short rst_getTCPchecksum (struct iphdr *iphdr, struct tcphdr *tcphdr, unsigned short tcpLen)
 Compute an TCP checksum.

unsigned short rst_getUDPchecksum (struct iphdr *iphdr, struct udphdr *udp, unsigned short udpLen)
 Compute an UDP checksum.


Define Documentation

#define CKSUM_CARRY  )     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
 


Function Documentation

unsigned short checksumCC unsigned long  sum  ) 
 

long inChecksum unsigned short *  buf,
int  len
 

unsigned char* rst_ethData struct rst_buf rBuf  ) 
 

Get the address of the Ethernet header in rBuf.

unsigned short rst_getICMPchecksum struct icmphdr *  icmp,
unsigned short  icmpLen
 

Compute an ICMP checksum.

unsigned short rst_getIPchecksum struct iphdr *  ip  ) 
 

Compute an IP checksum.

unsigned short rst_getTCPchecksum struct iphdr *  iphdr,
struct tcphdr *  tcphdr,
unsigned short  tcpLen
 

Compute an TCP checksum.

unsigned short rst_getUDPchecksum struct iphdr *  iphdr,
struct udphdr *  udp,
unsigned short  udpLen
 

Compute an UDP checksum.

void rst_htonp struct rst_buf rBuf  ) 
 

Do host-to-network byte swapping and checksum calculation.

Parameters:
rBuf an initialized rst_buf
Precondition:
rBuf.buf[0..rBuf.bufLen-1] is allocated

for each non-null pointer p in rBuf, *p is in rBuf.buf[0..rBuf.bufLen-1]

for each non-null pointer p in rBuf, any length fields in *p specify a header that lies in rBuf.buf[0..rBuf.bufLen-1]

Postcondition:
for each non-null pointer p in rBuf, appropriate byte swapping and checksum calculation has been done.

unsigned char* rst_icmpData struct rst_buf rBuf  ) 
 

Get the address of the ICMP header in rBuf.

void rst_initARPreply struct rst_arphdr arphdr,
unsigned char *  senderMAC,
unsigned int  senderIP,
unsigned char *  targetMAC,
unsigned int  targetIP
 

Initialize an ARP reply header.

Parameters:
arphdr address of header to be initialized
senderMAC sender's MAC address
senderIP sender's IP address
targetMAC target's MAC address
targetIP target's IP address
Precondition:
arphdr points to at least RST_ARP_HDR_LEN bytes

senderMAC points to at least 6 bytes

targetMAC points to at least 6 bytes

Postcondition:
arphdr initialized, in host byte order

void rst_initARPrequest struct rst_arphdr arphdr,
unsigned char *  senderMAC,
unsigned int  senderIP,
unsigned int  targetIP
 

Initialize an ARP request header.

Parameters:
arphdr address of header to be initialized
senderMAC sender's MAC address
senderIP sender's IP address
targetIP target's IP address
Precondition:
arphdr points to at least RST_ARP_HDR_LEN bytes

senderMAC points to at least 6 bytes

Postcondition:
arphdr initialized, in host byte order

void rst_initEth struct ethhdr *  ethhdr,
unsigned char *  dst,
unsigned char *  src,
unsigned short  proto
 

Initialize an Ethernet header.

Parameters:
ethhdr address of header to be initialized
dst destination MAC address
src source MAC address
proto next layer protocol
Precondition:
ethhdr points to at least RST_ETH_HDR_LEN bytes

dst points to at least 6 bytes

src points to at least 6 bytes

Postcondition:
ethhdr initialized, in host byte order

void rst_initICMP struct icmphdr *  icmphdr,
unsigned char  type
 

Initialize an ICMP header.

Parameters:
icmphdr address of header to be initialized
type ICMP type
Precondition:
icmphdr points to at least RST_ICMP_HDR_LEN bytes
Postcondition:
icmphdr initialized, in host byte order

void rst_initIP struct iphdr *  iphdr,
unsigned short  totalLen,
unsigned char  protocol,
unsigned int  srcAddr,
unsigned int  dstAddr
 

Initialize an IP header.

Parameters:
iphdr address of header to be initialized
totalLen total IP packet length in bytes
protocol next layer protocol
srcAddr IP source address
dstAddr IP destination address
Precondition:
iphdr points to at least RST_IP_HDR_LEN bytes
Postcondition:
iphdr initialized, in host byte order

void rst_initRbuf struct rst_buf rBuf,
unsigned char *  buf,
int  bufLen,
unsigned int  mask
 

Initialize an rst_buf.

Parameters:
rBuf rst_buf to be initialized
buf frame byte array
bufLen length of buf
mask specification of active header pointers
Postcondition:
rBuf.buf == buf

rBuf.bufLen == bufLen

the masked rBuf pointers point to the appropriate locations in buf; the unmasked pointers are null

void rst_initTCP struct tcphdr *  tcphdr,
unsigned short  srcPort,
unsigned short  dstPort
 

Initialize a TCP header.

Parameters:
tcphdr address of header to be initialized
srcPort source port
dstPort destination port
Precondition:
tcphdr points to at least RST_TCP_HDR_LEN bytes
Postcondition:
tcphdr initialized, in host byte order

void rst_initUDP struct udphdr *  udphdr,
unsigned short  srcPort,
unsigned short  dstPort,
unsigned short  len
 

Initialize a UDP header.

Parameters:
udphdr address of header to be initialized
srcPort source port
dstPort destination port
len total UDP length in bytes
Precondition:
udphdr points to at least RST_UDP_HDR_LEN bytes
Postcondition:
udphdr initialized, in host byte order

unsigned char* rst_ipData struct rst_buf rBuf  ) 
 

Get the address of the IP header in rBuf.

void rst_ntohp struct rst_buf rBuf  ) 
 

Parse an incoming packet and do network-to-host byte swapping.

Parameters:
rBuf an rst_buf containing the packet to be parsed in rBuf.buf[0..rBuf.bufLen-1]
Precondition:
rBuf.buf[0..rBuf.bufLen-1] is allocated and "legal"
Postcondition:
for each non-null pointer p in rBuf, appropriate byte swapping and checksum calculation has been done.

unsigned char* rst_tcpData struct rst_buf rBuf  ) 
 

Get the address of the TCP header in rBuf.

unsigned char* rst_udpData struct rst_buf rBuf  ) 
 

Get the address of the UDP header in rBuf.

int rst_verifyRbuf struct rst_buf rBuf  ) 
 

Check that an rst_buf is safe, in the sense that a call to rst_htonp will not abort.

Three kinds of checks are made:

  1. The non-null header pointers are one of:
    • Ethernet
    • Ethernet and ARP
    • Ethernet and IP
    • Ethernet, IP and ICMP
    • Ethernet, IP and TCP
    • Ethernet, IP and UDP
  2. For the non-null header pointers, the headers start at buf[0], are contiguous and non-overlapping, and are completely contained in buf.
  3. The data indicated by the dynamic length fields, where present, are completely contained in buf.
Parameters:
rBuf an rst_buf
Precondition:
rBuf.buf[0..rBuf.bufLen-1] is allocated

rBuf.bufLen >= 0

no IP or TCP options are present

Returns:
0 if rBuf is safe; non-zero otherwise


Generated on Sun Jul 18 17:30:56 2004 by doxygen 1.3.6