--- embedaddon/libnet/src/libnet_build_igmp.c 2012/02/21 22:14:23 1.1.1.1 +++ embedaddon/libnet/src/libnet_build_igmp.c 2013/07/22 11:54:42 1.1.1.2 @@ -1,5 +1,5 @@ /* - * $Id: libnet_build_igmp.c,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $ + * $Id: libnet_build_igmp.c,v 1.1.1.2 2013/07/22 11:54:42 misho Exp $ * * libnet * libnet_build_igmp.c - IGMP packet assembler @@ -40,10 +40,10 @@ #endif libnet_ptag_t -libnet_build_igmp(u_int8_t type, u_int8_t code, u_int16_t sum, u_int32_t ip, -u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) +libnet_build_igmp(uint8_t type, uint8_t reserved, uint16_t sum, uint32_t ip, +const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) { - u_int32_t n, h; + uint32_t n, h; libnet_pblock_t *p; struct libnet_igmp_hdr igmp_hdr; @@ -66,32 +66,20 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l } memset(&igmp_hdr, 0, sizeof(igmp_hdr)); - igmp_hdr.igmp_type = type; /* packet type */ - igmp_hdr.igmp_code = code; /* packet code */ - igmp_hdr.igmp_sum = (sum ? htons(sum) : 0); /* packet checksum */ - igmp_hdr.igmp_group.s_addr = htonl(ip); + igmp_hdr.igmp_type = type; + igmp_hdr.igmp_code = reserved; + igmp_hdr.igmp_sum = (sum ? htons(sum) : 0); + igmp_hdr.igmp_group.s_addr = ip; - n = libnet_pblock_append(l, p, (u_int8_t *)&igmp_hdr, LIBNET_IGMP_H); + n = libnet_pblock_append(l, p, (uint8_t *)&igmp_hdr, LIBNET_IGMP_H); if (n == -1) { goto bad; } - if ((payload && !payload_s) || (!payload && payload_s)) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): payload inconsistency\n", __func__); - goto bad; - } + /* boilerplate payload sanity check / append macro */ + LIBNET_DO_PAYLOAD(l, p); - if (payload && payload_s) - { - n = libnet_pblock_append(l, p, payload, payload_s); - if (n == -1) - { - goto bad; - } - } if (sum == 0) { /* @@ -101,7 +89,6 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l */ libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); } - return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_IGMP_H)); bad: