--- embedaddon/libnet/src/libnet_build_arp.c 2012/02/21 22:14:23 1.1 +++ embedaddon/libnet/src/libnet_build_arp.c 2023/09/27 11:11:38 1.1.1.3 @@ -1,5 +1,5 @@ /* - * $Id: libnet_build_arp.c,v 1.1 2012/02/21 22:14:23 misho Exp $ + * $Id: libnet_build_arp.c,v 1.1.1.3 2023/09/27 11:11:38 misho Exp $ * * libnet * libnet_build_arp.c - ARP packet assembler @@ -30,22 +30,15 @@ * */ -#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_arp(u_int16_t hrd, u_int16_t pro, u_int8_t hln, u_int8_t pln, -u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, u_int8_t *tpa, -u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) +libnet_build_arp(uint16_t hrd, uint16_t pro, uint8_t hln, uint8_t pln, +uint16_t op, const uint8_t *sha, const uint8_t *spa, const uint8_t *tha, const uint8_t *tpa, +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_arp_hdr arp_hdr; @@ -74,7 +67,7 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l arp_hdr.ar_pln = pln; /* protocol address length */ arp_hdr.ar_op = htons(op); /* opcode command */ - n = libnet_pblock_append(l, p, (u_int8_t *)&arp_hdr, LIBNET_ARP_H); + n = libnet_pblock_append(l, p, (uint8_t *)&arp_hdr, LIBNET_ARP_H); if (n == -1) { /* err msg set in libnet_pblock_append() */ @@ -105,23 +98,9 @@ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l 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) - { - /* err msg set in libnet_pblock_append() */ - goto bad; - } - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_ARP_H)); bad: libnet_pblock_delete(l, p); @@ -129,8 +108,8 @@ bad: } libnet_ptag_t -libnet_autobuild_arp(u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, -u_int8_t *tpa, libnet_t *l) +libnet_autobuild_arp(uint16_t op, const uint8_t *sha, const uint8_t *spa, const uint8_t *tha, +const uint8_t *tpa, libnet_t *l) { u_short hrd; @@ -145,7 +124,7 @@ u_int8_t *tpa, libnet_t *l) default: hrd = 0; snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): unsupported link type\n", __func__); + "%s(): unsupported link type", __func__); return (-1); /* add other link-layers */ } @@ -157,13 +136,18 @@ u_int8_t *tpa, libnet_t *l) 4, /* protocol addr size */ op, /* operation type */ sha, /* sender hardware addr */ - spa, /* sender protocol addr */ + spa, /* sender protocol addr */ tha, /* target hardware addr */ - tpa, /* target protocol addr */ + tpa, /* target protocol addr */ NULL, /* payload */ 0, /* payload size */ l, /* libnet context */ 0)); /* libnet id */ } -/* EOF */ +/** + * Local Variables: + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + */