b0VIM 6.2:JW@zemikerounder.local~mike/Projects/libnet/sample/icmp_redirect.c0123 !"#Upth`idahC`T 9 X q & B j h ] L 7 IHAO sd/) @#3s& pjeJ  IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */ LIBNET_IPV4_H + payload_s, /* length */ t = libnet_build_ipv4( } exit(EXIT_FAILURE); usage(argv[0]); { if (!src_ip || !dst_ip || !gw_ip) } } break; } exit(1); fprintf(stderr, "Bad gateway IP address: %s\n", optarg); { if ((gw_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) case 'g': break; } exit(1); fprintf(stderr, "Bad source IP address: %s\n", optarg); { if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) case 's': break; } exit(1); fprintf(stderr, "Bad destination IP address: %s\n", optarg); { if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1) case 'd': { switch (c) { while((c = getopt(argc, argv, "d:s:g:")) != EOF) gw_ip = 0; dst_ip = 0; src_ip = 0; } exit(EXIT_FAILURE); fprintf(stderr, "libnet_init() failed: %s", errbuf); { if (l == NULL) errbuf); /* errbuf */ NULL, /* network interface */ LIBNET_LINK, /* injection type */ l = libnet_init( */ * Initialize the library. Root priviledges are required. /* printf("libnet 1.1 packet shaping: ICMP redirect[link]\n"); char errbuf[LIBNET_ERRBUF_SIZE]; u_long payload_s = 8; u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5}; u_long src_ip, dst_ip, gw_ip; libnet_ptag_t t; libnet_t *l; int c;{main(int argc, char **argv)int#include "./libnet_test.h"#endif#include "../include/config.h"#if (HAVE_CONFIG_H) */ * * SUCH DAMAGE. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * * documentation and/or other materials provided with the distribution. * notice, this list of conditions and the following disclaimer in the * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer. * 1. Redistributions of source code must retain the above copyright * are met: * modification, are permitted provided that the following conditions * Redistribution and use in source and binary forms, with or without * * All rights reserved. * Copyright (c) 2003 Alberto Ornaghi * Copyright (c) 1998 - 2004 Mike D. Schiffman * * Build an ICMP redirect packet * libnet 1.1 * * $Id: .icmp_redirect.c.swp,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $/*daC`~@v- \ P ? 9 c . \ K E O  Q >maPJs)XcQKF?!4.PNMCB/* EOF */} fprintf(stderr, "usage: %s -s source_ip -d destination_ip -g gateway_ip\n ", name);{usage(char *name)void} return (EXIT_FAILURE); libnet_destroy(l);bad: return (EXIT_SUCCESS); libnet_destroy(l); } fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c); { else } goto bad; fprintf(stderr, "Write error: %s\n", libnet_geterror(l)); { if (c == -1) c = libnet_write(l); */ * Write it to the wire. /* } goto bad; fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l)); { if (t == -1) 0); /* libnet id */ l, /* libnet handle */ 0, /* payload size */ NULL, /* payload */ ETHERTYPE_IP, /* protocol type */ enet_src, /* ethernet source */ enet_dst, /* ethernet destination */ t = libnet_build_ethernet( } goto bad; fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l)); { if (t == -1) 0); l, /* libnet handle */ 0, /* payload size */ NULL, /* payload */ dst_ip, /* destination IP */ src_ip, /* source IP */ 0, /* checksum */ IPPROTO_ICMP, /* protocol */ 64, /* TTL */ 0, /* IP Frag */ 0xee, /* IP ID */ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */ LIBNET_IPV4_H + payload_s, /* length */ LIBNET_IPV4_H + LIBNET_ICMPV4_REDIRECT_H + t = libnet_build_ipv4( } goto bad; fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l)); { if (t == -1) 0); /* libnet id */ l, /* libnet handle */ 0, NULL, gw_ip, 0, /* checksum */ ICMP_REDIRECT_HOST, /* code */ ICMP_REDIRECT, /* type */ t = libnet_build_icmpv4_redirect( } goto bad; libnet_geterror(l)); fprintf(stderr, "Can't build error IP header: %s\n", { if (t == -1) 0); l, /* libnet handle */ payload_s, /* payload size */ payload, /* payload */ src_ip, /* destination IP */ dst_ip, /* source IP */ 0, /* checksum */ IPPROTO_ICMP, /* protocol */ 64, /* TTL */ 0, /* IP Frag */ 0x42, /* IP ID */