OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / test / OSPF / ospf_hello.c
1 /*
2  *  $Id: ospf_hello.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet
5  *  ospf_hello.c - OSPF Hello 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 sock, warn, len;
44     u_char *pack, *to, *from, *neighbor;
45     u_long src, dst, addaid, addrid, nbr,  auth[2];
46
47     if (argc != 4) 
48         help(argv[0]);
49
50     from = argv[1];
51     to = argv[2];
52     neighbor = argv[3];
53
54     len = LIBNET_OSPF_H + LIBNET_HELLO_H + LIBNET_IP_H + LIBNET_AUTH_H;
55     pack = (u_char *)malloc(len);
56
57     sock = libnet_open_raw_sock(IPPROTO_RAW);
58     if (sock == -1) {
59         perror("socket");
60         free(pack);
61         exit(-1);
62     }
63
64
65     src = libnet_name_resolve(from, 0);
66     dst = libnet_name_resolve(to, 0);
67     nbr = libnet_name_resolve(neighbor, 0);
68
69     addrid = 0x23696969;
70     addaid = 0xc0ffee00;        /* GENERIC : FAKE : ETC */
71
72     libnet_build_ip(LIBNET_OSPF_H + LIBNET_AUTH_H + LIBNET_HELLO_H, 0x00,
73                 101, IP_DF, 254, IPPROTO_OSPF, src, dst, NULL, 0, pack);
74
75     auth[0] = 0;
76     auth[1] = 0;
77
78     libnet_build_ospf(LIBNET_HELLO_H + LIBNET_AUTH_H, LIBNET_OSPF_HELLO,
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_hello(0xffffffff, 2, 0x00, 0x00, 30, src, src, nbr,
85                 NULL, 0, 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 != len) {
91         printf("Error sending: %d bytes written : %s\n", warn, strerror(errno));
92         free(pack);
93         exit(warn);
94     } else {
95         printf("%d bytes written\n", warn); 
96     }
97     free(pack);
98     return (0);
99 }
100
101 void
102 help(char *pname)
103 {
104     printf("Usage: %s <source ip> <dest. ip> <neighbor>\n", pname);
105     printf("[Use x.x.x.x format]\n");
106     exit(0);
107 }