OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / test / OSPF / ospf_request.c
1 /*
2  *  $Id: ospf_request.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet
5  *  ospf_request.c - generic OSPF LSR packet builder
6  *
7  *  Copyright (c) 1999, 2000 Andrew Reiter <areiter@bindview.com>
8  *  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  */
32
33 #if (HAVE_CONFIG_H)
34 #include "../../include/config.h"
35 #endif
36 #include "../libnet_test.h"
37
38 void    help(char *);
39
40 int
41 main(int argc, char **argv)
42 {
43     int warn, sock, len;
44     u_char *pack;
45     char *from, *to, *adrtr;
46     u_long src, dest, advrouter, addaid, addrid;
47     u_char auth[2]; 
48
49     if (argc != 4)
50         help(argv[0]);
51
52     from = argv[1];
53     to = argv[2];
54     adrtr = argv[3]; 
55
56     sock = libnet_open_raw_sock(IPPROTO_RAW);
57     if (sock == -1) {
58         perror("socket");
59         exit(-1);
60     }
61
62     src = libnet_name_resolve(from, 0);
63     dest = libnet_name_resolve(to, 0);
64     advrouter = libnet_name_resolve(adrtr, 0);
65
66     addaid = 0xc0ffeeb0;
67     addrid = 0xb00f00d0;
68
69     len = LIBNET_IP_H + LIBNET_OSPF_H + LIBNET_AUTH_H + LIBNET_LSR_H;
70     pack = (u_char *)malloc(len);
71     
72     libnet_build_ip(LIBNET_OSPF_H + LIBNET_AUTH_H + LIBNET_LSR_H, 0x00,
73             (u_short)rand(), IP_DF, 0xff, IPPROTO_OSPF, src, dest, NULL,
74             0, pack);
75
76     memset(auth, 0, sizeof(auth));
77
78     libnet_build_ospf(LIBNET_AUTH_H + LIBNET_LSR_H, LIBNET_OSPF_LSR,
79             addrid, addaid, LIBNET_OSPF_AUTH_NULL, NULL, 0, pack +
80             LIBNET_IP_H);
81
82     LIBNET_OSPF_AUTHCPY(pack + LIBNET_IP_H + LIBNET_OSPF_H, auth);
83
84     libnet_build_ospf_lsr(LIBNET_LS_TYPE_RTR, 0xffffffff, advrouter, NULL, 0, 
85                         pack + LIBNET_IP_H + LIBNET_OSPF_H + LIBNET_AUTH_H);
86
87     libnet_do_checksum(pack, IPPROTO_OSPF, len);
88
89     warn = libnet_write_ip(sock, pack, len); 
90     if (warn == -1) {
91         printf("Error writing packet to wire\n");
92         free(pack);
93     } else {
94         printf("%d bytes written\n", warn);
95     }
96
97     free(pack);
98     return (0);
99 }
100
101 void
102 help(char *pname)
103 {
104     printf("Usage: %s <source ip> <dest. ip> <router ip>\n", pname);
105     printf("[Use x.x.x.x format]\n");
106     exit(0);
107 }