merged debian patch to make it compile with new headers
[oss-qm-packages.git] / lib / x25_sr.c
blob649c4e6a35bdbb7ce468ccd73f0e06278957258e
1 /*
2 * lib/x25_sr.c This file contains an implementation of the "X.25"
3 * route change support functions.
5 * Version: @(#)x25_sr.c 1.00 08/15/98
7 * Author: Stephane Fillod, <sfillod@charybde.gyptis.frmug.org>
8 * based on inet_sr.c
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 #include "config.h"
18 #if HAVE_AFX25
19 #include <asm/types.h>
20 #include <sys/param.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <sys/ioctl.h>
24 #include <linux/x25.h>
25 #include <ctype.h>
26 #include <errno.h>
27 #include <netdb.h>
28 #include <resolv.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <unistd.h>
33 #include "version.h"
34 #include "net-support.h"
35 #include "pathnames.h"
36 #define EXTERN
37 #if 0
38 #include "net-locale.h"
39 #endif
40 #include "intl.h"
42 #include "net-features.h"
44 extern struct aftype x25_aftype;
46 static int skfd = -1;
49 static int usage(void)
51 fprintf(stderr,"Usage: x25_route [-v] del Target[/mask] [dev] If\n");
52 fprintf(stderr," x25_route [-v] add Target[/mask] [dev] If\n");
53 return(E_USAGE);
57 static int X25_setroute(int action, int options, char **args)
59 struct x25_route_struct rt;
60 struct sockaddr_x25 sx25;
61 char target[128];
62 signed int sigdigits;
64 if (*args == NULL)
65 return(usage());
67 strcpy(target, *args++);
69 /* Clean out the x25_route_struct structure. */
70 memset((char *) &rt, 0, sizeof(struct x25_route_struct));
73 if ((sigdigits = x25_aftype.input(0, target, (struct sockaddr *)&sx25)) < 0) {
74 x25_aftype.herror(target);
75 return (1);
77 rt.sigdigits=sigdigits;
79 /* x25_route_struct.address isn't type struct sockaddr_x25, Why? */
80 memcpy(&rt.address, &sx25.sx25_addr, sizeof(struct x25_address));
82 while (*args) {
83 if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {
84 args++;
85 if (!*args)
86 return(usage());
87 } else
88 if (args[1])
89 return(usage());
90 if (rt.device[0])
91 return(usage());
92 strcpy(rt.device, *args);
93 args++;
95 if (rt.device[0]=='\0')
96 return(usage());
98 /* sanity checks.. */
99 if (rt.sigdigits > 15) {
100 fprintf(stderr, _("route: bogus netmask %d\n"), rt.sigdigits);
101 return(E_OPTERR);
104 if (rt.sigdigits > strlen(rt.address.x25_addr)) {
105 fprintf(stderr, _("route: netmask doesn't match route address\n"));
106 return(E_OPTERR);
109 /* Create a socket to the X25 kernel. */
110 if ((skfd = socket(AF_X25, SOCK_SEQPACKET, 0)) < 0) {
111 perror("socket");
112 return(E_SOCK);
115 /* Tell the kernel to accept this route. */
116 if (action==RTACTION_DEL) {
117 if (ioctl(skfd, SIOCDELRT, &rt) < 0) {
118 perror("SIOCDELRT");
119 close(skfd);
120 return(E_SOCK);
122 } else {
123 if (ioctl(skfd, SIOCADDRT, &rt) < 0) {
124 perror("SIOCADDRT");
125 close(skfd);
126 return(E_SOCK);
130 /* Close the socket. */
131 (void) close(skfd);
132 return(0);
135 int X25_rinput(int action, int options, char **args)
137 if (action == RTACTION_FLUSH) {
138 fprintf(stderr,"Flushing `x25' routing table not supported\n");
139 return(usage());
141 if (options & FLAG_CACHE) {
142 fprintf(stderr,"Modifying `x25' routing cache not supported\n");
143 return(usage());
145 if ((*args == NULL) || (action == RTACTION_HELP))
146 return(usage());
148 return(X25_setroute(action, options, args));
150 #endif /* HAVE_AFX25 */