version 1.1.1.1, 2012/02/21 22:14:23
|
version 1.1.1.2, 2013/07/22 11:54:42
|
Line 40
|
Line 40
|
#endif |
#endif |
|
|
libnet_ptag_t |
libnet_ptag_t |
libnet_build_udp(u_int16_t sp, u_int16_t dp, u_int16_t len, u_int16_t sum, | libnet_build_udp(uint16_t sp, uint16_t dp, uint16_t len, uint16_t sum, |
u_int8_t *payload, 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; |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
struct libnet_udp_hdr udp_hdr; |
struct libnet_udp_hdr udp_hdr; |
|
|
Line 53 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 53 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
} |
} |
|
|
n = LIBNET_UDP_H + payload_s; /* size of memory block */ |
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 |
* Find the existing protocol block if a ptag is specified, or create |
Line 68 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 67 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
memset(&udp_hdr, 0, sizeof(udp_hdr)); |
memset(&udp_hdr, 0, sizeof(udp_hdr)); |
udp_hdr.uh_sport = htons(sp); /* source port */ |
udp_hdr.uh_sport = htons(sp); /* source port */ |
udp_hdr.uh_dport = htons(dp); /* destination 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 */ |
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) |
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; |
|
} |
|
} |
|
|
|
if (sum == 0) |
if (sum == 0) |
{ |
{ |
/* |
/* |
Line 102 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
Line 88 u_int8_t *payload, u_int32_t payload_s, libnet_t *l, l
|
*/ |
*/ |
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); |
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: |
bad: |
libnet_pblock_delete(l, p); |
libnet_pblock_delete(l, p); |
return (-1); |
return (-1); |