Annotation of embedaddon/libnet/sample/icmp6_echoreq.c, revision 1.1
1.1 ! misho 1: /*
! 2: * $Id: icmp6_echoreq.c,v 1.1.1.1 2003/06/26 21:55:10 route Exp $
! 3: *
! 4: * Poseidon++ (c) 1996 - 2002 Mike D. Schiffman <mike@infonexus.com>
! 5: * Redone from synflood example by Stefan Schlott <stefan@ploing.de>
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: *
! 16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 17: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 18: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 19: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 20: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 21: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 22: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 24: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 25: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 26: * SUCH DAMAGE.
! 27: *
! 28: */
! 29:
! 30: #if (HAVE_CONFIG_H)
! 31: #include "../include/config.h"
! 32: #endif
! 33: #include "./libnet_test.h"
! 34:
! 35: struct t_pack
! 36: {
! 37: struct libnet_ipv6_hdr ip;
! 38: struct libnet_tcp_hdr tcp;
! 39: };
! 40:
! 41:
! 42: int
! 43: main(int argc, char **argv)
! 44: {
! 45: struct libnet_in6_addr dst_ip;
! 46: struct libnet_in6_addr src_ip;
! 47: u_short dst_prt = 0;
! 48: u_short src_prt = 0;
! 49: libnet_t *l;
! 50: libnet_ptag_t t;
! 51: u_char *cp;
! 52: char errbuf[LIBNET_ERRBUF_SIZE];
! 53: int i, c, packet_amt, burst_int, burst_amt, build_ip;
! 54: char srcname[100],dstname[100];
! 55:
! 56: packet_amt = 0;
! 57: burst_int = 0;
! 58: burst_amt = 1;
! 59:
! 60: printf("libnet 1.1 echo request ICMP6[raw]\n");
! 61:
! 62: /*
! 63: * Initialize the library. Root priviledges are required.
! 64: */
! 65: l = libnet_init(
! 66: LIBNET_RAW6, /* injection type */
! 67: NULL, /* network interface */
! 68: errbuf); /* error buffer */
! 69:
! 70: if (l == NULL)
! 71: {
! 72: fprintf(stderr, "libnet_init() failed: %s", errbuf);
! 73: exit(EXIT_FAILURE);
! 74: }
! 75:
! 76: while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
! 77: {
! 78: switch (c)
! 79: {
! 80: case 't':
! 81: if (!(cp = strrchr(optarg, '/')))
! 82: {
! 83: usage(argv[0]);
! 84: exit(EXIT_FAILURE);
! 85: }
! 86: *cp++ = 0;
! 87: dst_prt = (u_short)atoi(cp);
! 88: dst_ip = libnet_name2addr6(l, optarg, 1);
! 89: if (strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0)
! 90: {
! 91: fprintf(stderr, "Bad IP6 address: %s\n", optarg);
! 92: exit(EXIT_FAILURE);
! 93: }
! 94: break;
! 95: case 'a':
! 96: packet_amt = atoi(optarg);
! 97: break;
! 98: case 'i':
! 99: burst_int = atoi(optarg);
! 100: break;
! 101: case 'b':
! 102: burst_amt = atoi(optarg);
! 103: break;
! 104: default:
! 105: usage(argv[0]);
! 106: exit(EXIT_FAILURE);
! 107: }
! 108: }
! 109:
! 110: if (!dst_prt || strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
! 111: {
! 112: usage(argv[0]);
! 113: exit(EXIT_FAILURE);
! 114: }
! 115:
! 116:
! 117:
! 118: libnet_seed_prand(l);
! 119: libnet_addr2name6_r(src_ip,1,srcname,sizeof(srcname));
! 120: libnet_addr2name6_r(dst_ip,1,dstname,sizeof(dstname));
! 121:
! 122: for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;)
! 123: {
! 124: for (i = 0; i < packet_amt; i++)
! 125: {
! 126: char payload[56];
! 127: int i;
! 128: for (i=0; i<56; i++) payload[i]='A'+((char)(i%26));
! 129: t = libnet_build_icmpv4_echo(ICMP6_ECHO,0,0,1,0,payload,sizeof(payload),l,t);
! 130:
! 131: if (build_ip)
! 132: {
! 133: build_ip = 0;
! 134: libnet_build_ipv6(0,0,
! 135: LIBNET_ICMPV6_H + sizeof(payload),
! 136: IPPROTO_ICMP6,
! 137: 64,
! 138: src_ip,
! 139: dst_ip,
! 140: NULL,
! 141: 0,
! 142: l,
! 143: 0);
! 144: }
! 145: printf("%15s/%5d -> %15s/%5d\n",
! 146: srcname,
! 147: ntohs(src_prt),
! 148: dstname,
! 149: dst_prt);
! 150: c = libnet_write(l);
! 151: if (c == -1)
! 152: {
! 153: fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
! 154: }
! 155: #if !(__WIN32__)
! 156: usleep(250);
! 157: #else
! 158: Sleep(250);
! 159: #endif
! 160:
! 161: }
! 162: #if !(__WIN32__)
! 163: sleep(burst_int);
! 164: #else
! 165: Sleep(burst_int * 1000);
! 166: #endif
! 167: }
! 168: exit(EXIT_SUCCESS);
! 169: }
! 170:
! 171:
! 172: void
! 173: usage(char *nomenclature)
! 174: {
! 175: fprintf(stderr,
! 176: "\n\nusage: %s -t -a [-i -b]\n"
! 177: "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
! 178: "\t-a number of packets to send per burst\n"
! 179: "\t-i packet burst sending interval (defaults to 0)\n"
! 180: "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
! 181: }
! 182:
! 183:
! 184: /* EOF */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>