OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [route/] [route.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
 * route        This file contains an implementation of the command
3
 *              that manages the IP routing table in the kernel.
4
 *
5
 * Version:     $Id: route.c,v 1.1 2002-03-17 19:58:52 simons Exp $
6
 *
7
 * Maintainer:  Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de>
8
 *
9
 * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10
 *              (derived from FvK's 'route.c     1.70    01/04/94')
11
 *
12
 * Modifications:
13
 *              Johannes Stille:        for Net-2Debugged by
14
 *                                      <johannes@titan.os.open.de>
15
 *              Linus Torvalds:         Misc Changes
16
 *              Alan Cox:               add the new mtu/window stuff
17
 *              Miquel van Smoorenburg: rt_add and rt_del
18
 *       {1.79} Bernd Eckenfels:        route_info
19
 *       {1.80} Bernd Eckenfels:        reject, metric, irtt, 1.2.x support.
20
 *       {1.81} Bernd Eckenfels:        reject routes need a dummy device
21
 *960127 {1.82} Bernd Eckenfels:        'mod' and 'dyn' 'reinstate' added
22
 *960129 {1.83} Bernd Eckenfels:        resolve and getsock now in lib/,
23
 *                                      REJECT displays '-' as gatway.
24
 *960202 {1.84} Bernd Eckenfels:        net-features support added
25
 *960203 {1.85} Bernd Eckenfels:        "#ifdef' in '#if' for net-features
26
 *                                      -A  (aftrans) support, get_longopts
27
 *960206 {1.86} Bernd Eckenfels:        route_init();
28
 *960218 {1.87} Bernd Eckenfels:        netinet/in.h added
29
 *960221 {1.88} Bernd Eckenfels:        aftrans_dfl support
30
 *960222 {1.90} Bernd Eckenfels:        moved all AF specific code to lib/.
31
 *960413 {1.91} Bernd Eckenfels:        new RTACTION support+FLAG_CACHE/FIB
32
 *960426 {1.92} Bernd Eckenfels:        FLAG_SYM/-N support
33
 *960823 {x.xx} Frank Strauss:          INET6 stuff
34
 *980629 {1.95} Arnaldo Carvalho de Melo: gettext instead of catgets
35
 *990101 {1.96} Bernd Eckenfels:        fixed usage and FLAG_CACHE Output
36
 *
37
 */
38
#include <sys/types.h>
39
#ifdef __UCLINUX__
40
#include <gnu/types.h>
41
#endif
42
#include <sys/ioctl.h>
43
#include <sys/socket.h>
44
#include <net/if.h>
45
/* #include <net/route.h> realy broken */
46
#include <netinet/in.h>
47
#include <netdb.h>
48
#include <netinet/in.h>
49
#include <arpa/nameser.h>
50
#include <resolv.h>
51
#include <linux/param.h>
52
#include <stdio.h>
53
#include <errno.h>
54
#include <fcntl.h>
55
#include <stdlib.h>
56
#include <string.h>
57
#include <getopt.h>
58
#include <unistd.h>
59
#include <ctype.h>
60
#include "net-support.h"
61
#include "config.h"
62
#include "intl.h"
63
#include "pathnames.h"
64
#include "version.h"
65
 
66
#define DFLT_AF "inet"
67
 
68
#define FEATURE_ROUTE
69
#include "lib/net-features.h"   /* needs some of the system includes above! */
70
 
71
char *Release = RELEASE, *Version = "route 1.96 (1999-01-01)";
72
 
73
int opt_n = 0;                   /* numerical output flag        */
74
int opt_v = 0;                   /* debugging output flag        */
75
int opt_e = 1;                  /* 1,2,3=type of routetable     */
76
int opt_fc = 0;                  /* routing cache/FIB */
77
int opt_h = 0;                   /* help selected                */
78
struct aftype *ap;              /* current address family       */
79
 
80
static void usage(void)
81
{
82
    fprintf(stderr, _("Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables\n"));
83
    fprintf(stderr, _("       route [-v] [-FC] {add|del|flush} ...  Modify routing table for AF.\n\n"));
84
 
85
    fprintf(stderr, _("       route {-h|--help} [<AF>]              Detailed usage syntax for specified AF.\n"));
86
    fprintf(stderr, _("       route {-V|--version}                  Display version/author and exit.\n\n"));
87
 
88
    fprintf(stderr, _("        -v, --verbose            be verbose\n"));
89
    fprintf(stderr, _("        -n, --numeric            dont resolve names\n"));
90
    fprintf(stderr, _("        -N, --symbolic           resolve hardware names\n"));
91
    fprintf(stderr, _("        -e, --extend             display other/more information\n"));
92
    fprintf(stderr, _("        -F, --fib                display Forwarding Information Base (default)\n"));
93
    fprintf(stderr, _("        -C, --cache              display routing cache instead of FIB\n\n"));
94
 
95
    fprintf(stderr, _("  <AF>=Use '-A <af>' or '--<af>' Default: %s\n"), DFLT_AF);
96
    fprintf(stderr, _("  List of possible address families (which support routing):\n"));
97
    print_aflist(1); /* 1 = routeable */
98
    exit(E_USAGE);
99
}
100
 
101
 
102
static void version(void)
103
{
104
    fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features);
105
    exit(E_VERSION);
106
}
107
 
108
 
109
int main(int argc, char **argv)
110
{
111
    int i, lop, what = 0;
112
#ifdef __UCLINUX__
113
#define getopt_long(a,b,c,d,e)  getopt(a,b,c)
114
#else
115
    struct option longopts[] =
116
    {
117
        AFTRANS_OPTS,
118
        {"extend", 0, 0, 'e'},
119
        {"verbose", 0, 0, 'v'},
120
        {"version", 0, 0, 'V'},
121
        {"numeric", 0, 0, 'n'},
122
        {"symbolic", 0, 0, 'N'},
123
        {"protocol", 1, 0, 'A'},
124
        {"cache", 0, 0, 'C'},
125
        {"fib", 0, 0, 'F'},
126
        {"help", 0, 0, 'h'},
127
        {NULL, 0, 0, 0}
128
    };
129
#endif
130
    char **tmp;
131
    char *progname;
132
    int options;
133
#if I18N
134
    bindtextdomain("net-tools", "/usr/share/locale");
135
    textdomain("net-tools");
136
#endif
137
    getroute_init();            /* Set up AF routing support */
138
    setroute_init();
139
    afname[0] = '\0';
140
    progname = argv[0];
141
 
142
    /* getopts and -net wont work :-/ */
143
    for (tmp = argv; *tmp; tmp++) {
144
        if (!strcmp(*tmp, "-net"))
145
            strcpy(*tmp, "#net");
146
        else if (!strcmp(*tmp, "-host"))
147
            strcpy(*tmp, "#host");
148
    }
149
 
150
    /* Fetch the command-line arguments. */
151
    while ((i = getopt_long(argc, argv, "A:eCFhnNVv?", longopts, &lop)) != EOF)
152
        switch (i) {
153
        case -1:
154
            break;
155
        case 'n':
156
            opt_n |= FLAG_NUM;
157
            break;
158
        case 'N':
159
            opt_n |= FLAG_SYM;
160
            break;
161
        case 'v':
162
            opt_v |= FLAG_VERBOSE;
163
            break;
164
        case 'e':
165
            opt_e++;
166
            break;
167
        case 1:
168
            if (lop < 0 || lop >= AFTRANS_CNT) {
169
                EINTERN("route.c", "longopts 1 range");
170
                break;
171
            }
172
#ifdef __UCLINUX__
173
            printf("%s(%d): no longopts()\n", __FILE__, __LINE__);
174
#else
175
            if ((i = aftrans_opt(longopts[lop].name)))
176
                exit(i);
177
#endif
178
            break;
179
        case 'C':
180
            opt_fc |= FLAG_CACHE;
181
            break;
182
        case 'F':
183
            opt_fc |= FLAG_FIB;
184
            break;
185
        case 'A':
186
            if ((i = aftrans_opt(optarg)))
187
                exit(i);
188
            break;
189
        case 'V':
190
            version();
191
        case 'h':
192
        case '?':
193
            opt_h++;
194
            break;
195
        default:
196
            usage();
197
        }
198
 
199
    argv += optind;
200
    argc -= optind;
201
 
202
    if (opt_h) {
203
        if (!afname[0])
204
            usage();
205
        else
206
            what = RTACTION_HELP;
207
    } else {
208
        if (!afname[0])
209
            /* this will initialise afname[] */
210
            aftrans_def("route", progname, DFLT_AF);
211
 
212
        /* Do we have to show the contents of the routing table? */
213
        if (*argv == NULL) {
214
            what = RTACTION_SHOW;
215
        } else {
216
            if (!strcmp(*argv, "add"))
217
                what = RTACTION_ADD;
218
            else if (!strcmp(*argv, "del") || !strcmp(*argv, "delete"))
219
                what = RTACTION_DEL;
220
            else if (!strcmp(*argv, "flush"))
221
                what = RTACTION_FLUSH;
222
            else
223
                usage();
224
        }
225
    }
226
 
227
    options = (opt_e & FLAG_EXT) | opt_n | opt_fc | opt_v;
228
    if (!opt_fc)
229
        options |= FLAG_FIB;
230
 
231
    if (what == RTACTION_SHOW)
232
        i = route_info(afname, options);
233
    else
234
        i = route_edit(what, afname, options, ++argv);
235
 
236
    if (i == E_OPTERR)
237
        usage();
238
 
239
    return (i);
240
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.