version 1.1.1.1, 2012/02/21 22:14:23
|
version 1.1.1.3, 2023/09/27 11:11:38
|
Line 30
|
Line 30
|
* |
* |
*/ |
*/ |
|
|
#if (HAVE_CONFIG_H) | #include "common.h" |
#include "../include/config.h" | |
#endif | |
#if (!(_WIN32) || (__CYGWIN__)) | |
#include "../include/libnet.h" | |
#else | |
#include "../include/win32/libnet.h" | |
#endif | |
|
|
libnet_ptag_t |
libnet_ptag_t |
libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_int16_t type, u_int8_t *payload, | libnet_build_ethernet(const uint8_t *dst, const uint8_t *src, uint16_t type, |
u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) | 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; |
libnet_pblock_t *p; |
struct libnet_ethernet_hdr eth_hdr; |
struct libnet_ethernet_hdr eth_hdr; |
|
|
Line 76 libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_
|
Line 69 libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_
|
return (-1); |
return (-1); |
} |
} |
|
|
memset(ð_hdr, 0, sizeof(eth_hdr)); | memset(ð_hdr, 0, sizeof(eth_hdr)); |
memcpy(eth_hdr.ether_dhost, dst, ETHER_ADDR_LEN); /* destination address */ | memcpy(eth_hdr.ether_dhost, dst, ETHER_ADDR_LEN); /* destination address */ |
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */ |
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */ |
eth_hdr.ether_type = htons(type); /* packet type */ |
eth_hdr.ether_type = htons(type); /* packet type */ |
|
|
n = libnet_pblock_append(l, p, (u_int8_t *)ð_hdr, LIBNET_ETH_H); | n = libnet_pblock_append(l, p, (uint8_t *)ð_hdr, LIBNET_ETH_H); |
if (n == -1) |
if (n == -1) |
{ |
{ |
goto bad; |
goto bad; |
} |
} |
|
|
if ((payload && !payload_s) || (!payload && payload_s)) | /* boilerplate payload sanity check / append macro */ |
{ | LIBNET_DO_PAYLOAD(l, p); |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, | |
"%s(): payload inconsistency\n", __func__); | |
goto bad; | |
} | |
|
|
if (payload && payload_s) |
|
{ |
|
n = libnet_pblock_append(l, p, payload, payload_s); |
|
if (n == -1) |
|
{ |
|
goto bad; |
|
} |
|
} |
|
|
|
return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_ETH_H)); |
return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_ETH_H)); |
bad: |
bad: |
libnet_pblock_delete(l, p); |
libnet_pblock_delete(l, p); |
Line 111 bad:
|
Line 91 bad:
|
|
|
|
|
libnet_ptag_t |
libnet_ptag_t |
libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t type, libnet_t *l) | libnet_autobuild_ethernet(const uint8_t *dst, uint16_t type, libnet_t *l) |
{ |
{ |
u_int32_t n, h; | uint32_t n, h; |
struct libnet_ether_addr *src; |
struct libnet_ether_addr *src; |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
libnet_ptag_t ptag; |
libnet_ptag_t ptag; |
Line 154 libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t typ
|
Line 134 libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t typ
|
return (-1); |
return (-1); |
} |
} |
|
|
memset(ð_hdr, 0, sizeof(eth_hdr)); | memset(ð_hdr, 0, sizeof(eth_hdr)); |
memcpy(eth_hdr.ether_dhost, dst, ETHER_ADDR_LEN); /* destination address */ | memcpy(eth_hdr.ether_dhost, dst, ETHER_ADDR_LEN); /* destination address */ |
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */ |
memcpy(eth_hdr.ether_shost, src, ETHER_ADDR_LEN); /* source address */ |
eth_hdr.ether_type = htons(type); /* packet type */ |
eth_hdr.ether_type = htons(type); /* packet type */ |
|
|
n = libnet_pblock_append(l, p, (u_int8_t *)ð_hdr, LIBNET_ETH_H); | n = libnet_pblock_append(l, p, (uint8_t *)ð_hdr, LIBNET_ETH_H); |
if (n == -1) |
if (n == -1) |
{ |
{ |
goto bad; |
goto bad; |
Line 170 bad:
|
Line 150 bad:
|
libnet_pblock_delete(l, p); |
libnet_pblock_delete(l, p); |
return (-1); |
return (-1); |
} |
} |
/* EOF */ | |
| /** |
| * Local Variables: |
| * indent-tabs-mode: nil |
| * c-file-style: "stroustrup" |
| * End: |
| */ |