libnet_build_icmp.c   libnet_build_icmp.c 
skipping to change at line 42 skipping to change at line 42
#if (HAVE_CONFIG_H) #if (HAVE_CONFIG_H)
#include "../include/config.h" #include "../include/config.h"
#endif #endif
#if (!(_WIN32) || (__CYGWIN__)) #if (!(_WIN32) || (__CYGWIN__))
#include "../include/libnet.h" #include "../include/libnet.h"
#else #else
#include "../include/win32/libnet.h" #include "../include/win32/libnet.h"
#endif #endif
#include <assert.h>
/* some common cruft for completing ICMP error packets */ /* some common cruft for completing ICMP error packets */
#define LIBNET_BUILD_ICMP_ERR_FINISH(len) \ #define LIBNET_BUILD_ICMP_ERR_FINISH(len) \
do \ do \
{ \ { \
n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, len); \ n = libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, len); \
if (n == -1) \ if (n == -1) \
{ \ { \
goto bad; \ goto bad; \
} \ } \
\ \
skipping to change at line 316 skipping to change at line 318
uint32_t n, h; uint32_t n, h;
libnet_pblock_t *p; libnet_pblock_t *p;
struct libnet_icmpv4_hdr icmp_hdr; struct libnet_icmpv4_hdr icmp_hdr;
if (l == NULL) if (l == NULL)
{ {
return (-1); return (-1);
} }
/* size of memory block */ /* size of memory block */
n = LIBNET_ICMPV4_TIMXCEED_H; n = LIBNET_ICMPV4_TIMXCEED_H + payload_s;
/* /*
* FREDRAYNAL: as ICMP checksum includes what is embedded in * FREDRAYNAL: as ICMP checksum includes what is embedded in
* the payload, and what is after the ICMP header, we need to include * the payload, and what is after the ICMP header, we need to include
* those 2 sizes. * those 2 sizes.
*/ */
h = LIBNET_ICMPV4_TIMXCEED_H + payload_s + l->total_size; h = LIBNET_ICMPV4_TIMXCEED_H + payload_s + l->total_size;
/* /*
* Find the existing protocol block if a ptag is specified, or create * Find the existing protocol block if a ptag is specified, or create
* a new one. * a new one.
skipping to change at line 365 skipping to change at line 367
{ {
uint32_t n, h; uint32_t n, h;
libnet_pblock_t *p; libnet_pblock_t *p;
struct libnet_icmpv4_hdr icmp_hdr; struct libnet_icmpv4_hdr icmp_hdr;
if (l == NULL) if (l == NULL)
{ {
return (-1); return (-1);
} }
n = LIBNET_ICMPV4_REDIRECT_H; /* size of memory block */ n = LIBNET_ICMPV4_REDIRECT_H + payload_s; /* size of memo ry block */
/* /*
* FREDRAYNAL: as ICMP checksum includes what is embedded in * FREDRAYNAL: as ICMP checksum includes what is embedded in
* the payload, and what is after the ICMP header, we need to include * the payload, and what is after the ICMP header, we need to include
* those 2 sizes. * those 2 sizes.
*/ */
h = LIBNET_ICMPV4_REDIRECT_H + payload_s + l->total_size; h = LIBNET_ICMPV4_REDIRECT_H + payload_s + l->total_size;
/* /*
* Find the existing protocol block if a ptag is specified, or create * Find the existing protocol block if a ptag is specified, or create
* a new one. * a new one.
skipping to change at line 399 skipping to change at line 401
LIBNET_BUILD_ICMP_ERR_FINISH(LIBNET_ICMPV4_REDIRECT_H); LIBNET_BUILD_ICMP_ERR_FINISH(LIBNET_ICMPV4_REDIRECT_H);
return (ptag ? ptag : libnet_pblock_update(l, p, h, return (ptag ? ptag : libnet_pblock_update(l, p, h,
LIBNET_PBLOCK_ICMPV4_REDIRECT_H)); LIBNET_PBLOCK_ICMPV4_REDIRECT_H));
bad: bad:
libnet_pblock_delete(l, p); libnet_pblock_delete(l, p);
return (-1); return (-1);
} }
libnet_ptag_t libnet_ptag_t
libnet_build_icmpv6_unreach(u_int8_t type, u_int8_t code, u_int16_t sum, libnet_build_icmpv6_common(
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) uint8_t type, uint8_t code, uint16_t sum,
const void* specific, uint32_t specific_s, uint8_t pblock_type,
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; libnet_pblock_t *p;
struct libnet_icmpv6_hdr icmp_hdr; struct libnet_icmpv6_hdr icmp_hdr;
if (l == NULL) if (l == NULL)
{ {
return (-1); return (-1);
} }
n = LIBNET_ICMPV6_UNREACH_H + payload_s; /* size of memory block n = LIBNET_ICMPV6_COMMON_H + specific_s + payload_s;
*/
p = libnet_pblock_probe(l, ptag, n, pblock_type);
/*
* Find the existing protocol block if a ptag is specified, or create
* a new one.
*/
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV6_UNREACH_H);
if (p == NULL) if (p == NULL)
{ {
return (-1); return (-1);
} }
memset(&icmp_hdr, 0, sizeof(icmp_hdr)); memset(&icmp_hdr, 0, sizeof(icmp_hdr));
icmp_hdr.icmp_type = type; /* packet type */ icmp_hdr.icmp_type = type;
icmp_hdr.icmp_code = code; /* packet code */ icmp_hdr.icmp_code = code;
icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ icmp_hdr.icmp_sum = htons(sum);
icmp_hdr.id = 0; /* must be 0 */
icmp_hdr.seq = 0; /* must be 0 */ if (libnet_pblock_append(l, p, (uint8_t *)&icmp_hdr, LIBNET_ICMPV6_COMM
ON_H) < 0)
{
goto bad;
}
LIBNET_BUILD_ICMP_ERR_FINISH(LIBNET_ICMPV6_UNREACH_H); if (libnet_pblock_append(l, p, specific, specific_s) < 0)
{
goto bad;
}
if (libnet_pblock_append(l, p, payload, payload_s) < 0)
{
goto bad;
}
if (sum == 0)
{
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
}
return ptag ? ptag : libnet_pblock_update(l, p, 0, pblock_type);
return (ptag ? ptag : libnet_pblock_update(l, p, h,
LIBNET_PBLOCK_ICMPV6_UNREACH_H));
bad: bad:
libnet_pblock_delete(l, p); libnet_pblock_delete(l, p);
return (-1);
return -1;
} }
/* EOF */ libnet_ptag_t libnet_build_icmpv6(uint8_t type, uint8_t code, uint16_t sum,
uint8_t* payload, uint32_t payload_s,
libnet_t* l, libnet_ptag_t ptag)
{
return libnet_build_icmpv6_common(
type, code, sum,
NULL, 0, LIBNET_PBLOCK_ICMPV6_UNREACH_H,
payload, payload_s,
l, ptag);
}
libnet_ptag_t
libnet_build_icmpv6_unreach(
uint8_t type, uint8_t code, uint16_t sum,
uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag
)
{
struct libnet_icmpv6_unreach specific;
memset(&specific, 0, sizeof(specific));
return libnet_build_icmpv6_common(
type, code, sum,
&specific, sizeof(specific), LIBNET_PBLOCK_ICMPV6_UNREACH_H,
payload, payload_s,
l, ptag);
}
libnet_ptag_t
libnet_build_icmpv6_echo(
uint8_t type, uint8_t code, uint16_t sum,
uint16_t id, uint16_t seq,
uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag
)
{
struct libnet_icmpv6_echo specific;
memset(&specific, 0, sizeof(specific));
specific.id = htons(id);
specific.seq = htons(seq);
return libnet_build_icmpv6_common(
type, code, sum,
&specific, sizeof(specific), LIBNET_PBLOCK_ICMPV6_ECHO_H,
payload, payload_s,
l, ptag);
}
libnet_ptag_t libnet_build_icmpv6_ndp_nsol(
uint8_t type, uint8_t code, uint16_t sum,
struct libnet_in6_addr target,
uint8_t *payload, uint32_t payload_s,
libnet_t* l, libnet_ptag_t ptag)
{
struct libnet_icmpv6_ndp_nsol specific;
memset(&specific, 0, sizeof(specific));
specific.reserved = 0;
specific.target_addr = target;
return libnet_build_icmpv6_common(
type, code, sum,
&specific, sizeof(specific), LIBNET_PBLOCK_ICMPV6_NDP_NSOL_H,
payload, payload_s,
l, ptag);
}
libnet_ptag_t libnet_build_icmpv6_ndp_nadv(
uint8_t type, uint8_t code, uint16_t sum,
uint32_t flags, struct libnet_in6_addr target,
uint8_t *payload, uint32_t payload_s,
libnet_t* l, libnet_ptag_t ptag)
{
struct libnet_icmpv6_ndp_nadv specific;
memset(&specific, 0, sizeof(specific));
specific.flags = htonl(flags);
specific.target_addr = target;
return libnet_build_icmpv6_common(
type, code, sum,
&specific, sizeof(specific), LIBNET_PBLOCK_ICMPV6_NDP_NADV_H,
payload, payload_s,
l, ptag);
}
libnet_ptag_t libnet_build_icmpv6_ndp_opt(
uint8_t type, uint8_t* option, uint32_t option_s,
libnet_t* l, libnet_ptag_t ptag)
{
struct libnet_icmpv6_ndp_opt opt;
uint32_t n;
static uint8_t pad[8] = { 0 };
uint32_t pad_s = 0;
libnet_pblock_t* p;
if(l == NULL)
return -1;
if(!option)
option_s = 0;
/* options need to be padded to a multiple of 8-bytes, and opts.len is
in units of 8-bytes */
n = sizeof(opt) + option_s;
if(n % 8)
{
n += 8 - (n % 8);
}
if(n > (0xff * 8))
{
return -1;
}
pad_s = n - option_s - sizeof(opt);
assert((n % 8) == 0);
assert(pad_s < sizeof(pad));
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV6_NDP_OPT_H);
if(p == NULL)
return -1;
memset(&opt, 0, sizeof(opt));
opt.type = type;
opt.len = n / 8;
if(libnet_pblock_append(l, p, &opt, sizeof(opt)) == -1)
goto bad;
if(libnet_pblock_append(l, p, option, option_s) == -1)
goto bad;
if(libnet_pblock_append(l, p, pad, pad_s) == -1)
goto bad;
return ptag ? ptag : libnet_pblock_update(l, p, n, LIBNET_PBLOCK_ICMPV6
_NDP_OPT_H);
bad:
libnet_pblock_delete(l, p);
return -1;
}
 End of changes. 12 change blocks. 
21 lines changed or deleted 41 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/