#include <UDPSerializer.h>
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) |
Converts between UDPPacket and binary (network byte order) UDP header.
Definition at line 28 of file UDPSerializer.h.
UDPSerializer::UDPSerializer | ( | ) | [inline] |
Definition at line 31 of file UDPSerializer.h.
{}
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; }