hlswmaster/src/plugin_helper.c

49 lines
1.0 KiB
C
Raw Normal View History

2006-02-02 16:24:06 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include "plugin.h"
#include "netpkt.h"
struct net_pkt * pkt_factory(char *dstip, unsigned int dstport, char *buf, unsigned int size) {
struct net_pkt *pkt;
if (!(pkt = malloc(sizeof(struct net_pkt) + size)))
return NULL;
INIT_LIST_HEAD(&pkt->list);
pkt->addr.sin_family = AF_INET;
pkt->addr.sin_port = htons(dstport);
if (dstip)
inet_aton(dstip, &pkt->addr.sin_addr);
else
inet_aton("255.255.255.255", &pkt->addr.sin_addr);
pkt->size = size;
memcpy(pkt->buf, buf, size);
return pkt;
}
int pkt_memcmp(struct net_pkt *pkt, unsigned int offset, char *search, unsigned int size) {
if (offset >= pkt->size)
return 1;
if (offset + size >= pkt->size)
size = pkt->size - offset;
return memcmp(pkt->buf, search, size);
}
int pkt_strcmp(struct net_pkt *pkt, unsigned int offset, char *search) {
return pkt_memcmp(pkt, offset, search, strlen(search));
}