--- embedaddon/libnet/src/libnet_build_cdp.c 2012/02/21 22:14:23 1.1.1.1 +++ embedaddon/libnet/src/libnet_build_cdp.c 2013/07/22 11:54:42 1.1.1.2 @@ -1,5 +1,5 @@ /* - * $Id: libnet_build_cdp.c,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $ + * $Id: libnet_build_cdp.c,v 1.1.1.2 2013/07/22 11:54:42 misho Exp $ * * libnet * libnet_build_cdp.c - CDP packet assembler @@ -40,11 +40,11 @@ #endif libnet_ptag_t -libnet_build_cdp(u_int8_t version, u_int8_t ttl, u_int16_t sum, u_int16_t type, -u_int16_t len, u_int8_t *value, u_int8_t *payload, u_int32_t payload_s, +libnet_build_cdp(uint8_t version, uint8_t ttl, uint16_t sum, uint16_t type, +uint16_t len, const uint8_t *value, 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_cdp_hdr cdp_hdr; @@ -53,8 +53,8 @@ libnet_t *l, libnet_ptag_t ptag) return (-1); } - n = LIBNET_CDP_H + len + payload_s; - h = LIBNET_CDP_H + len + payload_s; + n = LIBNET_CDP_H + LIBNET_CDP_H + len + payload_s; + h = LIBNET_CDP_H + LIBNET_CDP_H + len + payload_s; /* * Find the existing protocol block if a ptag is specified, or create @@ -73,7 +73,7 @@ libnet_t *l, libnet_ptag_t ptag) cdp_hdr.cdp_type = htons(type); cdp_hdr.cdp_len = htons(len + 4); /* 4 bytes for len and type */ - n = libnet_pblock_append(l, p, (u_int8_t *)&cdp_hdr, LIBNET_CDP_H); + n = libnet_pblock_append(l, p, (uint8_t *)&cdp_hdr, LIBNET_CDP_H); if (n == -1) { goto bad; @@ -86,22 +86,9 @@ libnet_t *l, libnet_ptag_t ptag) 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) { /* @@ -120,10 +107,10 @@ bad: int /* Not Yet Implemented */ -libnet_build_cdp_value(u_int16_t type, u_int16_t len, u_int8_t *value, libnet_t *l, +libnet_build_cdp_value(uint16_t type, uint16_t len, uint8_t *value, libnet_t *l, libnet_ptag_t ptag) { - u_int32_t n; + uint32_t n; libnet_pblock_t *p; struct libnet_cdp_value_hdr cdp_value_hdr; @@ -148,9 +135,9 @@ libnet_build_cdp_value(u_int16_t type, u_int16_t len, return (-1); } - memset(&cdp_value_hdr, 0, sizeof(cdp_value_hdr)); - cdp_value_hdr.cdp_type = htons(type); - cdp_value_hdr.cdp_len = htons(len + 4); /* 4 bytes for len and type */ + memset(&cdp_value_hdr, 0, sizeof(cdp_value_hdr)); + cdp_value_hdr.cdp_type = htons(type); + cdp_value_hdr.cdp_len = htons(len + LIBNET_CDP_VALUE_H); /* 4 bytes for len and type */ switch (type) { @@ -172,7 +159,7 @@ libnet_build_cdp_value(u_int16_t type, u_int16_t len, break; } - n = libnet_pblock_append(l, p, (u_int8_t *)&cdp_value_hdr, LIBNET_CDP_H); + n = libnet_pblock_append(l, p, (uint8_t *)&cdp_value_hdr, LIBNET_CDP_VALUE_H); if (n == -1) { return (-1);