--- embedaddon/libnet/src/libnet_build_udp.c 2012/02/21 22:14:23 1.1.1.1 +++ embedaddon/libnet/src/libnet_build_udp.c 2023/09/27 11:11:38 1.1.1.3 @@ -1,5 +1,5 @@ /* - * $Id: libnet_build_udp.c,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $ + * $Id: libnet_build_udp.c,v 1.1.1.3 2023/09/27 11:11:38 misho Exp $ * * libnet * libnet_build_udp.c - UDP packet assembler @@ -30,20 +30,13 @@ * */ -#if (HAVE_CONFIG_H) -#include "../include/config.h" -#endif -#if (!(_WIN32) || (__CYGWIN__)) -#include "../include/libnet.h" -#else -#include "../include/win32/libnet.h" -#endif +#include "common.h" libnet_ptag_t -libnet_build_udp(u_int16_t sp, u_int16_t dp, u_int16_t len, u_int16_t sum, -u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) +libnet_build_udp(uint16_t sp, uint16_t dp, uint16_t len, uint16_t sum, +const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) { - u_int32_t n, h; + uint32_t n; libnet_pblock_t *p; struct libnet_udp_hdr udp_hdr; @@ -53,7 +46,6 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l } n = LIBNET_UDP_H + payload_s; /* size of memory block */ - h = len; /* header length (for cksum) */ /* * Find the existing protocol block if a ptag is specified, or create @@ -68,31 +60,18 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l memset(&udp_hdr, 0, sizeof(udp_hdr)); udp_hdr.uh_sport = htons(sp); /* source port */ udp_hdr.uh_dport = htons(dp); /* destination port */ - udp_hdr.uh_ulen = htons(h); /* total length of UDP packet*/ + udp_hdr.uh_ulen = htons(len); /* total length of UDP packet*/ udp_hdr.uh_sum = (sum ? htons(sum) : 0);/* checksum */ - n = libnet_pblock_append(l, p, (u_int8_t *)&udp_hdr, LIBNET_UDP_H); + n = libnet_pblock_append(l, p, (uint8_t *)&udp_hdr, LIBNET_UDP_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) { /* @@ -102,10 +81,15 @@ 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_UDP_H)); + return (ptag ? ptag : libnet_pblock_update(l, p, len, LIBNET_PBLOCK_UDP_H)); bad: libnet_pblock_delete(l, p); return (-1); } -/* EOF */ +/** + * Local Variables: + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + */