#include #include #include #include #include #include #include #include #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)); }