Public Member Functions

UDPSerializer Class Reference

#include <UDPSerializer.h>

List of all members.

Public Member Functions

 UDPSerializer ()
int serialize (const UDPPacket *pkt, unsigned char *buf, unsigned int bufsize)
void parse (const unsigned char *buf, unsigned int bufsize, UDPPacket *pkt)

Detailed Description

Converts between UDPPacket and binary (network byte order) UDP header.

Definition at line 28 of file UDPSerializer.h.


Constructor & Destructor Documentation

UDPSerializer::UDPSerializer (  )  [inline]

Definition at line 31 of file UDPSerializer.h.

{}


Member Function Documentation

void UDPSerializer::parse ( const unsigned char *  buf,
unsigned int  bufsize,
UDPPacket *  pkt 
)

Puts a packet sniffed from the wire into an UDPPacket.

Definition at line 53 of file UDPSerializer.cc.

{

    struct udphdr *udphdr = (struct udphdr*) buf;

    dest->setSourcePort(ntohs(udphdr->uh_sport));
    dest->setDestinationPort(ntohs(udphdr->uh_dport));
    dest->setByteLength(8);
    cPacket *encapPacket = new cPacket("Payload-from-wire");
    encapPacket->setByteLength(ntohs(udphdr->uh_ulen) - sizeof(struct udphdr));
    dest->encapsulate(encapPacket);
    dest->setName(encapPacket->getName());
}

int UDPSerializer::serialize ( const UDPPacket *  pkt,
unsigned char *  buf,
unsigned int  bufsize 
)

Serializes an UDPPacket for transmission on the wire. Returns the length of data written into buffer.

Definition at line 40 of file UDPSerializer.cc.

{
    struct udphdr *udphdr = (struct udphdr *) (buf);
    int packetLength;

    packetLength = pkt->getByteLength();
    udphdr->uh_sport = htons(pkt->getSourcePort());
    udphdr->uh_dport = htons(pkt->getDestinationPort());
    udphdr->uh_ulen  = htons(packetLength);
    udphdr->uh_sum   = TCPIPchecksum::checksum(buf, packetLength);
    return packetLength;
}


The documentation for this class was generated from the following files: