ostinato/server/pcapextra.cpp
Srivats P. a1ae3e7e6c Refactoring
- Major code reorganization of the server code across several classes with fewer 'friends'
	- New server classes - AbstractPort, PcapPort, WinPcapPort, PortManager
	- With this reorg classes have more focus than earlier and will be hopefully easy to extend

Fixes
	- Ostinato client is now able to successfully reconnect and talk to the Ostinato server after a disconnect - earlier, if a method had been pending during the disconnect, the communication was not up after a reconnect; pending methods are cleaned up at disconnect now
2009-12-26 17:33:27 +00:00

60 lines
1.2 KiB
C++

#include "pcapextra.h"
#include <string.h> // memcpy()
#include <stdlib.h> // malloc(), free()
/* NOTE: All code borrowed from WinPcap */
#ifndef Q_OS_WIN32
pcap_send_queue* pcap_sendqueue_alloc (u_int memsize)
{
pcap_send_queue *tqueue;
/* Allocate the queue */
tqueue = (pcap_send_queue*)malloc(sizeof(pcap_send_queue));
if(tqueue == NULL){
return NULL;
}
/* Allocate the buffer */
tqueue->buffer = (char*)malloc(memsize);
if(tqueue->buffer == NULL){
free(tqueue);
return NULL;
}
tqueue->maxlen = memsize;
tqueue->len = 0;
return tqueue;
}
void pcap_sendqueue_destroy (pcap_send_queue *queue)
{
free(queue->buffer);
free(queue);
}
int pcap_sendqueue_queue (pcap_send_queue *queue,
const struct pcap_pkthdr *pkt_header, const u_char *pkt_data)
{
if(queue->len + sizeof(struct pcap_pkthdr) + pkt_header->caplen >
queue->maxlen)
{
return -1;
}
/* Copy the pcap_pkthdr header*/
memcpy(queue->buffer + queue->len, pkt_header, sizeof(struct pcap_pkthdr));
queue->len += sizeof(struct pcap_pkthdr);
/* copy the packet */
memcpy(queue->buffer + queue->len, pkt_data, pkt_header->caplen);
queue->len += pkt_header->caplen;
return 0;
}
#endif