Annotation of embedaddon/libnet/sample/icmp6_unreach.c, revision 1.1.1.1
1.1 misho 1: /*
2: * $Id: icmp6_unreach.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: 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 unreach/admin prohibited 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: uint8_t payload[56];
127: int i;
128: for (i=0; i<sizeof(payload); i++)
129: payload[i]='A'+(i%26);
130: t = libnet_build_icmpv6_unreach (
131: ICMP6_UNREACH, /* type */
132: ICMP6_ADM_PROHIBITED, /* code */
133: 0, /* checksum */
134: payload, /* payload */
135: sizeof(payload), /* payload length */
136: l, /* libnet context */
137: t); /* libnet ptag */
138:
139:
140:
141: if (build_ip)
142: {
143: build_ip = 0;
144: libnet_build_ipv6(0,0,
145: LIBNET_IPV6_H + LIBNET_ICMPV6_H + sizeof(payload),
146: IPPROTO_ICMP6,
147: 64,
148: src_ip,
149: dst_ip,
150: NULL,
151: 0,
152: l,
153: 0);
154: }
155: printf("%15s/%5d -> %15s/%5d\n",
156: srcname,
157: ntohs(src_prt),
158: dstname,
159: dst_prt);
160: c = libnet_write(l);
161: if (c == -1)
162: {
163: fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
164: }
165: #if !(__WIN32__)
166: usleep(250);
167: #else
168: Sleep(250);
169: #endif
170:
171: }
172: #if !(__WIN32__)
173: sleep(burst_int);
174: #else
175: Sleep(burst_int * 1000);
176: #endif
177: }
178: exit(EXIT_SUCCESS);
179: }
180:
181:
182: void
183: usage(char *nomenclature)
184: {
185: fprintf(stderr,
186: "\n\nusage: %s -t -a [-i -b]\n"
187: "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
188: "\t-a number of packets to send per burst\n"
189: "\t-i packet burst sending interval (defaults to 0)\n"
190: "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
191: }
192:
193:
194: /* EOF */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>