From 51b642cea9038a945c723dfbde41a922153348d3 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 1 Apr 2009 20:33:17 -0700 Subject: Removed CVS crud, again. --- libnet/sample/.#icmp_unreach.c.1.2 | 190 ------------ libnet/src/.#libnet_build_icmp.c.1.12 | 558 ---------------------------------- libnet/src/.#libnet_internal.c.1.10 | 308 ------------------- 3 files changed, 1056 deletions(-) delete mode 100644 libnet/sample/.#icmp_unreach.c.1.2 delete mode 100644 libnet/src/.#libnet_build_icmp.c.1.12 delete mode 100644 libnet/src/.#libnet_internal.c.1.10 diff --git a/libnet/sample/.#icmp_unreach.c.1.2 b/libnet/sample/.#icmp_unreach.c.1.2 deleted file mode 100644 index 0c155db..0000000 --- a/libnet/sample/.#icmp_unreach.c.1.2 +++ /dev/null @@ -1,190 +0,0 @@ -/* - * $Id: icmp_unreach.c,v 1.2 2004/01/03 20:31:01 mike Exp $ - * - * libnet 1.1 - * Build an ICMP unreachable packet - * - * Hacked by Aaron Turner to illustrate two bugs - * - * Copyright (c) 1998 - 2004 Mike D. Schiffman - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#if (HAVE_CONFIG_H) -#include "../include/config.h" -#endif -#include "./libnet_test.h" - -int -main(int argc, char **argv) -{ - int c, i; - libnet_t *l = NULL; - libnet_ptag_t icmp = 0, ip = 0, eth = 0; - u_long src_ip, dst_ip; - u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5}; - u_long payload_s = 8; - int mode = LIBNET_LINK; - char errbuf[LIBNET_ERRBUF_SIZE]; - - printf("libnet 1.1 packet shaping: ICMP unreachable[link]\n"); - - src_ip = 0; - dst_ip = 0; - - while((c = getopt(argc, argv, "d:s:r")) != EOF) - { - switch (c) - { - case 'd': - if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) - { - fprintf(stderr, "Bad destination IP address: %s\n", optarg); - exit(1); - } - break; - case 's': - if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) - { - fprintf(stderr, "Bad source IP address: %s\n", optarg); - exit(1); - } - break; - case 'r': - mode = LIBNET_RAW4; - break; - } - } - if (!src_ip || !dst_ip) - { - usage(argv[0]); - exit(EXIT_FAILURE); - } - - /* - * Initialize the library. Root priviledges are required. - */ - l = libnet_init( - mode, /* injection type */ - NULL, /* network interface */ - errbuf); /* errbuf */ - - if (l == NULL) - { - fprintf(stderr, "libnet_init() failed: %s", errbuf); - exit(EXIT_FAILURE); - } - -for (i = 1; i <= 255; i ++) { - icmp = libnet_build_icmpv4_unreach( - ICMP_UNREACH, /* type */ - ICMP_UNREACH_PORT, /* code */ - 0, /* checksum */ - LIBNET_IPV4_H + payload_s, /* o length */ - IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* o IP tos */ - (u_int16_t)i, /* o IP ID */ - 0, /* o frag */ - 64, /* o TTL */ - IPPROTO_UDP, /* o protocol */ - 0, /* o checksum */ - dst_ip, /* o source IP */ - src_ip, /* o destination IP */ - payload, /* payload */ - payload_s, /* payload size */ - l, /* libnet handle */ - icmp); - if (icmp == -1) - { - fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l)); - goto bad; - } - - ip = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_ICMPV4_UNREACH_H + - LIBNET_IPV4_H + payload_s, /* length */ - IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */ - (u_int16_t)i, /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_ICMP, /* protocol */ - 0, /* checksum */ - src_ip, /* source IP */ - dst_ip, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - ip); - if (ip == -1) - { - fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l)); - goto bad; - } - - if (mode == LIBNET_LINK) { - eth = libnet_build_ethernet( - enet_dst, /* ethernet destination */ - enet_src, /* ethernet source */ - ETHERTYPE_IP, /* protocol type */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - eth); /* libnet id */ - - if (eth == -1) - { - fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l)); - goto bad; - } - } - /* - * Write it to the wire. - */ - libnet_diag_dump_pblock(l); - c = libnet_write(l); - if (c == -1) - { - fprintf(stderr, "Write error: %s\n", libnet_geterror(l)); - goto bad; - } - else - { - fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c); - } -} - libnet_destroy(l); - return (EXIT_SUCCESS); -bad: - libnet_destroy(l); - return (EXIT_FAILURE); -} - - -void -usage(char *name) -{ - fprintf(stderr, "usage: %s [-r] -s source_ip -d destination_ip\n ", name); -} - -/* EOF */ diff --git a/libnet/src/.#libnet_build_icmp.c.1.12 b/libnet/src/.#libnet_build_icmp.c.1.12 deleted file mode 100644 index 1590eb7..0000000 --- a/libnet/src/.#libnet_build_icmp.c.1.12 +++ /dev/null @@ -1,558 +0,0 @@ -/* - * $Id: libnet_build_icmp.c,v 1.12 2004/02/16 23:13:38 mike Exp $ - * - * libnet - * libnet_build_icmp.c - ICMP packet assemblers - * - * Copyright (c) 1998 - 2004 Mike D. Schiffman - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#if (HAVE_CONFIG_H) -#include "../include/config.h" -#endif -#if (!(_WIN32) || (__CYGWIN__)) -#include "../include/libnet.h" -#else -#include "../include/win32/libnet.h" -#endif - -libnet_ptag_t -libnet_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, -libnet_t *l, libnet_ptag_t ptag) -{ - u_int32_t n, h; - libnet_pblock_t *p; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - n = LIBNET_ICMPV4_ECHO_H + payload_s; /* size of memory block */ - h = LIBNET_ICMPV4_ECHO_H + payload_s; /* hl for checksum */ - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_ECHO_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.icmp_id = htons(id); /* packet id */ - icmp_hdr.icmp_seq = htons(seq); /* packet seq */ - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, LIBNET_ICMPV4_ECHO_H); - if (n == -1) - { - goto bad; - } - - if ((payload && !payload_s) || (!payload && payload_s)) - { - 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 checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_ECHO_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -libnet_ptag_t -libnet_build_icmpv4_mask(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int16_t id, u_int16_t seq, u_int32_t mask, u_int8_t *payload, -u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) -{ - u_int32_t n, h; - libnet_pblock_t *p; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - n = LIBNET_ICMPV4_MASK_H + payload_s; /* size of memory block */ - h = LIBNET_ICMPV4_MASK_H + payload_s; /* hl for checksum */ - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_MASK_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.icmp_id = htons(id); /* packet id */ - icmp_hdr.icmp_seq = htons(seq); /* packet seq */ - icmp_hdr.icmp_mask = htonl(mask); /* address mask */ - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, LIBNET_ICMPV4_MASK_H); - if (n == -1) - { - goto bad; - } - - if ((payload && !payload_s) || (!payload && payload_s)) - { - 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 checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_MASK_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -libnet_ptag_t -libnet_build_icmpv4_timestamp(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int16_t id, u_int16_t seq, n_time otime, n_time rtime, n_time ttime, -u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) -{ - u_int32_t n, h; - libnet_pblock_t *p; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - n = LIBNET_ICMPV4_TS_H + payload_s; /* size of memory block */ - h = LIBNET_ICMPV4_TS_H + payload_s; /* hl for checksum */ - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_TS_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.icmp_id = htons(id); /* packet id */ - icmp_hdr.icmp_seq = htons(seq); /* packet seq */ - icmp_hdr.icmp_otime = htonl(otime); /* original timestamp */ - icmp_hdr.icmp_rtime = htonl(rtime); /* receive timestamp */ - icmp_hdr.icmp_ttime = htonl(ttime); /* transmit timestamp */ - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, LIBNET_ICMPV4_TS_H); - if (n == -1) - { - goto bad; - } - - if ((payload && !payload_s) || (!payload && payload_s)) - { - 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 checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_TS_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -libnet_ptag_t -libnet_build_icmpv4_unreach(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, u_int16_t orig_frag, -u_int8_t orig_ttl, u_int8_t orig_prot, u_int16_t orig_check, -u_int32_t orig_src, u_int32_t orig_dst, u_int8_t *payload, u_int32_t payload_s, -libnet_t *l, libnet_ptag_t ptag) -{ - u_int32_t n, h; - libnet_ptag_t ipv4; - libnet_pblock_t *p, *q; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - p = NULL; - /* payload refers to the payload in the original IP header */ - if ((payload && !payload_s) || (!payload && payload_s)) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): payload inconsistency\n", __func__); - goto bad; - } - - /* - * Build the original IPv4 header in its own pblock. We stick the - * payload here. - */ - ipv4 = libnet_build_ipv4(orig_len, orig_tos, orig_id, orig_frag, orig_ttl, - orig_prot, orig_check, orig_src, orig_dst, payload, payload_s, l, 0); - - if (ipv4 == -1) - { - /* error set elsewhere */ - return (-1); - } - - if (orig_check == 0) - { - int c = 0; - l->aligner = 8 - (l->link_offset % 8); - q = libnet_pblock_find(l, ipv4); - c = libnet_do_checksum(l, q->buf, libnet_pblock_p2p(q->type), - q->h_len); - if (c == -1) - { - /* err msg set in libnet_do_checksum() */ - return (-1); - } - } - - /* - * Now we can build the ICMP part of the packet - */ - n = LIBNET_ICMPV4_UNREACH_H; /* size of memory block */ - /* hl for checksum */ - h = LIBNET_ICMPV4_UNREACH_H + LIBNET_IPV4_H + payload_s; - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_UNREACH_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.icmp_id = 0; /* must be 0 */ - icmp_hdr.icmp_seq = 0; /* must be 0 */ - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, - LIBNET_ICMPV4_UNREACH_H); - if (n == -1) - { - /* error set elsewhere */ - goto bad; - } - - if (sum == 0) - { - /* - * If checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_UNREACH_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -libnet_ptag_t -libnet_build_icmpv4_timeexceed(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, u_int16_t orig_frag, -u_int8_t orig_ttl, u_int8_t orig_prot, u_int16_t orig_check, -u_int32_t orig_src, u_int32_t orig_dst, u_int8_t *payload, u_int32_t payload_s, -libnet_t *l, libnet_ptag_t ptag) -{ - u_int32_t n, h; - libnet_ptag_t ipv4; - libnet_pblock_t *p, *q; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - p = NULL; - /* payload refers to the payload in the original IP header */ - if ((payload && !payload_s) || (!payload && payload_s)) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): payload inconsistency\n", __func__); - goto bad; - } - - /* - * Build the original IPv4 header in its own pblock. We stick the - * payload here. - */ - ipv4 = libnet_build_ipv4(orig_len, orig_tos, orig_id, orig_frag, orig_ttl, - orig_prot, orig_check, orig_src, orig_dst, payload, payload_s, l, 0); - - if (ipv4 == -1) - { - /* error set elsewhere */ - return (-1); - } - - if (orig_check == 0) - { - int c = 0; - l->aligner = 8 - (l->link_offset % 8); - q = libnet_pblock_find(l, ipv4); - c = libnet_do_checksum(l, q->buf, libnet_pblock_p2p(q->type), - q->h_len); - if (c == -1) - { - /* err msg set in libnet_do_checksum() */ - return (-1); - } - } - - /* size of memory block */ - n = LIBNET_ICMPV4_TIMXCEED_H; - /* hl for checksum */ - h = LIBNET_ICMPV4_TIMXCEED_H + LIBNET_IPV4_H + payload_s; - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_TIMXCEED_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.icmp_id = 0; /* must be 0 */ - icmp_hdr.icmp_seq = 0; /* must be 0 */ - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, - LIBNET_ICMPV4_TIMXCEED_H); - if (n == -1) - { - goto bad; - } - - if (sum == 0) - { - /* - * If checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_TIMXCEED_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -libnet_ptag_t -libnet_build_icmpv4_redirect(u_int8_t type, u_int8_t code, u_int16_t sum, -u_int32_t gateway, u_int16_t orig_len, u_int8_t orig_tos, u_int16_t orig_id, -u_int16_t orig_frag, u_int8_t orig_ttl, u_int8_t orig_prot, -u_int16_t orig_check, u_int32_t orig_src, u_int32_t orig_dst, -u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag) - -{ - u_int32_t n, h; - libnet_ptag_t ipv4; - libnet_pblock_t *p, *q; - struct libnet_icmpv4_hdr icmp_hdr; - - if (l == NULL) - { - return (-1); - } - - p = NULL; - /* payload refers to the payload in the original IP header */ - if ((payload && !payload_s) || (!payload && payload_s)) - { - snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, - "%s(): payload inconsistency\n", __func__); - goto bad; - } - - /* - * Build the original IPv4 header in its own pblock. We stick the - * payload here. - */ - ipv4 = libnet_build_ipv4(orig_len, orig_tos, orig_id, orig_frag, orig_ttl, - orig_prot, orig_check, orig_src, orig_dst, payload, payload_s, l, 0); - - if (ipv4 == -1) - { - /* error set elsewhere */ - return (-1); - } - - if (orig_check == 0) - { - int c = 0; - l->aligner = 8 - (l->link_offset % 8); - q = libnet_pblock_find(l, ipv4); - c = libnet_do_checksum(l, q->buf, libnet_pblock_p2p(q->type), - q->h_len); - if (c == -1) - { - /* err msg set in libnet_do_checksum() */ - return (-1); - } - } - - n = LIBNET_ICMPV4_REDIRECT_H; /* size of memory block */ - /* hl for checksum */ - h = LIBNET_ICMPV4_REDIRECT_H + LIBNET_IPV4_H + payload_s; - - /* - * Find the existing protocol block if a ptag is specified, or create - * a new one. - */ - p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_ICMPV4_REDIRECT_H); - if (p == NULL) - { - return (-1); - } - - memset(&icmp_hdr, 0, sizeof(icmp_hdr)); - icmp_hdr.icmp_type = type; /* packet type */ - icmp_hdr.icmp_code = code; /* packet code */ - icmp_hdr.icmp_sum = (sum ? htons(sum) : 0); /* checksum */ - icmp_hdr.hun.gateway = gateway; - - n = libnet_pblock_append(l, p, (u_int8_t *)&icmp_hdr, - LIBNET_ICMPV4_REDIRECT_H); - if (n == -1) - { - goto bad; - } - - if (sum == 0) - { - /* - * If checksum is zero, by default libnet will compute a checksum - * for the user. The programmer can override this by calling - * libnet_toggle_checksum(l, ptag, 1); - */ - libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM); - } - return (ptag ? ptag : libnet_pblock_update(l, p, h, - LIBNET_PBLOCK_ICMPV4_REDIRECT_H)); -bad: - libnet_pblock_delete(l, p); - return (-1); -} - -/* EOF */ diff --git a/libnet/src/.#libnet_internal.c.1.10 b/libnet/src/.#libnet_internal.c.1.10 deleted file mode 100644 index e443c63..0000000 --- a/libnet/src/.#libnet_internal.c.1.10 +++ /dev/null @@ -1,308 +0,0 @@ -/* - * $Id: libnet_internal.c,v 1.10 2004/01/28 19:45:00 mike Exp $ - * - * libnet - * libnet_internal.c - secret routines! - * - * Copyright (c) 1998 - 2004 Mike D. Schiffman - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ - -#if (HAVE_CONFIG_H) -#include "../include/config.h" -#endif -#if (!(_WIN32) || (__CYGWIN__)) -#include "../include/libnet.h" -#else -#include "../include/win32/libnet.h" -#endif - - -void -__libnet_dump_hex(u_int8_t *packet, u_int32_t len, int swap, FILE *stream) -{ - int i, s_cnt; - u_int16_t *p; - - p = (u_int16_t *)packet; - s_cnt = len / sizeof(u_int16_t); - - fprintf(stream, "\t"); - for (i = 0; --s_cnt >= 0; i++) - { - if ((!(i % 8))) - { - fprintf(stream, "\n%02x\t", (i * 2)); - } - fprintf(stream, "%04x ", swap ? ntohs(*(p++)) : *(p++)); - } - - /* - * Mop up an odd byte. - */ - if (len & 1) - { - if ((!(i % 8))) - { - fprintf(stream, "\n%02x\t", (i * 2)); - } - fprintf(stream, "%02x ", *(u_int8_t *)p); - } - fprintf(stream, "\n"); -} - - -void -__libnet_dump_context(libnet_t *l) -{ - if (l == NULL) - { - return; - } - - fprintf(stderr, "fd:\t\t%d\n", l->fd); - - switch (l->injection_type) - { - case LIBNET_LINK: - fprintf(stderr, "injection type:\tLIBNET_LINK\n"); - break; - case LIBNET_RAW4: - fprintf(stderr, "injection type:\tLIBNET_RAW4\n"); - break; - case LIBNET_RAW6: - fprintf(stderr, "injection type:\tLIBNET_RAW6\n"); - break; - case LIBNET_LINK_ADV: - fprintf(stderr, "injection type:\tLIBNET_LINK_ADV\n"); - break; - case LIBNET_RAW4_ADV: - fprintf(stderr, "injection type:\tLIBNET_RAW4_ADV\n"); - break; - case LIBNET_RAW6_ADV: - fprintf(stderr, "injection type:\tLIBNET_RAW6_ADV\n"); - break; - default: - fprintf(stderr, "injection type:\tinvalid injection type %d\n", - l->injection_type); - break; - } - - fprintf(stderr, "pblock start:\t%p\n", l->protocol_blocks); - fprintf(stderr, "pblock end:\t%p\n", l->pblock_end); - fprintf(stderr, "link type:\t%d\n", l->link_type); - fprintf(stderr, "link offset:\t%d\n", l->link_offset); - fprintf(stderr, "aligner:\t%d\n", l->aligner); - fprintf(stderr, "device:\t\t%s\n", l->device); - fprintf(stderr, "packets sent:\t%lld\n", l->stats.packets_sent); - fprintf(stderr, "packet errors:\t%lld\n", l->stats.packet_errors); - fprintf(stderr, "bytes written:\t%lld\n", l->stats.bytes_written); - fprintf(stderr, "ptag state:\t%d\n", l->ptag_state); - fprintf(stderr, "context label:\t%s\n", l->label); - fprintf(stderr, "last errbuf:\t%s\n", l->err_buf); - fprintf(stderr, "total size:\t%d\n", l->total_size); -} - -void -__libnet_dump_pblock(libnet_t *l) -{ - u_int32_t n; - libnet_pblock_t *p; - - for (p = l->protocol_blocks; p; p = p->next) - { - fprintf(stderr, "pblock type:\t%s\n", - __libnet_dump_pblock_type(p->type)); - fprintf(stderr, "ptag number:\t%d\n", p->ptag); - fprintf(stderr, "pblock address:\t%p\n", p); - fprintf(stderr, "next pblock\t%p ", p->next); - if (p->next) - { - fprintf(stderr, "(%s)", __libnet_dump_pblock_type(p->next->type)); - } - fprintf(stderr, "\n"); - fprintf(stderr, "prev pblock\t%p ", p->prev); - if (p->prev) - { - fprintf(stderr, "(%s)", __libnet_dump_pblock_type(p->prev->type)); - } - fprintf(stderr, "\n"); - fprintf(stderr, "buf:\t\t"); - for (n = 0; n < p->b_len; n++) - { - fprintf(stderr, "%02x", p->buf[n]); - } - fprintf(stderr, "\nbuffer length:\t%d\n", p->b_len); - if ((p->flags) & LIBNET_PBLOCK_DO_CHECKSUM) - { - fprintf(stderr, "checksum flag:\tYes\n"); - fprintf(stderr, "chksum length:\t%d\n", p->h_len); - } - else - { - fprintf(stderr, "checksum flag:\tNo\n"); - } - fprintf(stderr, "bytes copied:\t%d\n\n", p->copied); - } -} - -int8_t * -__libnet_dump_pblock_type(u_int8_t type) -{ - static int8_t buf[50]; - switch (type) - { - case LIBNET_PBLOCK_ARP_H: - return ("arp header"); - case LIBNET_PBLOCK_DHCPV4_H: - return ("dhcpv4 header"); - case LIBNET_PBLOCK_DNSV4_H: - return ("dnsv4 header"); - case LIBNET_PBLOCK_ETH_H: - return ("ethernet header"); - case LIBNET_PBLOCK_ICMPV4_H: - return ("icmpv4 header"); - case LIBNET_PBLOCK_ICMPV4_ECHO_H: - return ("icmpv4 echo header"); - case LIBNET_PBLOCK_ICMPV4_MASK_H: - return ("icmpv4 mask header"); - case LIBNET_PBLOCK_ICMPV4_UNREACH_H: - return ("icmpv4 unreachable header"); - case LIBNET_PBLOCK_ICMPV4_TIMXCEED_H: - return ("icmpv4 time exceeded header"); - case LIBNET_PBLOCK_ICMPV4_REDIRECT_H: - return ("icmpv4 redirect header"); - case LIBNET_PBLOCK_ICMPV4_TS_H: - return ("icmpv4 timestamp header"); - case LIBNET_PBLOCK_IGMP_H: - return ("igmp header"); - case LIBNET_PBLOCK_IPV4_H: - return ("ipv4 header"); - case LIBNET_PBLOCK_IPO_H: - return ("ip options header"); - case LIBNET_PBLOCK_IPDATA: - return ("ip data"); - case LIBNET_PBLOCK_OSPF_H: - return ("ospf header"); - case LIBNET_PBLOCK_OSPF_HELLO_H: - return ("ospf hello header"); - case LIBNET_PBLOCK_OSPF_DBD_H: - return ("ospf dbd header"); - case LIBNET_PBLOCK_OSPF_LSR_H: - return ("ospf lsr header"); - case LIBNET_PBLOCK_OSPF_LSU_H: - return ("ospf lsu header"); - case LIBNET_PBLOCK_OSPF_LSA_H: - return ("ospf lsa header"); - case LIBNET_PBLOCK_OSPF_AUTH_H: - return ("ospf authentication header"); - case LIBNET_PBLOCK_OSPF_CKSUM: - return ("ospf checksum"); - case LIBNET_PBLOCK_LS_RTR_H: - return ("ospf ls rtr header"); - case LIBNET_PBLOCK_LS_NET_H: - return ("ospf ls net header"); - case LIBNET_PBLOCK_LS_SUM_H: - return ("ospf ls sum header"); - case LIBNET_PBLOCK_LS_AS_EXT_H: - return ("ospf ls as extension header"); - case LIBNET_PBLOCK_NTP_H: - return ("ntp header"); - case LIBNET_PBLOCK_RIP_H: - return ("rip header"); - case LIBNET_PBLOCK_TCP_H: - return ("tcp header"); - case LIBNET_PBLOCK_TCPO_H: - return ("tcp options header"); - case LIBNET_PBLOCK_TCPDATA: - return ("tcp data"); - case LIBNET_PBLOCK_UDP_H: - return ("udp header"); - case LIBNET_PBLOCK_VRRP_H: - return ("vrrp header"); - case LIBNET_PBLOCK_DATA_H: - return ("data"); - case LIBNET_PBLOCK_CDP_H: - return ("cdp header"); - case LIBNET_PBLOCK_IPSEC_ESP_HDR_H: - return ("ipsec esp header"); - case LIBNET_PBLOCK_IPSEC_ESP_FTR_H: - return ("ipsec esp footer"); - case LIBNET_PBLOCK_IPSEC_AH_H: - return ("ipsec authentication header"); - case LIBNET_PBLOCK_802_1Q_H: - return ("802.1q header"); - case LIBNET_PBLOCK_802_2_H: - return ("802.2 header"); - case LIBNET_PBLOCK_802_2SNAP_H: - return ("802.2SNAP header"); - case LIBNET_PBLOCK_802_3_H: - return ("802.3 header"); - case LIBNET_PBLOCK_STP_CONF_H: - return ("stp configuration header"); - case LIBNET_PBLOCK_STP_TCN_H: - return ("stp tcn header"); - case LIBNET_PBLOCK_ISL_H: - return ("isl header"); - case LIBNET_PBLOCK_IPV6_H: - return ("ipv6 header"); - case LIBNET_PBLOCK_802_1X_H: - return ("802.1x header"); - case LIBNET_PBLOCK_RPC_CALL_H: - return ("rpc call header"); - case LIBNET_PBLOCK_MPLS_H: - return ("mlps header"); - case LIBNET_PBLOCK_FDDI_H: - return ("fddi header"); - case LIBNET_PBLOCK_TOKEN_RING_H: - return ("token ring header"); - case LIBNET_PBLOCK_BGP4_HEADER_H: - return ("bgp header"); - case LIBNET_PBLOCK_BGP4_OPEN_H: - return ("bgp open header"); - case LIBNET_PBLOCK_BGP4_UPDATE_H: - return ("bgp update header"); - case LIBNET_PBLOCK_BGP4_NOTIFICATION_H: - return ("bgp notification header"); - case LIBNET_PBLOCK_GRE_H: - return ("gre header"); - case LIBNET_PBLOCK_GRE_SRE_H: - return ("gre sre header"); - case LIBNET_PBLOCK_IPV6_FRAG_H: - return ("ipv6 fragmentation header"); - case LIBNET_PBLOCK_IPV6_ROUTING_H: - return ("ipv6 routing header"); - case LIBNET_PBLOCK_IPV6_DESTOPTS_H: - return ("ipv6 destination options header"); - case LIBNET_PBLOCK_IPV6_HBHOPTS_H: - return ("ipv6 hop by hop options header"); - default: - snprintf(buf, sizeof(buf), - "%s(): unknown pblock type: %d", __func__, type); - return (buf); - } - return ("unreachable code"); -} -/* EOF */ -- cgit v1.2.1