Initial revision
[platform/upstream/net-tools.git] / lib / getroute.c
1 /*
2  * lib/getroute.c       This file contains a small interface function to
3  *                      use the AF specific print routine for the routing
4  *                      table.
5  *
6  * NET-LIB      A collection of functions used from the base set of the
7  *              NET-3 Networking Distribution for the LINUX operating
8  *              system. (net-tools, net-drivers)
9  *
10  * Version:     lib/getroute.c 1.03 (1996-04-13)
11  *
12  * Author:      Bernd 'eckes' Eckenfels <net-tools@lina.inka.de>
13  *              Copyright 1999 Bernd Eckenfels, Germany
14  *
15  * Modifications:
16  *
17  *951020 {0.10} Bernd Eckenfels:        creation
18  *960202 {0.90} Bernd Eckenfels:        rewrite to use getaftype.
19  *960204 {0.91} Bernd Eckenfels:        takes constant list of AFs
20  *960206 {1.01} Bernd Eckenfels:        route_init will enable routing
21  *                                      support in the AF handlers
22  *960221 {1.02} Bernd Eckenfels:        renamed from route_info to getroute.c
23  *960413 {1.03} Bernd Eckenfels:        new RTACTION support
24  *
25  *              This program is free software; you can redistribute it
26  *              and/or  modify it under  the terms of  the GNU General
27  *              Public  License as  published  by  the  Free  Software
28  *              Foundation;  either  version 2 of the License, or  (at
29  *              your option) any later version.
30  */
31 #include <stdio.h>
32 #include <string.h>
33 #include "net-support.h"
34 #include "pathnames.h"
35 #include "version.h"
36 #include "config.h"
37 #include "net-locale.h"
38
39 extern  struct aftype   unspec_aftype;
40 extern  struct aftype   unix_aftype;
41 extern  struct aftype   inet_aftype;
42 extern  struct aftype   inet6_aftype;
43 extern  struct aftype   ax25_aftype;
44 extern  struct aftype   netrom_aftype;
45 extern  struct aftype   ipx_aftype;
46 extern  struct aftype   ddp_aftype;
47
48 void
49 getroute_init(void)
50 {
51 #if HAVE_AFINET
52         inet_aftype.rprint = INET_rprint;
53 #endif
54 #if HAVE_AFINET6
55         inet6_aftype.rprint = INET6_rprint;
56 #endif
57 #if HAVE_AFNETROM
58         netrom_aftype.rprint = NETROM_rprint;
59 #endif
60 #if HAVE_AFAX25
61         ax25_aftype.rprint = AX25_rprint;
62 #endif
63 #if HAVE_AFIPX
64         ipx_aftype.rprint = IPX_rprint;
65 #endif
66 #if HAVE_AFATALK
67         ddp_aftype.rprint = DDP_rprint;
68 #endif
69 }
70
71 int
72 route_info(const char *afname, int options)
73 {
74   struct aftype *ap;
75   char *tmp1,*tmp2;
76   int found=E_NOTFOUND,rc;
77   char buf[256];
78   
79   strncpy(buf,afname,sizeof(buf));
80   buf[sizeof(buf)-1]='\0';
81    
82   tmp1=buf;
83   
84   while(tmp1) {
85         
86         ap=NULL;
87         
88         if ((tmp2=index(tmp1,',')))
89                 *tmp2++='\0';
90   
91         if (!tmp1[0]) {
92                 tmp1=tmp2;
93                 continue;
94         }
95         
96         ap = get_aftype(tmp1);
97   
98         if (!ap) {
99                 fprintf(stderr,NLS_CATGETS(catfd, netstatSet, netstat_route_no_support, "Address family `%s' not supported.\n"),tmp1);
100                 return(E_OPTERR);
101         }
102         tmp1=tmp2;
103   
104         if (!ap->rprint) {
105                 fprintf(stderr,NLS_CATGETS(catfd, netstatSet, netstat_type_no_route, "No routing for address family `%s'.\n"),ap->name);
106                 return(E_OPTERR);
107         }
108         
109         found = 0;
110         
111         if ((rc = ap->rprint(options)))
112                 return(rc);
113         
114   }
115   return(found);
116 }