2 * $Id: silvertongue.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
5 * silvertongue.c - ICMP_REDIRECT Packet assembly tester
7 * Written by Nicholas Brawn with some modifications by Mike D. Schiffman.
8 * Copyright (c) 1999, 2000 Nicholas Brawn <nick@feralmonkey.org>
9 * Copyright (c) 1998, 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "../../include/config.h"
38 #include "../libnet_test.h"
41 main(int argc, char **argv)
45 u_long src, dst, gateway;
50 "usage: %s <old_router> <target> <new_gateway>\n",
55 if (!(src = libnet_name_resolve(argv[1], 1)))
57 perror("Error resolving source host");
61 if (!(dst = libnet_name_resolve(argv[2], 1)))
63 perror("Error resolving destination host");
67 if (!(gateway = libnet_name_resolve(argv[3], 1)))
69 perror("Error resolving gateway host");
73 if (libnet_init_packet(IP_MAXPACKET, &buf) == -1)
75 perror("Couldn't allocate memory for header");
79 if ((sockfd = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
81 perror("Couldn't open raw socket");
85 libnet_build_ip(LIBNET_ICMP_REDIRECT_H + LIBNET_IP_H,
86 IPTOS_LOWDELAY | IPTOS_THROUGHPUT,
97 libnet_build_icmp_redirect(
101 0, /* just an ip header */
102 IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* IP tos */
106 IPPROTO_ICMP, /* Transport protocol */
108 src, /* Destination IP */
109 NULL, /* pointer to payload */
110 0, /* size of payload */
111 buf + LIBNET_IP_H); /* packet header memory */
115 libnet_do_checksum(buf, IPPROTO_ICMP, LIBNET_ICMP_REDIRECT_H +
118 c = libnet_write_ip(sockfd, buf, LIBNET_ICMP_REDIRECT_H + 2 *
120 if (c != LIBNET_ICMP_REDIRECT_H + 2 * LIBNET_IP_H)
122 fprintf(stderr, "Error writing to socket, only wrote %d bytes\n", c);
125 printf("Completed, wrote %d bytes\n", c);
126 libnet_destroy_packet(&buf);