--- embedaddon/libnet/src/libnet_advanced.c 2012/02/21 22:14:23 1.1 +++ embedaddon/libnet/src/libnet_advanced.c 2023/09/27 11:11:38 1.1.1.3 @@ -1,5 +1,5 @@ /* - * $Id: libnet_advanced.c,v 1.1 2012/02/21 22:14:23 misho Exp $ + * $Id: libnet_advanced.c,v 1.1.1.3 2023/09/27 11:11:38 misho Exp $ * * libnet * libnet_advanced.c - Advanced routines @@ -30,17 +30,10 @@ * */ -#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" int -libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, u_int32_t *packet_s) +libnet_adv_cull_packet(libnet_t *l, uint8_t **packet, uint32_t *packet_s) { *packet = NULL; *packet_s = 0; @@ -48,7 +41,7 @@ libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, if (l->injection_type != LIBNET_LINK_ADV) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): advanced link mode not enabled\n", __func__); + "%s(): advanced link mode not enabled", __func__); return (-1); } @@ -57,8 +50,8 @@ libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, } int -libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, u_int8_t **header, - u_int32_t *header_s) +libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, uint8_t **header, + uint32_t *header_s) { libnet_pblock_t *p; @@ -68,7 +61,7 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag if (l->injection_type != LIBNET_LINK_ADV) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): advanced link mode not enabled\n", __func__); + "%s(): advanced link mode not enabled", __func__); return (-1); } @@ -76,7 +69,7 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag if (p == NULL) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): ptag not found, you sure it exists?\n", __func__); + "%s(): ptag not found, you sure it exists?", __func__); return (-1); } *header = p->buf; @@ -86,14 +79,14 @@ libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag } int -libnet_adv_write_link(libnet_t *l, u_int8_t *packet, u_int32_t packet_s) +libnet_adv_write_link(libnet_t *l, const uint8_t *packet, uint32_t packet_s) { int c; if (l->injection_type != LIBNET_LINK_ADV) { snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): advanced link mode not enabled\n", __func__); + "%s(): advanced link mode not enabled", __func__); return (-1); } c = libnet_write_link(l, packet, packet_s); @@ -119,8 +112,42 @@ libnet_adv_write_link(libnet_t *l, u_int8_t *packet, u return (c); } +int +libnet_adv_write_raw_ipv4(libnet_t *l, const uint8_t *packet, uint32_t packet_s) +{ + int c; + + if (l->injection_type != LIBNET_RAW4_ADV) + { + snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, + "%s(): advanced raw4 mode not enabled", __func__); + return (-1); + } + c = libnet_write_raw_ipv4(l, packet, packet_s); + + /* do statistics */ + if (c == packet_s) + { + l->stats.packets_sent++; + l->stats.bytes_written += c; + } + else + { + l->stats.packet_errors++; + /* + * XXX - we probably should have a way to retrieve the number of + * bytes actually written (since we might have written something). + */ + if (c > 0) + { + l->stats.bytes_written += c; + } + } + return (c); +} + void -libnet_adv_free_packet(libnet_t *l, u_int8_t *packet) +libnet_adv_free_packet(libnet_t *l, uint8_t *packet) { /* * Restore original pointer address so free won't complain about a @@ -133,4 +160,9 @@ libnet_adv_free_packet(libnet_t *l, u_int8_t *packet) free(packet); } -/* EOF */ +/** + * Local Variables: + * indent-tabs-mode: nil + * c-file-style: "stroustrup" + * End: + */