[go: up one dir, main page]

Menu

[fc3a13]: / lib / x25_sr.c  Maximize  Restore  History

Download this file

152 lines (129 with data), 3.6 kB

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