URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 744 to Rev 745
- ↔ Reverse comparison
Rev 744 → Rev 745
/trunk/uclinux/userland/ping/Makefile
0,0 → 1,17
OBJS = ping.o |
|
CC = or32-uclibc-gcc |
LD = or32-uclibc-gcc |
STRIP = or32-uclibc-strip |
|
CFLAGS := $(CFLAGS) -Wall -Werror-implicit-function-declaration -D__USE_BSD |
LDFLAGS := -r -d |
|
all: ping |
|
ping: $(OBJS) |
$(LD) $(OBJS) $(LDFLAGS) -o $@ |
$(STRIP) -g $@ |
|
clean: |
rm -f *.[oa] *.coff *~ core ping |
/trunk/uclinux/userland/ping/ping.c
0,0 → 1,1205
/* |
* Copyright (c) 1989 The Regents of the University of California. |
* All rights reserved. |
* |
* This code is derived from software contributed to Berkeley by |
* Mike Muuss. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* 3. All advertising materials mentioning features or use of this software |
* must display the following acknowledgement: |
* This product includes software developed by the University of |
* California, Berkeley and its contributors. |
* 4. Neither the name of the University nor the names of its contributors |
* may be used to endorse or promote products derived from this software |
* without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
|
char copyright[] = |
"@(#) Copyright (c) 1989 The Regents of the University of California.\n" |
"All rights reserved.\n"; |
/* |
* From: @(#)ping.c 5.9 (Berkeley) 5/12/91 |
*/ |
char rcsid[] = "$Original-Id: ping.c,v 1.22 1997/06/08 19:39:47 dholland Exp $"; |
char pkg[] = "netkit-base-0.10"; |
|
/* |
* P I N G . C |
* |
* Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, |
* measure round-trip-delays and packet loss across network paths. |
* |
* Author - |
* Mike Muuss |
* U. S. Army Ballistic Research Laboratory |
* December, 1983 |
* |
* Status - |
* Public Domain. Distribution Unlimited. |
* Bugs - |
* More statistics could always be gathered. |
* This program has to run SUID to ROOT to access the ICMP socket. |
*/ |
|
#include <sys/param.h> |
#include <sys/socket.h> |
#include <sys/file.h> |
#include <sys/time.h> |
#include <sys/signal.h> |
|
#include <netinet/in.h> |
#include <netinet/ip.h> |
#include <netinet/ip_icmp.h> |
#include <arpa/inet.h> |
#include <netdb.h> |
#include <unistd.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <getopt.h> |
#include <resolv.h> |
|
/* |
* Note: on some systems dropping root makes the process dumpable or |
* traceable. In that case if you enable dropping root and someone |
* traces ping, they get control of a raw socket and can start |
* spoofing whatever packets they like. SO BE CAREFUL. |
*/ |
#ifdef __linux__ |
#define SAFE_TO_DROP_ROOT |
#endif |
|
#if defined(__GLIBC__) && (__GLIBC__ >= 2) |
#define icmphdr icmp |
/* |
#define ICMP_DEST_UNREACH ICMP_UNREACH |
#define ICMP_NET_UNREACH ICMP_UNREACH_NET |
#define ICMP_HOST_UNREACH ICMP_UNREACH_HOST |
#define ICMP_PORT_UNREACH ICMP_UNREACH_PORT |
#define ICMP_PROT_UNREACH ICMP_UNREACH_PROTOCOL |
#define ICMP_FRAG_NEEDED ICMP_UNREACH_NEEDFRAG |
#define ICMP_SR_FAILED ICMP_UNREACH_SRCFAIL |
#define ICMP_NET_UNKNOWN ICMP_UNREACH_NET_UNKNOWN |
#define ICMP_HOST_UNKNOWN ICMP_UNREACH_HOST_UNKNOWN |
#define ICMP_HOST_ISOLATED ICMP_UNREACH_ISOLATED |
#define ICMP_NET_UNR_TOS ICMP_UNREACH_TOSNET |
#define ICMP_HOST_UNR_TOS ICMP_UNREACH_TOSHOST |
#define ICMP_SOURCE_QUENCH ICMP_SOURCEQUENCH |
#define ICMP_REDIR_NET ICMP_REDIRECT_NET |
#define ICMP_REDIR_HOST ICMP_REDIRECT_HOST |
#define ICMP_REDIR_NETTOS ICMP_REDIRECT_TOSNET |
#define ICMP_REDIR_HOSTTOS ICMP_REDIRECT_TOSHOST |
#define ICMP_TIME_EXCEEDED ICMP_TIMXCEED |
#define ICMP_EXC_TTL ICMP_TIMXCEED_INTRANS |
#define ICMP_EXC_FRAGTIME ICMP_TIMXCEED_REASS |
#define ICMP_PARAMETERPROB ICMP_PARAMPROB |
#define ICMP_TIMESTAMP ICMP_TSTAMP |
#define ICMP_TIMESTAMPREPLY ICMP_TSTAMPREPLY |
#define ICMP_INFO_REQUEST ICMP_IREQ |
#define ICMP_INFO_REPLY ICMP_IREQREPLY |
*/ |
#else |
#define ICMP_MINLEN 28 |
#define inet_ntoa(x) inet_ntoa(*((struct in_addr *)&(x))) |
#endif |
|
|
#define DEFDATALEN (64 - 8) /* default data length */ |
#define MAXIPLEN 60 |
#define MAXICMPLEN 76 |
#define MAXPACKET (2048 - 60 - 8)/* max packet size */ |
#define MAXWAIT 10 /* max seconds to wait for response */ |
#define NROUTES 9 /* number of record route slots */ |
|
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ |
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ |
#define SET(bit) (A(bit) |= B(bit)) |
#define CLR(bit) (A(bit) &= (~B(bit))) |
#define TST(bit) (A(bit) & B(bit)) |
|
/* various options */ |
int options; |
#define F_FLOOD 0x001 |
#define F_INTERVAL 0x002 |
#define F_NUMERIC 0x004 |
#define F_PINGFILLED 0x008 |
#define F_QUIET 0x010 |
#define F_RROUTE 0x020 |
#define F_SO_DEBUG 0x040 |
#define F_SO_DONTROUTE 0x080 |
#define F_VERBOSE 0x100 |
|
/* multicast options */ |
int moptions; |
#define MULTICAST_NOLOOP 0x001 |
#define MULTICAST_TTL 0x002 |
#define MULTICAST_IF 0x004 |
|
/* |
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum |
* number of received sequence numbers we can keep track of. Change 128 |
* to 8192 for complete accuracy... |
*/ |
#define MAX_DUP_CHK (8 * 128) |
int mx_dup_ck = MAX_DUP_CHK; |
char rcvd_tbl[MAX_DUP_CHK / 8]; |
|
struct sockaddr whereto; /* who to ping */ |
int datalen = DEFDATALEN; |
int s; /* socket file descriptor */ |
u_char outpack[MAXPACKET]; |
char BSPACE = '\b'; /* characters written for flood */ |
char DOT = '.'; |
static char *hostname; |
static int ident; /* process id to identify our packets */ |
|
/* counters */ |
static long npackets; /* max packets to transmit */ |
static long nreceived; /* # of packets we got back */ |
static long nrepeats; /* number of duplicates */ |
static long ntransmitted; /* sequence # for outbound packets = #sent */ |
static int interval = 1; /* interval between packets */ |
|
/* timing */ |
static int timing; /* flag to do timing */ |
static long tmin = LONG_MAX; /* minimum round trip time */ |
static long tmax = 0; /* maximum round trip time */ |
static u_long tsum; /* sum of all times, for doing average */ |
|
/* protos */ |
static char *pr_addr(u_long); |
static int in_cksum(u_short *addr, int len); |
static void catcher(int); |
static void finish(int ignore); |
static void pinger(void); |
static void fill(void *bp, char *patp); |
static void usage(void); |
static void pr_pack(char *buf, int cc, struct sockaddr_in *from); |
static void tvsub(struct timeval *out, struct timeval *in); |
static void pr_icmph(struct icmphdr *icp); |
static void pr_retip(struct iphdr *ip); |
|
|
int |
main(int argc, char *argv[]) |
{ |
struct timeval timeout; |
struct hostent *hp; |
struct sockaddr_in *to; |
struct protoent *proto; |
struct in_addr ifaddr; |
int i; |
int ch, fdmask, hold, packlen, preload; |
u_char *datap, *packet; |
char *target, hnamebuf[MAXHOSTNAMELEN]; |
u_char ttl, loop; |
int am_i_root; |
#ifdef IP_OPTIONS |
char rspace[3 + 4 * NROUTES + 1]; /* record route space */ |
#endif |
|
static char *null = NULL; |
|
/*__environ = &null;*/ |
am_i_root = (getuid()==0); |
|
/* |
* Pull this stuff up front so we can drop root if desired. |
*/ |
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { |
if (errno==EPERM) { |
fprintf(stderr, "ping: ping must run as root\n"); |
} |
else perror("ping: socket"); |
exit(2); |
} |
|
#ifdef SAFE_TO_DROP_ROOT |
setuid(getuid()); |
#endif |
|
preload = 0; |
datap = &outpack[8 + sizeof(struct timeval)]; |
while ((ch = getopt(argc, argv, "I:LRc:dfh:i:l:np:qrs:t:v")) != EOF) |
switch(ch) { |
case 'c': |
npackets = atoi(optarg); |
if (npackets <= 0) { |
(void)fprintf(stderr, |
"ping: bad number of packets to transmit.\n"); |
exit(2); |
} |
break; |
case 'd': |
options |= F_SO_DEBUG; |
break; |
case 'f': |
if (!am_i_root) { |
(void)fprintf(stderr, |
"ping: %s\n", strerror(EPERM)); |
exit(2); |
} |
options |= F_FLOOD; |
setbuf(stdout, NULL); |
break; |
case 'i': /* wait between sending packets */ |
interval = atoi(optarg); |
if (interval <= 0) { |
(void)fprintf(stderr, |
"ping: bad timing interval.\n"); |
exit(2); |
} |
options |= F_INTERVAL; |
break; |
case 'l': |
if (!am_i_root) { |
(void)fprintf(stderr, |
"ping: %s\n", strerror(EPERM)); |
exit(2); |
} |
preload = atoi(optarg); |
if (preload < 0) { |
(void)fprintf(stderr, |
"ping: bad preload value.\n"); |
exit(2); |
} |
break; |
case 'n': |
options |= F_NUMERIC; |
break; |
case 'p': /* fill buffer with user pattern */ |
options |= F_PINGFILLED; |
fill(datap, optarg); |
break; |
case 'q': |
options |= F_QUIET; |
break; |
case 'R': |
options |= F_RROUTE; |
break; |
case 'r': |
options |= F_SO_DONTROUTE; |
break; |
case 's': /* size of packet to send */ |
datalen = atoi(optarg); |
if (datalen > MAXPACKET) { |
(void)fprintf(stderr, |
"ping: packet size too large.\n"); |
exit(2); |
} |
if (datalen <= 0) { |
(void)fprintf(stderr, |
"ping: illegal packet size.\n"); |
exit(2); |
} |
break; |
case 'v': |
options |= F_VERBOSE; |
break; |
case 'L': |
moptions |= MULTICAST_NOLOOP; |
loop = 0; |
break; |
case 't': |
moptions |= MULTICAST_TTL; |
i = atoi(optarg); |
if (i < 0 || i > 255) { |
printf("ttl %u out of range\n", i); |
exit(2); |
} |
ttl = i; |
break; |
case 'I': |
moptions |= MULTICAST_IF; |
{ |
int i1, i2, i3, i4; |
char junk; |
|
if (sscanf(optarg, "%u.%u.%u.%u%c", |
&i1, &i2, &i3, &i4, &junk) != 4) { |
printf("bad interface address '%s'\n", |
optarg); |
exit(2); |
} |
ifaddr.s_addr = (i1<<24)|(i2<<16)|(i3<<8)|i4; |
ifaddr.s_addr = htonl(ifaddr.s_addr); |
} |
break; |
default: |
usage(); |
} |
argc -= optind; |
argv += optind; |
|
if (argc != 1) |
usage(); |
target = *argv; |
|
memset(&whereto, 0, sizeof(struct sockaddr)); |
to = (struct sockaddr_in *)&whereto; |
to->sin_family = AF_INET; |
if (inet_aton(target, &to->sin_addr)) { |
hostname = target; |
} |
else { |
/* |
char * addr = resolve_name(target, 0); |
if (!addr) { |
(void)fprintf(stderr, |
"ping: unknown host %s\n", target); |
exit(2); |
} |
to->sin_addr.s_addr = inet_addr(addr); |
hostname = target; |
*/ |
|
hp = gethostbyname(target); |
if (!hp) { |
(void)fprintf(stderr, |
"ping: unknown host %s\n", target); |
exit(2); |
} |
to->sin_family = hp->h_addrtype; |
if (hp->h_length > (int)sizeof(to->sin_addr)) { |
hp->h_length = sizeof(to->sin_addr); |
} |
memcpy(&to->sin_addr, hp->h_addr, hp->h_length); |
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1); |
hostname = hnamebuf; |
|
} |
|
if (options & F_FLOOD && options & F_INTERVAL) { |
(void)fprintf(stderr, |
"ping: -f and -i incompatible options.\n"); |
exit(2); |
} |
|
if (datalen >= (int)sizeof(struct timeval)) /* can we time transfer */ |
timing = 1; |
packlen = datalen + MAXIPLEN + MAXICMPLEN; |
packet = malloc((u_int)packlen); |
if (!packet) { |
(void)fprintf(stderr, "ping: out of memory.\n"); |
exit(2); |
} |
if (!(options & F_PINGFILLED)) |
for (i = 8; i < datalen; ++i) |
*datap++ = i; |
|
ident = getpid() & 0xFFFF; |
hold = 1; |
|
if (options & F_SO_DEBUG) |
(void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&hold, |
sizeof(hold)); |
|
if (options & F_SO_DONTROUTE) |
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, |
sizeof(hold)); |
|
/* this is necessary for broadcast pings to work */ |
setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&hold, sizeof(hold)); |
|
/* record route option */ |
if (options & F_RROUTE) { |
#ifdef IP_OPTIONS |
memset(rspace, 0, sizeof(rspace)); |
rspace[IPOPT_OPTVAL] = IPOPT_RR; |
rspace[IPOPT_OLEN] = sizeof(rspace)-1; |
rspace[IPOPT_OFFSET] = IPOPT_MINOFF; |
if (setsockopt(s, IPPROTO_IP, IP_OPTIONS, rspace, |
sizeof(rspace)) < 0) { |
perror("ping: record route"); |
exit(2); |
} |
#else |
(void)fprintf(stderr, |
"ping: record route not available in this implementation.\n"); |
exit(2); |
#endif /* IP_OPTIONS */ |
} |
|
/* |
* When pinging the broadcast address, you can get a lot of answers. |
* Doing something so evil is useful if you are trying to stress the |
* ethernet, or just want to fill the arp cache to get some stuff for |
* /etc/ethers. |
*/ |
hold = 48 * 1024; |
(void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold, |
sizeof(hold)); |
|
/*#if 0*/ |
if (moptions & MULTICAST_NOLOOP) { |
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, |
&loop, 1) == -1) { |
perror ("can't disable multicast loopback"); |
exit(92); |
} |
} |
if (moptions & MULTICAST_TTL) { |
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, |
&ttl, 1) == -1) { |
perror ("can't set multicast time-to-live"); |
exit(93); |
} |
} |
if (moptions & MULTICAST_IF) { |
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, |
&ifaddr, sizeof(ifaddr)) == -1) { |
perror ("can't set multicast source interface"); |
exit(94); |
} |
} |
/*#endif*/ |
|
if (to->sin_family == AF_INET) |
(void)printf("PING %s (%s): %d data bytes\n", hostname, |
inet_ntoa(*(struct in_addr *)&to->sin_addr.s_addr), |
datalen); |
else |
(void)printf("PING %s: %d data bytes\n", hostname, datalen); |
|
(void)signal(SIGINT, finish); |
(void)signal(SIGALRM, catcher); |
|
while (preload--) /* fire off them quickies */ |
pinger(); |
|
if ((options & F_FLOOD) == 0) |
catcher(0); /* start things going */ |
|
for (;;) { |
struct sockaddr_in from; |
register int cc; |
int fromlen; |
|
if (options & F_FLOOD) { |
pinger(); |
timeout.tv_sec = 0; |
timeout.tv_usec = 10000; |
fdmask = 1 << s; |
if (select(s + 1, (fd_set *)&fdmask, (fd_set *)NULL, |
(fd_set *)NULL, &timeout) < 1) |
continue; |
} |
fromlen = sizeof(from); |
if ((cc = recvfrom(s, (char *)packet, packlen, 0, |
(struct sockaddr *)&from, &fromlen)) < 0) { |
if (errno == EINTR) |
continue; |
perror("ping: recvfrom"); |
continue; |
} |
pr_pack((char *)packet, cc, &from); |
if (npackets && nreceived >= npackets) |
break; |
} |
finish(0); |
/* NOTREACHED */ |
return 0; |
} |
|
/* |
* catcher -- |
* This routine causes another PING to be transmitted, and then |
* schedules another SIGALRM for 1 second from now. |
* |
* bug -- |
* Our sense of time will slowly skew (i.e., packets will not be |
* launched exactly at 1-second intervals). This does not affect the |
* quality of the delay and loss statistics. |
*/ |
static void |
catcher(int ignore) |
{ |
int waittime; |
|
(void)ignore; |
pinger(); |
(void)signal(SIGALRM, catcher); |
if (!npackets || ntransmitted < npackets) |
alarm((u_int)interval); |
else { |
if (nreceived) { |
waittime = 2 * tmax / 1000; |
if (!waittime) |
waittime = 1; |
if (waittime > MAXWAIT) |
waittime = MAXWAIT; |
} else |
waittime = MAXWAIT; |
(void)signal(SIGALRM, finish); |
(void)alarm((u_int)waittime); |
} |
} |
|
#if !defined(__GLIBC__) || (__GLIBC__ < 2) |
#define icmp_type type |
#define icmp_code code |
#define icmp_cksum checksum |
#define icmp_id un.echo.id |
#define icmp_seq un.echo.sequence |
#define icmp_gwaddr un.gateway |
#endif /* __GLIBC__ */ |
|
#define ip_hl ihl |
#define ip_v version |
#define ip_tos tos |
#define ip_len tot_len |
#define ip_id id |
#define ip_off frag_off |
#define ip_ttl ttl |
#define ip_p protocol |
#define ip_sum check |
#define ip_src saddr |
#define ip_dst daddr |
|
/* |
* pinger -- |
* Compose and transmit an ICMP ECHO REQUEST packet. The IP packet |
* will be added on by the kernel. The ID field is our UNIX process ID, |
* and the sequence number is an ascending integer. The first 8 bytes |
* of the data portion are used to hold a UNIX "timeval" struct in VAX |
* byte-order, to compute the round-trip time. |
*/ |
static void |
pinger(void) |
{ |
register struct icmphdr *icp; |
register int cc; |
int i; |
|
icp = (struct icmphdr *)outpack; |
icp->icmp_type = ICMP_ECHO; |
icp->icmp_code = 0; |
icp->icmp_cksum = 0; |
icp->icmp_seq = ntransmitted++; |
icp->icmp_id = ident; /* ID */ |
|
CLR(icp->icmp_seq % mx_dup_ck); |
|
if (timing) |
(void)gettimeofday((struct timeval *)&outpack[8], |
(struct timezone *)NULL); |
|
cc = datalen + 8; /* skips ICMP portion */ |
|
/* compute ICMP checksum here */ |
icp->icmp_cksum = in_cksum((u_short *)icp, cc); |
|
i = sendto(s, (char *)outpack, cc, 0, &whereto, |
sizeof(struct sockaddr)); |
|
if (i < 0 || i != cc) { |
if (i < 0) |
perror("ping: sendto"); |
(void)printf("ping: wrote %s %d chars, ret=%d\n", |
hostname, cc, i); |
} |
if (!(options & F_QUIET) && options & F_FLOOD) |
(void)write(STDOUT_FILENO, &DOT, 1); |
} |
|
/* |
* pr_pack -- |
* Print out the packet, if it came from us. This logic is necessary |
* because ALL readers of the ICMP socket get a copy of ALL ICMP packets |
* which arrive ('tis only fair). This permits multiple copies of this |
* program to be run without having intermingled output (or statistics!). |
*/ |
void |
pr_pack(char *buf, int cc, struct sockaddr_in *from) |
{ |
register struct icmphdr *icp; |
register int i; |
register u_char *cp,*dp; |
/*#if 0*/ |
register u_long l; |
register int j; |
static int old_rrlen; |
static char old_rr[MAX_IPOPTLEN]; |
/*#endif*/ |
struct iphdr *ip; |
struct timeval tv, *tp; |
long triptime = 0; |
int hlen, dupflag; |
|
(void)gettimeofday(&tv, (struct timezone *)NULL); |
|
/* Check the IP header */ |
ip = (struct iphdr *)buf; |
hlen = ip->ip_hl << 2; |
if (cc < datalen + ICMP_MINLEN) { |
if (options & F_VERBOSE) |
(void)fprintf(stderr, |
"ping: packet too short (%d bytes) from %s\n", cc, |
inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr)); |
return; |
} |
|
/* Now the ICMP part */ |
cc -= hlen; |
icp = (struct icmphdr *)(buf + hlen); |
if (icp->icmp_type == ICMP_ECHOREPLY) { |
if (icp->icmp_id != ident) |
return; /* 'Twas not our ECHO */ |
++nreceived; |
if (timing) { |
#ifndef icmp_data |
tp = (struct timeval *)(icp + 1); |
#else |
tp = (struct timeval *)icp->icmp_data; |
#endif |
tvsub(&tv, tp); |
triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100); |
tsum += triptime; |
if (triptime < tmin) |
tmin = triptime; |
if (triptime > tmax) |
tmax = triptime; |
} |
|
if (TST(icp->icmp_seq % mx_dup_ck)) { |
++nrepeats; |
--nreceived; |
dupflag = 1; |
} else { |
SET(icp->icmp_seq % mx_dup_ck); |
dupflag = 0; |
} |
|
if (options & F_QUIET) |
return; |
|
if (options & F_FLOOD) |
(void)write(STDOUT_FILENO, &BSPACE, 1); |
else { |
(void)printf("%d bytes from %s: icmp_seq=%u", cc, |
inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr), |
icp->icmp_seq); |
(void)printf(" ttl=%d", ip->ip_ttl); |
if (timing) |
(void)printf(" time=%ld.%ld ms", triptime/10, |
triptime%10); |
if (dupflag) |
(void)printf(" (DUP!)"); |
/* check the data */ |
#ifndef icmp_data |
cp = ((u_char*)(icp + 1) + 8); |
#else |
cp = (u_char*)icp->icmp_data + 8; |
#endif |
dp = &outpack[8 + sizeof(struct timeval)]; |
for (i = 8; i < datalen; ++i, ++cp, ++dp) { |
if (*cp != *dp) { |
(void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x", |
i, *dp, *cp); |
cp = (u_char*)(icp + 1); |
for (i = 8; i < datalen; ++i, ++cp) { |
if ((i % 32) == 8) |
(void)printf("\n\t"); |
(void)printf("%x ", *cp); |
} |
break; |
} |
} |
} |
} else { |
/* We've got something other than an ECHOREPLY */ |
if (!(options & F_VERBOSE)) |
return; |
(void)printf("%d bytes from %s: ", cc, |
pr_addr(from->sin_addr.s_addr)); |
pr_icmph(icp); |
} |
|
/*#if 0*/ |
/* Display any IP options */ |
cp = (u_char *)buf + sizeof(struct iphdr); |
|
for (; hlen > (int)sizeof(struct iphdr); --hlen, ++cp) |
switch (*cp) { |
case IPOPT_EOL: |
hlen = 0; |
break; |
case IPOPT_LSRR: |
(void)printf("\nLSRR: "); |
hlen -= 2; |
j = *++cp; |
++cp; |
if (j > IPOPT_MINOFF) |
for (;;) { |
l = *++cp; |
l = (l<<8) + *++cp; |
l = (l<<8) + *++cp; |
l = (l<<8) + *++cp; |
if (l == 0) |
(void)printf("\t0.0.0.0"); |
else |
(void)printf("\t%s", pr_addr(ntohl(l))); |
hlen -= 4; |
j -= 4; |
if (j <= IPOPT_MINOFF) |
break; |
(void)putchar('\n'); |
} |
break; |
case IPOPT_RR: |
j = *++cp; /* get length */ |
i = *++cp; /* and pointer */ |
hlen -= 2; |
if (i > j) |
i = j; |
i -= IPOPT_MINOFF; |
if (i <= 0) |
continue; |
if (i == old_rrlen |
&& cp == (u_char *)buf + sizeof(struct iphdr) + 2 |
&& !memcmp((char *)cp, old_rr, i) |
&& !(options & F_FLOOD)) { |
(void)printf("\t(same route)"); |
i = ((i + 3) / 4) * 4; |
hlen -= i; |
cp += i; |
break; |
} |
old_rrlen = i; |
memcpy(old_rr, cp, i); |
(void)printf("\nRR: "); |
for (;;) { |
l = *++cp; |
l = (l<<8) + *++cp; |
l = (l<<8) + *++cp; |
l = (l<<8) + *++cp; |
if (l == 0) |
(void)printf("\t0.0.0.0"); |
else |
(void)printf("\t%s", pr_addr(ntohl(l))); |
hlen -= 4; |
i -= 4; |
if (i <= 0) |
break; |
(void)putchar('\n'); |
} |
break; |
case IPOPT_NOP: |
(void)printf("\nNOP"); |
break; |
default: |
(void)printf("\nunknown option %x", *cp); |
break; |
} |
/*#endif*/ |
if (!(options & F_FLOOD)) { |
(void)putchar('\n'); |
(void)fflush(stdout); |
} |
} |
|
/* |
* in_cksum -- |
* Checksum routine for Internet Protocol family headers (C Version) |
*/ |
static int |
in_cksum(u_short *addr, int len) |
{ |
register int nleft = len; |
register u_short *w = addr; |
register int sum = 0; |
u_short answer = 0; |
|
/* |
* Our algorithm is simple, using a 32 bit accumulator (sum), we add |
* sequential 16 bit words to it, and at the end, fold back all the |
* carry bits from the top 16 bits into the lower 16 bits. |
*/ |
while (nleft > 1) { |
sum += *w++; |
nleft -= 2; |
} |
|
/* mop up an odd byte, if necessary */ |
if (nleft == 1) { |
*(u_char *)(&answer) = *(u_char *)w ; |
sum += answer; |
} |
|
/* add back carry outs from top 16 bits to low 16 bits */ |
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ |
sum += (sum >> 16); /* add carry */ |
answer = ~sum; /* truncate to 16 bits */ |
return(answer); |
} |
|
/* |
* tvsub -- |
* Subtract 2 timeval structs: out = out - in. Out is assumed to |
* be >= in. |
*/ |
static void |
tvsub(register struct timeval *out, register struct timeval *in) |
{ |
if ((out->tv_usec -= in->tv_usec) < 0) { |
--out->tv_sec; |
out->tv_usec += 1000000; |
} |
out->tv_sec -= in->tv_sec; |
} |
|
/* |
* finish -- |
* Print out statistics, and give up. |
*/ |
static void |
finish(int ignore) |
{ |
(void)ignore; |
|
(void)signal(SIGINT, SIG_IGN); |
(void)putchar('\n'); |
(void)fflush(stdout); |
(void)printf("--- %s ping statistics ---\n", hostname); |
(void)printf("%ld packets transmitted, ", ntransmitted); |
(void)printf("%ld packets received, ", nreceived); |
if (nrepeats) |
(void)printf("+%ld duplicates, ", nrepeats); |
if (ntransmitted) { |
if (nreceived > ntransmitted) |
(void)printf("-- somebody's printing up packets!"); |
else |
(void)printf("%d%% packet loss", |
(int) (((ntransmitted - nreceived) * 100) / |
ntransmitted)); |
} |
(void)putchar('\n'); |
if (nreceived && timing) |
(void)printf("round-trip min/avg/max = %ld.%ld/%lu.%ld/%ld.%ld ms\n", |
tmin/10, tmin%10, |
(tsum / (nreceived + nrepeats))/10, |
(tsum / (nreceived + nrepeats))%10, |
tmax/10, tmax%10); |
|
if (nreceived==0) exit(1); |
exit(0); |
} |
|
#ifdef notdef |
static char *ttab[] = { |
"Echo Reply", /* ip + seq + udata */ |
"Dest Unreachable", /* net, host, proto, port, frag, sr + IP */ |
"Source Quench", /* IP */ |
"Redirect", /* redirect type, gateway, + IP */ |
"Echo", |
"Time Exceeded", /* transit, frag reassem + IP */ |
"Parameter Problem", /* pointer + IP */ |
"Timestamp", /* id + seq + three timestamps */ |
"Timestamp Reply", /* " */ |
"Info Request", /* id + sq */ |
"Info Reply" /* " */ |
}; |
#endif |
|
/* |
* pr_icmph -- |
* Print a descriptive string about an ICMP header. |
*/ |
static void |
pr_icmph(struct icmphdr *icp) |
{ |
switch(icp->icmp_type) { |
case ICMP_ECHOREPLY: |
(void)printf("Echo Reply\n"); |
/* XXX ID + Seq + Data */ |
break; |
case ICMP_DEST_UNREACH: |
switch(icp->icmp_code) { |
case ICMP_NET_UNREACH: |
(void)printf("Destination Net Unreachable\n"); |
break; |
case ICMP_HOST_UNREACH: |
(void)printf("Destination Host Unreachable\n"); |
break; |
case ICMP_PROT_UNREACH: |
(void)printf("Destination Protocol Unreachable\n"); |
break; |
case ICMP_PORT_UNREACH: |
(void)printf("Destination Port Unreachable\n"); |
break; |
case ICMP_FRAG_NEEDED: |
(void)printf("frag needed and DF set\n"); |
break; |
case ICMP_SR_FAILED: |
(void)printf("Source Route Failed\n"); |
break; |
case ICMP_NET_UNKNOWN: |
(void)printf("Network Unknown\n"); |
break; |
case ICMP_HOST_UNKNOWN: |
(void)printf("Host Unknown\n"); |
break; |
case ICMP_HOST_ISOLATED: |
(void)printf("Host Isolated\n"); |
break; |
case ICMP_NET_UNR_TOS: |
printf("Destination Network Unreachable At This TOS\n"); |
break; |
case ICMP_HOST_UNR_TOS: |
printf("Destination Host Unreachable At This TOS\n"); |
break; |
#ifdef ICMP_PKT_FILTERED |
case ICMP_PKT_FILTERED: |
(void)printf("Packet Filtered\n"); |
break; |
#endif |
#ifdef ICMP_PREC_VIOLATION |
case ICMP_PREC_VIOLATION: |
(void)printf("Precedence Violation\n"); |
break; |
#endif |
#ifdef ICMP_PREC_CUTOFF |
case ICMP_PREC_CUTOFF: |
(void)printf("Precedence Cutoff\n"); |
break; |
#endif |
default: |
(void)printf("Dest Unreachable, Unknown Code: %d\n", |
icp->icmp_code); |
break; |
} |
/* Print returned IP header information */ |
#ifndef icmp_data |
pr_retip((struct iphdr *)(icp + 1)); |
#else |
pr_retip((struct iphdr *)icp->icmp_data); |
#endif |
break; |
case ICMP_SOURCE_QUENCH: |
(void)printf("Source Quench\n"); |
#ifndef icmp_data |
pr_retip((struct iphdr *)(icp + 1)); |
#else |
pr_retip((struct iphdr *)icp->icmp_data); |
#endif |
break; |
case ICMP_REDIRECT: |
switch(icp->icmp_code) { |
case ICMP_REDIR_NET: |
(void)printf("Redirect Network"); |
break; |
case ICMP_REDIR_HOST: |
(void)printf("Redirect Host"); |
break; |
case ICMP_REDIR_NETTOS: |
(void)printf("Redirect Type of Service and Network"); |
break; |
case ICMP_REDIR_HOSTTOS: |
(void)printf("Redirect Type of Service and Host"); |
break; |
default: |
(void)printf("Redirect, Bad Code: %d", icp->icmp_code); |
break; |
} |
(void)printf("(New addr: %s)\n", |
inet_ntoa(icp->icmp_gwaddr)); |
#ifndef icmp_data |
pr_retip((struct iphdr *)(icp + 1)); |
#else |
pr_retip((struct iphdr *)icp->icmp_data); |
#endif |
break; |
case ICMP_ECHO: |
(void)printf("Echo Request\n"); |
/* XXX ID + Seq + Data */ |
break; |
case ICMP_TIME_EXCEEDED: |
switch(icp->icmp_code) { |
case ICMP_EXC_TTL: |
(void)printf("Time to live exceeded\n"); |
break; |
case ICMP_EXC_FRAGTIME: |
(void)printf("Frag reassembly time exceeded\n"); |
break; |
default: |
(void)printf("Time exceeded, Bad Code: %d\n", |
icp->icmp_code); |
break; |
} |
#ifndef icmp_data |
pr_retip((struct iphdr *)(icp + 1)); |
#else |
pr_retip((struct iphdr *)icp->icmp_data); |
#endif |
break; |
case ICMP_PARAMETERPROB: |
(void)printf("Parameter problem: IP address = %s\n", |
inet_ntoa (icp->icmp_gwaddr)); |
#ifndef icmp_data |
pr_retip((struct iphdr *)(icp + 1)); |
#else |
pr_retip((struct iphdr *)icp->icmp_data); |
#endif |
break; |
case ICMP_TIMESTAMP: |
(void)printf("Timestamp\n"); |
/* XXX ID + Seq + 3 timestamps */ |
break; |
case ICMP_TIMESTAMPREPLY: |
(void)printf("Timestamp Reply\n"); |
/* XXX ID + Seq + 3 timestamps */ |
break; |
case ICMP_INFO_REQUEST: |
(void)printf("Information Request\n"); |
/* XXX ID + Seq */ |
break; |
case ICMP_INFO_REPLY: |
(void)printf("Information Reply\n"); |
/* XXX ID + Seq */ |
break; |
#ifdef ICMP_MASKREQ |
case ICMP_MASKREQ: |
(void)printf("Address Mask Request\n"); |
break; |
#endif |
#ifdef ICMP_MASKREPLY |
case ICMP_MASKREPLY: |
(void)printf("Address Mask Reply\n"); |
break; |
#endif |
default: |
(void)printf("Bad ICMP type: %d\n", icp->icmp_type); |
} |
} |
|
/* |
* pr_iph -- |
* Print an IP header with options. |
*/ |
static void |
pr_iph(struct iphdr *ip) |
{ |
int hlen; |
u_char *cp; |
|
hlen = ip->ip_hl << 2; |
cp = (u_char *)ip + 20; /* point to options */ |
|
(void)printf("Vr HL TOS Len ID Flg off TTL Pro cks Src Dst Data\n"); |
(void)printf(" %1x %1x %02x %04x %04x", |
ip->ip_v, ip->ip_hl, ip->ip_tos, ip->ip_len, ip->ip_id); |
(void)printf(" %1x %04x", ((ip->ip_off) & 0xe000) >> 13, |
(ip->ip_off) & 0x1fff); |
(void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p, ip->ip_sum); |
(void)printf(" %s ", inet_ntoa(*((struct in_addr *) &ip->ip_src))); |
(void)printf(" %s ", inet_ntoa(*((struct in_addr *) &ip->ip_dst))); |
/* dump and option bytes */ |
while (hlen-- > 20) { |
(void)printf("%02x", *cp++); |
} |
(void)putchar('\n'); |
} |
|
/* |
* pr_addr -- |
* Return an ascii host address as a dotted quad and optionally with |
* a hostname. |
*/ |
static char * |
pr_addr(u_long l) |
{ |
struct hostent *hp; |
static char buf[256]; |
|
if ((options & F_NUMERIC) || |
!(hp = gethostbyaddr((char *)&l, 4, AF_INET))) |
(void)sprintf(buf, /*sizeof(buf),*/ "%s", |
inet_ntoa(*(struct in_addr *)&l)); |
else |
(void)sprintf(buf, /*sizeof(buf),*/ "%s (%s)", hp->h_name, |
inet_ntoa(*(struct in_addr *)&l)); |
return(buf); |
} |
|
/* |
* pr_retip -- |
* Dump some info on a returned (via ICMP) IP packet. |
*/ |
static void |
pr_retip(struct iphdr *ip) |
{ |
int hlen; |
u_char *cp; |
|
pr_iph(ip); |
hlen = ip->ip_hl << 2; |
cp = (u_char *)ip + hlen; |
|
if (ip->ip_p == 6) |
(void)printf("TCP: from port %u, to port %u (decimal)\n", |
(*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); |
else if (ip->ip_p == 17) |
(void)printf("UDP: from port %u, to port %u (decimal)\n", |
(*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); |
} |
|
static void |
fill(void *bp1, char *patp) |
{ |
register int ii, jj, kk; |
int pat[16]; |
char *cp, *bp = (char *)bp1; |
|
for (cp = patp; *cp; cp++) |
if (!isxdigit(*cp)) { |
(void)fprintf(stderr, |
"ping: patterns must be specified as hex digits.\n"); |
exit(2); |
} |
ii = sscanf(patp, |
"%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", |
&pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], |
&pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12], |
&pat[13], &pat[14], &pat[15]); |
|
if (ii > 0) |
for (kk = 0; kk <= MAXPACKET - (8 + ii); kk += ii) |
for (jj = 0; jj < ii; ++jj) |
bp[jj + kk] = pat[jj]; |
if (!(options & F_QUIET)) { |
(void)printf("PATTERN: 0x"); |
for (jj = 0; jj < ii; ++jj) |
(void)printf("%02x", bp[jj] & 0xFF); |
(void)printf("\n"); |
} |
} |
|
static void |
usage(void) |
{ |
(void)fprintf(stderr, |
"usage: ping [-LRdfnqrv] [-c count] [-i wait] [-l preload]\n\t[-p pattern] [-s packetsize] [-t ttl] [-I interface address] host\n"); |
exit(2); |
} |
/trunk/uclinux/userland/route/route.c
0,0 → 1,240
/* |
* route This file contains an implementation of the command |
* that manages the IP routing table in the kernel. |
* |
* Version: $Id: route.c,v 1.1 2002-03-17 19:58:52 simons Exp $ |
* |
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* (derived from FvK's 'route.c 1.70 01/04/94') |
* |
* Modifications: |
* Johannes Stille: for Net-2Debugged by |
* <johannes@titan.os.open.de> |
* Linus Torvalds: Misc Changes |
* Alan Cox: add the new mtu/window stuff |
* Miquel van Smoorenburg: rt_add and rt_del |
* {1.79} Bernd Eckenfels: route_info |
* {1.80} Bernd Eckenfels: reject, metric, irtt, 1.2.x support. |
* {1.81} Bernd Eckenfels: reject routes need a dummy device |
*960127 {1.82} Bernd Eckenfels: 'mod' and 'dyn' 'reinstate' added |
*960129 {1.83} Bernd Eckenfels: resolve and getsock now in lib/, |
* REJECT displays '-' as gatway. |
*960202 {1.84} Bernd Eckenfels: net-features support added |
*960203 {1.85} Bernd Eckenfels: "#ifdef' in '#if' for net-features |
* -A (aftrans) support, get_longopts |
*960206 {1.86} Bernd Eckenfels: route_init(); |
*960218 {1.87} Bernd Eckenfels: netinet/in.h added |
*960221 {1.88} Bernd Eckenfels: aftrans_dfl support |
*960222 {1.90} Bernd Eckenfels: moved all AF specific code to lib/. |
*960413 {1.91} Bernd Eckenfels: new RTACTION support+FLAG_CACHE/FIB |
*960426 {1.92} Bernd Eckenfels: FLAG_SYM/-N support |
*960823 {x.xx} Frank Strauss: INET6 stuff |
*980629 {1.95} Arnaldo Carvalho de Melo: gettext instead of catgets |
*990101 {1.96} Bernd Eckenfels: fixed usage and FLAG_CACHE Output |
* |
*/ |
#include <sys/types.h> |
#ifdef __UCLINUX__ |
#include <gnu/types.h> |
#endif |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if.h> |
/* #include <net/route.h> realy broken */ |
#include <netinet/in.h> |
#include <netdb.h> |
#include <netinet/in.h> |
#include <arpa/nameser.h> |
#include <resolv.h> |
#include <linux/param.h> |
#include <stdio.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <stdlib.h> |
#include <string.h> |
#include <getopt.h> |
#include <unistd.h> |
#include <ctype.h> |
#include "net-support.h" |
#include "config.h" |
#include "intl.h" |
#include "pathnames.h" |
#include "version.h" |
|
#define DFLT_AF "inet" |
|
#define FEATURE_ROUTE |
#include "lib/net-features.h" /* needs some of the system includes above! */ |
|
char *Release = RELEASE, *Version = "route 1.96 (1999-01-01)"; |
|
int opt_n = 0; /* numerical output flag */ |
int opt_v = 0; /* debugging output flag */ |
int opt_e = 1; /* 1,2,3=type of routetable */ |
int opt_fc = 0; /* routing cache/FIB */ |
int opt_h = 0; /* help selected */ |
struct aftype *ap; /* current address family */ |
|
static void usage(void) |
{ |
fprintf(stderr, _("Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables\n")); |
fprintf(stderr, _(" route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.\n\n")); |
|
fprintf(stderr, _(" route {-h|--help} [<AF>] Detailed usage syntax for specified AF.\n")); |
fprintf(stderr, _(" route {-V|--version} Display version/author and exit.\n\n")); |
|
fprintf(stderr, _(" -v, --verbose be verbose\n")); |
fprintf(stderr, _(" -n, --numeric dont resolve names\n")); |
fprintf(stderr, _(" -N, --symbolic resolve hardware names\n")); |
fprintf(stderr, _(" -e, --extend display other/more information\n")); |
fprintf(stderr, _(" -F, --fib display Forwarding Information Base (default)\n")); |
fprintf(stderr, _(" -C, --cache display routing cache instead of FIB\n\n")); |
|
fprintf(stderr, _(" <AF>=Use '-A <af>' or '--<af>' Default: %s\n"), DFLT_AF); |
fprintf(stderr, _(" List of possible address families (which support routing):\n")); |
print_aflist(1); /* 1 = routeable */ |
exit(E_USAGE); |
} |
|
|
static void version(void) |
{ |
fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features); |
exit(E_VERSION); |
} |
|
|
int main(int argc, char **argv) |
{ |
int i, lop, what = 0; |
#ifdef __UCLINUX__ |
#define getopt_long(a,b,c,d,e) getopt(a,b,c) |
#else |
struct option longopts[] = |
{ |
AFTRANS_OPTS, |
{"extend", 0, 0, 'e'}, |
{"verbose", 0, 0, 'v'}, |
{"version", 0, 0, 'V'}, |
{"numeric", 0, 0, 'n'}, |
{"symbolic", 0, 0, 'N'}, |
{"protocol", 1, 0, 'A'}, |
{"cache", 0, 0, 'C'}, |
{"fib", 0, 0, 'F'}, |
{"help", 0, 0, 'h'}, |
{NULL, 0, 0, 0} |
}; |
#endif |
char **tmp; |
char *progname; |
int options; |
#if I18N |
bindtextdomain("net-tools", "/usr/share/locale"); |
textdomain("net-tools"); |
#endif |
getroute_init(); /* Set up AF routing support */ |
setroute_init(); |
afname[0] = '\0'; |
progname = argv[0]; |
|
/* getopts and -net wont work :-/ */ |
for (tmp = argv; *tmp; tmp++) { |
if (!strcmp(*tmp, "-net")) |
strcpy(*tmp, "#net"); |
else if (!strcmp(*tmp, "-host")) |
strcpy(*tmp, "#host"); |
} |
|
/* Fetch the command-line arguments. */ |
while ((i = getopt_long(argc, argv, "A:eCFhnNVv?", longopts, &lop)) != EOF) |
switch (i) { |
case -1: |
break; |
case 'n': |
opt_n |= FLAG_NUM; |
break; |
case 'N': |
opt_n |= FLAG_SYM; |
break; |
case 'v': |
opt_v |= FLAG_VERBOSE; |
break; |
case 'e': |
opt_e++; |
break; |
case 1: |
if (lop < 0 || lop >= AFTRANS_CNT) { |
EINTERN("route.c", "longopts 1 range"); |
break; |
} |
#ifdef __UCLINUX__ |
printf("%s(%d): no longopts()\n", __FILE__, __LINE__); |
#else |
if ((i = aftrans_opt(longopts[lop].name))) |
exit(i); |
#endif |
break; |
case 'C': |
opt_fc |= FLAG_CACHE; |
break; |
case 'F': |
opt_fc |= FLAG_FIB; |
break; |
case 'A': |
if ((i = aftrans_opt(optarg))) |
exit(i); |
break; |
case 'V': |
version(); |
case 'h': |
case '?': |
opt_h++; |
break; |
default: |
usage(); |
} |
|
argv += optind; |
argc -= optind; |
|
if (opt_h) { |
if (!afname[0]) |
usage(); |
else |
what = RTACTION_HELP; |
} else { |
if (!afname[0]) |
/* this will initialise afname[] */ |
aftrans_def("route", progname, DFLT_AF); |
|
/* Do we have to show the contents of the routing table? */ |
if (*argv == NULL) { |
what = RTACTION_SHOW; |
} else { |
if (!strcmp(*argv, "add")) |
what = RTACTION_ADD; |
else if (!strcmp(*argv, "del") || !strcmp(*argv, "delete")) |
what = RTACTION_DEL; |
else if (!strcmp(*argv, "flush")) |
what = RTACTION_FLUSH; |
else |
usage(); |
} |
} |
|
options = (opt_e & FLAG_EXT) | opt_n | opt_fc | opt_v; |
if (!opt_fc) |
options |= FLAG_FIB; |
|
if (what == RTACTION_SHOW) |
i = route_info(afname, options); |
else |
i = route_edit(what, afname, options, ++argv); |
|
if (i == E_OPTERR) |
usage(); |
|
return (i); |
} |
/trunk/uclinux/userland/route/README.ipv6
0,0 → 1,28
Notes for IPv6 |
-------------- |
|
If you are using libc5, you may need to edit the Makefile so that |
libinet6 is linked in and your IPv6 include files are found in the |
right place. The definitions in question are at about line 91. You may |
also find that the header files provided with inet6-apps are not exactly |
what net-tools expects. This is not a bug in net-tools as such and will |
not be fixed in future releases (though if anybody would like to contribute |
a patch I would be happy to add a pointer to it here.) If you have the |
option you might consider changing to glibc instead (see below) in which |
case you can use the header files supplied with the C library. |
|
If you use glibc, you should ensure that you have version 2.1 or later |
installed. The 2.1 release is available from |
<ftp://sourceware.cygnus.com/pub/glibc among> other places. With this |
version of the C library there should be no need to edit the Makefile |
or apply any patches to net-tools. |
|
Version 2.0 of glibc has no support for IPv6; patches did exist at one |
point but they are now seriously outdated. Instead you should upgrade |
to glibc 2.1. |
|
BUGS |
---- |
|
"ifconfig eth0 add ..." does not currently auto-load the IPv6 module. |
|
/trunk/uclinux/userland/route/include/sockets.h
0,0 → 1,4
extern int skfd, ipx_sock, ax25_sock, rose_sock, inet_sock, inet6_sock, |
ddp_sock, ec_sock; |
|
extern int sockets_open(int family); |
/trunk/uclinux/userland/route/include/interface.h
0,0 → 1,92
struct user_net_device_stats { |
unsigned long rx_packets; /* total packets received */ |
unsigned long tx_packets; /* total packets transmitted */ |
unsigned long rx_bytes; /* total bytes received */ |
unsigned long tx_bytes; /* total bytes transmitted */ |
unsigned long rx_errors; /* bad packets received */ |
unsigned long tx_errors; /* packet transmit problems */ |
unsigned long rx_dropped; /* no space in linux buffers */ |
unsigned long tx_dropped; /* no space available in linux */ |
unsigned long rx_multicast; /* multicast packets received */ |
unsigned long rx_compressed; |
unsigned long tx_compressed; |
unsigned long collisions; |
|
/* detailed rx_errors: */ |
unsigned long rx_length_errors; |
unsigned long rx_over_errors; /* receiver ring buff overflow */ |
unsigned long rx_crc_errors; /* recved pkt with crc error */ |
unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
unsigned long rx_missed_errors; /* receiver missed packet */ |
/* detailed tx_errors */ |
unsigned long tx_aborted_errors; |
unsigned long tx_carrier_errors; |
unsigned long tx_fifo_errors; |
unsigned long tx_heartbeat_errors; |
unsigned long tx_window_errors; |
}; |
|
struct interface { |
struct interface *next; |
|
char name[IFNAMSIZ]; /* interface name */ |
short type; /* if type */ |
short flags; /* various flags */ |
int metric; /* routing metric */ |
int mtu; /* MTU value */ |
int tx_queue_len; /* transmit queue length */ |
struct ifmap map; /* hardware setup */ |
struct sockaddr addr; /* IP address */ |
struct sockaddr dstaddr; /* P-P IP address */ |
struct sockaddr broadaddr; /* IP broadcast address */ |
struct sockaddr netmask; /* IP network mask */ |
struct sockaddr ipxaddr_bb; /* IPX network address */ |
struct sockaddr ipxaddr_sn; /* IPX network address */ |
struct sockaddr ipxaddr_e3; /* IPX network address */ |
struct sockaddr ipxaddr_e2; /* IPX network address */ |
struct sockaddr ddpaddr; /* Appletalk DDP address */ |
struct sockaddr ecaddr; /* Econet address */ |
int has_ip; |
int has_ipx_bb; |
int has_ipx_sn; |
int has_ipx_e3; |
int has_ipx_e2; |
int has_ax25; |
int has_ddp; |
int has_econet; |
char hwaddr[32]; /* HW address */ |
int statistics_valid; |
struct user_net_device_stats stats; /* statistics */ |
int keepalive; /* keepalive value for SLIP */ |
int outfill; /* outfill value for SLIP */ |
}; |
|
extern int if_fetch(struct interface *ife); |
|
extern int for_all_interfaces(int (*)(struct interface *, void *), void *); |
extern struct interface *lookup_interface(char *name); |
extern int if_readlist(void); |
|
extern int do_if_fetch(struct interface *ife); |
extern int do_if_print(struct interface *ife, void *cookie); |
|
extern void ife_print(struct interface *ptr); |
|
/* Defines for poor glibc2.0 users, the feature check is done at runtime */ |
#if !defined(SIOCSIFTXQLEN) |
#define SIOCSIFTXQLEN 0x8943 |
#define SIOCGIFTXQLEN 0x8942 |
#endif |
|
#if !defined(ifr_qlen) |
/* Actually it is ifru_ivalue, but that is not present in 2.0 kernel headers */ |
#define ifr_qlen ifr_ifru.ifru_mtu |
#endif |
|
#define HAVE_TXQUEUELEN |
|
#define HAVE_DYNAMIC |
#ifndef IFF_DYNAMIC |
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */ |
#endif |
/trunk/uclinux/userland/route/include/ipx.h
0,0 → 1,30
|
/* Sanitised ipx.h for net-tools. */ |
|
#ifndef _IPX_H_ |
#define _IPX_H_ |
|
#define IPX_NODE_LEN 6 |
#define IPX_MTU 576 |
|
struct sockaddr_ipx { |
#if LINUX_VERSION_CODE > 131328 /* 2.1.0 or later */ |
sa_family_t sipx_family; |
#else |
short sipx_family; |
#endif |
unsigned short sipx_port; |
unsigned int sipx_network; |
unsigned char sipx_node[IPX_NODE_LEN]; |
unsigned char sipx_type; |
unsigned char sipx_zero; /* 16 byte fill */ |
}; |
|
#define IPX_FRAME_NONE 0 |
#define IPX_FRAME_SNAP 1 |
#define IPX_FRAME_8022 2 |
#define IPX_FRAME_ETHERII 3 |
#define IPX_FRAME_8023 4 |
#define IPX_FRAME_TR_8022 5 |
|
#endif |
/trunk/uclinux/userland/route/include/util-ank.h
0,0 → 1,80
#ifndef __UTILS_H__ |
#define __UTILS_H__ 1 |
|
#include <asm/types.h> |
|
extern int preferred_family; |
extern int show_stats; |
extern int show_details; |
extern int show_raw; |
extern int resolve_hosts; |
|
#ifndef IPPROTO_ESP |
#define IPPROTO_ESP 50 |
#endif |
#ifndef IPPROTO_AH |
#define IPPROTO_AH 51 |
#endif |
|
#define SPRINT_BSIZE 64 |
#define SPRINT_BUF(x) char x[SPRINT_BSIZE] |
|
|
#define NEXT_ARG() \ |
argv++; \ |
if (--argc <= 0) \ |
usage(); |
|
typedef struct |
{ |
__u8 family; |
__u8 bytelen; |
__s16 bitlen; |
__u32 data[4]; |
} inet_prefix; |
|
extern __u32 get_addr32(char *name); |
extern int get_addr_1(inet_prefix *dst, char *arg, int family); |
extern int get_prefix_1(inet_prefix *dst, char *arg, int family); |
extern int get_addr(inet_prefix *dst, char *arg, int family); |
extern int get_prefix(inet_prefix *dst, char *arg, int family); |
|
extern int scan_number(char *arg, unsigned *val); |
|
extern int get_integer(int *val, char *arg, int base); |
extern int get_unsigned(unsigned *val, char *arg, int base); |
#define get_byte get_u8 |
#define get_ushort get_u16 |
#define get_short get_s16 |
extern int get_u32(__u32 *val, char *arg, int base); |
extern int get_u16(__u16 *val, char *arg, int base); |
extern int get_s16(__s16 *val, char *arg, int base); |
extern int get_u8(__u8 *val, char *arg, int base); |
extern int get_s8(__s8 *val, char *arg, int base); |
|
extern int get_tc_classid(__u32 *h, char *str); |
extern int print_tc_classid(char *buf, int len, __u32 h); |
extern char * sprint_tc_classid(__u32 h, char *buf); |
|
/* static void usage(void) __attribute__((noreturn)); */ |
void invarg(char *) __attribute__((noreturn)); |
int matches(char *arg, char *pattern); |
extern int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits); |
|
extern int ipaddr_list(int argc, char **argv); |
extern int iproute_monitor(int argc, char **argv); |
extern int do_ipaddr(int argc, char **argv); |
extern int do_iproute(int argc, char **argv); |
extern int do_iprule(int argc, char **argv); |
extern int do_ipneigh(int argc, char **argv); |
extern int do_iptunnel(int argc, char **argv); |
extern int do_iplink(int argc, char **argv); |
extern int do_ipmonitor(int argc, char **argv); |
extern int do_multiaddr(int argc, char **argv); |
extern int do_qdisc(int argc, char **argv); |
extern int do_class(int argc, char **argv); |
extern int do_filter(int argc, char **argv); |
|
extern const char *format_host(int af, void *addr, __u8 *abuf, int alen); |
|
#endif /* __UTILS_H__ */ |
/trunk/uclinux/userland/route/config.h
0,0 → 1,68
/* |
* config.h Automatically generated configuration includefile |
* |
* NET-TOOLS A collection of programs that form the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. |
* |
* DO NOT EDIT DIRECTLY |
* |
*/ |
|
/* |
* |
* Internationalization |
* |
* The net-tools package has currently been translated to French, |
* German and Brazilian Portugese. Other translations are, of |
* course, welcome. Answer `n' here if you have no support for |
* internationalization on your system. |
* |
*/ |
#define I18N 0 |
|
/* |
* |
* Protocol Families. |
* |
*/ |
#define HAVE_AFUNIX 1 |
#define HAVE_AFINET 1 |
#define HAVE_AFINET6 0 |
#define HAVE_AFIPX 0 |
#define HAVE_AFATALK 0 |
#define HAVE_AFAX25 0 |
#define HAVE_AFNETROM 0 |
#define HAVE_AFROSE 0 |
#define HAVE_AFECONET 0 |
#define HAVE_AFDECnet 0 |
|
/* |
* |
* Device Hardware types. |
* |
*/ |
#define HAVE_HWETHER 1 |
#define HAVE_HWARC 0 |
#define HAVE_HWSLIP 1 |
#define HAVE_HWPPP 1 |
#define HAVE_HWTUNNEL 0 |
#define HAVE_HWTR 0 |
#define HAVE_HWAX25 0 |
#define HAVE_HWROSE 0 |
#define HAVE_HWNETROM 0 |
#define HAVE_HWFR 0 |
#define HAVE_HWSIT 0 |
#define HAVE_HWFDDI 0 |
#define HAVE_HWHIPPI 0 |
#define HAVE_HWASH 0 |
#define HAVE_HWHDLCLAPB 0 |
#define HAVE_HWIRDA 0 |
|
/* |
* |
* Other Features. |
* |
*/ |
#define HAVE_FW_MASQUERADE 1 |
#define HAVE_IP_TOOLS 0 |
/trunk/uclinux/userland/route/intl.h
0,0 → 1,11
/* Dummy header for libintl.h */ |
|
#if I18N |
#undef __OPTIMIZE__ |
#include <libintl.h> |
#define _(String) gettext((String)) |
#define N_(String) (String) |
#else |
#define _(String) (String) |
#define N_(String) (String) |
#endif |
/trunk/uclinux/userland/route/README
0,0 → 1,78
README |
|
Information about the net-tools package |
NET-TOOLS A collection of programs that form the base set of the |
NET-3 networking distribution for the Linux operating |
system. |
|
This package includes the important tools for controlling the network |
subsystem of the Linux kernel. This includes arp, hostname, ifconfig, |
netstat, rarp and route. Additionally, this package contains |
utilities relating to particular network hardware types (plipconfig, |
slattach) and advanced aspects of IP configuration (iptunnel, |
ipmaddr). |
|
Please include the output of "program --version" when reporting bugs. |
|
|
Contents: |
|
README This file. |
|
README.ipv6 Notes for people hacking IPv6. |
|
INSTALLING Installation instructions. |
|
COPYING Your free copy of the GNU Public License. |
|
TODO Some things that need to be done. |
|
|
Notes |
----- |
|
This is net-tools 1.52. Notable changes since 1.51 include: |
|
- Jean-Michel Vansteene updated the French translation. |
- Dag Brattli contributed support for IrDA |
- some bugs have been fixed |
|
Notable changes since 1.50 include: |
|
- Tuan Hoang added support to netstat for printing multicast group |
information (option --groups) |
- Jan Kratochvil added support to netstat for displaying details of |
the process owning a socket (option --programs) |
- Steve Whitehouse contributed support for DECnet |
- some bugs and compilation problems have been fixed |
|
|
You need kernel 2.0 or later to use these programs. These programs |
should compile cleanly with both glibc (version 2.0 or 2.1) and libc5, |
though support for libc5 is not well tested. |
|
The NLS support was changed from catgets to GNU gettext by Arnaldo |
Carvalho de Melo <acme@conectiva.com.br> in June, 1998, to make the |
source more readable. Translations to brazilian portuguese (pt_BR), |
German (de) and French (fr) are available and others are welcome! |
|
route/netstat -r do not yet support different address families |
cleanly. IPX/DDP/AX25 people, please feel free to add the code. |
|
ifconfig now supports changing media types for interfaces. This requires |
a version 2.2 kernel, and many devices do not support it yet. |
|
The tools now support the layout of the 2.2 kernel /proc files (Bernd |
Eckenfels). |
|
Some configuration options require kernel version 2.2 and/or |
particular versions of the C library. The defaults should be safe for |
all common environments but some of the more esoteric hardware and |
protocol families may be more touchy. Feel free to send patches if |
you have problems. |
|
Phil Blundell |
philb@gnu.org |
|
Bernd Eckenfels |
net-tools@lina.inka.de |
/trunk/uclinux/userland/route/arp.c
0,0 → 1,776
/* |
* arp This file contains an implementation of the command |
* that maintains the kernel's ARP cache. It is derived |
* from Berkeley UNIX arp(8), but cleaner and with sup- |
* port for devices other than Ethernet. |
* |
* NET-TOOLS A collection of programs that form the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. |
* |
* Version: $Id: arp.c,v 1.1 2002-03-17 19:58:52 simons Exp $ |
* |
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* |
* Changes: |
* (based on work from Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>) |
* Alan Cox : modified for NET3 |
* Andrew Tridgell : proxy arp netmasks |
* Bernd Eckenfels : -n option |
* Bernd Eckenfels : Use only /proc for display |
* {1.60} Bernd Eckenfels : new arpcode (-i) for 1.3.42 but works |
* with 1.2.x, too |
* {1.61} Bernd Eckenfels : more verbose messages |
* {1.62} Bernd Eckenfels : check -t for hw adresses and try to |
* explain EINVAL (jeff) |
*970125 {1.63} Bernd Eckenfels : -a print hardwarename instead of tiltle |
*970201 {1.64} Bernd Eckenfels : net-features.h support |
*970203 {1.65} Bernd Eckenfels : "#define" in "#if", |
* -H|-A additional to -t|-p |
*970214 {1.66} Bernd Eckenfels : Fix optarg required for -H and -A |
*970412 {1.67} Bernd Eckenfels : device=""; is default |
*970514 {1.68} Bernd Eckenfels : -N and -D |
*970517 {1.69} Bernd Eckenfels : usage() fixed |
*970622 {1.70} Bernd Eckenfels : arp -d priv |
*970106 {1.80} Bernd Eckenfels : new syntax without -D and with "dev <If>", |
* ATF_MAGIC, ATF_DONTPUB support. |
* Typo fix (Debian Bug#5728 Giuliano Procida) |
*970803 {1.81} Bernd Eckenfels : removed junk comment line 1 |
*970925 {1.82} Bernd Eckenfels : include fix for libc6 |
*980213 (1.83) Phil Blundell: set ATF_COM on new entries |
*980629 (1.84) Arnaldo Carvalho de Melo: gettext instead of catgets |
*990101 {1.85} Bernd Eckenfels fixed usage and return codes |
*990105 (1.86) Phil Blundell: don't ignore EINVAL in arp_set |
* |
* 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 <sys/types.h> |
#include <sys/socket.h> |
#include <sys/ioctl.h> |
#include <net/if.h> |
/* #include <linux/netdevice.h> */ |
/* #include <linux/if_arp.h> */ |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <fcntl.h> |
#include <string.h> |
#include <getopt.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "config.h" |
#include "intl.h" |
#include "util.h" |
|
#define DFLT_AF "inet" |
#define DFLT_HW "ether" |
|
#define FEATURE_ARP |
#include "lib/net-features.h" |
|
char *Release = RELEASE, *Version = "arp 1.85 (1999-01-05)"; |
|
int opt_n = 0; /* do not resolve addresses */ |
int opt_N = 0; /* use symbolic names */ |
int opt_v = 0; /* debugging output flag */ |
int opt_D = 0; /* HW-address is devicename */ |
int opt_e = 0; /* 0=BSD output, 1=new linux */ |
int opt_a = 0; /* all entries, substring match */ |
struct aftype *ap; /* current address family */ |
struct hwtype *hw; /* current hardware type */ |
int sockfd = 0; /* active socket descriptor */ |
int hw_set = 0; /* flag if hw-type was set (-H) */ |
char device[16] = ""; /* current device */ |
static void usage(void); |
|
/* Delete an entry from the ARP cache. */ |
static int arp_del(char **args) |
{ |
char host[128]; |
struct arpreq req; |
struct sockaddr sa; |
int flags = 0; |
int err; |
|
memset((char *) &req, 0, sizeof(req)); |
|
/* Resolve the host name. */ |
if (*args == NULL) { |
fprintf(stderr, _("arp: need host name\n")); |
return (-1); |
} |
safe_strncpy(host, *args, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
return (-1); |
} |
/* If a host has more than one address, use the correct one! */ |
memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr)); |
|
if (hw_set) |
req.arp_ha.sa_family = hw->type; |
|
req.arp_flags = ATF_PERM; |
args++; |
while (*args != NULL) { |
if (opt_v) |
fprintf(stderr, "args=%s\n", *args); |
if (!strcmp(*args, "pub")) { |
flags |= 1; |
args++; |
continue; |
} |
if (!strcmp(*args, "priv")) { |
flags |= 2; |
args++; |
continue; |
} |
if (!strcmp(*args, "temp")) { |
req.arp_flags &= ~ATF_PERM; |
args++; |
continue; |
} |
if (!strcmp(*args, "trail")) { |
req.arp_flags |= ATF_USETRAILERS; |
args++; |
continue; |
} |
if (!strcmp(*args, "dontpub")) { |
#ifdef HAVE_ATF_DONTPUB |
req.arp_flags |= ATF_DONTPUB; |
#else |
ENOSUPP("arp", "ATF_DONTPUB"); |
#endif |
args++; |
continue; |
} |
if (!strcmp(*args, "auto")) { |
#ifdef HAVE_ATF_MAGIC |
req.arp_flags |= ATF_MAGIC; |
#else |
ENOSUPP("arp", "ATF_MAGIC"); |
#endif |
args++; |
continue; |
} |
if (!strcmp(*args, "dev")) { |
if (*++args == NULL) |
usage(); |
safe_strncpy(device, *args, sizeof(device)); |
args++; |
continue; |
} |
if (!strcmp(*args, "netmask")) { |
if (*++args == NULL) |
usage(); |
if (strcmp(*args, "255.255.255.255") != 0) { |
strcpy(host, *args); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
return (-1); |
} |
memcpy((char *) &req.arp_netmask, (char *) &sa, |
sizeof(struct sockaddr)); |
req.arp_flags |= ATF_NETMASK; |
} |
args++; |
continue; |
} |
usage(); |
} |
if (flags == 0) |
flags = 3; |
|
strcpy(req.arp_dev, device); |
|
err = -1; |
|
/* Call the kernel. */ |
if (flags & 2) { |
if (opt_v) |
fprintf(stderr, "arp: SIOCDARP(nopub)\n"); |
if ((err = ioctl(sockfd, SIOCDARP, &req) < 0)) { |
if (errno == ENXIO) { |
if (flags & 1) |
goto nopub; |
printf(_("No ARP entry for %s\n"), host); |
return (-1); |
} |
perror("SIOCDARP(priv)"); |
return (-1); |
} |
} |
if ((flags & 1) && (err)) { |
nopub: |
req.arp_flags |= ATF_PUBL; |
if (opt_v) |
fprintf(stderr, "arp: SIOCDARP(pub)\n"); |
if (ioctl(sockfd, SIOCDARP, &req) < 0) { |
if (errno == ENXIO) { |
printf(_("No ARP entry for %s\n"), host); |
return (-1); |
} |
perror("SIOCDARP(pub)"); |
return (-1); |
} |
} |
return (0); |
} |
|
/* Get the hardware address to a specified interface name */ |
static int arp_getdevhw(char *ifname, struct sockaddr *sa, struct hwtype *hw) |
{ |
struct ifreq ifr; |
struct hwtype *xhw; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { |
fprintf(stderr, _("arp: cant get HW-Address for `%s': %s.\n"), ifname, strerror(errno)); |
return (-1); |
} |
if (hw && (ifr.ifr_hwaddr.sa_family != hw->type)) { |
fprintf(stderr, _("arp: protocol type mismatch.\n")); |
return (-1); |
} |
memcpy((char *) sa, (char *) &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); |
|
if (opt_v) { |
if (!(xhw = get_hwntype(ifr.ifr_hwaddr.sa_family)) || (xhw->sprint == 0)) { |
xhw = get_hwntype(-1); |
} |
fprintf(stderr, _("arp: device `%s' has HW address %s `%s'.\n"), ifname, xhw->name, xhw->sprint(&ifr.ifr_hwaddr)); |
} |
return (0); |
} |
|
/* Set an entry in the ARP cache. */ |
static int arp_set(char **args) |
{ |
char host[128]; |
struct arpreq req; |
struct sockaddr sa; |
int flags; |
|
memset((char *) &req, 0, sizeof(req)); |
|
/* Resolve the host name. */ |
if (*args == NULL) { |
fprintf(stderr, _("arp: need host name\n")); |
return (-1); |
} |
safe_strncpy(host, *args++, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
return (-1); |
} |
/* If a host has more than one address, use the correct one! */ |
memcpy((char *) &req.arp_pa, (char *) &sa, sizeof(struct sockaddr)); |
|
/* Fetch the hardware address. */ |
if (*args == NULL) { |
fprintf(stderr, _("arp: need hardware address\n")); |
return (-1); |
} |
if (opt_D) { |
if (arp_getdevhw(*args++, &req.arp_ha, hw_set ? hw : NULL) < 0) |
return (-1); |
} else { |
if (hw->input(*args++, &req.arp_ha) < 0) { |
fprintf(stderr, _("arp: invalid hardware address\n")); |
return (-1); |
} |
} |
|
/* Check out any modifiers. */ |
flags = ATF_PERM | ATF_COM; |
while (*args != NULL) { |
if (!strcmp(*args, "temp")) { |
flags &= ~ATF_PERM; |
args++; |
continue; |
} |
if (!strcmp(*args, "pub")) { |
flags |= ATF_PUBL; |
args++; |
continue; |
} |
if (!strcmp(*args, "priv")) { |
flags &= ~ATF_PUBL; |
args++; |
continue; |
} |
if (!strcmp(*args, "trail")) { |
flags |= ATF_USETRAILERS; |
args++; |
continue; |
} |
if (!strcmp(*args, "dontpub")) { |
#ifdef HAVE_ATF_DONTPUB |
flags |= ATF_DONTPUB; |
#else |
ENOSUPP("arp", "ATF_DONTPUB"); |
#endif |
args++; |
continue; |
} |
if (!strcmp(*args, "auto")) { |
#ifdef HAVE_ATF_MAGIC |
flags |= ATF_MAGIC; |
#else |
ENOSUPP("arp", "ATF_MAGIC"); |
#endif |
args++; |
continue; |
} |
if (!strcmp(*args, "dev")) { |
if (*++args == NULL) |
usage(); |
safe_strncpy(device, *args, sizeof(device)); |
args++; |
continue; |
} |
if (!strcmp(*args, "netmask")) { |
if (*++args == NULL) |
usage(); |
if (strcmp(*args, "255.255.255.255") != 0) { |
strcpy(host, *args); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
return (-1); |
} |
memcpy((char *) &req.arp_netmask, (char *) &sa, |
sizeof(struct sockaddr)); |
flags |= ATF_NETMASK; |
} |
args++; |
continue; |
} |
usage(); |
} |
|
/* Fill in the remainder of the request. */ |
req.arp_flags = flags; |
|
strcpy(req.arp_dev, device); |
|
/* Call the kernel. */ |
if (opt_v) |
fprintf(stderr, "arp: SIOCSARP()\n"); |
if (ioctl(sockfd, SIOCSARP, &req) < 0) { |
perror("SIOCSARP"); |
return (-1); |
} |
return (0); |
} |
|
|
/* Process an EtherFile */ |
static int arp_file(char *name) |
{ |
char buff[1024]; |
char *sp, *args[32]; |
int linenr, argc; |
FILE *fp; |
|
if ((fp = fopen(name, "r")) == NULL) { |
fprintf(stderr, _("arp: cannot open etherfile %s !\n"), name); |
return (-1); |
} |
/* Read the lines in the file. */ |
linenr = 0; |
while (fgets(buff, sizeof(buff), fp) != (char *) NULL) { |
linenr++; |
if (opt_v == 1) |
fprintf(stderr, ">> %s", buff); |
if ((sp = strchr(buff, '\n')) != (char *) NULL) |
*sp = '\0'; |
if (buff[0] == '#' || buff[0] == '\0') |
continue; |
|
argc = getargs(buff, args); |
if (argc < 2) { |
fprintf(stderr, _("arp: format error on line %u of etherfile %s !\n"), |
linenr, name); |
continue; |
} |
if (arp_set(args) != 0) |
fprintf(stderr, _("arp: cannot set entry on line %u of etherfile %s !\n"), |
linenr, name); |
} |
|
(void) fclose(fp); |
return (0); |
} |
|
|
/* Print the contents of an ARP request block. */ |
static void arp_disp_2(char *name, int type, int arp_flags, char *hwa, char *mask, char *dev) |
{ |
static int title = 0; |
struct hwtype *xhw; |
char flags[10]; |
|
xhw = get_hwntype(type); |
if (xhw == NULL) |
xhw = get_hwtype(DFLT_HW); |
|
if (title++ == 0) { |
printf(_("Address\t\t\tHWtype\tHWaddress\t Flags Mask\t\t Iface\n")); |
} |
/* Setup the flags. */ |
flags[0] = '\0'; |
if (arp_flags & ATF_COM) |
strcat(flags, "C"); |
if (arp_flags & ATF_PERM) |
strcat(flags, "M"); |
if (arp_flags & ATF_PUBL) |
strcat(flags, "P"); |
#ifdef HAVE_ATF_MAGIC |
if (arp_flags & ATF_MAGIC) |
strcat(flags, "A"); |
#endif |
#ifdef HAVE_ATF_DONTPUB |
if (arp_flags & ATF_DONTPUB) |
strcat(flags, "!"); |
#endif |
if (arp_flags & ATF_USETRAILERS) |
strcat(flags, "T"); |
|
if (!(arp_flags & ATF_NETMASK)) |
mask = ""; |
|
printf("%-23.23s\t", name); |
|
if (!(arp_flags & ATF_COM)) { |
if (arp_flags & ATF_PUBL) |
printf("%-8.8s%-20.20s", "*", "*"); |
else |
printf("%-8.8s%-20.20s", "", _("(incomplete)")); |
} else { |
printf("%-8.8s%-20.20s", xhw->name, hwa); |
} |
|
printf("%-6.6s%-15.15s %s\n", flags, mask, dev); |
} |
|
/* Print the contents of an ARP request block. */ |
static void arp_disp(char *name, char *ip, int type, int arp_flags, char *hwa, char *mask, char *dev) |
{ |
struct hwtype *xhw; |
|
xhw = get_hwntype(type); |
if (xhw == NULL) |
xhw = get_hwtype(DFLT_HW); |
|
printf(_("%s (%s) at "), name, ip); |
|
if (!(arp_flags & ATF_COM)) { |
if (arp_flags & ATF_PUBL) |
printf("* "); |
else |
printf(_("<incomplete> ")); |
} else { |
printf("%s [%s] ", hwa, xhw->name); |
} |
|
if (arp_flags & ATF_NETMASK) |
printf(_("netmask %s "), mask); |
|
if (arp_flags & ATF_PERM) |
printf("PERM "); |
if (arp_flags & ATF_PUBL) |
printf("PUP "); |
#ifdef HAVE_ATF_MAGIC |
if (arp_flags & ATF_MAGIC) |
printf("AUTO "); |
#endif |
#ifdef HAVE_ATF_DONTPUB |
if (arp_flags & ATF_DONTPUB) |
printf("DONTPUB "); |
#endif |
if (arp_flags & ATF_USETRAILERS) |
printf("TRAIL "); |
|
printf(_("on %s\n"), dev); |
} |
|
|
/* Display the contents of the ARP cache in the kernel. */ |
static int arp_show(char *name) |
{ |
char host[100]; |
struct sockaddr sa; |
char ip[100]; |
char hwa[100]; |
char mask[100]; |
char line[200]; |
char dev[100]; |
int type, flags; |
FILE *fp; |
char *hostname; |
int num, entries = 0, showed = 0; |
|
host[0] = '\0'; |
|
if (name != NULL) { |
/* Resolve the host name. */ |
safe_strncpy(host, name, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
return (-1); |
} |
strcpy(host, ap->sprint(&sa, 1)); |
} |
/* Open the PROCps kernel table. */ |
if ((fp = fopen(_PATH_PROCNET_ARP, "r")) == NULL) { |
perror(_PATH_PROCNET_ARP); |
return (-1); |
} |
/* Bypass header -- read until newline */ |
if (fgets(line, sizeof(line), fp) != (char *) NULL) { |
strcpy(mask, "-"); |
strcpy(dev, "-"); |
/* Read the ARP cache entries. */ |
for (; fgets(line, sizeof(line), fp);) { |
num = sscanf(line, "%s 0x%x 0x%x %100s %100s %100s\n", |
ip, &type, &flags, hwa, mask, dev); |
if (num < 4) |
break; |
|
entries++; |
/* if the user specified hw-type differs, skip it */ |
if (hw_set && (type != hw->type)) |
continue; |
|
/* if the user specified address differs, skip it */ |
if (host[0] && strcmp(ip, host)) |
continue; |
|
/* if the user specified device differs, skip it */ |
if (device[0] && strcmp(dev, device)) |
continue; |
|
showed++; |
/* This IS ugly but it works -be */ |
if (opt_n) |
hostname = "?"; |
else { |
if (ap->input(0, ip, &sa) < 0) |
hostname = ip; |
else |
hostname = ap->sprint(&sa, opt_n | 0x8000); |
if (strcmp(hostname, ip) == 0) |
hostname = "?"; |
} |
|
if (opt_e) |
arp_disp_2(hostname[0] == '?' ? ip : hostname, type, flags, hwa, mask, dev); |
else |
arp_disp(hostname, ip, type, flags, hwa, mask, dev); |
} |
} |
if (opt_v) |
printf(_("Entries: %d\tSkipped: %d\tFound: %d\n"), entries, entries - showed, showed); |
|
if (!showed) { |
if (host[0] && !opt_a) |
printf(_("%s (%s) -- no entry\n"), name, host); |
else if (hw_set || host[0] || device[0]) { |
printf(_("arp: in %d entries no match found.\n"), entries); |
} |
} |
(void) fclose(fp); |
return (0); |
} |
|
static void version(void) |
{ |
fprintf(stderr, "%s\n%s\n%s\n", Release, Version, Features); |
exit(E_VERSION); |
} |
|
static void usage(void) |
{ |
fprintf(stderr, _("Usage:\n arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache\n")); |
fprintf(stderr, _(" arp [-v] [-i <if>] -d <hostname> [pub][nopub] <-Delete ARP entry\n")); |
fprintf(stderr, _(" arp [-vnD] [<HW>] [-i <if>] -f <filename> <-Add entry from file\n")); |
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [temp][nopub] <-Add entry\n")); |
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -s <hostname> <hwaddr> [netmask <nm>] pub <-''-\n")); |
fprintf(stderr, _(" arp [-v] [<HW>] [-i <if>] -Ds <hostname> <if> [netmask <nm>] pub <-''-\n\n")); |
|
fprintf(stderr, _(" -a display (all) hosts in alternative (BSD) style\n")); |
fprintf(stderr, _(" -s, --set set a new ARP entry\n")); |
fprintf(stderr, _(" -d, --delete delete a specified entry\n")); |
fprintf(stderr, _(" -v, --verbose be verbose\n")); |
fprintf(stderr, _(" -n, --numeric dont resolve names\n")); |
fprintf(stderr, _(" -i, --device specify network interface (e.g. eth0)\n")); |
fprintf(stderr, _(" -D, --use-device read <hwaddr> from given device\n")); |
fprintf(stderr, _(" -f, --file read new entries from file\n\n")); |
|
fprintf(stderr, _(" <HW>=Use '-H <hw>' to specify hardware address type. Default: %s\n"), DFLT_HW); |
fprintf(stderr, _(" List of possible hardware types (which support ARP):\n")); |
print_hwlist(1); /* 1 = ARPable */ |
exit(E_USAGE); |
} |
|
int main(int argc, char **argv) |
{ |
int i, lop, what; |
#ifdef EMBED |
#define getopt_long(a,b,c,d,e) getopt(a,b,c) |
#else |
struct option longopts[] = |
{ |
{"verbose", 0, 0, 'v'}, |
{"version", 0, 0, 'V'}, |
{"all", 0, 0, 'a'}, |
{"delete", 0, 0, 'd'}, |
{"file", 0, 0, 'f'}, |
{"numeric", 0, 0, 'n'}, |
{"set", 0, 0, 's'}, |
{"protocol", 1, 0, 'A'}, |
{"hw-type", 1, 0, 'H'}, |
{"device", 0, 0, 'i'}, |
{"help", 0, 0, 'h'}, |
{"use-device", 0, 0, 'D'}, |
{"symbolic", 0, 0, 'N'}, |
{NULL, 0, 0, 0} |
}; |
#endif |
|
#if I18N |
bindtextdomain("net-tools", "/usr/share/locale"); |
textdomain("net-tools"); |
#endif |
|
/* Initialize variables... */ |
if ((hw = get_hwtype(DFLT_HW)) == NULL) { |
fprintf(stderr, _("%s: hardware type not supported!\n"), DFLT_HW); |
return (-1); |
} |
if ((ap = get_aftype(DFLT_AF)) == NULL) { |
fprintf(stderr, _("%s: address family not supported!\n"), DFLT_AF); |
return (-1); |
} |
what = 0; |
|
/* Fetch the command-line arguments. */ |
/* opterr = 0; */ |
while ((i = getopt_long(argc, argv, "A:H:adfp:nsei:t:vh?DNV", longopts, &lop)) != EOF) |
switch (i) { |
case 'a': |
what = 1; |
opt_a = 1; |
break; |
case 'f': |
what = 2; |
break; |
case 'd': |
what = 3; |
break; |
case 's': |
what = 4; |
break; |
|
|
case 'e': |
opt_e = 1; |
break; |
case 'n': |
opt_n = FLAG_NUM; |
break; |
case 'D': |
opt_D = 1; |
break; |
case 'N': |
opt_N = FLAG_SYM; |
fprintf(stderr, _("arp: -N not yet supported.\n")); |
break; |
case 'v': |
opt_v = 1; |
break; |
|
case 'A': |
case 'p': |
ap = get_aftype(optarg); |
if (ap == NULL) { |
fprintf(stderr, _("arp: %s: unknown address family.\n"), |
optarg); |
exit(-1); |
} |
break; |
case 'H': |
case 't': |
hw = get_hwtype(optarg); |
if (hw == NULL) { |
fprintf(stderr, _("arp: %s: unknown hardware type.\n"), |
optarg); |
exit(-1); |
} |
hw_set = 1; |
break; |
case 'i': |
safe_strncpy(device, optarg, sizeof(device)); |
break; |
|
case 'V': |
version(); |
case '?': |
case 'h': |
default: |
usage(); |
} |
|
if (ap->af != AF_INET) { |
fprintf(stderr, _("arp: %s: kernel only supports 'inet'.\n"), |
ap->name); |
exit(-1); |
} |
if (hw->alen <= 0) { |
fprintf(stderr, _("arp: %s: hardware type without ARP support.\n"), |
hw->name); |
exit(-1); |
} |
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
perror("socket"); |
exit(-1); |
} |
/* Now see what we have to do here... */ |
switch (what) { |
case 0: |
opt_e = 1; |
what = arp_show(argv[optind]); |
break; |
|
case 1: /* show an ARP entry in the cache */ |
what = arp_show(argv[optind]); |
break; |
|
case 2: /* process an EtherFile */ |
what = arp_file(argv[optind]); |
break; |
|
case 3: /* delete an ARP entry from the cache */ |
what = arp_del(&argv[optind]); |
break; |
|
case 4: /* set an ARP entry in the cache */ |
what = arp_set(&argv[optind]); |
break; |
|
default: |
usage(); |
} |
|
exit(what); |
} |
/trunk/uclinux/userland/route/Makefile.org
0,0 → 1,246
# |
# Makefile Main Makefile for the net-tools Package |
# |
# NET-TOOLS A collection of programs that form the base set of the |
# NET-3 Networking Distribution for the LINUX operating |
# system. |
# |
# Version: Makefile 1.45 (1996-06-29) |
# |
# Author: Bernd Eckenfels <net-tools@lina.inka.de> |
# Copyright 1995-1996 Bernd Eckebnfels, Germany |
# |
# URLs: ftp://ftp.inka.de/pub/comp/Linux/networking/NetTools/ |
# ftp://ftp.linux.org.uk/pub/linux/Networking/PROGRAMS/NetTools/ |
# http://www.inka.de/sites/lina/linux/NetTools/index_en.html |
# |
# Based on: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
# Copyright 1988-1993 MicroWalt Corporation |
# |
# Modifications: |
# Extensively modified from 01/21/94 onwards by |
# Alan Cox <A.Cox@swansea.ac.uk> |
# Copyright 1993-1994 Swansea University Computer Society |
# |
# Be careful! |
# This Makefile doesn't describe complete dependencies for all include files. |
# If you change include files you might need to do make clean. |
# |
# {1.20} Bernd Eckenfels: Even more modifications for the new |
# package layout |
# {1.21} Bernd Eckenfels: Check if config.in is newer than |
# config.status |
# {1.22} Bernd Eckenfels: Include ypdomainname and nisdomainame |
# |
# 1.3.50-BETA6 private Release |
# |
#960125 {1.23} Bernd Eckenfels: Peter Tobias' rewrite for |
# makefile-based installation |
# 1.3.50-BETA6a private Release |
# |
#960201 {1.24} Bernd Eckenfels: net-features.h added |
# |
#960201 1.3.50-BETA6b private Release |
# |
#960203 1.3.50-BETA6c private Release |
# |
#960204 1.3.50-BETA6d private Release |
# |
#960204 {1.25} Bernd Eckenfels: DISTRIBUTION added |
# |
#960205 1.3.50-BETA6e private Release |
# |
#960206 {1.26} Bernd Eckenfels: afrt.o removed (cleaner solution) |
# |
#960215 1.3.50-BETA6f Release |
# |
#960216 {1.30} Bernd Eckenfels: net-lib support |
#960322 {1.31} Bernd Eckenfels: moveable netlib, TOPDIR |
#960424 {1.32} Bernd Eckenfels: included the URLs in the Comment |
# |
#960514 1.31-alpha release |
# |
#960518 {1.33} Bernd Eckenfels: -I/usr/src/linux/include comment added |
# |
# 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. |
# |
|
# set the base of the Installation |
# BASEDIR = /mnt |
|
# path to the net-lib support library. Default: lib |
NET_LIB_PATH = lib |
NET_LIB_NAME = net-tools |
|
PROGS := ifconfig hostname arp netstat route rarp slattach plipconfig |
|
-include config.make |
ifeq ($(HAVE_IP_TOOLS),1) |
PROGS += iptunnel ipmaddr |
endif |
|
# Compiler and Linker Options |
# You may need to uncomment and edit these if you are using libc5 and IPv6. |
COPTS = -D_GNU_SOURCE -O2 -Wall -g # -I/usr/inet6/include |
LOPTS = |
RESLIB = # -L/usr/inet6/lib -linet6 |
|
ifeq ($(HAVE_AFDECnet),1) |
DNLIB = -ldnet |
endif |
|
# -------- end of user definitions -------- |
|
MAINTAINER = Philip.Blundell@pobox.com |
RELEASE = 1.52 |
|
.EXPORT_ALL_VARIABLES: |
|
ifeq ("$(NET_LIB_PATH)","lib2") |
TOPDIR = .. |
else |
TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) |
endif |
|
NET-LIB = $(NET_LIB_PATH)/lib$(NET_LIB_NAME).a |
|
CFLAGS = $(COPTS) -I. -idirafter ./include/ -I$(NET_LIB_PATH) |
LDFLAGS = $(LOPTS) -L$(NET_LIB_PATH) |
|
SUBDIRS = man/ $(NET_LIB_PATH)/ |
|
CC = gcc |
LD = gcc |
|
NLIB = -l$(NET_LIB_NAME) |
|
MDEFINES = COPTS='$(COPTS)' LOPTS='$(LOPTS)' TOPDIR='$(TOPDIR)' |
|
%.o: %.c config.h version.h intl.h net-features.h $< |
$(CC) $(CFLAGS) -c $< |
|
all: config.h version.h subdirs $(PROGS) |
|
config: cleanconfig config.h |
|
install: all savebin installbin installdata |
|
update: all installbin installdata |
|
mostlyclean: |
rm -f *.o DEADJOE config.new *~ *.orig lib/*.o |
|
clean: mostlyclean |
rm -f $(PROGS) |
@for i in $(SUBDIRS); do (cd $$i && make clean) ; done |
@cd po && make clean |
|
cleanconfig: |
rm -f config.h |
|
clobber: clean |
rm -f $(PROGS) config.h version.h config.status |
@for i in $(SUBDIRS); do (cd $$i && make clobber) ; done |
|
|
dist: clobber |
@echo Creating net-tools-$(RELEASE) in .. |
@tar -cvz -f ../net-tools-$(RELEASE).tar.gz -C .. net-tools-${RELEASE} |
|
|
config.h: config.in Makefile |
@echo "Configuring the Linux net-tools (NET-3 Base Utilities)..." ; echo |
@if [ config.status -nt config.in ]; \ |
then ./configure.sh <config.status; \ |
else ./configure.sh <config.in; \ |
fi |
|
|
version.h: Makefile |
@echo "#define RELEASE \"net-tools $(RELEASE)\"" >version.h |
|
|
$(NET-LIB): config.h version.h intl.h libdir |
|
i18n.h: i18ndir |
|
libdir: |
@$(MAKE) -C $(NET_LIB_PATH) $(MDEFINES) |
|
i18ndir: |
@$(MAKE) -C po |
|
subdirs: |
@for i in $(SUBDIRS); do $(MAKE) -C $$i $(MDEFINES) ; done |
|
ifconfig: $(NET-LIB) ifconfig.o |
$(CC) $(LDFLAGS) -o ifconfig ifconfig.o $(NLIB) $(RESLIB) |
|
hostname: hostname.o |
$(CC) $(LDFLAGS) -o hostname hostname.o $(DNLIB) |
|
route: $(NET-LIB) route.o |
$(CC) $(LDFLAGS) -o route route.o $(NLIB) $(RESLIB) |
|
arp: $(NET-LIB) arp.o |
$(CC) $(LDFLAGS) -o arp arp.o $(NLIB) $(RESLIB) |
|
rarp: $(NET-LIB) rarp.o |
$(CC) $(LDFLAGS) -o rarp rarp.o $(NLIB) |
|
slattach: $(NET-LIB) slattach.o |
$(CC) $(LDFLAGS) -o slattach slattach.o $(NLIB) |
|
plipconfig: $(NET-LIB) plipconfig.o |
$(CC) $(LDFLAGS) -o plipconfig plipconfig.o $(NLIB) |
|
netstat: $(NET-LIB) netstat.o statistics.o |
$(CC) $(LDFLAGS) -o netstat netstat.o statistics.o $(NLIB) $(RESLIB) |
|
iptunnel: $(NET-LIB) iptunnel.o |
$(CC) $(LDFLAGS) -o iptunnel iptunnel.o $(NLIB) $(RESLIB) |
|
ipmaddr: $(NET-LIB) ipmaddr.o |
$(CC) $(LDFLAGS) -o ipmaddr ipmaddr.o $(NLIB) $(RESLIB) |
|
installbin: |
install -m 0755 -d ${BASEDIR}/sbin |
install -m 0755 -d ${BASEDIR}/bin |
install -m 0755 arp ${BASEDIR}/sbin |
install -m 0755 ifconfig ${BASEDIR}/sbin |
install -m 0755 netstat ${BASEDIR}/bin |
install -m 0755 rarp ${BASEDIR}/sbin |
install -m 0755 route ${BASEDIR}/sbin |
install -m 0755 hostname ${BASEDIR}/bin |
install -m 0755 slattach $(BASEDIR)/sbin |
install -m 0755 plipconfig $(BASEDIR)/sbin |
ifeq ($(HAVE_IP_TOOLS),1) |
install -m 0755 ipmaddr $(BASEDIR)/sbin |
install -m 0755 iptunnel $(BASEDIR)/sbin |
endif |
ln -fs hostname $(BASEDIR)/bin/dnsdomainname |
ln -fs hostname $(BASEDIR)/bin/ypdomainname |
ln -fs hostname $(BASEDIR)/bin/nisdomainname |
ln -fs hostname $(BASEDIR)/bin/domainname |
ifeq ($(HAVE_AFDECnet),1) |
ln -fs hostname $(BASEDIR)/bin/nodename |
endif |
|
savebin: |
@for i in ${BASEDIR}/sbin/arp ${BASEDIR}/sbin/ifconfig \ |
${BASEDIR}/bin/netstat \ |
${BASEDIR}/sbin/rarp ${BASEDIR}/sbin/route \ |
${BASEDIR}/bin/hostname ${BASEDIR}/bin/ypdomainname \ |
${BASEDIR}/bin/dnsdomainname ${BASEDIR}/bin/nisdomainname \ |
${BASEDIR}/bin/domainname ; do \ |
[ -f $$i ] && cp -f $$i $$i.old ; done ; echo Saved. |
|
installdata: |
$(MAKE) -C man install |
$(MAKE) -C po install |
|
# End of Makefile. |
/trunk/uclinux/userland/route/INSTALLING
0,0 → 1,55
net-tools |
|
INSTALLING |
|
Please read the file `README' before you start with the installation of the |
net-tools. |
|
|
|
HACKERS WAY |
----------- |
cd /usr/src ; tar xvzf net-tools*.tar.gz |
less Makefile ; make config ; make ; make -n install ; make install |
|
|
|
CONFIGURE |
--------- |
First of all change into the net-tools directory. |
|
Before you start with the Installation please have a look into the toplevel |
Makefile. There are some configuration options with explanations. |
|
To configure the compilation use "make config". |
|
If you have a recent Kernel you can and SHOULD answer ALL the Configuration |
Options with YES. You only have to decide about the NLS: |
|
If you don't know whether GNU gettext is supported on your system or not, run |
msgfmt. If it exists, there is every chance that GNU gettext is |
supported. |
|
|
COMPILE |
------- |
To compile simply use "make". |
|
There should be no warnings or errors. |
|
|
|
INSTALLATION |
------------ |
If you want to install the binaries use "make install". |
|
This will generate backups of your old binaries. If you dont want the |
backups, please use "make update" instead. To change the default permissions |
and ownerships of the installed binaries and manpages edit the Makefile. You |
can test the Installation with "make -n install". This will tell make: Don't |
run any commands, just print them. |
|
|
|
Bernd 'eckes' Eckenfels |
<net-tools@lina.inka.de> |
/trunk/uclinux/userland/route/ABOUT-NLS
0,0 → 1,203
Notes on the GNU Translation Project |
************************************ |
|
GNU is going international! The GNU Translation Project is a way to |
get maintainers, translators and users all together, so GNU will |
gradually become able to speak many native languages. A few packages |
already provide native language translation for their messages. |
|
If you found this `ABOUT-NLS' file inside a GNU distribution, you |
may assume that the distributed package does use GNU `gettext' |
internally, itself available at your nearest GNU archive site. But you |
do not need to install GNU `gettext' prior to configuring, installing |
or using this package with messages translated. |
|
Installers will find here some useful hints. These notes also |
explain how users should proceed for getting the programs to use the |
available translations. They tell how people wanting to contribute and |
work at translations should contact the appropriate team. |
|
When reporting bugs in the `intl/' directory or bugs which may be |
related to internationalization, you should tell about the version of |
`gettext' which is used. The information can be found in the |
`intl/VERSION' file, in internationalized packages. |
|
One advise in advance |
===================== |
|
If you want to exploit the full power of the GNU `gettext' package |
you should configure it using |
|
--with-gnu-gettext. |
|
No existing implementation at this point provides so many useful |
features (such as locale alias or message inheritance). It is also not |
possible to provide this additional functionality on top of a catgets |
implementation. |
|
Future versions of GNU `gettext' will very likely provide even more |
functionality. So it might be a good idea to change to GNU `gettext' |
as soon as possible. |
|
INSTALL Matters |
=============== |
|
Some GNU packages are "localizable" when properly installed; the |
programs they contain can be made to speak your own native language. |
Most such packages use GNU `gettext'. Other packages have their own |
ways to internationalization, predating GNU `gettext'. |
|
By default, this package will be installed to allow translation of |
messages. It will automatically detect whether the system provides |
usable `catgets' or `gettext' functions. If neither is available, the |
GNU `gettext' own library will be used. However, installers may use |
special options at configuration time for changing this behaviour. The |
commands: |
|
./configure --with-gnu-gettext |
./configure --disable-nls |
|
will respectively bypass system `catgets' or `gettext' to use GNU |
`gettext', or else, totally disable translation of messages. |
|
When you already have GNU `gettext' installed on your system and run |
configure without an option for your new package, configure will |
probably detect the previously built and installed `libintl.a' file and |
will decide to use this. This might be not what is desirable. You |
should use the more recent version of the GNU `gettext' library. I.e. |
if the file `intl/VERSION' shows that the library which comes with this |
package is more recent, you should use |
|
./configure --with-gnu-gettext |
|
to prevent auto-detection. |
|
Internationalized packages have usually many `po/LL.po' files, where |
LL gives an ISO 639 two-letter code identifying the language. Unless |
translations are disabled, all those available are installed together |
with the package. However, the environment variable `LINGUAS' may be |
set, prior to configuration, to limit the installed set. `LINGUAS' |
should then contain a space separated list of two-letter codes, stating |
which languages are allowed. |
|
Using This Package |
================== |
|
As a user, if your language has been installed for this package, you |
only have to set the `LANG' environment variable to the appropriate |
ISO 639 `LL' two-letter code prior to using the programs in the |
package. For example, let's suppose that you speak German. At the |
shell prompt, merely execute `setenv LANG de' (in `csh') or |
`export LANG; LANG=de' (in `sh'). This can be done from your `.login' |
or `.profile' file, once and for all. Packages which are not |
internationalized will merely ignore the setting of this variable. |
|
Translating Teams |
================= |
|
The GNU `gettext' tool set contains *everything* maintainers need |
for internationalizing their packages for messages. It also contains |
quite useful tools for helping translators at localizing messages to |
their native language, once a package has already been |
internationalized. |
|
To achieve the GNU Translation Project, we need many interested |
people who like their own language and write it well, and who are also |
able to synergize with other translators speaking the same language. |
Each translating team has its own mailing list, courtesy of Linux |
International. You may reach your translating team at the address |
`LL@li.org', replacing LL by the two-letter ISO 639 code for your |
language. Language codes are *not* the same as country codes given in |
ISO 3166. The following translating teams exist, as of November 1995: |
|
Chinese `zh', Czech `cs', Danish `da', Dutch `nl', English `en', |
Esperanto `eo', Finnish `fi', French `fr', Irish `ga', German |
`de', Greek `el', Italian `it', Japanese `ja', Indonesian `in', |
Norwegian `no', Persian `fa', Polish `pl', Portuguese `pt', |
Russian `ru', Spanish `es', Swedish `sv', Telugu `te' and Turkish |
`tr'. |
|
For example, you may reach the Chinese translating team by writing to |
`zh@li.org'. |
|
If you'd like to volunteer to *work* at translating messages, you |
should become a member of the translating team for your own language. |
The subscribing address is *not* the same as the list itself, it has |
`-request' appended. For example, Swedish people can send a message to |
`sv-request@li.org', having this message body: |
|
subscribe |
|
Keep in mind that team members should be interested in *working* at |
translations, or at solving translational difficulties, rather than |
merely lurking around. If your team does not exist yet and you want to |
start one, please write to `gnu-translation@prep.ai.mit.edu'; you will |
then reach the GNU coordinator for all translator teams. |
|
The English team is special. It works at improving and uniformizing |
the terminology used in GNU. Proven linguistic skill are praised more |
than programming skill, here. For the time being, please avoid |
subscribing to the English team unless explicitely invited to do so. |
|
Available Packages |
================== |
|
Languages are not equally supported in all GNU packages. The |
following matrix shows the current state of GNU internationalization, |
as of November 1995. Listed are: internationalized packages, and |
languages for which work is in progress, or about to start. |
|
See note cs de en fr it ja nl no pt sv |
\ .-------------------------------. |
chess (1) | X / X | |
clisp | X X X | |
diffutils (2) | / . | |
fileutils | . / | |
flex (3) | / . | |
m4 | - / - - . - | |
gettext | X / X X X | |
ptx | - / - - | |
recode | - / - - - | |
sh-utils | . / . | |
sharutils | X / X X X X X | |
tar | X / X - X X | |
textutils | . / . | |
wdiff | - - / - - | |
`-------------------------------' |
cs de en fr it ja nl no pt sv |
|
The interpretation legend and notes are: |
|
`/' |
There is no PO file, this package merely defaults to this language. |
|
`.' |
The effort of localizing this package has been undertaken by |
someone, or by a translating team, and work is, or should be in |
progress. |
|
`-' |
A PO file for this package and this language is completed and is |
currently available in a pretest release, or is all ready for |
inclusion in the next release of this package. |
|
`X' |
The localization of this package to this particular language is |
fully completed, and now distributed through an official release. |
|
(1) |
This package is translated to specific languages by methods |
predating GNU `gettext'. Translations are all kept on disk files, |
and sources contain numbers where one normally expects strings. |
|
(2) |
This package is planned to switch to GNU `gettext'. For the time |
being, it uses temporary means for internationalization. |
|
(3) |
This package has its translatable strings marked, but does not use |
GNU `gettext'. A convenience patch may be available separately. |
|
If November 1995 seems to be old, you may fetch a more recent copy |
of this `ABOUT-NLS' file on most GNU archive sites. |
|
/trunk/uclinux/userland/route/ifconfig.c
0,0 → 1,1115
/* |
* ifconfig This file contains an implementation of the command |
* that either displays or sets the characteristics of |
* one or more of the system's networking interfaces. |
* |
* Version: $Id: ifconfig.c,v 1.1 2002-03-17 19:58:52 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* and others. Copyright 1993 MicroWalt Corporation |
* |
* 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. |
* {1.34} - 19980630 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
* - gettext instead of catgets for i18n |
* 10/1998 - Andi Kleen. Use interface list primitives. |
*/ |
|
#define DFLT_AF "inet" |
|
#include "config.h" |
|
#include <features.h> |
#include <sys/types.h> |
#ifdef EMBED |
#include <gnu/types.h> |
#endif |
#include <sys/socket.h> |
#include <sys/ioctl.h> |
#include <netinet/in.h> |
#include <net/if.h> |
#include <net/if_arp.h> |
#include <stdio.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <ctype.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
#include <netdb.h> |
|
/* Ugh. But libc5 doesn't provide POSIX types. */ |
#include <asm/types.h> |
|
#ifdef HAVE_HWSLIP |
#include <linux/if_slip.h> |
#endif |
|
#if HAVE_AFINET6 |
|
#ifndef _LINUX_IN6_H |
/* |
* This is in linux/include/net/ipv6.h. |
*/ |
|
struct in6_ifreq { |
struct in6_addr ifr6_addr; |
__u32 ifr6_prefixlen; |
unsigned int ifr6_ifindex; |
}; |
|
#endif |
|
#define IPV6_ADDR_ANY 0x0000U |
|
#define IPV6_ADDR_UNICAST 0x0001U |
#define IPV6_ADDR_MULTICAST 0x0002U |
#define IPV6_ADDR_ANYCAST 0x0004U |
|
#define IPV6_ADDR_LOOPBACK 0x0010U |
#define IPV6_ADDR_LINKLOCAL 0x0020U |
#define IPV6_ADDR_SITELOCAL 0x0040U |
|
#define IPV6_ADDR_COMPATv4 0x0080U |
|
#define IPV6_ADDR_SCOPE_MASK 0x00f0U |
|
#define IPV6_ADDR_MAPPED 0x1000U |
#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ |
|
#endif /* HAVE_AFINET6 */ |
|
#ifdef IFF_PORTSEL |
static const char *if_port_text[][4] = |
{ |
/* Keep in step with <linux/netdevice.h> */ |
{"unknown", NULL, NULL, NULL}, |
{"10base2", "bnc", "coax", NULL}, |
{"10baseT", "utp", "tpe", NULL}, |
{"AUI", "thick", "db15", NULL}, |
{"100baseT", NULL, NULL, NULL}, |
{"100baseTX", NULL, NULL, NULL}, |
{"100baseFX", NULL, NULL, NULL}, |
{NULL, NULL, NULL, NULL}, |
}; |
#endif |
|
#if HAVE_AFIPX |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netipx/ipx.h> |
#else |
#include "ipx.h" |
#endif |
#endif |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "../intl.h" |
#include "interface.h" |
#include "sockets.h" |
#include "util.h" |
|
char *Release = RELEASE, *Version = "ifconfig 1.39 (1999-03-18)"; |
|
int opt_a = 0; /* show all interfaces */ |
int opt_i = 0; /* show the statistics */ |
int opt_v = 0; /* debugging output flag */ |
|
int addr_family = 0; /* currently selected AF */ |
|
|
void ife_print(struct interface *ptr) |
{ |
struct aftype *ap; |
struct hwtype *hw; |
int hf; |
int can_compress = 0; |
#if HAVE_AFIPX |
static struct aftype *ipxtype = NULL; |
#endif |
#if HAVE_AFECONET |
static struct aftype *ectype = NULL; |
#endif |
#if HAVE_AFATALK |
static struct aftype *ddptype = NULL; |
#endif |
#if HAVE_AFINET6 |
FILE *f; |
char addr6[40], devname[20]; |
struct sockaddr_in6 sap; |
int plen, scope, dad_status, if_idx; |
extern struct aftype inet6_aftype; |
char addr6p[8][5]; |
#endif |
|
ap = get_afntype(ptr->addr.sa_family); |
if (ap == NULL) |
ap = get_afntype(0); |
|
hf = ptr->type; |
|
if (hf == ARPHRD_CSLIP || hf == ARPHRD_CSLIP6) |
can_compress = 1; |
|
hw = get_hwntype(hf); |
if (hw == NULL) |
hw = get_hwntype(-1); |
|
printf(_("%-9.9s Link encap:%s "), ptr->name, hw->title); |
/* For some hardware types (eg Ash, ATM) we don't print the |
hardware address if it's null. */ |
if (hw->sprint != NULL && (! (hw_null_address(hw, ptr->hwaddr) && |
hw->suppress_null_addr))) |
printf(_("HWaddr %s "), hw->print(ptr->hwaddr)); |
#ifdef IFF_PORTSEL |
if (ptr->flags & IFF_PORTSEL) { |
printf(_("Media:%s"), if_port_text[ptr->map.port][0]); |
if (ptr->flags & IFF_AUTOMEDIA) |
printf(_("(auto)")); |
} |
#endif |
printf("\n"); |
|
#if HAVE_AFINET |
if (ptr->has_ip) { |
printf(_(" %s addr:%s "), ap->name, |
ap->sprint(&ptr->addr, 1)); |
if (ptr->flags & IFF_POINTOPOINT) { |
printf(_(" P-t-P:%s "), ap->sprint(&ptr->dstaddr, 1)); |
} |
if (ptr->flags & IFF_BROADCAST) { |
printf(_(" Bcast:%s "), ap->sprint(&ptr->broadaddr, 1)); |
} |
printf(_(" Mask:%s\n"), ap->sprint(&ptr->netmask, 1)); |
} |
#endif |
|
#if HAVE_AFINET6 |
/* FIXME: should be integrated into interface.c. */ |
|
if ((f = fopen(_PATH_PROCNET_IFINET6, "r")) != NULL) { |
while (fscanf(f, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %20s\n", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
&if_idx, &plen, &scope, &dad_status, devname) != EOF) { |
if (!strcmp(devname, ptr->name)) { |
sprintf(addr6, "%s:%s:%s:%s:%s:%s:%s:%s", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
inet6_aftype.input(1, addr6, (struct sockaddr *) &sap); |
printf(_(" inet6 addr: %s/%d"), |
inet6_aftype.sprint((struct sockaddr *) &sap, 1), plen); |
printf(_(" Scope:")); |
switch (scope) { |
case 0: |
printf(_("Global")); |
break; |
case IPV6_ADDR_LINKLOCAL: |
printf(_("Link")); |
break; |
case IPV6_ADDR_SITELOCAL: |
printf(_("Site")); |
break; |
case IPV6_ADDR_COMPATv4: |
printf(_("Compat")); |
break; |
case IPV6_ADDR_LOOPBACK: |
printf(_("Host")); |
break; |
default: |
printf(_("Unknown")); |
} |
printf("\n"); |
} |
} |
fclose(f); |
} |
#endif |
|
#if HAVE_AFIPX |
if (ipxtype == NULL) |
ipxtype = get_afntype(AF_IPX); |
|
if (ipxtype != NULL) { |
if (ptr->has_ipx_bb) |
printf(_(" IPX/Ethernet II addr:%s\n"), |
ipxtype->sprint(&ptr->ipxaddr_bb, 1)); |
if (ptr->has_ipx_sn) |
printf(_(" IPX/Ethernet SNAP addr:%s\n"), |
ipxtype->sprint(&ptr->ipxaddr_sn, 1)); |
if (ptr->has_ipx_e2) |
printf(_(" IPX/Ethernet 802.2 addr:%s\n"), |
ipxtype->sprint(&ptr->ipxaddr_e2, 1)); |
if (ptr->has_ipx_e3) |
printf(_(" IPX/Ethernet 802.3 addr:%s\n"), |
ipxtype->sprint(&ptr->ipxaddr_e3, 1)); |
} |
#endif |
|
#if HAVE_AFATALK |
if (ddptype == NULL) |
ddptype = get_afntype(AF_APPLETALK); |
if (ddptype != NULL) { |
if (ptr->has_ddp) |
printf(_(" EtherTalk Phase 2 addr:%s\n"), ddptype->sprint(&ptr->ddpaddr, 1)); |
} |
#endif |
|
#if HAVE_AFECONET |
if (ectype == NULL) |
ectype = get_afntype(AF_ECONET); |
if (ectype != NULL) { |
if (ptr->has_econet) |
printf(_(" econet addr:%s\n"), ectype->sprint(&ptr->ecaddr, 1)); |
} |
#endif |
|
printf(" "); |
if (ptr->flags == 0) |
printf(_("[NO FLAGS] ")); |
if (ptr->flags & IFF_UP) |
printf(_("UP ")); |
if (ptr->flags & IFF_BROADCAST) |
printf(_("BROADCAST ")); |
if (ptr->flags & IFF_DEBUG) |
printf(_("DEBUG ")); |
if (ptr->flags & IFF_LOOPBACK) |
printf(_("LOOPBACK ")); |
if (ptr->flags & IFF_POINTOPOINT) |
printf(_("POINTOPOINT ")); |
if (ptr->flags & IFF_NOTRAILERS) |
printf(_("NOTRAILERS ")); |
if (ptr->flags & IFF_RUNNING) |
printf(_("RUNNING ")); |
if (ptr->flags & IFF_NOARP) |
printf(_("NOARP ")); |
if (ptr->flags & IFF_PROMISC) |
printf(_("PROMISC ")); |
if (ptr->flags & IFF_ALLMULTI) |
printf(_("ALLMULTI ")); |
if (ptr->flags & IFF_SLAVE) |
printf(_("SLAVE ")); |
if (ptr->flags & IFF_MASTER) |
printf(_("MASTER ")); |
if (ptr->flags & IFF_MULTICAST) |
printf(_("MULTICAST ")); |
#ifdef HAVE_DYNAMIC |
if (ptr->flags & IFF_DYNAMIC) |
printf(_("DYNAMIC ")); |
#endif |
|
printf(_(" MTU:%d Metric:%d"), |
ptr->mtu, ptr->metric ? ptr->metric : 1); |
#ifdef SIOCSKEEPALIVE |
if (ptr->outfill || ptr->keepalive) |
printf(_(" Outfill:%d Keepalive:%d"), |
ptr->outfill, ptr->keepalive); |
#endif |
printf("\n"); |
|
/* If needed, display the interface statistics. */ |
|
if (ptr->statistics_valid) { |
/* XXX: statistics are currently only printed for the primary address, |
* not for the aliases, although strictly speaking they're shared |
* by all addresses. |
*/ |
printf(" "); |
|
printf(_("RX packets:%lu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"), |
ptr->stats.rx_packets, ptr->stats.rx_errors, |
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors, |
ptr->stats.rx_frame_errors); |
if (can_compress) |
printf(_(" compressed:%lu\n"), ptr->stats.rx_compressed); |
|
printf(" "); |
|
printf(_("TX packets:%lu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"), |
ptr->stats.tx_packets, ptr->stats.tx_errors, |
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors, |
ptr->stats.tx_carrier_errors); |
printf(_(" collisions:%lu "), ptr->stats.collisions); |
if (can_compress) |
printf(_("compressed:%lu "), ptr->stats.tx_compressed); |
if (ptr->tx_queue_len != -1) |
printf(_("txqueuelen:%d "), ptr->tx_queue_len); |
printf("\n"); |
} |
|
if ((ptr->map.irq || ptr->map.mem_start || ptr->map.dma || |
ptr->map.base_addr)) { |
printf(" "); |
if (ptr->map.irq) |
printf(_("Interrupt:%d "), ptr->map.irq); |
if (ptr->map.base_addr >= 0x100) /* Only print devices using it for |
I/O maps */ |
printf(_("Base address:0x%x "), ptr->map.base_addr); |
if (ptr->map.mem_start) { |
printf(_("Memory:%lx-%lx "), ptr->map.mem_start, ptr->map.mem_end); |
} |
if (ptr->map.dma) |
printf(_("DMA chan:%x "), ptr->map.dma); |
printf("\n"); |
} |
printf("\n"); |
} |
|
static int if_print(char *ifname) |
{ |
int res; |
|
if (!ifname) { |
res = for_all_interfaces(do_if_print, &opt_a); |
} else { |
struct interface *ife; |
|
ife = lookup_interface(ifname); |
res = do_if_fetch(ife); |
if (res >= 0) |
ife_print(ife); |
} |
return res; |
} |
|
|
/* Set a certain interface flag. */ |
static int set_flag(char *ifname, short flag) |
{ |
struct ifreq ifr; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) { |
fprintf(stderr, _("%s: unknown interface: %s\n"), |
ifname, strerror(errno)); |
return (-1); |
} |
strcpy(ifr.ifr_name, ifname); |
ifr.ifr_flags |= flag; |
if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) { |
perror("SIOCSIFFLAGS"); |
return -1; |
} |
return (0); |
} |
|
|
/* Clear a certain interface flag. */ |
static int clr_flag(char *ifname, short flag) |
{ |
struct ifreq ifr; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) { |
fprintf(stderr, _("%s: unknown interface: %s\n"), |
ifname, strerror(errno)); |
return -1; |
} |
strcpy(ifr.ifr_name, ifname); |
ifr.ifr_flags &= ~flag; |
if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) { |
perror("SIOCSIFFLAGS"); |
return -1; |
} |
return (0); |
} |
|
|
static void usage(void) |
{ |
fprintf(stderr, _("Usage:\n ifconfig [-a] [-i] [-v] <interface> [[<AF>] <address>]\n")); |
/* XXX: it would be useful to have the add/del syntax even without IPv6. |
the 2.1 interface address lists make this natural */ |
#ifdef HAVE_AFINET6 |
fprintf(stderr, _(" [add <address>[/<prefixlen>]]\n")); |
#ifdef SIOCDIFADDR |
fprintf(stderr, _(" [del <address>[/<prefixlen>]]\n")); |
#endif |
/* XXX the kernel supports tunneling even without ipv6 */ |
#endif |
#if HAVE_AFINET |
fprintf(stderr, _(" [[-]broadcast [<address>]] [[-]pointopoint [<address>]]\n")); |
fprintf(stderr, _(" [netmask <address>] [dstaddr <address>] [tunnel <address>]\n")); |
#endif |
#ifdef SIOCSKEEPALIVE |
fprintf(stderr, _(" [outfill <NN>] [keepalive <NN>]\n")); |
#endif |
fprintf(stderr, _(" [hw <HW> <address>] [metric <NN>] [mtu <NN>]\n")); |
fprintf(stderr, _(" [[-]trailers] [[-]arp] [[-]allmulti]\n")); |
fprintf(stderr, _(" [multicast] [[-]promisc]\n")); |
fprintf(stderr, _(" [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]\n")); |
#ifdef HAVE_TXQUEUELEN |
fprintf(stderr, _(" [txqueuelen <NN>]\n")); |
#endif |
#ifdef HAVE_DYNAMIC |
fprintf(stderr, _(" [[-]dynamic]\n")); |
#endif |
fprintf(stderr, _(" [up|down] ...\n\n")); |
|
fprintf(stderr, _(" <HW>=Hardware Type.\n")); |
fprintf(stderr, _(" List of possible hardware types:\n")); |
print_hwlist(0); /* 1 = ARPable */ |
fprintf(stderr, _(" <AF>=Address family. Default: %s\n"), DFLT_AF); |
fprintf(stderr, _(" List of possible address families:\n")); |
print_aflist(0); /* 1 = routeable */ |
exit(E_USAGE); |
} |
|
static void version(void) |
{ |
fprintf(stderr, "%s\n%s\n", Release, Version); |
exit(1); |
} |
|
static int set_netmask(int skfd, struct ifreq *ifr, struct sockaddr *sa) |
{ |
int err = 0; |
|
memcpy((char *) &ifr->ifr_netmask, (char *) sa, |
sizeof(struct sockaddr)); |
if (ioctl(skfd, SIOCSIFNETMASK, ifr) < 0) { |
fprintf(stderr, "SIOCSIFNETMASK: %s\n", |
strerror(errno)); |
err = 1; |
} |
return 0; |
} |
|
int main(int argc, char **argv) |
{ |
struct sockaddr sa; |
char host[128]; |
struct aftype *ap; |
struct hwtype *hw; |
struct ifreq ifr; |
int goterr = 0, didnetmask = 0; |
char **spp; |
int fd; |
#if HAVE_AFINET6 |
extern struct aftype inet6_aftype; |
struct sockaddr_in6 sa6; |
struct in6_ifreq ifr6; |
unsigned long prefix_len; |
char *cp; |
#endif |
|
#if I18N |
bindtextdomain("net-tools", "/usr/share/locale"); |
textdomain("net-tools"); |
#endif |
|
/* Create a channel to the NET kernel. */ |
if ((skfd = sockets_open(0)) < 0) { |
perror("socket"); |
exit(1); |
} |
|
/* Find any options. */ |
argc--; |
argv++; |
while (argc && *argv[0] == '-') { |
if (!strcmp(*argv, "-a")) |
opt_a = 1; |
|
if (!strcmp(*argv, "-v")) |
opt_v = 1; |
|
if (!strcmp(*argv, "-V") || !strcmp(*argv, "-version") || |
!strcmp(*argv, "--version")) |
version(); |
|
if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") || |
!strcmp(*argv, "-help") || !strcmp(*argv, "--help")) |
usage(); |
|
argv++; |
argc--; |
} |
|
/* Do we have to show the current setup? */ |
if (argc == 0) { |
int err = if_print((char *) NULL); |
(void) close(skfd); |
exit(err < 0); |
} |
/* No. Fetch the interface name. */ |
spp = argv; |
safe_strncpy(ifr.ifr_name, *spp++, IFNAMSIZ); |
if (*spp == (char *) NULL) { |
int err = if_print(ifr.ifr_name); |
(void) close(skfd); |
exit(err < 0); |
} |
/* The next argument is either an address family name, or an option. */ |
if ((ap = get_aftype(*spp)) == NULL) |
ap = get_aftype(DFLT_AF); |
else { |
/* XXX: should print the current setup if no args left, but only |
for this family */ |
spp++; |
addr_family = ap->af; |
} |
|
if (sockets_open(addr_family) < 0) { |
perror("family socket"); |
exit(1); |
} |
/* Process the remaining arguments. */ |
while (*spp != (char *) NULL) { |
if (!strcmp(*spp, "arp")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_NOARP); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-arp")) { |
goterr |= set_flag(ifr.ifr_name, IFF_NOARP); |
spp++; |
continue; |
} |
#ifdef IFF_PORTSEL |
if (!strcmp(*spp, "media") || !strcmp(*spp, "port")) { |
if (*++spp == NULL) |
usage(); |
if (!strcasecmp(*spp, "auto")) { |
goterr |= set_flag(ifr.ifr_name, IFF_AUTOMEDIA); |
} else { |
int i, j, newport; |
char *endp; |
newport = strtol(*spp, &endp, 10); |
if (*endp != 0) { |
newport = -1; |
for (i = 0; if_port_text[i][0] && newport == -1; i++) { |
for (j = 0; if_port_text[i][j]; j++) { |
if (!strcasecmp(*spp, if_port_text[i][j])) { |
newport = i; |
break; |
} |
} |
} |
} |
spp++; |
if (newport == -1) { |
fprintf(stderr, _("Unknown media type.\n")); |
goterr = 1; |
} else { |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) { |
goterr = 1; |
continue; |
} |
ifr.ifr_map.port = newport; |
if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) { |
perror("SIOCSIFMAP"); |
goterr = 1; |
} |
} |
} |
continue; |
} |
#endif |
|
if (!strcmp(*spp, "trailers")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_NOTRAILERS); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-trailers")) { |
goterr |= set_flag(ifr.ifr_name, IFF_NOTRAILERS); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "promisc")) { |
goterr |= set_flag(ifr.ifr_name, IFF_PROMISC); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-promisc")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_PROMISC); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "multicast")) { |
goterr |= set_flag(ifr.ifr_name, IFF_MULTICAST); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-multicast")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_MULTICAST); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "allmulti")) { |
goterr |= set_flag(ifr.ifr_name, IFF_ALLMULTI); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-allmulti")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_ALLMULTI); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "up")) { |
goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING)); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "down")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_UP); |
spp++; |
continue; |
} |
#ifdef HAVE_DYNAMIC |
if (!strcmp(*spp, "dynamic")) { |
goterr |= set_flag(ifr.ifr_name, IFF_DYNAMIC); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-dynamic")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_DYNAMIC); |
spp++; |
continue; |
} |
#endif |
|
if (!strcmp(*spp, "metric")) { |
if (*++spp == NULL) |
usage(); |
ifr.ifr_metric = atoi(*spp); |
if (ioctl(skfd, SIOCSIFMETRIC, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFMETRIC: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "mtu")) { |
if (*++spp == NULL) |
usage(); |
ifr.ifr_mtu = atoi(*spp); |
if (ioctl(skfd, SIOCSIFMTU, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFMTU: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#ifdef SIOCSKEEPALIVE |
if (!strcmp(*spp, "keepalive")) { |
if (*++spp == NULL) |
usage(); |
ifr.ifr_data = (caddr_t) atoi(*spp); |
if (ioctl(skfd, SIOCSKEEPALIVE, &ifr) < 0) { |
fprintf(stderr, "SIOCSKEEPALIVE: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#endif |
|
#ifdef SIOCSOUTFILL |
if (!strcmp(*spp, "outfill")) { |
if (*++spp == NULL) |
usage(); |
ifr.ifr_data = (caddr_t) atoi(*spp); |
if (ioctl(skfd, SIOCSOUTFILL, &ifr) < 0) { |
fprintf(stderr, "SIOCSOUTFILL: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#endif |
|
if (!strcmp(*spp, "-broadcast")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_BROADCAST); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "broadcast")) { |
if (*++spp != NULL) { |
safe_strncpy(host, *spp, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr.ifr_broadaddr, (char *) &sa, |
sizeof(struct sockaddr)); |
if (ioctl(ap->fd, SIOCSIFBRDADDR, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFBRDADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
spp++; |
} |
goterr |= set_flag(ifr.ifr_name, IFF_BROADCAST); |
continue; |
} |
if (!strcmp(*spp, "dstaddr")) { |
if (*++spp == NULL) |
usage(); |
safe_strncpy(host, *spp, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa, |
sizeof(struct sockaddr)); |
if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFDSTADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "netmask")) { |
if (*++spp == NULL || didnetmask) |
usage(); |
safe_strncpy(host, *spp, (sizeof host)); |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
didnetmask++; |
goterr = set_netmask(ap->fd, &ifr, &sa); |
spp++; |
continue; |
} |
#ifdef HAVE_TXQUEUELEN |
if (!strcmp(*spp, "txqueuelen")) { |
if (*++spp == NULL) |
usage(); |
ifr.ifr_qlen = strtoul(*spp, NULL, 0); |
if (ioctl(skfd, SIOCSIFTXQLEN, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFTXQLEN: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#endif |
|
if (!strcmp(*spp, "mem_start")) { |
if (*++spp == NULL) |
usage(); |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) { |
goterr = 1; |
continue; |
} |
ifr.ifr_map.mem_start = strtoul(*spp, NULL, 0); |
if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "io_addr")) { |
if (*++spp == NULL) |
usage(); |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) { |
goterr = 1; |
continue; |
} |
ifr.ifr_map.base_addr = strtol(*spp, NULL, 0); |
if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "irq")) { |
if (*++spp == NULL) |
usage(); |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) { |
goterr = 1; |
continue; |
} |
ifr.ifr_map.irq = atoi(*spp); |
if (ioctl(skfd, SIOCSIFMAP, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFMAP: %s\n", strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "-pointopoint")) { |
goterr |= clr_flag(ifr.ifr_name, IFF_POINTOPOINT); |
spp++; |
continue; |
} |
if (!strcmp(*spp, "pointopoint")) { |
if (*(spp + 1) != NULL) { |
spp++; |
safe_strncpy(host, *spp, (sizeof host)); |
if (ap->input(0, host, &sa)) { |
ap->herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr.ifr_dstaddr, (char *) &sa, |
sizeof(struct sockaddr)); |
if (ioctl(ap->fd, SIOCSIFDSTADDR, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFDSTADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
} |
goterr |= set_flag(ifr.ifr_name, IFF_POINTOPOINT); |
spp++; |
continue; |
}; |
|
if (!strcmp(*spp, "hw")) { |
if (*++spp == NULL) |
usage(); |
if ((hw = get_hwtype(*spp)) == NULL) |
usage(); |
if (*++spp == NULL) |
usage(); |
safe_strncpy(host, *spp, (sizeof host)); |
if (hw->input(host, &sa) < 0) { |
fprintf(stderr, _("%s: invalid %s address.\n"), host, hw->name); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr.ifr_hwaddr, (char *) &sa, |
sizeof(struct sockaddr)); |
if (ioctl(skfd, SIOCSIFHWADDR, &ifr) < 0) { |
fprintf(stderr, "SIOCSIFHWADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#if HAVE_AFINET6 |
if (!strcmp(*spp, "add")) { |
if (*++spp == NULL) |
usage(); |
if ((cp = strchr(*spp, '/'))) { |
prefix_len = atol(cp + 1); |
if ((prefix_len < 0) || (prefix_len > 128)) |
usage(); |
*cp = 0; |
} else { |
prefix_len = 0; |
} |
safe_strncpy(host, *spp, (sizeof host)); |
if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) { |
inet6_aftype.herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr, |
sizeof(struct in6_addr)); |
|
fd = get_socket_for_af(AF_INET6); |
if (fd < 0) { |
fprintf(stderr, _("No support for INET6 on this system.\n")); |
goterr = 1; |
spp++; |
continue; |
} |
if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) { |
perror("SIOGIFINDEX"); |
goterr = 1; |
spp++; |
continue; |
} |
ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
ifr6.ifr6_prefixlen = prefix_len; |
if (ioctl(fd, SIOCSIFADDR, &ifr6) < 0) { |
perror("SIOCSIFADDR"); |
goterr = 1; |
} |
spp++; |
continue; |
} |
if (!strcmp(*spp, "del")) { |
if (*++spp == NULL) |
usage(); |
if ((cp = strchr(*spp, '/'))) { |
prefix_len = atol(cp + 1); |
if ((prefix_len < 0) || (prefix_len > 128)) |
usage(); |
*cp = 0; |
} else { |
prefix_len = 0; |
} |
safe_strncpy(host, *spp, (sizeof host)); |
if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) { |
inet6_aftype.herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr, |
sizeof(struct in6_addr)); |
|
fd = get_socket_for_af(AF_INET6); |
if (fd < 0) { |
fprintf(stderr, _("No support for INET6 on this system.\n")); |
goterr = 1; |
spp++; |
continue; |
} |
if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) { |
perror("SIOGIFINDEX"); |
goterr = 1; |
spp++; |
continue; |
} |
ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
ifr6.ifr6_prefixlen = prefix_len; |
#ifdef SIOCDIFADDR |
if (ioctl(fd, SIOCDIFADDR, &ifr6) < 0) { |
fprintf(stderr, "SIOCDIFADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
#else |
fprintf(stderr, _("Address deletion not supported on this system.\n")); |
#endif |
spp++; |
continue; |
} |
if (!strcmp(*spp, "tunnel")) { |
if (*++spp == NULL) |
usage(); |
if ((cp = strchr(*spp, '/'))) { |
prefix_len = atol(cp + 1); |
if ((prefix_len < 0) || (prefix_len > 128)) |
usage(); |
*cp = 0; |
} else { |
prefix_len = 0; |
} |
safe_strncpy(host, *spp, (sizeof host)); |
if (inet6_aftype.input(1, host, (struct sockaddr *) &sa6) < 0) { |
inet6_aftype.herror(host); |
goterr = 1; |
spp++; |
continue; |
} |
memcpy((char *) &ifr6.ifr6_addr, (char *) &sa6.sin6_addr, |
sizeof(struct in6_addr)); |
|
fd = get_socket_for_af(AF_INET6); |
if (fd < 0) { |
fprintf(stderr, _("No support for INET6 on this system.\n")); |
goterr = 1; |
spp++; |
continue; |
} |
if (ioctl(fd, SIOGIFINDEX, &ifr) < 0) { |
perror("SIOGIFINDEX"); |
goterr = 1; |
spp++; |
continue; |
} |
ifr6.ifr6_ifindex = ifr.ifr_ifindex; |
ifr6.ifr6_prefixlen = prefix_len; |
|
if (ioctl(fd, SIOCSIFDSTADDR, &ifr6) < 0) { |
fprintf(stderr, "SIOCSIFDSTADDR: %s\n", |
strerror(errno)); |
goterr = 1; |
} |
spp++; |
continue; |
} |
#endif |
|
/* If the next argument is a valid hostname, assume OK. */ |
safe_strncpy(host, *spp, (sizeof host)); |
|
/* FIXME: sa is too small for INET6 addresses, inet6 should use that too, |
broadcast is unexpected */ |
if (ap->getmask) { |
switch (ap->getmask(host, &sa, NULL)) { |
case -1: |
usage(); |
break; |
case 1: |
if (didnetmask) |
usage(); |
|
goterr = set_netmask(skfd, &ifr, &sa); |
didnetmask++; |
break; |
} |
} |
if (ap->input(0, host, &sa) < 0) { |
ap->herror(host); |
usage(); |
} |
memcpy((char *) &ifr.ifr_addr, (char *) &sa, sizeof(struct sockaddr)); |
{ |
int r = 0; /* to shut gcc up */ |
switch (ap->af) { |
#if HAVE_AFINET |
case AF_INET: |
fd = get_socket_for_af(AF_INET); |
if (fd < 0) { |
fprintf(stderr, _("No support for INET on this system.\n")); |
exit(1); |
} |
r = ioctl(fd, SIOCSIFADDR, &ifr); |
break; |
#endif |
#if HAVE_AFECONET |
case AF_ECONET: |
fd = get_socket_for_af(AF_ECONET); |
if (fd < 0) { |
fprintf(stderr, _("No support for ECONET on this system.\n")); |
exit(1); |
} |
r = ioctl(fd, SIOCSIFADDR, &ifr); |
break; |
#endif |
default: |
fprintf(stderr, |
_("Don't know how to set addresses for family %d.\n"), ap->af); |
exit(1); |
} |
if (r < 0) { |
perror("SIOCSIFADDR"); |
goterr = 1; |
} |
} |
/* |
* Don't do the set_flag() if the address is an alias with a - at the |
* end, since it's deleted already! - Roman |
* |
* Should really use regex.h here, not sure though how well it'll go |
* with the cross-platform support etc. |
*/ |
{ |
char *ptr; |
short int found_colon = 0; |
for (ptr = ifr.ifr_name; *ptr; ptr++ ) |
if (*ptr == ':') found_colon++; |
|
if (!(found_colon && *(ptr - 1) == '-')) |
goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING)); |
} |
|
spp++; |
} |
|
return (goterr); |
} |
/trunk/uclinux/userland/route/TODO
0,0 → 1,32
TODO for net-tools |
|
[ ] pt_BR man pages translation revision, it was done for net-tools 1.33... |
[ ] more translations! see the contents of the po directory and ABOUT-NLS |
[ ] netstat ddp support |
[ ] lib/netrom_rt.c rprint should not rewind _PATH_PROCNET_NR_NEIGH |
[ ] ARPHRD_METRICOM [1.3.82] |
[ ] include proxy arp description into man page. |
[ ] netstat -i: XOVR!=compressed |
[ ] nettools.8 man-page |
[ ] lib/ddp.c: /etc/atalk.names support |
[ ] ARPHRD_LOOPBACK in new kernels, ok? dont think so :-/ |
[ ] ARPHRD_LOCALTLK and aarp? |
[ ] ARCNET support? linux/drivers/net/arcnet.c |
[ ] ifconfig support for isdn4linux, linefill... |
[ ] Wilfred's Suggestion for config files for route and ifconfig (expand arp |
file format) |
[ ] make netstat display more interesting states from interface |
(CSLIP? BSDCOMP?) |
[ ] netstat netconfiguration info screen (forwarding, supplied protocols...) |
[ ] net-features.h in all tools |
[ ] check netstat -o |
[ ] supply some informations about new features to HOWTOs |
[ ] Config file only works with bash not ash. |
[ ] Token ring is almost totally untested. |
[ ] additional tools for IPX, AX.25 etc be bundled [ipxripd004, ipx_* tools |
from caldera, axattach] into existing bins |
[ ] "SIOCAX25OPTRT" [Joerg (DL1BKE)]. 1.3.75 |
[ ] dummy NOARP?! (2. default route for preveting hostunreachables on linedrop) |
[ ] ppp_dev_stat called for each dev in ifconfig, why? (1.3.17) |
[ ] linux/include/net/br.h? |
[ ] get rid of local ipx.h copy |
/trunk/uclinux/userland/route/lib/getroute.c
0,0 → 1,113
/* |
* lib/getroute.c This file contains a small interface function to |
* use the AF specific print routine for the routing |
* table. |
* |
* NET-LIB A collection of functions used from the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. (net-tools, net-drivers) |
* |
* Version: $Id: getroute.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* |
* Modifications: |
* |
*951020 {0.10} Bernd Eckenfels: creation |
*960202 {0.90} Bernd Eckenfels: rewrite to use getaftype. |
*960204 {0.91} Bernd Eckenfels: takes constant list of AFs |
*960206 {1.01} Bernd Eckenfels: route_init will enable routing |
* support in the AF handlers |
*960221 {1.02} Bernd Eckenfels: renamed from route_info to getroute.c |
*960413 {1.03} Bernd Eckenfels: new RTACTION support |
*980701 {1.04} Arnaldo C. Melo: GNU gettext instead of catgets |
* |
* 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 <stdio.h> |
#include <string.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "config.h" |
#include "intl.h" |
#include "util.h" |
|
extern struct aftype unspec_aftype; |
extern struct aftype unix_aftype; |
extern struct aftype inet_aftype; |
extern struct aftype inet6_aftype; |
extern struct aftype ax25_aftype; |
extern struct aftype netrom_aftype; |
extern struct aftype ipx_aftype; |
extern struct aftype ddp_aftype; |
|
void getroute_init(void) |
{ |
#if HAVE_AFINET |
inet_aftype.rprint = INET_rprint; |
#endif |
#if HAVE_AFINET6 |
inet6_aftype.rprint = INET6_rprint; |
#endif |
#if HAVE_AFNETROM |
netrom_aftype.rprint = NETROM_rprint; |
#endif |
#if HAVE_AFAX25 |
ax25_aftype.rprint = AX25_rprint; |
#endif |
#if HAVE_AFIPX |
ipx_aftype.rprint = IPX_rprint; |
#endif |
#if HAVE_AFATALK |
ddp_aftype.rprint = DDP_rprint; |
#endif |
} |
|
int route_info(const char *afname, int options) |
{ |
struct aftype *ap; |
char *tmp1, *tmp2; |
int found = E_NOTFOUND, rc; |
char buf[256]; |
|
safe_strncpy(buf, afname, sizeof(buf)); |
|
tmp1 = buf; |
|
while (tmp1) { |
|
ap = NULL; |
|
if ((tmp2 = index(tmp1, ','))) |
*tmp2++ = '\0'; |
|
if (!tmp1[0]) { |
tmp1 = tmp2; |
continue; |
} |
ap = get_aftype(tmp1); |
|
if (!ap) { |
fprintf(stderr, _("Address family `%s' not supported.\n"), tmp1); |
return (E_OPTERR); |
} |
tmp1 = tmp2; |
|
if (!ap->rprint) { |
fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name); |
return (E_OPTERR); |
} |
found = 0; |
|
if ((rc = ap->rprint(options))) |
return (rc); |
|
} |
return (found); |
} |
/trunk/uclinux/userland/route/lib/inet.c
0,0 → 1,417
/* |
* lib/inet.c This file contains an implementation of the "INET" |
* support functions for the net-tools. |
* (NET-3 base distribution). |
* |
* Version: $Id: inet.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified: |
*960113 {1.21} Bernd Eckenfels : rresolve cache bug. |
*960128 {1.22} Bernd Eckenfels : endian bug in print |
*960203 {1.23} Bernd Eckenfels : net-features support |
*960217 {1.24} Bernd Eckenfels : get_sname |
*960219 {1.25} Bernd Eckenfels : extern int h_errno |
*960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255 |
*980101 {1.27} Bernd Eckenfels : resolve raw sockets in /etc/protocols |
*990302 {1.28} Phil Blundell : add netmask to INET_rresolve |
* |
* 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" |
|
/* FIXME. Split this file into inet4.c for the IPv4 specific parts |
and inet.c for those shared between IPv4 and IPv6. */ |
|
#if HAVE_AFINET || HAVE_AFINET6 |
#include <netinet/in.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.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" |
#include "intl.h" |
#include "util.h" |
|
extern int h_errno; /* some netdb.h versions don't export this */ |
|
struct addr { |
struct sockaddr_in addr; |
char *name; |
struct addr *next; |
}; |
|
struct service { |
int number; |
char *name; |
struct service *next; |
}; |
|
static struct service *tcp_name = NULL, *udp_name = NULL, *raw_name = NULL; |
|
#if HAVE_AFINET |
|
static struct addr *INET_nn = NULL; /* addr-to-name cache */ |
|
|
static int INET_resolve(char *name, struct sockaddr_in *sin) |
{ |
struct hostent *hp; |
struct netent *np; |
|
/* Grmpf. -FvK */ |
sin->sin_family = AF_INET; |
sin->sin_port = 0; |
|
/* Default is special, meaning 0.0.0.0. */ |
if (!strcmp(name, "default")) { |
sin->sin_addr.s_addr = INADDR_ANY; |
return (1); |
} |
/* Look to see if it's a dotted quad. */ |
if (inet_aton(name, &sin->sin_addr)) { |
return 0; |
} |
#ifdef EMBED |
return(-1); |
#else |
/* Try the NETWORKS database to see if this is a known network. */ |
if ((np = getnetbyname(name)) != (struct netent *) NULL) { |
sin->sin_addr.s_addr = htonl(np->n_net); |
strcpy(name, np->n_name); |
return 1; |
} |
#ifdef DEBUG |
res_init(); |
_res.options |= RES_DEBUG; |
#endif |
|
if ((hp = gethostbyname(name)) == (struct hostent *) NULL) { |
errno = h_errno; |
return -1; |
} |
memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length); |
strcpy(name, hp->h_name); |
return 0; |
#endif |
} |
|
|
static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric, |
unsigned int netmask) |
{ |
struct hostent *ent; |
struct netent *np; |
struct addr *pn; |
unsigned long ad, host_ad; |
|
/* Grmpf. -FvK */ |
if (sin->sin_family != AF_INET) { |
#ifdef DEBUG |
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin->sin_family); |
#endif |
errno = EAFNOSUPPORT; |
return (-1); |
} |
ad = (unsigned long) sin->sin_addr.s_addr; |
if (ad == INADDR_ANY) { |
if ((numeric & 0x7FFF) == 0) { |
if (numeric & 0x8000) |
strcpy(name, "default"); |
else |
strcpy(name, "*"); |
return (0); |
} |
} |
if (numeric & 0x7FFF) { |
strcpy(name, inet_ntoa(sin->sin_addr)); |
return (0); |
} |
#if 0 |
INET_nn = NULL; |
#endif |
pn = INET_nn; |
while (pn != NULL) { |
if (pn->addr.sin_addr.s_addr == ad) { |
strcpy(name, pn->name); |
return (0); |
} |
pn = pn->next; |
} |
|
host_ad = ntohl(ad); |
np = NULL; |
ent = NULL; |
#ifndef EMBED |
if ((ad & (~ netmask)) != 0) { |
ent = gethostbyaddr((char *) &ad, 4, AF_INET); |
if (ent != NULL) |
strcpy(name, ent->h_name); |
} else { |
np = getnetbyaddr(host_ad, AF_INET); |
if (np != NULL) { |
strcpy(name, np->n_name); |
} |
} |
#endif |
if ((ent == NULL) && (np == NULL)) { |
strcpy(name, inet_ntoa(sin->sin_addr)); |
} |
pn = (struct addr *) malloc(sizeof(struct addr)); |
pn->addr = *sin; |
pn->next = INET_nn; |
pn->name = (char *) malloc(strlen(name) + 1); |
strcpy(pn->name, name); |
INET_nn = pn; |
|
return (0); |
} |
|
|
static void INET_reserror(char *text) |
{ |
#ifdef EMBED |
printf(text); |
#else |
herror(text); |
#endif |
} |
|
|
/* Display an Internet socket address. */ |
static char *INET_print(unsigned char *ptr) |
{ |
return (inet_ntoa((*(struct in_addr *) ptr))); |
} |
|
|
/* Display an Internet socket address. */ |
static char *INET_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buff[128]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric, |
0xffffff00) != 0) |
return (NULL); |
return (buff); |
} |
|
char *INET_sprintmask(struct sockaddr *sap, int numeric, |
unsigned int netmask) |
{ |
static char buff[128]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric, |
netmask) != 0) |
return (NULL); |
return (buff); |
} |
|
|
static int INET_getsock(char *bufp, struct sockaddr *sap) |
{ |
char *sp = bufp, *bp; |
unsigned int i; |
unsigned val; |
struct sockaddr_in *sin; |
|
sin = (struct sockaddr_in *) sap; |
sin->sin_family = AF_INET; |
sin->sin_port = 0; |
|
val = 0; |
bp = (char *) &val; |
for (i = 0; i < sizeof(sin->sin_addr.s_addr); i++) { |
*sp = toupper(*sp); |
|
if ((*sp >= 'A') && (*sp <= 'F')) |
bp[i] |= (int) (*sp - 'A') + 10; |
else if ((*sp >= '0') && (*sp <= '9')) |
bp[i] |= (int) (*sp - '0'); |
else |
return (-1); |
|
bp[i] <<= 4; |
sp++; |
*sp = toupper(*sp); |
|
if ((*sp >= 'A') && (*sp <= 'F')) |
bp[i] |= (int) (*sp - 'A') + 10; |
else if ((*sp >= '0') && (*sp <= '9')) |
bp[i] |= (int) (*sp - '0'); |
else |
return (-1); |
|
sp++; |
} |
sin->sin_addr.s_addr = htonl(val); |
|
return (sp - bufp); |
} |
|
static int INET_input(int type, char *bufp, struct sockaddr *sap) |
{ |
switch (type) { |
case 1: |
return (INET_getsock(bufp, sap)); |
default: |
return (INET_resolve(bufp, (struct sockaddr_in *) sap)); |
} |
} |
|
static int INET_getnetmask(char *adr, struct sockaddr *m, char *name) |
{ |
struct sockaddr_in *mask = (struct sockaddr_in *) m; |
char *slash, *end; |
int prefix; |
|
if ((slash = strchr(adr, '/')) == NULL) |
return 0; |
|
*slash++ = '\0'; |
prefix = strtoul(slash, &end, 0); |
if (*end != '\0') |
return -1; |
|
if (name) { |
sprintf(name, "/%d", prefix); |
} |
mask->sin_family = AF_INET; |
mask->sin_addr.s_addr = htonl(~(0xffffffffU >> prefix)); |
return 1; |
} |
|
|
struct aftype inet_aftype = |
{ |
"inet", NULL, /*"DARPA Internet", */ AF_INET, sizeof(unsigned long), |
INET_print, INET_sprint, INET_input, INET_reserror, |
NULL /*INET_rprint */ , NULL /*INET_rinput */ , |
INET_getnetmask, |
-1, |
NULL |
}; |
|
#endif /* HAVE_AFINET */ |
|
static void add2list(struct service **namebase, struct service *item) |
{ |
if (*namebase == NULL) { |
*namebase = item; |
item->next = NULL; |
} else { |
item->next = *namebase; |
*namebase = item; |
} |
} |
|
|
static struct service *searchlist(struct service *servicebase, int number) |
{ |
struct service *item; |
|
for (item = servicebase; item != NULL; item = item->next) { |
if (item->number == number) |
return (item); |
} |
return (NULL); |
} |
|
|
#ifndef EMBED |
static int read_services(void) |
{ |
struct servent *se; |
struct protoent *pe; |
struct service *item; |
|
setservent(1); |
while ((se = getservent())) { |
/* Allocate a service entry. */ |
item = (struct service *) malloc(sizeof(struct service)); |
if (item == NULL) |
perror("netstat"); |
item->name = strdup(se->s_name); |
item->number = se->s_port; |
|
/* Fill it in. */ |
if (!strcmp(se->s_proto, "tcp")) { |
add2list(&tcp_name, item); |
} else if (!strcmp(se->s_proto, "udp")) { |
add2list(&udp_name, item); |
} else if (!strcmp(se->s_proto, "raw")) { |
add2list(&raw_name, item); |
} |
} |
endservent(); |
setprotoent(1); |
while ((pe = getprotoent())) { |
/* Allocate a service entry. */ |
item = (struct service *) malloc(sizeof(struct service)); |
if (item == NULL) |
perror("netstat"); |
item->name = strdup(pe->p_name); |
item->number = htons(pe->p_proto); |
add2list(&raw_name, item); |
} |
endprotoent(); |
return (0); |
} |
#endif |
|
|
char *get_sname(int socknumber, char *proto, int numeric) |
{ |
static char buffer[64], init = 0; |
struct service *item; |
|
if (socknumber == 0) |
return ("*"); |
if (numeric) { |
sprintf(buffer, "%d", ntohs(socknumber)); |
return (buffer); |
} |
#ifndef EMBED |
if (!init) { |
(void) read_services(); |
init = 1; |
} |
#endif |
buffer[0] = '\0'; |
if (!strcmp(proto, "tcp")) { |
if ((item = searchlist(tcp_name, socknumber)) != NULL) |
sprintf(buffer, "%s", item->name); |
} else if (!strcmp(proto, "udp")) { |
if ((item = searchlist(udp_name, socknumber)) != NULL) |
sprintf(buffer, "%s", item->name); |
} else if (!strcmp(proto, "raw")) { |
if ((item = searchlist(raw_name, socknumber)) != NULL) |
sprintf(buffer, "%s", item->name); |
|
} |
if (!buffer[0]) |
sprintf(buffer, "%d", ntohs(socknumber)); |
return (buffer); |
} |
|
#endif /* HAVE_AFINET || HAVE_AFINET6 */ |
/trunk/uclinux/userland/route/lib/sit.c
0,0 → 1,47
/* |
* lib/sit.c This file contains the SIT HW-type support. |
* |
* Version: $Id: sit.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Based on slip.c, modified by Frank Strauss, Aug 1996 |
* |
* 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_HWSIT |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
#ifndef ARPHRD_SIT |
#warning "No definition of ARPHRD_SIT in <net/if_arp.h>, using private value 776" |
#define ARPHRD_SIT 776 |
#endif |
|
struct hwtype sit_hwtype = |
{ |
"sit", NULL, /*"IPv6-in-IPv4", */ ARPHRD_SIT, 0, |
NULL, NULL, NULL, NULL |
}; |
|
#endif /* HAVE_HWSIT */ |
/trunk/uclinux/userland/route/lib/interface.c
0,0 → 1,512
/* Code to manipulate interface information, shared between ifconfig and |
netstat. |
|
10/1998 partly rewriten by Andi Kleen to support an interface list. |
I don't claim that the list operations are efficient @). |
|
$Id: interface.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
*/ |
|
#include "config.h" |
|
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/ioctl.h> |
#include <netinet/in.h> |
#include <net/if.h> |
#include <stdio.h> |
#include <errno.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
#include <ctype.h> |
|
#if HAVE_AFIPX |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netipx/ipx.h> |
#else |
#include "ipx.h" |
#endif |
#endif |
|
#if HAVE_AFECONET |
#include <neteconet/ec.h> |
#endif |
|
#ifdef HAVE_HWSLIP |
#include <linux/if_slip.h> |
#include <net/if_arp.h> |
#endif |
|
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "proc.h" |
|
#include "interface.h" |
#include "sockets.h" |
#include "util.h" |
#include "intl.h" |
|
int procnetdev_vsn = 1; |
|
static struct interface *int_list; |
|
void add_interface(struct interface *n) |
{ |
struct interface *ife, **pp; |
|
pp = &int_list; |
for (ife = int_list; ife; pp = &ife->next, ife = ife->next) { |
if (nstrcmp(ife->name, n->name) > 0) |
break; |
} |
n->next = (*pp); |
(*pp) = n; |
} |
|
struct interface *lookup_interface(char *name) |
{ |
struct interface *ife = NULL; |
|
if (int_list || if_readlist() >= 0) { |
for (ife = int_list; ife; ife = ife->next) { |
if (!strcmp(ife->name, name)) |
break; |
} |
} |
|
if (!ife) { |
new(ife); |
safe_strncpy(ife->name, name, IFNAMSIZ); |
add_interface(ife); |
} |
|
return ife; |
} |
|
int for_all_interfaces(int (*doit) (struct interface *, void *), void *cookie) |
{ |
struct interface *ife; |
|
if (!int_list && (if_readlist() < 0)) |
return -1; |
for (ife = int_list; ife; ife = ife->next) { |
int err = doit(ife, cookie); |
if (err) |
return err; |
} |
return 0; |
} |
|
static int if_readconf(void) |
{ |
int numreqs = 30; |
struct ifconf ifc; |
struct ifreq *ifr; |
int n, err = -1; |
int skfd; |
|
/* SIOCGIFCONF currently seems to only work properly on AF_INET sockets |
(as of 2.1.128) */ |
skfd = get_socket_for_af(AF_INET); |
if (skfd < 0) { |
fprintf(stderr, _("warning: no inet socket available: %s\n"), |
strerror(errno)); |
/* Try to soldier on with whatever socket we can get hold of. */ |
skfd = sockets_open(0); |
if (skfd < 0) |
return -1; |
} |
|
ifc.ifc_buf = NULL; |
for (;;) { |
ifc.ifc_len = sizeof(struct ifreq) * numreqs; |
ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); |
|
if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { |
perror("SIOCGIFCONF"); |
goto out; |
} |
if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { |
/* assume it overflowed and try again */ |
numreqs += 10; |
continue; |
} |
break; |
} |
|
ifr = ifc.ifc_req; |
for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { |
lookup_interface(ifr->ifr_name); |
ifr++; |
} |
err = 0; |
|
out: |
free(ifc.ifc_buf); |
return err; |
} |
|
static char *get_name(char *name, char *p) |
{ |
while (isspace(*p)) |
p++; |
while (*p) { |
if (isspace(*p)) |
break; |
if (*p == ':') { /* could be an alias */ |
char *dot = p, *dotname = name; |
*name++ = *p++; |
while (isdigit(*p)) |
*name++ = *p++; |
if (*p != ':') { /* it wasn't, backup */ |
p = dot; |
name = dotname; |
} |
if (*p == '\0') |
return NULL; |
p++; |
break; |
} |
*name++ = *p++; |
} |
*name++ = '\0'; |
return p; |
} |
|
static int procnetdev_version(char *buf) |
{ |
if (strstr(buf, "compressed")) |
return 3; |
if (strstr(buf, "bytes")) |
return 2; |
return 1; |
} |
|
static int get_dev_fields(char *bp, struct interface *ife) |
{ |
switch (procnetdev_vsn) { |
case 3: |
sscanf(bp, |
"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", |
&ife->stats.rx_bytes, |
&ife->stats.rx_packets, |
&ife->stats.rx_errors, |
&ife->stats.rx_dropped, |
&ife->stats.rx_fifo_errors, |
&ife->stats.rx_frame_errors, |
&ife->stats.rx_compressed, |
&ife->stats.rx_multicast, |
|
&ife->stats.tx_bytes, |
&ife->stats.tx_packets, |
&ife->stats.tx_errors, |
&ife->stats.tx_dropped, |
&ife->stats.tx_fifo_errors, |
&ife->stats.collisions, |
&ife->stats.tx_carrier_errors, |
&ife->stats.tx_compressed); |
break; |
case 2: |
sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", |
&ife->stats.rx_bytes, |
&ife->stats.rx_packets, |
&ife->stats.rx_errors, |
&ife->stats.rx_dropped, |
&ife->stats.rx_fifo_errors, |
&ife->stats.rx_frame_errors, |
|
&ife->stats.tx_bytes, |
&ife->stats.tx_packets, |
&ife->stats.tx_errors, |
&ife->stats.tx_dropped, |
&ife->stats.tx_fifo_errors, |
&ife->stats.collisions, |
&ife->stats.tx_carrier_errors); |
ife->stats.rx_multicast = 0; |
break; |
case 1: |
sscanf(bp, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", |
&ife->stats.rx_packets, |
&ife->stats.rx_errors, |
&ife->stats.rx_dropped, |
&ife->stats.rx_fifo_errors, |
&ife->stats.rx_frame_errors, |
|
&ife->stats.tx_packets, |
&ife->stats.tx_errors, |
&ife->stats.tx_dropped, |
&ife->stats.tx_fifo_errors, |
&ife->stats.collisions, |
&ife->stats.tx_carrier_errors); |
ife->stats.rx_bytes = 0; |
ife->stats.tx_bytes = 0; |
ife->stats.rx_multicast = 0; |
break; |
} |
return 0; |
} |
|
int if_readlist(void) |
{ |
FILE *fh; |
char buf[512]; |
struct interface *ife; |
int err; |
|
fh = fopen(_PATH_PROCNET_DEV, "r"); |
if (!fh) { |
perror(_PATH_PROCNET_DEV); |
return -1; |
} |
fgets(buf, sizeof buf, fh); /* eat line */ |
fgets(buf, sizeof buf, fh); |
|
#if 0 /* pretty, but can't cope with missing fields */ |
fmt = proc_gen_fmt(_PATH_PROCNET_DEV, 1, fh, |
"face", "", /* parsed separately */ |
"bytes", "%lu", |
"packets", "%lu", |
"errs", "%lu", |
"drop", "%lu", |
"fifo", "%lu", |
"frame", "%lu", |
"compressed", "%lu", |
"multicast", "%lu", |
"bytes", "%lu", |
"packets", "%lu", |
"errs", "%lu", |
"drop", "%lu", |
"fifo", "%lu", |
"colls", "%lu", |
"carrier", "%lu", |
"compressed", "%lu", |
NULL); |
if (!fmt) |
return -1; |
#else |
procnetdev_vsn = procnetdev_version(buf); |
#endif |
|
err = 0; |
while (fgets(buf, sizeof buf, fh)) { |
char *s; |
|
new(ife); |
|
s = get_name(ife->name, buf); |
get_dev_fields(s, ife); |
ife->statistics_valid = 1; |
|
add_interface(ife); |
} |
if (ferror(fh)) { |
perror(_PATH_PROCNET_DEV); |
err = -1; |
} |
if (!err) |
err = if_readconf(); |
|
#if 0 |
free(fmt); |
#endif |
return err; |
} |
|
/* Support for fetching an IPX address */ |
|
#if HAVE_AFIPX |
static int ipx_getaddr(int sock, int ft, struct ifreq *ifr) |
{ |
((struct sockaddr_ipx *) &ifr->ifr_addr)->sipx_type = ft; |
return ioctl(sock, SIOCGIFADDR, ifr); |
} |
#endif |
|
/* Fetch the interface configuration from the kernel. */ |
int if_fetch(struct interface *ife) |
{ |
struct ifreq ifr; |
int fd; |
char *ifname = ife->name; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) |
return (-1); |
ife->flags = ifr.ifr_flags; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) |
memset(ife->hwaddr, 0, 32); |
else |
memcpy(ife->hwaddr, ifr.ifr_hwaddr.sa_data, 8); |
|
ife->type = ifr.ifr_hwaddr.sa_family; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFMETRIC, &ifr) < 0) |
ife->metric = 0; |
else |
ife->metric = ifr.ifr_metric; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFMTU, &ifr) < 0) |
ife->mtu = 0; |
else |
ife->mtu = ifr.ifr_mtu; |
|
if (ife->type == ARPHRD_SLIP || ife->type == ARPHRD_CSLIP || |
ife->type == ARPHRD_SLIP6 || ife->type == ARPHRD_CSLIP6 || |
ife->type == ARPHRD_ADAPT) { |
#ifdef SIOCGOUTFILL |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGOUTFILL, &ifr) < 0) |
ife->outfill = 0; |
else |
ife->outfill = (unsigned int) ifr.ifr_data; |
#endif |
#ifdef SIOCGKEEPALIVE |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGKEEPALIVE, &ifr) < 0) |
ife->keepalive = 0; |
else |
ife->keepalive = (unsigned int) ifr.ifr_data; |
#endif |
} |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) |
memset(&ife->map, 0, sizeof(struct ifmap)); |
else |
memcpy(&ife->map, &ifr.ifr_map, sizeof(struct ifmap)); |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFMAP, &ifr) < 0) |
memset(&ife->map, 0, sizeof(struct ifmap)); |
else |
ife->map = ifr.ifr_map; |
|
#ifdef HAVE_TXQUEUELEN |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(skfd, SIOCGIFTXQLEN, &ifr) < 0) |
ife->tx_queue_len = -1; /* unknown value */ |
else |
ife->tx_queue_len = ifr.ifr_qlen; |
#else |
ife->tx_queue_len = -1; /* unknown value */ |
#endif |
|
#if HAVE_AFINET |
/* IPv4 address? */ |
fd = get_socket_for_af(AF_INET); |
if (fd >= 0) { |
strcpy(ifr.ifr_name, ifname); |
ifr.ifr_addr.sa_family = AF_INET; |
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
ife->has_ip = 1; |
ife->addr = ifr.ifr_addr; |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(fd, SIOCGIFDSTADDR, &ifr) < 0) |
memset(&ife->dstaddr, 0, sizeof(struct sockaddr)); |
else |
ife->dstaddr = ifr.ifr_dstaddr; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(fd, SIOCGIFBRDADDR, &ifr) < 0) |
memset(&ife->broadaddr, 0, sizeof(struct sockaddr)); |
else |
ife->broadaddr = ifr.ifr_broadaddr; |
|
strcpy(ifr.ifr_name, ifname); |
if (ioctl(fd, SIOCGIFNETMASK, &ifr) < 0) |
memset(&ife->netmask, 0, sizeof(struct sockaddr)); |
else |
ife->netmask = ifr.ifr_netmask; |
} else |
memset(&ife->addr, 0, sizeof(struct sockaddr)); |
} |
#endif |
|
#if HAVE_AFATALK |
/* DDP address maybe ? */ |
fd = get_socket_for_af(AF_APPLETALK); |
if (fd >= 0) { |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
ife->ddpaddr = ifr.ifr_addr; |
ife->has_ddp = 1; |
} |
} |
#endif |
|
#if HAVE_AFIPX |
/* Look for IPX addresses with all framing types */ |
fd = get_socket_for_af(AF_IPX); |
if (fd >= 0) { |
strcpy(ifr.ifr_name, ifname); |
if (!ipx_getaddr(fd, IPX_FRAME_ETHERII, &ifr)) { |
ife->has_ipx_bb = 1; |
ife->ipxaddr_bb = ifr.ifr_addr; |
} |
strcpy(ifr.ifr_name, ifname); |
if (!ipx_getaddr(fd, IPX_FRAME_SNAP, &ifr)) { |
ife->has_ipx_sn = 1; |
ife->ipxaddr_sn = ifr.ifr_addr; |
} |
strcpy(ifr.ifr_name, ifname); |
if (!ipx_getaddr(fd, IPX_FRAME_8023, &ifr)) { |
ife->has_ipx_e3 = 1; |
ife->ipxaddr_e3 = ifr.ifr_addr; |
} |
strcpy(ifr.ifr_name, ifname); |
if (!ipx_getaddr(fd, IPX_FRAME_8022, &ifr)) { |
ife->has_ipx_e2 = 1; |
ife->ipxaddr_e2 = ifr.ifr_addr; |
} |
} |
#endif |
|
#if HAVE_AFECONET |
/* Econet address maybe? */ |
fd = get_socket_for_af(AF_ECONET); |
if (fd >= 0) { |
strcpy(ifr.ifr_name, ifname); |
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { |
ife->ecaddr = ifr.ifr_addr; |
ife->has_econet = 1; |
} |
} |
#endif |
|
return 0; |
} |
|
int do_if_fetch(struct interface *ife) |
{ |
if (if_fetch(ife) < 0) { |
char *errmsg; |
if (errno == ENODEV) { |
/* Give better error message for this case. */ |
errmsg = _("Device not found"); |
} else { |
errmsg = strerror(errno); |
} |
fprintf(stderr, _("%s: error fetching interface information: %s\n"), |
ife->name, errmsg); |
return -1; |
} |
return 0; |
} |
|
int do_if_print(struct interface *ife, void *cookie) |
{ |
int *opt_a = (int *) cookie; |
int res; |
|
res = do_if_fetch(ife); |
if (res >= 0) { |
if ((ife->flags & IFF_UP) || *opt_a) |
ife_print(ife); |
} |
return res; |
} |
/trunk/uclinux/userland/route/lib/activate.c
0,0 → 1,77
/* |
* lib/activate.c This file contains a small interface function to |
* use the HW specific activate routines for line |
* disciplines |
* |
* NET-LIB A collection of functions used from the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. (net-tools, net-drivers) |
* |
* Version: $Id: activate.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> |
* Copyright 1996 Bernd Eckenfels, Germany |
* |
* Modifications: |
* |
*960322 {0.01} Bernd Eckenfels: creation |
*980411 {0.01i} Arnaldo Carvalho: i18n: now uses gettext |
* |
* 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 <stdio.h> |
#include <string.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "config.h" |
#include "intl.h" |
|
extern struct hwtype slip_hwtype; |
extern struct hwtype cslip_hwtype; |
extern struct hwtype slip6_hwtype; |
extern struct hwtype cslip6_hwtype; |
extern struct hwtype adaptive_hwtype; |
extern struct hwtype ppp_hwtype; |
|
extern int SLIP_activate(int fd); |
extern int CSLIP_activate(int fd); |
extern int SLIP6_activate(int fd); |
extern int CSLIP6_activate(int fd); |
extern int ADAPTIVE_activate(int fd); |
extern int PPP_activate(int fd); |
|
void activate_init(void) |
{ |
#if HAVE_HWSLIP |
slip_hwtype.activate = SLIP_activate; |
cslip_hwtype.activate = CSLIP_activate; |
slip6_hwtype.activate = SLIP6_activate; |
cslip6_hwtype.activate = CSLIP6_activate; |
adaptive_hwtype.activate = ADAPTIVE_activate; |
#endif |
#if HAVE_HWPPP |
ppp_hwtype.activate = PPP_activate; |
#endif |
} |
|
int activate_ld(const char *hwname, int fd) |
{ |
struct hwtype *hw; |
|
hw = get_hwtype(hwname); |
|
if (!hw) { |
fprintf(stderr, _("Hardware type `%s' not supported.\n"), hwname); |
return (E_NOSUPP); |
} |
if (!hw->activate) { |
fprintf(stderr, _("Cannot change line discipline to `%s'.\n"), hw->name); |
return (E_OPTERR); |
} |
return (hw->activate(fd)); |
} |
/trunk/uclinux/userland/route/lib/netrom.c
0,0 → 1,209
/* |
* lib/netrom.c This file contains an implementation of the "NET/ROM" |
* support functions for the NET-2 base distribution. |
* |
* Version: $Id: netrom.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* NOTE: I will redo this module as soon as I got the libax25.a |
* library sorted out. This library contains some useful |
* and often used address conversion functions, database |
* lookup stuff, and more of the like. |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Changes: |
* 980701 {1.21} Arnaldo Carvalho de Melo - GNU gettext instead of catgets, |
* strncpy instead of strcpy for |
* i18n strings |
* |
* 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_AFNETROM || HAVE_HWNETROM |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netax25/ax25.h> |
#else |
#include <linux/ax25.h> |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
static char netrom_errmsg[128]; |
|
extern struct aftype netrom_aftype; |
|
static char *NETROM_print(unsigned char *ptr) |
{ |
static char buff[8]; |
int i; |
|
for (i = 0; i < 6; i++) { |
buff[i] = ((ptr[i] & 0377) >> 1); |
if (buff[i] == ' ') |
buff[i] = '\0'; |
} |
buff[6] = '\0'; |
i = ((ptr[6] & 0x1E) >> 1); |
if (i != 0) |
sprintf(&buff[strlen(buff)], "-%d", i); |
return (buff); |
} |
|
|
/* Display an AX.25 socket address. */ |
static char *NETROM_sprint(struct sockaddr *sap, int numeric) |
{ |
char buf[64]; |
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); |
} |
|
|
static int NETROM_input(int type, char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char *orig, c; |
unsigned int i; |
|
sap->sa_family = netrom_aftype.af; |
ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; |
|
/* First, scan and convert the basic callsign. */ |
orig = bufp; |
i = 0; |
while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) { |
c = *bufp++; |
if (islower(c)) |
c = toupper(c); |
if (!(isupper(c) || isdigit(c))) { |
safe_strncpy(netrom_errmsg, _("Invalid callsign"), sizeof(netrom_errmsg)); |
#ifdef DEBUG |
fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) ((c << 1) & 0xFE); |
i++; |
} |
|
/* Callsign too long? */ |
if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { |
safe_strncpy(netrom_errmsg, _("Callsign too long"), sizeof(netrom_errmsg)); |
#ifdef DEBUG |
fprintf(stderr, "netrom_input(%s): %s !\n", netrom_errmsg, orig); |
#endif |
errno = E2BIG; |
return (-1); |
} |
/* Nope, fill out the address bytes with blanks. */ |
while (i++ < sizeof(ax25_address) - 1) { |
*ptr++ = (unsigned char) ((' ' << 1) & 0xFE); |
} |
|
/* See if we need to add an SSID field. */ |
if (*bufp == '-') { |
i = atoi(++bufp); |
*ptr = (unsigned char) ((i << 1) & 0xFE); |
} else { |
*ptr = (unsigned char) '\0'; |
} |
|
/* All done. */ |
#ifdef DEBUG |
fprintf(stderr, "netrom_input(%s): ", orig); |
for (i = 0; i < sizeof(ax25_address); i++) |
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); |
fprintf(stderr, "\n"); |
#endif |
|
return (0); |
} |
|
|
/* Display an error message. */ |
static void NETROM_herror(char *text) |
{ |
if (text == NULL) |
fprintf(stderr, "%s\n", netrom_errmsg); |
else |
fprintf(stderr, "%s: %s\n", text, netrom_errmsg); |
} |
|
|
static char *NETROM_hprint(struct sockaddr *sap) |
{ |
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return ("[NONE SET]"); |
return (NETROM_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); |
} |
|
|
static int NETROM_hinput(char *bufp, struct sockaddr *sap) |
{ |
if (NETROM_input(0, bufp, sap) < 0) |
return (-1); |
sap->sa_family = ARPHRD_NETROM; |
return (0); |
} |
|
#if 0 |
/* Set the line discipline of a terminal line. */ |
static int KISS_set_disc(int fd, int disc) |
{ |
if (ioctl(fd, TIOCSETD, &disc) < 0) { |
fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno)); |
return (-errno); |
} |
return (0); |
} |
|
|
/* Start the KISS encapsulation on the file descriptor. */ |
static int KISS_init(int fd) |
{ |
if (KISS_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (ioctl(fd, SIOCSIFENCAP, 4) < 0) |
return (-1); |
return (0); |
} |
#endif |
|
struct hwtype netrom_hwtype = |
{ |
"netrom", NULL, /* "AMPR NET/ROM", */ ARPHRD_NETROM, 7, |
NETROM_print, NETROM_hprint, NETROM_hinput, NULL |
}; |
|
struct aftype netrom_aftype = |
{ |
"netrom", NULL, /* "AMPR NET/ROM", */ AF_NETROM, 7, |
NETROM_print, NETROM_sprint, NETROM_input, NETROM_herror, |
NULL, NULL, NULL, |
-1, |
"/proc/net/nr" |
}; |
|
#endif /* HAVE_AFNETROM */ |
/trunk/uclinux/userland/route/lib/net-support.h
0,0 → 1,238
/* |
* lib/support.h This file contains the definitions of what is in the |
* support library. Most of all, it defines structures |
* for accessing support modules, and the function proto- |
* types. |
* |
* NET-LIB A collection of functions used from the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. (net-tools, net-drivers) |
* |
* Version: lib/net-support.h 1.35 (1996-01-01) |
* |
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modifications: |
*960125 {1.20} Bernd Eckenfels: reformated, layout |
*960202 {1.30} Bernd Eckenfels: rprint in aftype |
*960206 {1.31} Bernd Eckenfels: route_init |
*960219 {1.32} Bernd Eckenfels: type for ap->input() |
*960322 {1.33} Bernd Eckenfels: activate_ld and const in get_hwtype |
*960413 {1.34} Bernd Eckenfels: new RTACTION suport |
*990101 {1.35} Bernd Eckenfels: print_(hw|af)list support, added kerneldefines |
* |
* 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 <sys/socket.h> |
|
/* This structure defines protocol families and their handlers. */ |
struct aftype { |
char *name; |
char *title; |
int af; |
int alen; |
char *(*print) (unsigned char *); |
char *(*sprint) (struct sockaddr *, int numeric); |
int (*input) (int type, char *bufp, struct sockaddr *); |
void (*herror) (char *text); |
int (*rprint) (int options); |
int (*rinput) (int typ, int ext, char **argv); |
|
/* may modify src */ |
int (*getmask) (char *src, struct sockaddr * mask, char *name); |
|
int fd; |
char *flag_file; |
}; |
|
extern struct aftype *aftypes[]; |
|
/* This structure defines hardware protocols and their handlers. */ |
struct hwtype { |
char *name; |
char *title; |
int type; |
int alen; |
char *(*print) (unsigned char *); |
char *(*sprint) (struct sockaddr *); |
int (*input) (char *, struct sockaddr *); |
int (*activate) (int fd); |
int suppress_null_addr; |
}; |
|
|
extern struct hwtype *get_hwtype(const char *name); |
extern struct hwtype *get_hwntype(int type); |
extern void print_hwlist(int type); |
extern struct aftype *get_aftype(const char *name); |
extern struct aftype *get_afntype(int type); |
extern void print_aflist(int type); |
extern int hw_null_address(struct hwtype *hw, void *addr); |
|
extern int getargs(char *string, char *arguments[]); |
|
extern int get_socket_for_af(int af); |
|
extern void getroute_init(void); |
extern void setroute_init(void); |
extern void activate_init(void); |
extern int route_info(const char *afname, int flags); |
extern int route_edit(int action, const char *afname, int flags, char **argv); |
extern int activate_ld(const char *hwname, int fd); |
|
#define RTACTION_ADD 1 |
#define RTACTION_DEL 2 |
#define RTACTION_HELP 3 |
#define RTACTION_FLUSH 4 |
#define RTACTION_SHOW 5 |
|
#define FLAG_EXT 3 /* AND-Mask */ |
#define FLAG_NUM 4 |
#define FLAG_SYM 8 |
#define FLAG_CACHE 16 |
#define FLAG_FIB 32 |
#define FLAG_VERBOSE 64 |
|
extern int ip_masq_info(int numeric, int ext); |
|
extern int INET_rprint(int options); |
extern int INET6_rprint(int options); |
extern int DDP_rprint(int options); |
extern int IPX_rprint(int options); |
extern int NETROM_rprint(int options); |
extern int AX25_rprint(int options); |
|
extern int INET_rinput(int action, int flags, char **argv); |
extern int INET6_rinput(int action, int flags, char **argv); |
extern int DDP_rinput(int action, int flags, char **argv); |
extern int IPX_rinput(int action, int flags, char **argv); |
extern int NETROM_rinput(int action, int flags, char **argv); |
extern int AX25_rinput(int action, int flags, char **argv); |
|
extern int aftrans_opt(const char *arg); |
extern void aftrans_def(char *tool, char *argv0, char *dflt); |
|
extern char *get_sname(int socknumber, char *proto, int numeric); |
|
extern int flag_unx; |
extern int flag_ipx; |
extern int flag_ax25; |
extern int flag_ddp; |
extern int flag_netrom; |
extern int flag_inet; |
extern int flag_inet6; |
|
extern char afname[]; |
|
#define AFTRANS_OPTS \ |
{"ax25", 0, 0, 1}, \ |
{"ip", 0, 0, 1}, \ |
{"ipx", 0, 0, 1}, \ |
{"appletalk", 0, 0, 1}, \ |
{"netrom", 0, 0, 1}, \ |
{"inet", 0, 0, 1}, \ |
{"inet6", 0, 0, 1}, \ |
{"ddp", 0, 0, 1}, \ |
{"unix", 0, 0, 1}, \ |
{"tcpip", 0, 0, 1} |
#define AFTRANS_CNT 10 |
|
#define EINTERN(file, text) fprintf(stderr, \ |
"%s: Internal Error `%s'.\n",file,text); |
|
#define ENOSUPP(A,B) fprintf(stderr,\ |
_("%s: feature `%s' not supported.\n" \ |
"Please recompile `net-tools' with "\ |
"newer kernel source or full configuration.\n"),A,B) |
|
#define ESYSNOT(A,B) fprintf(stderr, _("%s: no support for `%s' on this system.\n"),A,B) |
|
#define E_NOTFOUND 8 |
#define E_SOCK 7 |
#define E_LOOKUP 6 |
#define E_VERSION 5 |
#define E_USAGE 4 |
#define E_OPTERR 3 |
#define E_INTERN 2 |
#define E_NOSUPP 1 |
|
|
/* ========== Kernel Defines ============= |
* Since it is not a good idea to depend on special kernel sources for the headers |
* and since the libc6 Headers are not always up to date, we keep a copy of the |
* most often used Flags in this file. We realy need a way to keep them up-to-date. |
* Perhaps anybody knows how the glibc2 folk is doing it? -ecki |
*/ |
|
/* Keep this ins sync with /usr/src/linux/include/linux/rtnetlink.h */ |
#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */ |
#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */ |
#define RTNH_F_ONLINK 4 /* Gateway is forced on link */ |
|
/* Keep this in sync with /usr/src/linux/include/linux/in_route.h */ |
#define RTCF_DEAD RTNH_F_DEAD |
#define RTCF_ONLINK RTNH_F_ONLINK |
/* #define RTCF_NOPMTUDISC RTM_F_NOPMTUDISC */ |
#define RTCF_NOTIFY 0x00010000 |
#define RTCF_DIRECTDST 0x00020000 |
#define RTCF_REDIRECTED 0x00040000 |
#define RTCF_TPROXY 0x00080000 |
#define RTCF_FAST 0x00200000 |
#define RTCF_MASQ 0x00400000 |
#define RTCF_SNAT 0x00800000 |
#define RTCF_DOREDIRECT 0x01000000 |
#define RTCF_DIRECTSRC 0x04000000 |
#define RTCF_DNAT 0x08000000 |
#define RTCF_BROADCAST 0x10000000 |
#define RTCF_MULTICAST 0x20000000 |
#define RTCF_REJECT 0x40000000 |
#define RTCF_LOCAL 0x80000000 |
|
/* Keep this in sync with /usr/src/linux/include/linux/ipv6_route.h */ |
#ifndef RTF_DEFAULT |
#define RTF_DEFAULT 0x00010000 /* default - learned via ND */ |
#endif |
#define RTF_ALLONLINK 0x00020000 /* fallback, no routers on link */ |
#ifndef RTF_ADDRCONF |
#define RTF_ADDRCONF 0x00040000 /* addrconf route - RA */ |
#endif |
#define RTF_NONEXTHOP 0x00200000 /* route with no nexthop */ |
#define RTF_EXPIRES 0x00400000 |
#define RTF_CACHE 0x01000000 /* cache entry */ |
#define RTF_FLOW 0x02000000 /* flow significant route */ |
#define RTF_POLICY 0x04000000 /* policy route */ |
#define RTF_LOCAL 0x80000000 |
|
/* Keep this in sync with /usr/src/linux/include/linux/route.h */ |
#define RTF_UP 0x0001 /* route usable */ |
#define RTF_GATEWAY 0x0002 /* destination is a gateway */ |
#define RTF_HOST 0x0004 /* host entry (net otherwise) */ |
#define RTF_REINSTATE 0x0008 /* reinstate route after tmout */ |
#define RTF_DYNAMIC 0x0010 /* created dyn. (by redirect) */ |
#define RTF_MODIFIED 0x0020 /* modified dyn. (by redirect) */ |
#define RTF_MTU 0x0040 /* specific MTU for this route */ |
#ifndef RTF_MSS |
#define RTF_MSS RTF_MTU /* Compatibility :-( */ |
#endif |
#define RTF_WINDOW 0x0080 /* per route window clamping */ |
#define RTF_IRTT 0x0100 /* Initial round trip time */ |
#define RTF_REJECT 0x0200 /* Reject route */ |
|
/* this is a 2.0.36 flag from /usr/src/linux/include/linux/route.h */ |
#define RTF_NOTCACHED 0x0400 /* this route isn't cached */ |
|
#ifdef HAVE_AFECONET |
#ifndef AF_ECONET |
#define AF_ECONET 19 /* Acorn Econet */ |
#endif |
#endif |
|
/* End of lib/support.h */ |
|
/trunk/uclinux/userland/route/lib/tunnel.c
0,0 → 1,49
/* |
* Tunnel.c, Alan Cox 1995. |
* |
*/ |
|
#include "config.h" |
|
#if HAVE_HWTUNNEL |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <linux/if_ether.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
extern struct hwtype ether_hwtype; |
|
static char *pr_tunnel(unsigned char *ptr) |
{ |
return (""); |
} |
|
|
static char *pr_stunnel(struct sockaddr *sap) |
{ |
return (""); |
} |
|
|
static int in_tunnel(char *bufp, struct sockaddr *sap) |
{ |
return (-1); |
} |
|
|
struct hwtype tunnel_hwtype = |
{ |
"tunnel", NULL, /*"IPIP Tunnel", */ ARPHRD_TUNNEL, 0, |
pr_tunnel, pr_stunnel, in_tunnel, NULL |
}; |
|
|
#endif /* HAVE_HWTUNNEL */ |
/trunk/uclinux/userland/route/lib/ax25_gr.c
0,0 → 1,64
/* |
* lib/ax25_gr.c This file contains an implementation of the "AX.25" |
* route print support functions. |
* |
* Version: $Id: ax25_gr.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd Eckenfels, <ecki@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> |
* |
* 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_AFAX25 |
#if 0 |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <linux/ax25.h> |
#include <linux/if_arp.h> /* ARPHRD_AX25 */ |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
int AX25_rprint(int options) |
{ |
FILE *f = fopen(_PATH_PROCNET_AX25_ROUTE, "r"); |
char buffer[256]; |
int use; |
|
if (f == NULL) { |
perror(_PATH_PROCNET_AX25_ROUTE); |
printf(_("AX.25 not configured in this system.\n")); /* xxx */ |
return 1; |
} |
printf(_("Kernel AX.25 routing table\n")); /* xxx */ |
printf(_("Destination Iface Use\n")); /* xxx */ |
fgets(buffer, 256, f); |
while (fgets(buffer, 256, f)) { |
buffer[9] = 0; |
buffer[14] = 0; |
use = atoi(buffer + 15); |
printf("%-9s %-5s %5d\n", |
buffer, buffer + 10, use); |
} |
fclose(f); |
return 0; |
} |
|
#endif /* HAVE_AFAX25 */ |
/trunk/uclinux/userland/route/lib/ddp.c
0,0 → 1,64
/* |
* DDP protocol output functions. |
* [Not yet input] |
* |
* Alan Cox <Alan.Cox@linux.org> |
* |
* $Id: ddp.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* 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_AFATALK |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <linux/atalk.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include <netinet/in.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
/* Display a ddp domain address. */ |
static char *ddp_print(unsigned char *ptr) |
{ |
static char buff[64]; |
struct sockaddr_at *sat = (struct sockaddr_at *) (ptr - 2); |
sprintf(buff, "%d/%d", (int) ntohs(sat->sat_addr.s_net), (int) sat->sat_addr.s_node); |
return (buff); |
} |
|
|
/* Display a ddp domain address. */ |
static char *ddp_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buf[64]; |
|
if (sap->sa_family != AF_APPLETALK) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (ddp_print(sap->sa_data)); |
} |
|
|
struct aftype ddp_aftype = |
{ |
"ddp", NULL, /*"Appletalk DDP", */ AF_APPLETALK, 0, |
ddp_print, ddp_sprint, NULL, NULL, |
NULL /*DDP_rprint */ , NULL, NULL, |
-1, |
"/proc/net/appletalk" |
}; |
|
#endif |
/trunk/uclinux/userland/route/lib/ether.c
0,0 → 1,155
/* |
* lib/ether.c This file contains an implementation of the "Ethernet" |
* support functions. |
* |
* Version: $Id: ether.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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_HWETHER |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <linux/if_ether.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
extern struct hwtype ether_hwtype; |
|
|
/* Display an Ethernet address in readable format. */ |
static char *pr_ether(unsigned char *ptr) |
{ |
static char buff[64]; |
|
#ifdef EMBED |
sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X", |
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
); |
#else |
snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", |
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
); |
#endif |
return (buff); |
} |
|
|
/* Display an Ethernet socket address. */ |
static char *pr_sether(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (pr_ether(sap->sa_data)); |
} |
|
|
/* Input an Ethernet address and convert to binary. */ |
static int in_ether(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char c, *orig; |
int i; |
unsigned val; |
|
sap->sa_family = ether_hwtype.type; |
ptr = sap->sa_data; |
|
i = 0; |
orig = bufp; |
while ((*bufp != '\0') && (i < ETH_ALEN)) { |
val = 0; |
c = *bufp++; |
if (isdigit(c)) |
val = c - '0'; |
else if (c >= 'a' && c <= 'f') |
val = c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val = c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
val <<= 4; |
c = *bufp; |
if (isdigit(c)) |
val |= c - '0'; |
else if (c >= 'a' && c <= 'f') |
val |= c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val |= c - 'A' + 10; |
else if (c == ':' || c == 0) |
val >>= 4; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
if (c != 0) |
bufp++; |
*ptr++ = (unsigned char) (val & 0377); |
i++; |
|
/* We might get a semicolon here - not required. */ |
if (*bufp == ':') { |
if (i == ETH_ALEN) { |
#ifdef DEBUG |
fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"), |
orig) |
#endif |
; /* nothing */ |
} |
bufp++; |
} |
} |
|
/* That's it. Any trailing junk? */ |
if ((i == ETH_ALEN) && (*bufp != '\0')) { |
#ifdef DEBUG |
fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig); |
errno = EINVAL; |
return (-1); |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data)); |
#endif |
|
return (0); |
} |
|
|
struct hwtype ether_hwtype = |
{ |
"ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN, |
pr_ether, pr_sether, in_ether, NULL |
}; |
|
|
#endif /* HAVE_HWETHER */ |
/trunk/uclinux/userland/route/lib/net-features.h
0,0 → 1,291
/* |
* lib/net-features.h This file contains the definitions of all kernel |
* dependend features. |
* |
* Version: features.h 0.03 (1996-03-22) |
* |
* Author: Bernd Eckenfels <net-tools@lina.inka.de> |
* Copyright 1996 Bernd Eckenfels, Germany |
* |
* Modifications: |
*960201 {0.01} Bernd Eckenfels: creation |
*960202 {0.02} Bernd Eckenfels: HW and AF added |
*960322 {0.03} Bernd Eckenfels: moved into the NET-LIB |
*980630 {0.04} Arnaldo Carvalho de Melo: changed NLS for I18N |
* |
* 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. |
*/ |
|
/* |
* This needs to be included AFTER the KErnel Header Files |
* one of the FEATURE_ should be defined to get the Feature Variable |
* definition included |
*/ |
|
#ifndef _NET_FEATURES_H |
#define _NET_FEATURES_H |
|
/* detect the present features */ |
|
#if defined (SIOCADDRTOLD) || defined (RTF_IRTT) /* route */ |
#define HAVE_NEW_ADDRT 1 |
#endif |
|
#ifdef RTF_IRTT /* route */ |
#define HAVE_RTF_IRTT 1 |
#endif |
|
#ifdef RTF_REJECT /* route */ |
#define HAVE_RTF_REJECT 1 |
#endif |
|
/* compose the feature information string */ |
|
#if defined (FEATURE_ARP) || defined (FEATURE_ROUTE) || defined (FEATURE_NETSTAT) |
static char *Features = |
|
/* ---------------------------------------------------- */ |
#ifdef FEATURE_ROUTE |
|
#if HAVE_NEW_ADDRT |
"+" |
#else |
"-" |
#endif |
"NEW_ADDRT " |
|
#if HAVE_RTF_IRTT |
"+" |
#else |
"-" |
#endif |
"RTF_IRTT " |
|
#if HAVE_RTF_REJECT |
"+" |
#else |
"-" |
#endif |
"RTF_REJECT " |
|
#endif /* FEATURE_ROUTE */ |
/* ---------------------------------------------------- */ |
|
|
/* ---------------------------------------------------- */ |
#ifdef FEATURE_NETSTAT |
|
#if HAVE_NEW_ADDRT |
"+" |
#else |
"-" |
#endif |
"NEW_ADDRT " |
|
#if HAVE_RTF_IRTT |
"+" |
#else |
"-" |
#endif |
"RTF_IRTT " |
|
#if HAVE_RTF_REJECT |
"+" |
#else |
"-" |
#endif |
"RTF_REJECT " |
|
#if HAVE_FW_MASQUERADE |
"+" |
#else |
"-" |
#endif |
"FW_MASQUERADE " |
|
#endif /* FEATURE_NETSTAT */ |
/* ---------------------------------------------------- */ |
|
|
#if I18N |
"+I18N" |
#else |
"-I18N" |
#endif /* I18N */ |
|
|
"\nAF: " |
#ifdef DFLT_AF |
"(" DFLT_AF ")" |
#endif |
|
#if HAVE_AFUNIX |
" +" |
#else |
" -" |
#endif |
"UNIX " |
#if HAVE_AFINET |
"+" |
#else |
"-" |
#endif |
"INET " |
#if HAVE_AFINET6 |
"+" |
#else |
"-" |
#endif |
"INET6 " |
#if HAVE_AFIPX |
"+" |
#else |
"-" |
#endif |
"IPX " |
#if HAVE_AFAX25 |
"+" |
#else |
"-" |
#endif |
"AX25 " |
#if HAVE_AFNETROM |
"+" |
#else |
"-" |
#endif |
"NETROM " |
#if HAVE_AFATALK |
"+" |
#else |
"-" |
#endif |
"ATALK " |
#if HAVE_AFECONET |
"+" |
#else |
"-" |
#endif |
"ECONET " |
#if HAVE_AFROSE |
"+" |
#else |
"-" |
#endif |
"ROSE " |
|
"\nHW: " |
|
#ifdef DFLT_HW |
"(" DFLT_HW ")" |
#endif |
|
#if HAVE_HWETHER |
" +" |
#else |
" -" |
#endif |
"ETHER " |
#if HAVE_HWARC |
"+" |
#else |
"-" |
#endif |
"ARC " |
#if HAVE_HWSLIP |
"+" |
#else |
"-" |
#endif |
"SLIP " |
#if HAVE_HWPPP |
"+" |
#else |
"-" |
#endif |
"PPP " |
#if HAVE_HWTUNNEL |
"+" |
#else |
"-" |
#endif |
"TUNNEL " |
#if HAVE_HWTR |
"+" |
#else |
"-" |
#endif |
"TR " |
#if HAVE_HWAX25 |
"+" |
#else |
"-" |
#endif |
"AX25 " |
|
#if HAVE_HWNETROM |
"+" |
#else |
"-" |
#endif |
"NETROM " |
|
#if HAVE_HWFR |
"+" |
#else |
"-" |
#endif |
"FR " |
|
#if HAVE_HWROSE |
"+" |
#else |
"-" |
#endif |
"ROSE " |
|
#if HAVE_HWASH |
"+" |
#else |
"-" |
#endif |
"ASH " |
|
#if HAVE_HWSIT |
"+" |
#else |
"-" |
#endif |
"SIT " |
|
#if HAVE_HWFDDI |
"+" |
#else |
"-" |
#endif |
"FDDI " |
|
#if HAVE_HWHIPPI |
"+" |
#else |
"-" |
#endif |
"HIPPI " |
|
#if HAVE_HWHDLCLAPB |
"+" |
#else |
"-" |
#endif |
"HDLC/LAPB " |
; |
|
|
#endif /* FEATURE_* */ |
|
#endif /* _NET_FEATURES_H */ |
/* End of features.h */ |
/trunk/uclinux/userland/route/lib/slip.c
0,0 → 1,62
/* |
* lib/slip.c This file contains the SLIP HW-type support. |
* |
* Version: $Id: slip.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified by Alan Cox, May 94 to cover NET-3 |
* |
* 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_HWSLIP |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
|
struct hwtype slip_hwtype = |
{ |
"slip", NULL, /*"Serial Line IP", */ ARPHRD_SLIP, 0, |
NULL, NULL, NULL, NULL |
}; |
struct hwtype cslip_hwtype = |
{ |
"cslip", NULL, /*"VJ Serial Line IP", */ ARPHRD_CSLIP, 0, |
NULL, NULL, NULL, NULL |
}; |
struct hwtype slip6_hwtype = |
{ |
"slip6", NULL, /*"6-bit Serial Line IP", */ ARPHRD_SLIP6, 0, |
NULL, NULL, NULL, NULL |
}; |
struct hwtype cslip6_hwtype = |
{ |
"cslip6", NULL, /*"VJ 6-bit Serial Line IP", */ ARPHRD_CSLIP6, 0, |
NULL, NULL, NULL, NULL |
}; |
struct hwtype adaptive_hwtype = |
{ |
"adaptive", NULL, /*"Adaptive Serial Line IP", */ ARPHRD_ADAPT, 0, |
NULL, NULL, NULL, NULL |
}; |
#endif /* HAVE_HWSLIP */ |
/trunk/uclinux/userland/route/lib/netrom_sr.c
0,0 → 1,47
#include "config.h" |
|
#if HAVE_AFNETROM |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
/* #include <net/route.h> realy broken */ |
#include <sys/ioctl.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" |
#include "intl.h" |
#include "net-features.h" |
|
extern struct aftype netrom_aftype; |
|
/* static int skfd = -1; */ |
|
/* acme: orphaned... */ |
#if 0 |
static int usage(void) |
{ |
fprintf(stderr, _("netrom usage\n")); |
|
return (E_USAGE); |
} |
#endif |
|
|
int NETROM_rinput(int action, int ext, char **args) |
{ |
|
fprintf(stderr, _("NET/ROM: this needs to be written\n")); |
return (0); |
} |
#endif /* HAVE_AFNETROM */ |
/trunk/uclinux/userland/route/lib/hippi.c
0,0 → 1,154
/* |
* lib/hippi.c This file contains an implementation of the "HIPPI" |
* support functions for the NET-2 base distribution. |
* |
* Version: $Id: hippi.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch> |
* |
* 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_HWHIPPI |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
/* |
* HIPPI magic constants. |
*/ |
|
#define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */ |
#ifndef ARPHRD_HIPPI |
#define ARPHRD_HIPPI 780 |
#warning "ARPHRD_HIPPI is not defined in <net/if_arp.h>. Using private value 708" |
#endif |
|
extern struct hwtype hippi_hwtype; |
|
|
/* Display an HIPPI address in readable format. */ |
static char *pr_hippi(unsigned char *ptr) |
{ |
static char buff[64]; |
|
sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X", |
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
); |
return (buff); |
} |
|
|
/* Display an HIPPI socket address. */ |
static char * |
pr_shippi(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return (safe_strncpy(buf, _("[NONE SET]"), 64)); |
return (pr_hippi(sap->sa_data)); |
} |
|
|
/* Input an HIPPI address and convert to binary. */ |
static int in_hippi(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char c, *orig; |
int i, val; |
|
sap->sa_family = hippi_hwtype.type; |
ptr = sap->sa_data; |
|
i = 0; |
orig = bufp; |
while ((*bufp != '\0') && (i < HIPPI_ALEN)) { |
val = 0; |
c = *bufp++; |
if (isdigit(c)) |
val = c - '0'; |
else if (c >= 'a' && c <= 'f') |
val = c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val = c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
val <<= 4; |
c = *bufp++; |
if (isdigit(c)) |
val |= c - '0'; |
else if (c >= 'a' && c <= 'f') |
val |= c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val |= c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) (val & 0377); |
i++; |
|
/* We might get a semicolon here - not required. */ |
if (*bufp == ':') { |
if (i == HIPPI_ALEN) { |
#ifdef DEBUG |
fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig) |
#endif |
; /* nothing */ |
} |
bufp++; |
} |
} |
|
/* That's it. Any trailing junk? */ |
if ((i == HIPPI_ALEN) && (*bufp != '\0')) { |
#ifdef DEBUG |
fprintf(stderr, _("in_hippi(%s): trailing junk!\n"), orig); |
errno = EINVAL; |
return (-1); |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data)); |
#endif |
|
return (0); |
} |
|
|
struct hwtype hippi_hwtype = |
{ |
"hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN, |
pr_hippi, pr_shippi, in_hippi, NULL |
}; |
|
|
#endif /* HAVE_HWHIPPI */ |
/trunk/uclinux/userland/route/lib/hdlclapb.c
0,0 → 1,60
/* |
* lib/hdlclapb.c |
* This file contains the HDLC/LAPB support for the NET-2 base |
* distribution. |
* |
* Version: $Id: hdlclapb.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Original Author: |
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified by Alan Cox, May 94 to cover NET-3 |
* |
* 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_HWHDLCLAPB |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
#ifndef ARPHRD_HDLC |
#warning "No definition of ARPHRD_HDLC in <net/if_arp.h>, using private value 513" |
#define ARPHRD_HDLC 513 |
#endif |
|
#ifndef ARPHRD_LAPB |
#warning "No definition of ARPHRD_HDLC in <net/if_arp.h>, using private value 516" |
#define ARPHRD_LAPB 516 |
#endif |
|
struct hwtype hdlc_hwtype = |
{ |
"hdlc", NULL, /*"(Cisco) HDLC", */ ARPHRD_HDLC, 0, |
NULL, NULL, NULL, NULL, |
}; |
struct hwtype lapb_hwtype = |
{ |
"lapb", NULL, /*"LAPB", */ ARPHRD_LAPB, 0, |
NULL, NULL, NULL, NULL, |
}; |
|
#endif /* HAVE_HWHDLCLAPB */ |
/trunk/uclinux/userland/route/lib/setroute.c
0,0 → 1,84
/* |
* lib/setroute.c This file contains a small interface function to |
* use the AF specific input routine for the routing |
* table. |
* |
* NET-LIB A collection of functions used from the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. (net-tools, net-drivers) |
* |
* Version: $Id: setroute.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* |
* Modifications: |
* |
*960221 {0.01} Bernd Eckenfels: generated from getroute.c |
*960413 {0.02} Bernd Eckenfels: new RTACTION support |
*960809 Frank Strauss: INET6 |
* |
* 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 <stdio.h> |
#include <string.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "config.h" |
#include "intl.h" |
|
extern struct aftype unspec_aftype; |
extern struct aftype unix_aftype; |
extern struct aftype inet_aftype; |
extern struct aftype inet6_aftype; |
extern struct aftype ax25_aftype; |
extern struct aftype netrom_aftype; |
extern struct aftype ipx_aftype; |
extern struct aftype ddp_aftype; |
|
void setroute_init(void) |
{ |
#if HAVE_AFINET |
inet_aftype.rinput = INET_rinput; |
#endif |
#if HAVE_AFINET6 |
inet6_aftype.rinput = INET6_rinput; |
#endif |
#if HAVE_AFNETROM |
netrom_aftype.rinput = NETROM_rinput; |
#endif |
#if HAVE_AFIPX |
ipx_aftype.rinput = IPX_rinput; |
#endif |
#if 0 |
#if HAVE_AFAX25 |
ax25_aftype.rinput = AX25_rinput; |
#endif |
#if HAVE_AFATALK |
ddp_aftype.rinput = DDP_rinput; |
#endif |
#endif |
} |
|
|
int route_edit(int action, const char *afname, int options, char **argv) |
{ |
struct aftype *ap; |
|
ap = get_aftype(afname); |
|
if (!ap) { |
fprintf(stderr, _("Address family `%s' not supported.\n"), afname); |
return (E_OPTERR); |
} |
if (!ap->rinput) { |
fprintf(stderr, _("No routing for address family `%s'.\n"), ap->name); |
return (E_OPTERR); |
} |
return (ap->rinput(action, options, argv)); |
} |
/trunk/uclinux/userland/route/lib/slip_ac.c
0,0 → 1,114
/* |
* lib/slip_ac.c This file contains the activation for the |
* SLIP line disciplines, called from activate_ld(). |
* |
* Version: $Id: slip_ac.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels |
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified by Alan Cox, May 94 to cover NET-3 |
* |
* 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_HWSLIP |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
|
/* Set the line discipline of a terminal line. */ |
static int SLIP_set_disc(int fd, int disc) |
{ |
if (ioctl(fd, TIOCSETD, &disc) < 0) { |
fprintf(stderr, "SLIP_set_disc(%d): %s\n", disc, strerror(errno)); |
return (-errno); |
} |
return (0); |
} |
|
|
/* Set the encapsulation type of a terminal line. */ |
static int SLIP_set_encap(int fd, int encap) |
{ |
if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) { |
fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno)); |
return (-errno); |
} |
return (0); |
} |
|
|
/* Start the SLIP encapsulation on the file descriptor. */ |
int SLIP_activate(int fd) |
{ |
if (SLIP_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (SLIP_set_encap(fd, 0) < 0) |
return (-1); |
return (0); |
} |
|
|
/* Start the VJ-SLIP encapsulation on the file descriptor. */ |
int CSLIP_activate(int fd) |
{ |
if (SLIP_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (SLIP_set_encap(fd, 1) < 0) |
return (-1); |
return (0); |
} |
|
|
/* Start the SLIP-6 encapsulation on the file descriptor. */ |
int SLIP6_activate(int fd) |
{ |
if (SLIP_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (SLIP_set_encap(fd, 2) < 0) |
return (-1); |
return (0); |
} |
|
|
/* Start the VJ-SLIP-6 encapsulation on the file descriptor. */ |
int CSLIP6_activate(int fd) |
{ |
if (SLIP_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (SLIP_set_encap(fd, 3) < 0) |
return (-1); |
return (0); |
} |
|
|
/* Start adaptive encapsulation on the file descriptor. */ |
int ADAPTIVE_activate(int fd) |
{ |
if (SLIP_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (SLIP_set_encap(fd, 8) < 0) |
return (-1); |
return (0); |
} |
#endif /* HAVE_HWSLIP */ |
/trunk/uclinux/userland/route/lib/sockets.c
0,0 → 1,63
/* sockets.c. Rewriten by Andi Kleen. Subject to the GPL. */ |
|
/* philb 14/11/98: we now stash the socket file descriptor inside |
the `aftype' structure rather than keeping it in a pile of separate |
variables. This is necessary so that "ifconfig eth0 broadcast ..." |
issues ioctls to the right socket for the address family in use; |
picking one at random doesn't always work. */ |
|
#include <sys/socket.h> |
#include <stdio.h> |
#include <unistd.h> |
|
#include "config.h" |
#include "sockets.h" |
#include "intl.h" |
#include "util.h" |
#include "net-support.h" |
|
#ifndef EMBED |
int skfd = -1; /* generic raw socket desc. */ |
#endif |
|
int sockets_open(int family) |
{ |
struct aftype **aft; |
int sfd = -1; |
static int force = -1; |
|
if (force < 0) { |
force = 0; |
if (kernel_version() < KRELEASE(2, 1, 0)) |
force = 1; |
if (access("/proc/net", R_OK)) |
force = 1; |
} |
for (aft = aftypes; *aft; aft++) { |
struct aftype *af = *aft; |
int type = SOCK_DGRAM; |
if (af->af == AF_UNSPEC) |
continue; |
if (family && family != af->af) |
continue; |
if (af->fd != -1) { |
sfd = af->fd; |
continue; |
} |
/* Check some /proc file first to not stress kmod */ |
if (!family && !force && af->flag_file) { |
if (access(af->flag_file, R_OK)) |
continue; |
} |
#if HAVE_AFNETROM |
if (af->af == AF_NETROM) |
type = SOCK_SEQPACKET; |
#endif |
af->fd = socket(af->af, type, 0); |
if (af->fd >= 0) |
sfd = af->fd; |
} |
if (sfd < 0) |
fprintf(stderr, _("No usable address families found.\n")); |
return sfd; |
} |
/trunk/uclinux/userland/route/lib/inet6_gr.c
0,0 → 1,275
/* |
Modifications: |
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, |
snprintf instead of sprintf |
*/ |
|
#include "config.h" |
|
#if HAVE_AFINET6 |
#include <asm/types.h> |
#include <asm/param.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
/* #include <net/route.h> realy broken */ |
#include <ctype.h> |
#include <errno.h> |
#include <netdb.h> |
#include <resolv.h> |
#include <stdlib.h> |
#include <string.h> |
#include <stdio.h> |
#include <unistd.h> |
#ifndef __GLIBC__ |
#include <netinet6/ipv6_route.h> /* glibc doesn't have this */ |
#endif |
#include "version.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "net-features.h" |
|
/* this is from linux/include/net/ndisc.h */ |
/* |
* Neighbor Cache Entry States (7.3.2.) |
*/ |
|
/* |
* The lsb is set for states that have a timer associated |
*/ |
|
#define NUD_NONE 0x00 |
#define NUD_INCOMPLETE 0x11 |
#define NUD_REACHABLE 0x20 |
#define NUD_STALE 0x30 |
#define NUD_DELAY 0x41 |
#define NUD_PROBE 0x51 |
#define NUD_FAILED 0x60 /* neighbour discovery failed */ |
|
#define NUD_IN_TIMER 0x01 |
|
#define NDISC_QUEUE_LEN 3 |
|
#define NCF_NOARP 0x0100 /* no ARP needed on this device */ |
#define NCF_SUBNET 0x0200 /* NC entry for subnet */ |
#define NCF_INVALID 0x0400 |
#define NCF_DELAY_EXPIRED 0x0800 /* time to move to PROBE */ |
#define NCF_ROUTER 0x1000 /* neighbour is a router */ |
#define NCF_HHVALID 0x2000 /* Hardware header is valid */ |
|
|
extern struct aftype inet6_aftype; |
|
|
int rprint_fib6(int ext, int numeric) |
{ |
char buff[4096], iface[16], flags[16]; |
char addr6[128], naddr6[128]; |
struct sockaddr_in6 saddr6, snaddr6; |
int num, iflags, metric, refcnt, use, prefix_len, slen; |
FILE *fp = fopen(_PATH_PROCNET_ROUTE6, "r"); |
|
char addr6p[8][5], saddr6p[8][5], naddr6p[8][5]; |
|
if (!fp) { |
perror(_PATH_PROCNET_ROUTE6); |
printf(_("INET6 (IPv6) not configured in this system.\n")); |
return 1; |
} |
printf(_("Kernel IPv6 routing table\n")); |
|
printf(_("Destination " |
"Next Hop " |
"Flags Metric Ref Use Iface\n")); |
|
while (fgets(buff, 1023, fp)) { |
num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %02x %4s%4s%4s%4s%4s%4s%4s%4s %08x %08x %08x %08x %s\n", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
&prefix_len, |
saddr6p[0], saddr6p[1], saddr6p[2], saddr6p[3], |
saddr6p[4], saddr6p[5], saddr6p[6], saddr6p[7], |
&slen, |
naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], |
naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7], |
&metric, &use, &refcnt, &iflags, iface); |
#if 0 |
if (num < 23) |
continue; |
#endif |
if (!(iflags & RTF_UP)) |
continue; |
/* Fetch and resolve the target address. */ |
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); |
snprintf(addr6, sizeof(addr6), "%s/%d", |
inet6_aftype.sprint((struct sockaddr *) &saddr6, 1), |
prefix_len); |
|
/* Fetch and resolve the nexthop address. */ |
snprintf(naddr6, sizeof(naddr6), "%s:%s:%s:%s:%s:%s:%s:%s", |
naddr6p[0], naddr6p[1], naddr6p[2], naddr6p[3], |
naddr6p[4], naddr6p[5], naddr6p[6], naddr6p[7]); |
inet6_aftype.input(1, naddr6, (struct sockaddr *) &snaddr6); |
snprintf(naddr6, sizeof(naddr6), "%s", |
inet6_aftype.sprint((struct sockaddr *) &snaddr6, 1)); |
|
/* Decode the flags. */ |
strcpy(flags, "U"); |
if (iflags & RTF_GATEWAY) |
strcat(flags, "G"); |
if (iflags & RTF_HOST) |
strcat(flags, "H"); |
if (iflags & RTF_DEFAULT) |
strcat(flags, "D"); |
if (iflags & RTF_ADDRCONF) |
strcat(flags, "A"); |
if (iflags & RTF_CACHE) |
strcat(flags, "C"); |
|
/* Print the info. */ |
printf("%-43s %-39s %-5s %-6d %-2d %7d %-8s\n", |
addr6, naddr6, flags, metric, refcnt, use, iface); |
} |
|
(void) fclose(fp); |
return (0); |
} |
|
int rprint_cache6(int ext, int numeric) |
{ |
char buff[4096], iface[16], flags[16]; |
char addr6[128], haddr[20], statestr[20]; |
struct sockaddr_in6 saddr6; |
int type, num, refcnt, prefix_len, location, state, gc; |
long tstamp, expire, ndflags, reachable, stale, delete; |
FILE *fp = fopen(_PATH_PROCNET_NDISC, "r"); |
char addr6p[8][5], haddrp[6][3]; |
|
if (!fp) { |
ESYSNOT("nd_print", "ND Table"); |
return 1; |
} |
printf(_("Kernel IPv6 Neighbour Cache\n")); |
|
if (ext == 2) |
printf(_("Neighbour " |
"HW Address " |
"Iface Flags Ref State\n")); |
else |
printf(_("Neighbour " |
"HW Address " |
"Iface Flags Ref State Stale(sec) Delete(sec)\n")); |
|
|
while (fgets(buff, 1023, fp)) { |
num = sscanf(buff, "%4s%4s%4s%4s%4s%4s%4s%4s %02x %02x %02x %02x %08lx %08lx %08lx %04x %04x %04lx %8s %2s%2s%2s%2s%2s%2s\n", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7], |
&location, &prefix_len, &type, &state, &expire, &tstamp, &reachable, &gc, &refcnt, |
&ndflags, iface, |
haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]); |
|
/* Fetch and resolve the nexthop address. */ |
snprintf(addr6, sizeof(addr6), "%s:%s:%s:%s:%s:%s:%s:%s", |
addr6p[0], addr6p[1], addr6p[2], addr6p[3], |
addr6p[4], addr6p[5], addr6p[6], addr6p[7]); |
inet6_aftype.input(1, addr6, (struct sockaddr *) &saddr6); |
snprintf(addr6, sizeof(addr6), "%s/%d", |
inet6_aftype.sprint((struct sockaddr *) &saddr6, numeric), |
prefix_len); |
|
/* Fetch the hardware address. */ |
snprintf(haddr, sizeof(haddr), "%s:%s:%s:%s:%s:%s", |
haddrp[0], haddrp[1], haddrp[2], haddrp[3], haddrp[4], haddrp[5]); |
|
/* Decode the flags. */ |
flags[0] = '\0'; |
if (ndflags & NCF_NOARP) |
strcat(flags, "N"); |
if (ndflags & NCF_SUBNET) |
strcat(flags, "S"); |
if (ndflags & NCF_INVALID) |
strcat(flags, "I"); |
if (ndflags & NCF_DELAY_EXPIRED) |
strcat(flags, "D"); |
if (ndflags & NCF_ROUTER) |
strcat(flags, "R"); |
if (ndflags & NCF_HHVALID) |
strcat(flags, "H"); |
|
/* Decode the state */ |
switch (state) { |
case NUD_NONE: |
strcpy(statestr, "NONE"); |
break; |
case NUD_INCOMPLETE: |
strcpy(statestr, "INCOMPLETE"); |
break; |
case NUD_REACHABLE: |
strcpy(statestr, "REACHABLE"); |
break; |
case NUD_STALE: |
strcpy(statestr, "STALE"); |
break; |
case NUD_DELAY: |
strcpy(statestr, "DELAY"); |
break; |
case NUD_PROBE: |
strcpy(statestr, "PROBE"); |
break; |
case NUD_FAILED: |
strcpy(statestr, "FAILED"); |
break; |
case NUD_IN_TIMER: |
strcpy(statestr, "IN TIMER"); |
break; |
default: |
snprintf(statestr, sizeof(statestr), "UNKNOWN %02x", state); |
break; |
} |
|
/* Print the info. */ |
printf("%-43s %-17s %-8s %-5s %-3d %-16s", |
addr6, haddr, iface, flags, refcnt, statestr); |
|
stale = 0; |
if (state == NUD_REACHABLE) |
stale = reachable > tstamp ? reachable - tstamp : 0; |
delete = gc > tstamp ? gc - tstamp : 0; |
if (ext != 2) { |
printf(" %-9ld ", stale / HZ); |
if (refcnt) |
printf(" * "); |
else |
printf(" %-7ld ", delete / HZ); |
} |
printf("\n"); |
} |
|
(void) fclose(fp); |
return (0); |
} |
|
int INET6_rprint(int options) |
{ |
int ext = options & FLAG_EXT; |
int numeric = options & (FLAG_NUM | FLAG_SYM); |
int rc = E_INTERN; |
|
if (options & FLAG_FIB) |
if ((rc = rprint_fib6(ext, numeric))) |
return (rc); |
|
if (options & FLAG_CACHE) |
if ((rc = rprint_cache6(ext, numeric))) |
return (rc); |
return (rc); |
} |
|
#endif /* HAVE_AFINET6 */ |
/trunk/uclinux/userland/route/lib/util.c
0,0 → 1,51
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */ |
/* $Id: util.c,v 1.1 2002-03-17 19:58:53 simons Exp $ */ |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <sys/utsname.h> |
|
#include "util.h" |
|
|
static void oom(void) |
{ |
fprintf(stderr, "out of virtual memory\n"); |
exit(2); |
} |
|
void *xmalloc(size_t sz) |
{ |
void *p = calloc(sz, 1); |
if (!p) |
oom(); |
return p; |
} |
|
void *xrealloc(void *oldp, size_t sz) |
{ |
void *p = realloc(oldp, sz); |
if (!p) |
oom(); |
return p; |
} |
|
int kernel_version(void) |
{ |
struct utsname uts; |
int major, minor, patch; |
|
if (uname(&uts) < 0) |
return -1; |
if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3) |
return -1; |
return KRELEASE(major, minor, patch); |
} |
|
|
/* Like strncpy but make sure the resulting string is always 0 terminated. */ |
char *safe_strncpy(char *dst, const char *src, size_t size) |
{ |
dst[size-1] = '\0'; |
return strncpy(dst,src,size-1); |
} |
/trunk/uclinux/userland/route/lib/irda.c
0,0 → 1,88
/********************************************************************* |
* |
* Filename: irda.c |
* Version: 0.1 |
* Description: A first attempt to make ifconfig understand IrDA |
* Status: Experimental. |
* Author: Dag Brattli <dagb@cs.uit.no> |
* Created at: Wed Apr 21 09:03:09 1999 |
* Modified at: Wed Apr 21 09:17:05 1999 |
* Modified by: Dag Brattli <dagb@cs.uit.no> |
* |
* 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. |
* |
* This program is distributed in the hope that it will be useful, |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* GNU General Public License for more details. |
* |
* You should have received a copy of the GNU General Public License |
* along with this program; if not, write to the Free Software |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
* MA 02111-1307 USA |
* |
********************************************************************/ |
|
#include "config.h" |
|
#if HAVE_AFIRDA || HAVE_HWIRDA |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
/* Probably not a good idea to include <linux/if_arp.h> */ |
#ifndef ARPHRD_IRDA |
#define ARPHRD_IRDA 783 |
#endif |
|
/* |
* Function irda_print (ptr) |
* |
* Print hardware address of interface |
* |
*/ |
static char *irda_print(unsigned char *ptr) |
{ |
static char buff[8]; |
|
sprintf(&buff[strlen(buff)], "%02x:%02x:%02x:%02x", ptr[3], ptr[2], |
ptr[1], ptr[0]); |
|
return (buff); |
} |
|
/* |
* Function irda_sprint (sap) |
* |
* Print IrDA socket address |
* |
*/ |
static char *irda_sprint(struct sockaddr *sap) |
{ |
/* NOP */ |
return NULL; |
} |
|
struct hwtype irda_hwtype = |
{ |
"irda", NULL, ARPHRD_IRDA, 2, |
irda_print, irda_sprint, NULL, NULL |
}; |
|
#endif /* HAVE_xxIRDA */ |
/trunk/uclinux/userland/route/lib/Makefile.org
0,0 → 1,53
# |
# lib/Makefile Makefile for the net-lib function collection |
# |
# NET-LIB A collection of functions used from the base set of the |
# NET-2 Networking Distribution for the LINUX operating |
# system. (net-tools, net-drivers) |
# |
# Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
# Copyright 1993 MicroWalt Corporation |
# |
# 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. |
# |
|
|
HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o irda.o |
AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o econet.o |
AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o |
AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o |
ACTOBJS = slip_ac.o ppp_ac.o activate.o |
VARIA = getargs.o masq_info.o proc.o util.o nstrcmp.o interface.o sockets.o util-ank.o |
|
OBJS = $(sort $(VARIA) $(AFOBJS) $(HWOBJS) \ |
$(AFGROBJS) $(AFSROBJS) $(ACTOBJS)) |
|
|
# This can be overwritten by the TOPLEVEL Makefile |
TOPDIR=.. |
CFLAGS += -I$(TOPDIR) -idirafter $(TOPDIR)/include # -fPIC |
SONAME=libnet-tools.so.0 |
|
.SUFFIXES: .a .so |
|
all: lib$(NET_LIB_NAME).a # lib$(NET_LIB_NAME).so |
|
lib$(NET_LIB_NAME).a: Makefile $(TOPDIR)/config.h $(OBJS) |
@echo Building $@ |
@rm -f $@ |
@ar rcs $@ $(OBJS) |
|
.a.so:; |
$(CC) -o $@ -shared -Wl,--whole-archive -Wl,--soname -Wl,$(SONAME) -nostdlib -nostartfiles $< |
|
clean: |
rm -f *.o *~ *.orig |
|
clobber: clean |
rm -f *.a *.so |
|
# End of lib/Makefile. |
/trunk/uclinux/userland/route/lib/util.h
0,0 → 1,16
#include <stddef.h> |
|
void *xmalloc(size_t sz); |
void *xrealloc(void *p, size_t sz); |
|
#define new(p) ((p) = xmalloc(sizeof(*(p)))) |
|
|
int kernel_version(void); |
#define KRELEASE(maj,min,patch) ((maj) * 10000 + (min)*1000 + (patch)) |
|
|
int nstrcmp(const char *, const char *); |
|
char *safe_strncpy(char *dst, const char *src, size_t size); |
|
/trunk/uclinux/userland/route/lib/unix.c
0,0 → 1,97
/* |
* lib/unix.c This file contains the general hardware types. |
* |
* Version: $Id: unix.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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" |
|
#include <sys/types.h> |
#include <sys/socket.h> |
#if HAVE_AFUNIX |
#include <sys/un.h> |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
|
/* Display an UNSPEC address. */ |
static char *UNSPEC_print(unsigned char *ptr) |
{ |
static char buff[64]; |
char *pos; |
unsigned int i; |
|
pos = buff; |
for (i = 0; i < sizeof(struct sockaddr); i++) { |
pos += sprintf(pos, "%02X-", (*ptr++ & 0377)); |
} |
buff[strlen(buff) - 1] = '\0'; |
return (buff); |
} |
|
|
/* Display an UNSPEC socket address. */ |
static char *UNSPEC_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (UNSPEC_print(sap->sa_data)); |
} |
|
|
#if HAVE_AFUNIX |
|
/* Display a UNIX domain address. */ |
static char *UNIX_print(unsigned char *ptr) |
{ |
return (ptr); |
} |
|
|
/* Display a UNIX domain address. */ |
static char *UNIX_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (UNIX_print(sap->sa_data)); |
} |
|
|
struct aftype unix_aftype = |
{ |
"unix", NULL, /*"UNIX Domain", */ AF_UNIX, 0, |
UNIX_print, UNIX_sprint, NULL, NULL, |
NULL, NULL, NULL, |
-1, |
"/proc/net/unix" |
}; |
#endif /* HAVE_AFUNIX */ |
|
|
struct aftype unspec_aftype = |
{ |
"unspec", NULL, /*"UNSPEC", */ AF_UNSPEC, 0, |
UNSPEC_print, UNSPEC_sprint, NULL, NULL, |
NULL, |
}; |
/trunk/uclinux/userland/route/lib/util-ank.c
0,0 → 1,322
/* |
* utils.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. |
* |
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
* |
* |
* Changes: |
* |
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses |
*/ |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <syslog.h> |
#include <fcntl.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <string.h> |
#include <netdb.h> |
#include <arpa/inet.h> |
#include <resolv.h> |
#ifdef __UCLINUX__ |
#include <limits.h> |
#define UING_MAX (~0U) |
#endif |
|
#include "intl.h" |
#include "util-ank.h" |
|
#ifndef AF_INET6 |
#define AF_INET6 10 |
#endif |
|
int scan_number(char *arg, unsigned *val) |
{ |
unsigned long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtoul(arg, &ptr, 0); |
if (!ptr || ptr == arg || *ptr || res > UINT_MAX) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_integer(int *val, char *arg, int base) |
{ |
long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtol(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > INT_MAX || res < INT_MIN) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_unsigned(unsigned *val, char *arg, int base) |
{ |
unsigned long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtoul(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > UINT_MAX) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_u32(__u32 *val, char *arg, int base) |
{ |
unsigned long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtoul(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > 0xFFFFFFFFUL) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_u16(__u16 *val, char *arg, int base) |
{ |
unsigned long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtoul(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > 0xFFFF) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_u8(__u8 *val, char *arg, int base) |
{ |
unsigned long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtoul(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > 0xFF) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_s16(__s16 *val, char *arg, int base) |
{ |
long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtol(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > 0x7FFF || res < -0x8000) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_s8(__s8 *val, char *arg, int base) |
{ |
long res; |
char *ptr; |
|
if (!arg || !*arg) |
return -1; |
res = strtol(arg, &ptr, base); |
if (!ptr || ptr == arg || *ptr || res > 0x7F || res < -0x80) |
return -1; |
*val = res; |
return 0; |
} |
|
int get_addr_1(inet_prefix *addr, char *name, int family) |
{ |
char *cp; |
unsigned char *ap = (unsigned char*)addr->data; |
int i; |
|
memset(addr, 0, sizeof(*addr)); |
|
if (strcmp(name, "default") == 0 || strcmp(name, "any") == 0) { |
addr->family = family; |
addr->bytelen = (family == AF_INET6 ? 16 : 4); |
addr->bitlen = -1; |
return 0; |
} |
|
if (strchr(name, ':')) { |
addr->family = AF_INET6; |
if (family != AF_UNSPEC && family != AF_INET6) |
return -1; |
if (inet_pton(AF_INET6, name, addr->data) <= 0) |
return -1; |
addr->bytelen = 16; |
addr->bitlen = -1; |
return 0; |
} |
|
addr->family = AF_INET; |
if (family != AF_UNSPEC && family != AF_INET) |
return -1; |
addr->bytelen = 4; |
addr->bitlen = -1; |
for (cp=name, i=0; *cp; cp++) { |
if (*cp <= '9' && *cp >= '0') { |
ap[i] = 10*ap[i] + (*cp-'0'); |
continue; |
} |
if (*cp == '.' && ++i <= 3) |
continue; |
return -1; |
} |
return 0; |
} |
|
int get_prefix_1(inet_prefix *dst, char *arg, int family) |
{ |
int err; |
unsigned plen; |
char *slash; |
|
memset(dst, 0, sizeof(*dst)); |
|
if (strcmp(arg, "default") == 0 || strcmp(arg, "any") == 0) { |
dst->family = family; |
dst->bytelen = 0; |
dst->bitlen = 0; |
return 0; |
} |
|
slash = strchr(arg, '/'); |
if (slash) |
*slash = 0; |
err = get_addr_1(dst, arg, family); |
if (err == 0) { |
dst->bitlen = (dst->family == AF_INET6 ? 128 : 32); |
if (slash) { |
if (scan_number(slash+1, &plen) || plen > dst->bitlen) { |
err = -1; |
goto done; |
} |
dst->bitlen = plen; |
} |
} |
done: |
if (slash) |
*slash = '/'; |
return err; |
} |
|
int get_addr(inet_prefix *dst, char *arg, int family) |
{ |
if (get_addr_1(dst, arg, family)) { |
fprintf(stderr, _("ip: %s is invalid inet address\n"), arg); |
exit(1); |
} |
return 0; |
} |
|
int get_prefix(inet_prefix *dst, char *arg, int family) |
{ |
if (get_prefix_1(dst, arg, family)) { |
fprintf(stderr, _("ip: %s is invalid inet prefix\n"), arg); |
exit(1); |
} |
return 0; |
} |
|
__u32 get_addr32(char *name) |
{ |
inet_prefix addr; |
if (get_addr_1(&addr, name, AF_INET)) { |
fprintf(stderr, _("ip: %s is invalid IPv4 address\n"), name); |
exit(1); |
} |
return addr.data[0]; |
} |
|
void invarg(char *msg) |
{ |
fprintf(stderr, _("ip: argument is wrong: %s\n"), msg); |
exit(1); |
} |
|
int matches(char *cmd, char *pattern) |
{ |
int len = strlen(cmd); |
if (len > strlen(pattern)) |
return -1; |
return memcmp(pattern, cmd, len); |
} |
|
int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits) |
{ |
__u32 *a1 = a->data; |
__u32 *a2 = b->data; |
int words = bits >> 0x05; |
|
bits &= 0x1f; |
|
if (words) |
if (memcmp(a1, a2, words << 2)) |
return -1; |
|
if (bits) { |
__u32 w1, w2; |
__u32 mask; |
|
w1 = a1[words]; |
w2 = a2[words]; |
|
mask = htonl((0xffffffff) << (0x20 - bits)); |
|
if ((w1 ^ w2) & mask) |
return 1; |
} |
|
return 0; |
} |
|
const char *format_host(int af, void *addr, __u8 *abuf, int alen) |
{ |
#ifdef RESOLVE_HOSTNAMES |
if (resolve_hosts) { |
int addrlen = 0; |
struct hostent *h_ent; |
switch (af) { |
case AF_INET: |
addrlen = 4; |
break; |
case AF_INET6: |
addrlen = 16; |
break; |
} |
if (addrlen && |
(h_ent = gethostbyaddr(addr, addrlen, af)) != NULL) { |
snprintf(abuf, alen-1, "%s", h_ent->h_name); |
return abuf; |
} |
} |
#endif |
return inet_ntop(af, addr, abuf, alen); |
} |
/trunk/uclinux/userland/route/lib/nstrcmp.c
0,0 → 1,34
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */ |
/* $Id: nstrcmp.c,v 1.1 2002-03-17 19:58:53 simons Exp $ */ |
#include <ctype.h> |
#include <stdlib.h> |
#include "util.h" |
|
/* like strcmp(), but knows about numbers */ |
int nstrcmp(const char *astr, const char *b) |
{ |
const char *a = astr; |
|
while (*a == *b) { |
if (*a == '\0') |
return 0; |
a++; |
b++; |
} |
if (isdigit(*a)) { |
if (!isdigit(*b)) |
return -1; |
while (a > astr) { |
a--; |
if (!isdigit(*a)) { |
a++; |
break; |
} |
if (!isdigit(*b)) |
return -1; |
b--; |
} |
return atoi(a) > atoi(b) ? 1 : -1; |
} |
return *a - *b; |
} |
/trunk/uclinux/userland/route/lib/inet_gr.c
0,0 → 1,457
/* |
$Id: inet_gr.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
|
Modifications: |
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets |
1999-01-01 - Bernd Eckenfels - fixed the routing cache printouts |
*/ |
|
#include "config.h" |
|
#if HAVE_AFINET |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
/* #include <net/route.h> realy broken */ |
#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" |
#include "intl.h" |
#include "net-features.h" |
#include "proc.h" |
extern struct aftype inet_aftype; |
|
extern char *INET_sprintmask(struct sockaddr *sap, int numeric, |
unsigned int netmask); |
|
int rprint_fib(int ext, int numeric) |
{ |
char buff[1024], iface[16], flags[64]; |
char gate_addr[128], net_addr[128]; |
char mask_addr[128]; |
int num, iflags, metric, refcnt, use, mss, window, irtt; |
FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r"); |
char *fmt; |
|
if (!fp) { |
perror(_PATH_PROCNET_ROUTE); |
printf(_("INET (IPv4) not configured in this system.\n")); |
return 1; |
} |
printf(_("Kernel IP routing table\n")); |
|
if (ext == 1) |
printf(_("Destination Gateway Genmask " |
"Flags Metric Ref Use Iface\n")); |
if (ext == 2) |
printf(_("Destination Gateway Genmask " |
"Flags MSS Window irtt Iface\n")); |
if (ext >= 3) |
printf(_("Destination Gateway Genmask " |
"Flags Metric Ref Use Iface " |
"MSS Window irtt\n")); |
|
irtt = 0; |
window = 0; |
mss = 0; |
|
fmt = proc_gen_fmt(_PATH_PROCNET_ROUTE, 0, fp, |
"Iface", "%16s", |
"Destination", "%128s", |
"Gateway", "%128s", |
"Flags", "%X", |
"RefCnt", "%d", |
"Use", "%d", |
"Metric", "%d", |
"Mask", "%128s", |
"MTU", "%d", |
"Window", "%d", |
"IRTT", "%d", |
NULL); |
/* "%16s %128s %128s %X %d %d %d %128s %d %d %d\n" */ |
|
if (!fmt) |
return 1; |
|
while (fgets(buff, 1023, fp)) { |
struct sockaddr snet_target, snet_gateway, snet_mask; |
struct sockaddr_in *sin_netmask; |
|
num = sscanf(buff, fmt, |
iface, net_addr, gate_addr, |
&iflags, &refcnt, &use, &metric, mask_addr, |
&mss, &window, &irtt); |
if (num < 10 || !(iflags & RTF_UP)) |
continue; |
|
/* Fetch and resolve the target address. */ |
(void) inet_aftype.input(1, net_addr, &snet_target); |
|
/* Fetch and resolve the gateway address. */ |
(void) inet_aftype.input(1, gate_addr, &snet_gateway); |
|
/* Fetch and resolve the genmask. */ |
(void) inet_aftype.input(1, mask_addr, &snet_mask); |
|
sin_netmask = (struct sockaddr_in *)&snet_mask; |
strcpy(net_addr, INET_sprintmask(&snet_target, |
(numeric | 0x8000), |
sin_netmask->sin_addr.s_addr)); |
net_addr[15] = '\0'; |
|
strcpy(gate_addr, inet_aftype.sprint(&snet_gateway, numeric)); |
gate_addr[15] = '\0'; |
|
strcpy(mask_addr, inet_aftype.sprint(&snet_mask, 1)); |
mask_addr[15] = '\0'; |
|
/* Decode the flags. */ |
flags[0] = '\0'; |
if (iflags & RTF_UP) |
strcat(flags, "U"); |
if (iflags & RTF_GATEWAY) |
strcat(flags, "G"); |
#if HAVE_RTF_REJECT |
if (iflags & RTF_REJECT) |
strcpy(flags, "!"); |
#endif |
if (iflags & RTF_HOST) |
strcat(flags, "H"); |
if (iflags & RTF_REINSTATE) |
strcat(flags, "R"); |
if (iflags & RTF_DYNAMIC) |
strcat(flags, "D"); |
if (iflags & RTF_MODIFIED) |
strcat(flags, "M"); |
if (iflags & RTF_DEFAULT) |
strcat(flags, "d"); |
if (iflags & RTF_ALLONLINK) |
strcat(flags, "a"); |
if (iflags & RTF_ADDRCONF) |
strcat(flags, "c"); |
if (iflags & RTF_NONEXTHOP) |
strcat(flags, "o"); |
if (iflags & RTF_EXPIRES) |
strcat(flags, "e"); |
if (iflags & RTF_CACHE) |
strcat(flags, "c"); |
if (iflags & RTF_FLOW) |
strcat(flags, "f"); |
if (iflags & RTF_POLICY) |
strcat(flags, "p"); |
if (iflags & RTF_LOCAL) |
strcat(flags, "l"); |
if (iflags & RTF_MTU) |
strcat(flags, "u"); |
if (iflags & RTF_WINDOW) |
strcat(flags, "w"); |
if (iflags & RTF_IRTT) |
strcat(flags, "i"); |
if (iflags & RTF_NOTCACHED) /* 2.0.36 */ |
strcat(flags, "n"); |
|
/* Print the info. */ |
if (ext == 1) { |
#if HAVE_RTF_REJECT |
if (iflags & RTF_REJECT) |
printf("%-15s - %-15s %-5s %-6d - %7d -\n", |
net_addr, mask_addr, flags, metric, use); |
else |
#endif |
printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", |
net_addr, gate_addr, mask_addr, flags, |
metric, refcnt, use, iface); |
} |
if (ext == 2) { |
#if HAVE_RTF_REJECT |
if (iflags & RTF_REJECT) |
printf("%-15s - %-15s %-5s - - - -\n", |
net_addr, mask_addr, flags); |
else |
#endif |
printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", |
net_addr, gate_addr, mask_addr, flags, |
mss, window, irtt, iface); |
} |
if (ext >= 3) { |
#if HAVE_RTF_REJECT |
if (iflags & RTF_REJECT) |
printf("%-15s - %-15s %-5s %-6d - %7d - - - -\n", |
net_addr, mask_addr, flags, metric, use); |
else |
#endif |
printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %d\n", |
net_addr, gate_addr, mask_addr, flags, |
metric, refcnt, use, iface, mss, window, irtt); |
} |
} |
|
free(fmt); |
(void) fclose(fp); |
return (0); |
} |
|
int rprint_cache(int ext, int numeric) |
{ |
char buff[1024], iface[16], flags[64]; |
char gate_addr[128], dest_addr[128], specdst[128]; |
char src_addr[128]; |
struct sockaddr snet; |
unsigned int iflags; |
int num, format, metric, refcnt, use, mss, window, irtt, hh, hhref, hhuptod, arp, tos; |
char *fmt = NULL; |
|
FILE *fp = fopen(_PATH_PROCNET_RTCACHE, "r"); |
|
if (!fp) { |
perror(_PATH_PROCNET_RTCACHE); |
printf(_("INET (IPv4) not configured in this system.\n")); |
return 1; |
} |
|
/* Okay, first thing we need to know is the format of the rt_cache. |
* I am aware of two possible layouts: |
* 2.2.0 |
* "Iface\tDestination\tGateway \tFlags\t\tRefCnt\tUse\tMetric\tSource\t\tMTU\tWindow\tIRTT\tTOS\tHHRef\tHHUptod\tSpecDst" |
* "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X" |
* |
* 2.0.36 |
* "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tSource\t\tMTU\tWindow\tIRTT\tHH\tARP" |
* "%s\t%08lX\t%08lX\t%02X\t%d\t%u\t%d\t%08lX\t%d\t%lu\t%u\t%d\t%1d" |
*/ |
|
format = proc_guess_fmt(_PATH_PROCNET_RTCACHE, fp, "IRTT",1,"TOS",2,"HHRef",4,"HHUptod",8,"SpecDst",16,"HH",32,"ARP",64,NULL); |
|
printf(_("Kernel IP routing cache\n")); |
|
switch(format) { |
case -1: /* I/O Error */ |
perror(_PATH_PROCNET_RTCACHE); |
exit(-1); |
break; |
case 63: /* 2.2.0 Format */ |
format = 2; |
break; |
case 97: /* 2.0.36 Format */ |
format = 1; |
break; |
default: |
printf("ERROR: proc_guess_fmt(%s,... returned: %d\n",_PATH_PROCNET_RTCACHE, format); |
break; |
} |
|
rewind(fp); |
|
if (ext == 1) |
printf(_("Source Destination Gateway " |
"Flags Metric Ref Use Iface\n")); |
if (ext == 2) |
printf(_("Source Destination Gateway " |
"Flags MSS Window irtt Iface\n")); |
|
if (format == 1) { |
if (ext >= 3) |
printf(_("Source Destination Gateway " |
"Flags Metric Ref Use Iface " |
"MSS Window irtt HH Arp\n")); |
|
fmt = proc_gen_fmt(_PATH_PROCNET_RTCACHE, 0, fp, |
"Iface", "%16s", |
"Destination", "%128s", |
"Gateway", "%128s", |
"Flags", "%X", |
"RefCnt", "%d", |
"Use", "%d", |
"Metric", "%d", |
"Source", "%128s", |
"MTU", "%d", |
"Window", "%d", |
"IRTT", "%d", |
"HH", "%d", |
"ARP", "%d", |
NULL); |
/* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d\n" */ |
} |
|
if (format == 2) { |
if (ext >= 3) |
printf(_("Source Destination Gateway " |
"Flags Metric Ref Use Iface " |
"MSS Window irtt TOS HHRef HHUptod SpecDst\n")); |
fmt = proc_gen_fmt(_PATH_PROCNET_RTCACHE, 0, fp, |
"Iface", "%16s", |
"Destination", "%128s", |
"Gateway", "%128s", |
"Flags", "%X", |
"RefCnt", "%d", |
"Use", "%d", |
"Metric", "%d", |
"Source", "%128s", |
"MTU", "%d", |
"Window", "%d", |
"IRTT", "%d", |
"TOS", "%d", |
"HHRef", "%d", |
"HHUptod", "%d", |
"SpecDst", "%128s", |
NULL); |
/* "%16s %128s %128s %X %d %d %d %128s %d %d %d %d %d %128s\n" */ |
} |
|
|
irtt = 0; |
window = 0; |
mss = 0; |
hh = 0; hhref = 0; hhuptod = 0; |
arp = 0; tos = 0; |
while (fgets(buff, 1023, fp)) { |
if (format == 1) { |
num = sscanf(buff, fmt, |
iface, dest_addr, gate_addr, |
&iflags, &refcnt, &use, &metric, src_addr, |
&mss, &window, &irtt, &hh, &arp); |
if (num < 12) |
continue; |
} |
if (format == 2) { |
num = sscanf(buff, fmt, |
iface, dest_addr, gate_addr, |
&iflags, &refcnt, &use, &metric, src_addr, |
&mss, &window, &irtt, &tos, &hhref, &hhuptod, &specdst); |
if (num < 12) |
continue; |
} |
|
|
/* Fetch and resolve the target address. */ |
(void) inet_aftype.input(1, dest_addr, &snet); |
strcpy(dest_addr, inet_aftype.sprint(&snet, numeric)); |
dest_addr[15] = '\0'; |
|
/* Fetch and resolve the gateway address. */ |
(void) inet_aftype.input(1, gate_addr, &snet); |
strcpy(gate_addr, inet_aftype.sprint(&snet, numeric)); |
gate_addr[15] = '\0'; |
|
/* Fetch and resolve the source. */ |
(void) inet_aftype.input(1, src_addr, &snet); |
strcpy(src_addr, inet_aftype.sprint(&snet, numeric)); |
src_addr[15] = '\0'; |
|
/* Fetch and resolve the SpecDst addrerss. */ |
(void) inet_aftype.input(1, specdst, &snet); |
strcpy(specdst, inet_aftype.sprint(&snet, numeric)); |
specdst[15] = '\0'; |
|
/* Decode the flags. */ |
flags[0] = '\0'; |
if (format == 1) { |
if (iflags & RTF_UP) |
strcat(flags, "U"); |
if (iflags & RTF_HOST) |
strcat(flags, "H"); |
} |
if (iflags & RTF_GATEWAY) |
strcat(flags, "G"); |
#if HAVE_RTF_REJECT |
if (iflags & RTF_REJECT) |
strcpy(flags, "!"); |
#endif |
if (iflags & RTF_REINSTATE) |
strcat(flags, "R"); |
if (iflags & RTF_DYNAMIC) |
strcat(flags, "D"); |
if (iflags & RTF_MODIFIED) |
strcat(flags, "M"); |
|
/* possible collision with 2.0 flags U and H */ |
if (format == 2) { |
if (iflags & RTCF_DEAD) |
strcat(flags, "-"); |
if (iflags & RTCF_ONLINK) |
strcat(flags, "o"); |
} |
if (iflags & RTCF_NOTIFY) |
strcat(flags, "n"); |
if (iflags & RTCF_DIRECTDST) |
strcat(flags, "d"); |
if (iflags & RTCF_TPROXY) |
strcat(flags, "t"); |
if (iflags & RTCF_FAST) |
strcat(flags, "f"); |
if (iflags & RTCF_MASQ) |
strcat(flags, "q"); |
if (iflags & RTCF_SNAT) |
strcat(flags, "Ns"); |
if (iflags & RTCF_DOREDIRECT) |
strcat(flags, "r"); |
if (iflags & RTCF_DIRECTSRC) |
strcat(flags, "i"); |
if (iflags & RTCF_DNAT) |
strcat(flags, "Nd"); |
if (iflags & RTCF_BROADCAST) |
strcat(flags, "b"); |
if (iflags & RTCF_MULTICAST) |
strcat(flags, "m"); |
if (iflags & RTCF_REJECT) |
strcat(flags, "#"); |
if (iflags & RTCF_LOCAL) |
strcat(flags, "l"); |
/* Print the info. */ |
if (ext == 1) { |
printf("%-15s %-15s %-15s %-5s %-6d %-2d %7d %s\n", |
src_addr, dest_addr, gate_addr, flags, |
metric, refcnt, use, iface); |
} |
if (ext == 2) { |
printf("%-15s %-15s %-15s %-5s %5d %-5d %6d %s\n", |
src_addr, dest_addr, gate_addr, flags, |
mss, window, irtt, iface); |
} |
if (format == 1) { |
if (ext >= 3) { |
printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-5d %-3d %d\n", |
src_addr, dest_addr, gate_addr, flags, |
metric, refcnt, use, iface, mss, window, irtt, hh, arp); |
} |
} |
if (format == 2) { |
if (ext >= 3) { |
printf("%-15s %-15s %-15s %-5s %-6d %-3d %6d %-6.6s %-5d %-6d %-5d %-3d %-3d %-3d %15s\n", |
src_addr, dest_addr, gate_addr, flags, |
metric, refcnt, use, iface, mss, window, irtt, tos, hhref, hhuptod, specdst); |
} |
} |
} |
|
free(fmt); |
(void) fclose(fp); |
return (0); |
} |
|
int INET_rprint(int options) |
{ |
int ext = options & FLAG_EXT; |
int numeric = options & (FLAG_NUM | FLAG_SYM); |
int rc = E_INTERN; |
|
if (options & FLAG_FIB) |
if ((rc = rprint_fib(ext, numeric))) |
return (rc); |
if (options & FLAG_CACHE) |
rc = rprint_cache(ext, numeric); |
|
return (rc); |
} |
|
#endif /* HAVE_AFINET */ |
/trunk/uclinux/userland/route/lib/ipx_gr.c
0,0 → 1,85
/* support for ap->rresolv missing */ |
/* |
Modifications: |
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, |
snprintf instead of sprintf |
*/ |
|
#include "config.h" |
|
#if HAVE_AFIPX |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netipx/ipx.h> |
#else |
#include "ipx.h" |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include <netinet/in.h> |
#include "version.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
/* UGLY */ |
|
int IPX_rprint(int options) |
{ |
/* int ext = options & FLAG_EXT; */ |
int numeric = options & FLAG_NUM; |
char buff[1024]; |
char net[128], router_net[128]; |
char router_node[128]; |
int num; |
FILE *fp = fopen(_PATH_PROCNET_IPX_ROUTE, "r"); |
struct aftype *ap; |
struct sockaddr sa; |
|
if ((ap = get_afntype(AF_IPX)) == NULL) { |
EINTERN("lib/ipx_rt.c", "AF_IPX missing"); |
return (-1); |
} |
|
if (!fp) { |
perror(_PATH_PROCNET_IPX_ROUTE); |
printf(_("IPX not configured in this system.\n")); |
return 1; |
} |
|
printf(_("Kernel IPX routing table\n")); /* xxx */ |
printf(_("Destination Router Net Router Node\n")); |
|
fgets(buff, 1023, fp); |
|
while (fgets(buff, 1023, fp)) { |
num = sscanf(buff, "%s %s %s", net, router_net, router_node); |
if (num < 3) |
continue; |
|
/* Fetch and resolve the Destination */ |
(void) ap->input(5, net, &sa); |
strcpy(net, ap->sprint(&sa, numeric)); |
|
/* Fetch and resolve the Router Net */ |
(void) ap->input(5, router_net, &sa); |
strcpy(router_net, ap->sprint(&sa, numeric)); |
|
/* Fetch and resolve the Router Node */ |
(void) ap->input(2, router_node, &sa); |
strcpy(router_node, ap->sprint(&sa, numeric)); |
|
printf("%-25s %-25s %-25s\n", net, router_net, router_node); |
} |
|
(void) fclose(fp); |
return (0); |
} |
|
#endif /* HAVE_AFIPX */ |
/trunk/uclinux/userland/route/lib/inet6_sr.c
0,0 → 1,188
/* |
Modifications: |
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets |
*/ |
|
#include "config.h" |
|
#if HAVE_AFINET6 |
#include <asm/types.h> |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
#include <net/if.h> |
#include <sys/ioctl.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> |
#ifdef __GLIBC__ |
#include <net/route.h> |
#else |
#include <netinet6/ipv6_route.h> /* glibc does not have this */ |
#endif |
#include "version.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "net-features.h" |
|
extern struct aftype inet6_aftype; |
|
static int skfd = -1; |
|
|
static int usage(void) |
{ |
fprintf(stderr, _("Usage: inet6_route [-vF] del Target\n")); |
fprintf(stderr, _(" inet6_route [-vF] add Target [gw Gw] [metric M] [[dev] If]\n")); |
fprintf(stderr, _(" inet6_route [-FC] flush NOT supported\n")); |
return (E_USAGE); |
} |
|
|
static int INET6_setroute(int action, int options, char **args) |
{ |
struct in6_rtmsg rt; |
struct ifreq ifr; |
struct sockaddr_in6 sa6; |
char target[128], gateway[128] = "NONE"; |
int metric, prefix_len; |
char *devname = NULL; |
char *cp; |
|
if (*args == NULL) |
return (usage()); |
|
strcpy(target, *args++); |
if ((cp = strchr(target, '/'))) { |
prefix_len = atol(cp + 1); |
if ((prefix_len < 0) || (prefix_len > 128)) |
usage(); |
*cp = 0; |
} else { |
prefix_len = 128; |
} |
|
/* Clean out the RTREQ structure. */ |
memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); |
|
if (inet6_aftype.input(1, target, (struct sockaddr *) &sa6) < 0) { |
inet6_aftype.herror(target); |
return (1); |
} |
memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); |
|
/* Fill in the other fields. */ |
rt.rtmsg_flags = RTF_UP; |
if (prefix_len == 128) |
rt.rtmsg_flags |= RTF_HOST; |
rt.rtmsg_metric = 1; |
rt.rtmsg_dst_len = prefix_len; |
|
while (*args) { |
if (!strcmp(*args, "metric")) { |
|
args++; |
if (!*args || !isdigit(**args)) |
return (usage()); |
metric = atoi(*args); |
rt.rtmsg_metric = metric; |
args++; |
continue; |
} |
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { |
args++; |
if (!*args) |
return (usage()); |
if (rt.rtmsg_flags & RTF_GATEWAY) |
return (usage()); |
strcpy(gateway, *args); |
if (inet6_aftype.input(1, gateway, |
(struct sockaddr *) &sa6) < 0) { |
inet6_aftype.herror(gateway); |
return (E_LOOKUP); |
} |
memcpy(&rt.rtmsg_gateway, sa6.sin6_addr.s6_addr, |
sizeof(struct in6_addr)); |
rt.rtmsg_flags |= RTF_GATEWAY; |
args++; |
continue; |
} |
if (!strcmp(*args, "mod")) { |
args++; |
rt.rtmsg_flags |= RTF_MODIFIED; |
continue; |
} |
if (!strcmp(*args, "dyn")) { |
args++; |
rt.rtmsg_flags |= RTF_DYNAMIC; |
continue; |
} |
if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { |
args++; |
if (!*args) |
return (usage()); |
} else if (args[1]) |
return (usage()); |
|
devname = *args; |
args++; |
} |
|
/* Create a socket to the INET6 kernel. */ |
if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { |
perror("socket"); |
return (E_SOCK); |
} |
if (devname) { |
memset(&ifr, 0, sizeof(ifr)); |
strcpy(ifr.ifr_name, devname); |
|
if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) { |
perror("SIOGIFINDEX"); |
return (E_SOCK); |
} |
rt.rtmsg_ifindex = ifr.ifr_ifindex; |
} else |
rt.rtmsg_ifindex = 0; |
|
/* 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 INET6_rinput(int action, int options, char **args) |
{ |
if (action == RTACTION_FLUSH) { |
fprintf(stderr, _("Flushing `inet6' routing table not supported\n")); |
return (usage()); |
} |
if ((*args == NULL) || (action == RTACTION_HELP)) |
return (usage()); |
|
return (INET6_setroute(action, options, args)); |
} |
#endif /* HAVE_AFINET6 */ |
/trunk/uclinux/userland/route/lib/loopback.c
0,0 → 1,71
/* |
* lib/loopback.c This file contains the general hardware types. |
* |
* Version: $Id: loopback.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modifications: |
* 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets |
* |
* 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" |
|
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
/* Display an UNSPEC address. */ |
static char *pr_unspec(unsigned char *ptr) |
{ |
static char buff[64]; |
char *pos; |
unsigned int i; |
|
pos = buff; |
for (i = 0; i < sizeof(struct sockaddr); i++) { |
pos += sprintf(pos, "%02X-", (*ptr++ & 0377)); |
} |
buff[strlen(buff) - 1] = '\0'; |
return (buff); |
} |
|
|
/* Display an UNSPEC socket address. */ |
static char *pr_sunspec(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (pr_unspec(sap->sa_data)); |
} |
|
|
struct hwtype unspec_hwtype = |
{ |
"unspec", NULL, /*"UNSPEC", */ -1, 0, |
pr_unspec, pr_sunspec, NULL, NULL |
}; |
|
struct hwtype loop_hwtype = |
{ |
"loop", NULL, /*"Local Loopback", */ ARPHRD_LOOPBACK, 0, |
NULL, NULL, NULL, NULL |
}; |
/trunk/uclinux/userland/route/lib/Makefile
0,0 → 1,24
|
CC = or32-uclibc-gcc |
LD = or32-uclibc-gcc |
RANLIB = or32-uclibc-ranlib |
|
LIB = libroute.a |
OBJS = activate.o ether.o inet6.o irda.o proc.o tunnel.o af.o fddi.o \ |
inet6_gr.o loopback.o rose.o unix.o arcnet.o frame.o inet6_sr.o \ |
masq_info.o rose_gr.o util-ank.o ash.o getargs.o inet_gr.o \ |
netrom.o setroute.o util.o ax25.o getroute.o inet_sr.o netrom_gr.o \ |
sit.o ax25_gr.o hdlclapb.o interface.o netrom_sr.o slip.o ddp.o \ |
hippi.o ipx.o nstrcmp.o slip_ac.o ddp_gr.o hw.o ipx_gr.o ppp.o \ |
sockets.o econet.o inet.o ipx_sr.o ppp_ac.o tr.o |
|
CFLAGS += -D_GNU_SOURCE -D__USE_BSD -Ilib -I../ -I../include -Wall -Werror-implicit-function-declaration |
|
all: $(LIB) $(EXEC) |
|
$(LIB): $(LIB)($(OBJS)) |
$(RANLIB) $(LIB) |
|
clean: |
rm -f $(LIB) *.o |
|
/trunk/uclinux/userland/route/lib/getargs.c
0,0 → 1,94
/* |
* lib/getargs.c General argument parser. |
* |
* Version: $Id: getargs.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993,1994 MicroWalt Corporation |
* |
* 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" |
#include <sys/types.h> |
#ifdef EMBED |
#include <gnu/types.h> |
#endif |
#include <sys/socket.h> |
#include <net/if.h> |
#include <errno.h> |
#include <signal.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
|
/* Split the input string into multiple fields. */ |
int getargs(char *string, char *arguments[]) |
{ |
int len = strlen(string); |
char temp[len+1]; |
char *sp, *ptr; |
int i, argc; |
char want; |
|
/* |
* Copy the string into a buffer. We may have to modify |
* the original string because of all the quoting... |
*/ |
sp = string; |
i = 0; |
strcpy(temp, string); |
ptr = temp; |
|
/* |
* Look for delimiters ("); if present whatever |
* they enclose will be considered one argument. |
*/ |
while (*ptr != '\0' && i < 31) { |
/* Ignore leading whitespace on input string. */ |
while (*ptr == ' ' || *ptr == '\t') |
ptr++; |
|
/* Set string pointer. */ |
arguments[i++] = sp; |
|
/* Check for any delimiters. */ |
if (*ptr == '"' || *ptr == '\'') { |
/* |
* Copy the string up to any whitespace OR the next |
* delimiter. If the delimiter was escaped, skip it |
* as it if was not there. |
*/ |
want = *ptr++; |
while (*ptr != '\0') { |
if (*ptr == want && *(ptr - 1) != '\\') { |
ptr++; |
break; |
} |
*sp++ = *ptr++; |
} |
} else { |
/* Just copy the string up to any whitespace. */ |
while (*ptr != '\0' && *ptr != ' ' && *ptr != '\t') |
*sp++ = *ptr++; |
} |
*sp++ = '\0'; |
|
/* Skip trailing whitespace. */ |
if (*ptr != '\0') { |
while (*ptr == ' ' || *ptr == '\t') |
ptr++; |
} |
} |
argc = i; |
while (i < 32) |
arguments[i++] = (char *) NULL; |
return (argc); |
} |
/trunk/uclinux/userland/route/lib/ddp_gr.c
0,0 → 1,24
#include "config.h" |
|
#if HAVE_AFATALK |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <linux/atalk.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include <netinet/in.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
int DDP_rprint(int options) |
{ |
fprintf(stderr, _("Routing table for `ddp' not yet supported.\n")); |
return (1); |
} |
#endif |
/trunk/uclinux/userland/route/lib/ppp.c
0,0 → 1,58
/* |
* lib/ppp.c This file contains the SLIP support for the NET-2 base |
* distribution. |
* |
* Version: $Id: ppp.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified by Alan Cox, May 94 to cover NET-3 |
* |
* Changes: |
* 980701 {1.12} Arnaldo Carvalho de Melo - GNU gettext instead of catgets |
* |
* 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_HWPPP |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
/* Start the PPP encapsulation on the file descriptor. */ |
static int do_ppp(int fd) |
{ |
fprintf(stderr, _("You cannot start PPP with this program.\n")); |
return -1; |
} |
|
|
|
|
struct hwtype ppp_hwtype = |
{ |
"ppp", NULL, /*"Point-Point Protocol", */ ARPHRD_PPP, 0, |
NULL, NULL, NULL, do_ppp |
}; |
|
|
#endif /* HAVE_PPP */ |
/trunk/uclinux/userland/route/lib/ipx.c
0,0 → 1,180
/* |
* IPX protocol output functions. |
* [Not yet input] |
* |
* Alan Cox <Alan.Cox@linux.org> |
* |
* 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. |
* Modifications: |
* 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets, |
* snprintf instead of sprintf |
*/ |
#include "config.h" |
|
#if HAVE_AFIPX |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netipx/ipx.h> |
#else |
#include "ipx.h" |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include <netinet/in.h> |
#include "version.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
#if (IPX_NODE_LEN != 6) |
#error "IPX_NODE_LEN != 6" |
#endif |
|
/* Display a ipx domain address. */ |
static char *IPX_print(unsigned char *ptr) |
{ |
static char buff[64]; |
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2); |
int t; |
|
|
for (t = IPX_NODE_LEN; t; t--) |
if (sipx->sipx_node[t - 1]) |
break; |
|
if (t && ntohl(sipx->sipx_network)) |
snprintf(buff, sizeof(buff), "%08lX:%02X%02X%02X%02X%02X%02X", |
(long int) ntohl(sipx->sipx_network), |
(int) sipx->sipx_node[0], (int) sipx->sipx_node[1], |
(int) sipx->sipx_node[2], (int) sipx->sipx_node[3], |
(int) sipx->sipx_node[4], (int) sipx->sipx_node[5]); |
else if (!t && ntohl(sipx->sipx_network)) |
snprintf(buff, sizeof(buff), "%08lX", (long int) ntohl(sipx->sipx_network)); |
else if (t && !ntohl(sipx->sipx_network)) |
snprintf(buff, sizeof(buff), "%02X%02X%02X%02X%02X%02X", |
(int) sipx->sipx_node[0], (int) sipx->sipx_node[1], |
(int) sipx->sipx_node[2], (int) sipx->sipx_node[3], |
(int) sipx->sipx_node[4], (int) sipx->sipx_node[5]); |
else |
buff[0] = '\0'; |
return (buff); |
} |
|
|
/* Display a ipx domain address. */ |
static char *IPX_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buf[64]; |
|
if (sap->sa_family != AF_IPX) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (IPX_print(sap->sa_data)); |
} |
|
|
static int IPX_getsock(char *bufp, struct sockaddr *sap) |
{ |
char *sp = bufp, *bp; |
unsigned int i; |
unsigned char val; |
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap; |
|
sipx->sipx_port = 0; |
|
val = 0; |
bp = (char *) sipx->sipx_node; |
for (i = 0; i < sizeof(sipx->sipx_node); i++) { |
*sp = toupper(*sp); |
|
if ((*sp >= 'A') && (*sp <= 'F')) |
bp[i] |= (int) (*sp - 'A') + 10; |
else if ((*sp >= '0') && (*sp <= '9')) |
bp[i] |= (int) (*sp - '0'); |
else |
return (-1); |
|
bp[i] <<= 4; |
sp++; |
*sp = toupper(*sp); |
|
if ((*sp >= 'A') && (*sp <= 'F')) |
bp[i] |= (int) (*sp - 'A') + 10; |
else if ((*sp >= '0') && (*sp <= '9')) |
bp[i] |= (int) (*sp - '0'); |
else |
return (-1); |
|
sp++; |
} |
if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) || |
(memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)) |
return (-1); |
|
return (0); |
} |
|
/* XXX define type which makes verbose format checks AF_input */ |
|
static int IPX_input(int type, char *bufp, struct sockaddr *sap) |
{ |
struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap; |
unsigned long netnum; |
char *ep; |
int nbo; |
|
sai->sipx_family = AF_IPX; |
sai->sipx_network = htonl(0); |
sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] = |
sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0'; |
sai->sipx_port = 0; |
|
if (type & 4) |
nbo = 1; |
else |
nbo = 0; |
|
type &= 3; |
if (type <= 1) { |
netnum = strtoul(bufp, &ep, 16); |
if ((netnum == 0xffffffffL) || (netnum == 0L)) |
return (-1); |
if (nbo) |
sai->sipx_network = netnum; |
else |
sai->sipx_network = htonl(netnum); |
} |
if (type == 1) { |
if (*ep != '\0') |
return (-2); |
return (0); |
} |
if (type == 0) { |
if (*ep != ':') |
return (-3); |
bufp = ep + 1; |
} |
return (IPX_getsock(bufp, sap)); |
} |
|
|
struct aftype ipx_aftype = |
{ |
"ipx", NULL, /*"IPX", */ AF_IPX, 0, |
IPX_print, IPX_sprint, IPX_input, NULL, |
NULL /*IPX_rprint */ , NULL, NULL, |
-1, |
"/proc/net/ipx" |
}; |
|
#endif |
/trunk/uclinux/userland/route/lib/rose_gr.c
0,0 → 1,68
|
/* |
* lib/rose_gr.c This file contains an implementation of the "ROSE" |
* route print support functions. |
* |
* Version: $Id: rose_gr.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> |
* based on ax25_gr.c by: |
* Bernd Eckenfels, <ecki@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> |
* |
* 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_AFROSE |
#if 0 |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <linux/rose.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> /* ARPHRD_ROSE */ |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
int ROSE_rprint(int options) |
{ |
FILE *f = NULL; |
char buffer[256]; |
int use; |
|
f=fopen(_PATH_PROCNET_ROSE_ROUTE, "r"); |
if (f == NULL) { |
perror(_PATH_PROCNET_ROSE_ROUTE); |
printf(_("ROSE not configured in this system.\n")); /* xxx */ |
return 1; |
} |
printf(_("Kernel ROSE routing table\n")); |
printf(_("Destination Iface Use\n")); |
fgets(buffer, 256, f); |
while (fgets(buffer, 256, f)) { |
buffer[9] = 0; |
buffer[14] = 0; |
use = atoi(buffer + 15); |
printf("%-9s %-5s %5d\n", |
buffer, buffer + 10, use); |
} |
fclose(f); |
return 0; |
} |
|
#endif /* HAVE_AFROSE */ |
/trunk/uclinux/userland/route/lib/ppp_ac.c
0,0 → 1,42
/* |
* lib/ppp_ac.c This file contains the activation for the |
* PPP line disciplines, called from activate_ld(). |
* |
* Version: $Id: ppp_ac.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels |
* |
* 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_HWPPP |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
/* Start the VJ-SLIP encapsulation on the file descriptor. */ |
int PPP_activate(int fd) |
{ |
fprintf(stderr, _("Sorry, use pppd!\n")); /* FIXME */ |
return (-1); |
} |
|
#endif /* HAVE_HWPPP */ |
/trunk/uclinux/userland/route/lib/inet_sr.c
0,0 → 1,327
/* |
Modifications: |
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets |
*/ |
|
#include "config.h" |
|
#if HAVE_AFINET |
#include <asm/types.h> |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
#ifdef EMBED |
#include <gnu/types.h> |
#include <asm/atomic.h> |
#include <linux/if_arp.h> |
#include <linux/route.h> |
#else |
#include <net/route.h> /* realy broken */ |
#endif |
#include <sys/ioctl.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" |
#include "intl.h" |
#include "net-features.h" |
#include "util.h" |
|
#if HAVE_NEW_ADDRT |
#define mask_in_addr(x) (((struct sockaddr_in *)&((x).rt_genmask))->sin_addr.s_addr) |
#define full_mask(x) (x) |
#else |
#define mask_in_addr(x) ((x).rt_genmask) |
#define full_mask(x) (((struct sockaddr_in *)&(x))->sin_addr.s_addr) |
#endif |
|
extern struct aftype inet_aftype; |
|
static int skfd = -1; |
|
|
static int usage(void) |
{ |
fprintf(stderr, _("Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]\n")); |
fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]\n")); |
fprintf(stderr, _(" [netmask N] [mss Mss] [window W] [irtt I]\n")); |
fprintf(stderr, _(" [mod] [dyn] [reinstate] [[dev] If]\n")); |
fprintf(stderr, _(" inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject\n")); |
fprintf(stderr, _(" inet_route [-FC] flush NOT supported\n")); |
return (E_USAGE); |
} |
|
static int INET_setroute(int action, int options, char **args) |
{ |
struct rtentry rt; |
char target[128], gateway[128] = "NONE", netmask[128] = "default"; |
int xflag, isnet; |
|
xflag = 0; |
|
if (!strcmp(*args, "#net")) { |
xflag = 1; |
args++; |
} else if (!strcmp(*args, "#host")) { |
xflag = 2; |
args++; |
} |
if (*args == NULL) |
return (usage()); |
|
safe_strncpy(target, *args++, (sizeof target)); |
|
/* Clean out the RTREQ structure. */ |
memset((char *) &rt, 0, sizeof(struct rtentry)); |
|
/* Special hack for /prefix syntax */ |
{ |
union { |
struct sockaddr_in m; |
struct sockaddr d; |
} mask; |
int n; |
|
n = inet_aftype.getmask(target, &mask.d, netmask); |
if (n < 0) |
return usage(); |
else if (n) |
rt.rt_genmask = full_mask(mask.d); |
} |
|
if ((isnet = inet_aftype.input(0, target, &rt.rt_dst)) < 0) { |
inet_aftype.herror(target); |
return (1); |
} |
switch (xflag) { |
case 1: |
isnet = 1; |
break; |
|
case 2: |
isnet = 0; |
break; |
|
default: |
break; |
} |
|
/* Fill in the other fields. */ |
rt.rt_flags = (RTF_UP | RTF_HOST); |
if (isnet) |
rt.rt_flags &= ~RTF_HOST; |
|
while (*args) { |
if (!strcmp(*args, "metric")) { |
int metric; |
|
args++; |
if (!*args || !isdigit(**args)) |
return (usage()); |
metric = atoi(*args); |
#if HAVE_NEW_ADDRT |
rt.rt_metric = metric + 1; |
#else |
ENOSUPP("inet_setroute", "NEW_ADDRT (metric)"); |
#endif |
args++; |
continue; |
} |
if (!strcmp(*args, "netmask")) { |
struct sockaddr mask; |
|
args++; |
if (!*args || mask_in_addr(rt)) |
return (usage()); |
safe_strncpy(netmask, *args, (sizeof netmask)); |
if ((isnet = inet_aftype.input(0, netmask, &mask)) < 0) { |
inet_aftype.herror(netmask); |
return (E_LOOKUP); |
} |
rt.rt_genmask = full_mask(mask); |
args++; |
continue; |
} |
if (!strcmp(*args, "gw") || !strcmp(*args, "gateway")) { |
args++; |
if (!*args) |
return (usage()); |
if (rt.rt_flags & RTF_GATEWAY) |
return (usage()); |
safe_strncpy(gateway, *args, (sizeof gateway)); |
if ((isnet = inet_aftype.input(0, gateway, &rt.rt_gateway)) < 0) { |
inet_aftype.herror(gateway); |
return (E_LOOKUP); |
} |
if (isnet) { |
fprintf(stderr, _("route: %s: cannot use a NETWORK as gateway!\n"), |
gateway); |
return (E_OPTERR); |
} |
rt.rt_flags |= RTF_GATEWAY; |
args++; |
continue; |
} |
if (!strcmp(*args, "mss")) { |
args++; |
rt.rt_flags |= RTF_MSS; |
if (!*args) |
return (usage()); |
rt.rt_mss = atoi(*args); |
args++; |
if (rt.rt_mss < 64 || rt.rt_mss > 32768) { |
fprintf(stderr, _("route: Invalid MSS.\n")); |
return (E_OPTERR); |
} |
continue; |
} |
if (!strcmp(*args, "window")) { |
args++; |
if (!*args) |
return (usage()); |
rt.rt_flags |= RTF_WINDOW; |
rt.rt_window = atoi(*args); |
args++; |
if (rt.rt_window < 128) { |
fprintf(stderr, _("route: Invalid window.\n")); |
return (E_OPTERR); |
} |
continue; |
} |
if (!strcmp(*args, "irtt")) { |
args++; |
if (!*args) |
return (usage()); |
args++; |
#if HAVE_RTF_IRTT |
rt.rt_flags |= RTF_IRTT; |
rt.rt_irtt = atoi(*(args - 1)); |
rt.rt_irtt *= (HZ / 100); /* FIXME */ |
#if 0 /* FIXME: do we need to check anything of this? */ |
if (rt.rt_irtt < 1 || rt.rt_irtt > (120 * HZ)) { |
fprintf(stderr, _("route: Invalid initial rtt.\n")); |
return (E_OPTERR); |
} |
#endif |
#else |
ENOSUPP("inet_setroute", "RTF_IRTT"); |
#endif |
continue; |
} |
if (!strcmp(*args, "reject")) { |
args++; |
#if HAVE_RTF_REJECT |
rt.rt_flags |= RTF_REJECT; |
#else |
ENOSUPP("inet_setroute", "RTF_REJECT"); |
#endif |
continue; |
} |
if (!strcmp(*args, "mod")) { |
args++; |
rt.rt_flags |= RTF_MODIFIED; |
continue; |
} |
if (!strcmp(*args, "dyn")) { |
args++; |
rt.rt_flags |= RTF_DYNAMIC; |
continue; |
} |
if (!strcmp(*args, "reinstate")) { |
args++; |
rt.rt_flags |= RTF_REINSTATE; |
continue; |
} |
if (!strcmp(*args, "device") || !strcmp(*args, "dev")) { |
args++; |
if (rt.rt_dev || *args == NULL) |
return usage(); |
rt.rt_dev = *args++; |
continue; |
} |
/* nothing matches */ |
if (!rt.rt_dev) { |
rt.rt_dev = *args++; |
if (*args) |
return usage(); /* must be last to catch typos */ |
} else |
return usage(); |
} |
|
#if HAVE_RTF_REJECT |
if ((rt.rt_flags & RTF_REJECT) && !rt.rt_dev) |
rt.rt_dev = "lo"; |
#endif |
|
/* sanity checks.. */ |
if (mask_in_addr(rt)) { |
__u32 mask = ~ntohl(mask_in_addr(rt)); |
if ((rt.rt_flags & RTF_HOST) && mask != 0xffffffff) { |
fprintf(stderr, _("route: netmask %.8x doesn't make sense with host route\n"), mask); |
return (E_OPTERR); |
} |
if (mask & (mask + 1)) { |
fprintf(stderr, _("route: bogus netmask %s\n"), netmask); |
return (E_OPTERR); |
} |
mask = ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr; |
if (mask & ~mask_in_addr(rt)) { |
fprintf(stderr, _("route: netmask doesn't match route address\n")); |
return (E_OPTERR); |
} |
} |
/* Fill out netmask if still unset */ |
if ((action == RTACTION_ADD) && rt.rt_flags & RTF_HOST) |
mask_in_addr(rt) = 0xffffffff; |
|
/* Create a socket to the INET kernel. */ |
if ((skfd = socket(AF_INET, SOCK_DGRAM, 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 INET_rinput(int action, int options, char **args) |
{ |
if (action == RTACTION_FLUSH) { |
fprintf(stderr, _("Flushing `inet' routing table not supported\n")); |
return (usage()); |
} |
if (options & FLAG_CACHE) { |
fprintf(stderr, _("Modifying `inet' routing cache not supported\n")); |
return (usage()); |
} |
if ((*args == NULL) || (action == RTACTION_HELP)) |
return (usage()); |
|
return (INET_setroute(action, options, args)); |
} |
#endif /* HAVE_AFINET */ |
/trunk/uclinux/userland/route/lib/proc.c
0,0 → 1,74
/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */ |
/* $Id: proc.c,v 1.1 2002-03-17 19:58:53 simons Exp $ */ |
/* Fixme: cannot currently cope with removed fields */ |
|
#include <string.h> |
#include <stdarg.h> |
#include <stdio.h> |
#include <ctype.h> |
|
/* Caller must free return string. */ |
|
char *proc_gen_fmt(char *name, int more, FILE * fh,...) |
{ |
char buf[512], format[512] = ""; |
char *title, *head, *hdr; |
va_list ap; |
|
if (!fgets(buf, (sizeof buf) - 1, fh)) |
return NULL; |
strcat(buf, " "); |
|
va_start(ap, fh); |
title = va_arg(ap, char *); |
for (hdr = buf; hdr;) { |
while (isspace(*hdr) || *hdr == '|') |
hdr++; |
head = hdr; |
hdr = strpbrk(hdr, "| \t\n"); |
if (hdr) |
*hdr++ = 0; |
|
if (!strcmp(title, head)) { |
strcat(format, va_arg(ap, char *)); |
title = va_arg(ap, char *); |
if (!title || !head) |
break; |
} else { |
strcat(format, "%*s"); /* XXX */ |
} |
strcat(format, " "); |
} |
va_end(ap); |
|
if (!more && title) { |
fprintf(stderr, "warning: %s does not contain required field %s\n", |
name, title); |
return NULL; |
} |
return strdup(format); |
} |
|
/* |
* this will generate a bitmask of present/missing fields in the header of |
* a /proc file. |
*/ |
int proc_guess_fmt(char *name, FILE *fh, ...) |
{ |
char buf[512]; |
char *tmp; |
int flag = 0; |
va_list ap; |
|
if (!fgets(buf, (sizeof buf) - 1, fh)) |
return -1; |
strcat(buf, "\0"); |
va_start(ap, fh); |
while((tmp = va_arg(ap, char *))) { |
int f = va_arg(ap, int); |
if (strstr(buf,tmp) != 0) |
flag |= f; |
} |
va_end(ap); |
return flag; |
} |
/trunk/uclinux/userland/route/lib/ipx_sr.c
0,0 → 1,36
#include "config.h" |
|
#if HAVE_AFIPX |
#include <sys/param.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.h> |
#include <sys/ioctl.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" |
#include "intl.h" |
|
#include "net-features.h" |
|
extern struct aftype ipx_aftype; |
|
/* static int skfd = -1; */ |
|
int IPX_rinput(int action, int ext, char **args) |
{ |
|
fprintf(stderr, _("IPX: this needs to be written\n")); |
return (0); |
} |
#endif /* HAVE_AFIPX */ |
/trunk/uclinux/userland/route/lib/fddi.c
0,0 → 1,154
/* |
* lib/fddi.c This file contains an implementation of the "FDDI" |
* support functions. |
* |
* Version: $Id: fddi.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Lawrence V. Stefani, <stefani@lkg.dec.com> |
* |
* 1998-07-01 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> GNU gettext |
* |
* 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" |
|
#include <features.h> |
|
#if HAVE_HWFDDI |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#ifndef ARPHRD_FDDI |
#error "No FDDI Support in your current Kernelsource Tree." |
#error "Disable HW Type FDDI" |
#endif |
#if __GLIBC__ >= 2 |
#include <netinet/if_fddi.h> |
#else |
#include <linux/if_fddi.h> |
#endif |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
extern struct hwtype fddi_hwtype; |
|
|
/* Display an FDDI address in readable format. */ |
static char *pr_fddi(unsigned char *ptr) |
{ |
static char buff[64]; |
|
snprintf(buff, sizeof(buff), "%02X-%02X-%02X-%02X-%02X-%02X", |
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
); |
return (buff); |
} |
|
|
/* Display an FDDI socket address. */ |
static char *pr_sfddi(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (pr_fddi(sap->sa_data)); |
} |
|
|
/* Input an FDDI address and convert to binary. */ |
static int in_fddi(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char c, *orig; |
int i, val; |
|
sap->sa_family = fddi_hwtype.type; |
ptr = sap->sa_data; |
|
i = 0; |
orig = bufp; |
while ((*bufp != '\0') && (i < FDDI_K_ALEN)) { |
val = 0; |
c = *bufp++; |
if (isdigit(c)) |
val = c - '0'; |
else if (c >= 'a' && c <= 'f') |
val = c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val = c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
val <<= 4; |
c = *bufp++; |
if (isdigit(c)) |
val |= c - '0'; |
else if (c >= 'a' && c <= 'f') |
val |= c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val |= c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_fddi(%s): invalid fddi address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) (val & 0377); |
i++; |
|
/* We might get a semicolon here - not required. */ |
if (*bufp == ':') { |
if (i == FDDI_K_ALEN) { |
#ifdef DEBUG |
fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"), |
orig) |
#endif |
; /* nothing */ |
} |
bufp++; |
} |
} |
|
/* That's it. Any trailing junk? */ |
if ((i == FDDI_K_ALEN) && (*bufp != '\0')) { |
#ifdef DEBUG |
fprintf(stderr, _("in_fddi(%s): trailing junk!\n"), orig); |
errno = EINVAL; |
return (-1); |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data)); |
#endif |
|
return (0); |
} |
|
|
struct hwtype fddi_hwtype = |
{ |
"fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)", */ ARPHRD_FDDI, FDDI_K_ALEN, |
pr_fddi, pr_sfddi, in_fddi, NULL |
}; |
|
|
#endif /* HAVE_HWFDDI */ |
/trunk/uclinux/userland/route/lib/proc.h
0,0 → 1,5
|
|
/* Generate a suitable scanf format for a column title line */ |
char *proc_gen_fmt(char *name, int more, FILE * fh,...); |
int proc_guess_fmt(char *name, FILE* fh,...); |
/trunk/uclinux/userland/route/lib/rose.c
0,0 → 1,155
/* |
* lib/rose.c This file contains an implementation of the "ROSE" |
* support functions for the NET-2 base distribution. |
* |
* Version: $Id: rose.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au> |
* based on ax25.c by: |
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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_AFROSE || HAVE_HWROSE |
#include <features.h> |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> /* ARPHRD_ROSE */ |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
#ifndef _NETROSE_ROSE_H |
#include <linux/ax25.h> |
#include <linux/rose.h> |
/* this will check for the broken #define PF_ROSE AF_ROSE define in some older kernel headers */ |
#undef AF_ROSE |
#if PF_ROSE == AF_ROSE |
#warning "Your <linux/rose.h> is broken and defines PF_ROSE, better remove the define in /usr/include/linux/rose.h (using private define for PF_ROSE meanwhile)" |
#undef PF_ROSE |
#define PF_ROSE 11 /* Amateur Radio X.25 PLP */ |
#endif |
/* now restore the value of AF_ROSE (which had to be deleted to catch the case where #define AF_ROSE PF_ROSE) */ |
#define AF_ROSE PF_ROSE |
#endif |
|
static char ROSE_errmsg[128]; |
|
extern struct aftype rose_aftype; |
|
static char * |
ROSE_print(unsigned char *ptr) |
{ |
static char buff[12]; |
|
snprintf(buff, sizeof(buff), "%02x%02x%02x%02x%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]); |
buff[10] = '\0'; |
return (buff); |
} |
|
/* Display a ROSE socket address. */ |
static char * |
ROSE_sprint(struct sockaddr *sap, int numeric) |
{ |
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return _("[NONE SET]"); |
|
return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr)); |
} |
|
|
static int ROSE_input(int type, char *bufp, struct sockaddr *sap) |
{ |
char *ptr; |
int i, o; |
|
sap->sa_family = rose_aftype.af; |
ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr; |
|
/* Node address the correct length ? */ |
if (strlen(bufp) != 10) { |
strcpy(ROSE_errmsg, _("Node address must be ten digits")); |
#ifdef DEBUG |
fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
/* Ok, lets set it */ |
for (i = 0, o = 0; i < 5; i++) { |
o = i * 2; |
ptr[i] = (((bufp[o] - '0') << 4) | (bufp[o + 1] - '0')); |
} |
|
/* All done. */ |
#ifdef DEBUG |
fprintf(stderr, "rose_input(%s): ", orig); |
for (i = 0; i < sizeof(rose_address); i++) |
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); |
fprintf(stderr, "\n"); |
#endif |
|
return (0); |
} |
|
|
/* Display an error message. */ |
static void ROSE_herror(char *text) |
{ |
if (text == NULL) |
fprintf(stderr, "%s\n", ROSE_errmsg); |
else |
fprintf(stderr, "%s: %s\n", text, ROSE_errmsg); |
} |
|
|
static char * |
ROSE_hprint(struct sockaddr *sap) |
{ |
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return _("[NONE SET]"); |
|
return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr)); |
} |
|
|
static int ROSE_hinput(char *bufp, struct sockaddr *sap) |
{ |
if (ROSE_input(0, bufp, sap) < 0) |
return (-1); |
sap->sa_family = ARPHRD_ROSE; |
return (0); |
} |
|
struct hwtype rose_hwtype = |
{ |
"rose", NULL, /*"AMPR ROSE", */ ARPHRD_ROSE, 10, |
ROSE_print, ROSE_hprint, ROSE_hinput, NULL |
}; |
|
struct aftype rose_aftype = |
{ |
"rose", NULL, /*"AMPR ROSE", */ AF_ROSE, 10, |
ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror, |
NULL, NULL, NULL, |
-1, |
"/proc/net/rose" |
}; |
|
#endif /* HAVE_xxROSE */ |
/trunk/uclinux/userland/route/lib/ash.c
0,0 → 1,108
/* |
* lib/ash.c This file contains an implementation of the Ash |
* support functions for the NET-2 base distribution. |
* $Id: ash.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
*/ |
|
#include "config.h" |
|
#if HAVE_HWASH |
|
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
#ifndef ARPHRD_ASH |
#warning "No definition of ARPHRD_ASH in <net/if_arp.h>, using private value 517" |
#define ARPHRD_ASH 517 |
#endif |
|
#define ASH_ALEN 64 |
|
extern struct hwtype ash_hwtype; |
|
/* Display an Ash address in readable format. */ |
static char *pr_ash(unsigned char *ptr) |
{ |
static char buff[128]; |
char *p = buff; |
unsigned int i = 0; |
|
p[0] = '['; |
p++; |
while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN)) |
sprintf(p++, "%1x", ptr[i++]); |
*(p++) = ']'; |
*p = 0; |
|
return buff; |
} |
|
/* Display an Ash socket address. */ |
static char *pr_sash(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, "[NONE SET]", 64); |
return pr_ash(sap->sa_data); |
} |
|
static unsigned char hamming[16] = |
{ |
0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f, |
0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea |
}; |
|
|
static int in_ash(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
unsigned int i = 0; |
|
sap->sa_family = ash_hwtype.type; |
ptr = sap->sa_data; |
|
while (bufp && i < ASH_ALEN) { |
char *next; |
int hop = strtol(bufp, &next, 16); |
ptr[i++] = hamming[hop]; |
switch (*next) { |
case ':': |
bufp = next + 1; |
break; |
case 0: |
bufp = NULL; |
break; |
default: |
fprintf(stderr, _("Malformed Ash address")); |
memset(ptr, 0xc9, ASH_ALEN); |
return -1; |
} |
} |
|
while (i < ASH_ALEN) |
ptr[i++] = 0xc9; |
|
return 0; |
} |
|
|
struct hwtype ash_hwtype = |
{ |
"ash", NULL, ARPHRD_ASH, ASH_ALEN, |
pr_ash, pr_sash, in_ash, NULL, |
1 |
}; |
|
#endif |
/trunk/uclinux/userland/route/lib/masq_info.c
0,0 → 1,210
/* |
* lib/masq_info.c This file contains a the functio masq_info |
* to print a table of current masquerade connections. |
* |
* NET-LIB A collection of functions used from the base set of the |
* NET-3 Networking Distribution for the LINUX operating |
* system. (net-tools, net-drivers) |
* |
* Version: $Id: masq_info.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd 'eckes' Eckenfels <net-tools@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* |
* Modifications: |
* |
*960217 {0.01} Bernd Eckenfels: creatin from the code of |
* Jos Vos' ipfwadm 2.0beta1 |
*950218 {0.02} Bernd Eckenfels: <linux/if.h> added |
* |
*980405 {0.03} Arnaldo Carvalho: i18n CATGETS -> gettext |
* |
* 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 <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <errno.h> |
#include <stdio.h> |
#include <malloc.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "version.h" |
#include "config.h" |
#include "intl.h" |
#include "net-features.h" |
|
#if HAVE_FW_MASQUERADE |
|
struct masq { |
unsigned long expires; /* Expiration timer */ |
char *proto; /* Which protocol are we talking? */ |
struct sockaddr_in src, dst; /* Source and destination IP addresses */ |
unsigned short sport, dport; /* Source and destination ports */ |
unsigned short mport; /* Masqueraded port */ |
unsigned long initseq; /* Add delta from this seq. on */ |
short delta; /* Delta in sequence numbers */ |
short pdelta; /* Delta in sequence numbers before last */ |
}; |
|
static struct aftype *ap; /* current address family */ |
static int has_pdelta; |
|
static void print_masq(struct masq *ms, int numeric, int ext) |
{ |
unsigned long minutes, seconds, sec100s; |
|
printf("%-4s", ms->proto); |
|
sec100s = ms->expires % 100L; |
seconds = (ms->expires / 100L) % 60; |
minutes = ms->expires / 6000L; |
|
printf("%3ld:%02ld.%02ld ", minutes, seconds, sec100s); |
|
if (ext > 1) { |
if (has_pdelta) |
printf("%10lu %5hd %5hd ", ms->initseq, |
ms->delta, ms->pdelta); |
else |
printf("%10lu %5hd - ", ms->initseq, |
ms->delta); |
} |
printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->src), numeric)); |
printf("%-20s ", ap->sprint((struct sockaddr *) &(ms->dst), numeric)); |
|
printf("%s -> ", get_sname(ms->sport, ms->proto, numeric)); |
printf("%s", get_sname(ms->dport, ms->proto, numeric)); |
printf(" (%s)\n", get_sname(ms->mport, ms->proto, numeric)); |
} |
|
|
static int read_masqinfo(FILE * f, struct masq *mslist, int nmslist) |
{ |
int n, nread = 0; |
struct masq *ms; |
char buf[256]; |
|
for (nread = 0; nread < nmslist; nread++) { |
ms = &mslist[nread]; |
if (has_pdelta) { |
if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %hd %lu", |
buf, |
(unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, |
(unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, |
&ms->mport, &ms->initseq, &ms->delta, |
&ms->pdelta, &ms->expires)) == -1) |
return nread; |
} else { |
if ((n = fscanf(f, " %s %lX:%hX %lX:%hX %hX %lX %hd %lu", |
buf, |
(unsigned long *) &ms->src.sin_addr.s_addr, &ms->sport, |
(unsigned long *) &ms->dst.sin_addr.s_addr, &ms->dport, |
&ms->mport, &ms->initseq, &ms->delta, |
&ms->expires)) == -1) |
return nread; |
} |
if ((has_pdelta && (n != 10)) || (!has_pdelta && (n != 9))) { |
EINTERN("masq_info.c", "ip_masquerade format error"); |
return (-1); |
} |
ms->src.sin_family = AF_INET; |
ms->dst.sin_family = AF_INET; |
|
if (strcmp("TCP", buf) == 0) |
ms->proto = "tcp"; |
else if (strcmp("UDP", buf) == 0) |
ms->proto = "udp"; |
else if (strcmp("ICMP", buf) == 0) |
ms->proto = "icmp"; |
else { |
EINTERN("masq_info.c", "ip_masquerade unknown type"); |
return (-1); |
} |
|
/* we always keep these addresses in network byte order */ |
ms->src.sin_addr.s_addr = htonl(ms->src.sin_addr.s_addr); |
ms->dst.sin_addr.s_addr = htonl(ms->dst.sin_addr.s_addr); |
ms->sport = htons(ms->sport); |
ms->dport = htons(ms->dport); |
ms->mport = htons(ms->mport); |
} |
return nread; |
} |
|
|
int ip_masq_info(int numeric, int ext) |
{ |
FILE *f; |
int i; |
char buf[256]; |
struct masq *mslist; |
int ntotal = 0, nread; |
|
if (!(f = fopen(_PATH_PROCNET_IP_MASQ, "r"))) { |
if (errno != ENOENT) { |
perror(_PATH_PROCNET_IP_MASQ); |
return (-1); |
} |
ESYSNOT("netstat", "ip_masquerade"); |
return (1); |
} |
if ((ap = get_aftype("inet")) == NULL) { |
ENOSUPP("masq_info", "AF INET"); |
fclose(f); |
return (-1); |
} |
fgets(buf, sizeof(buf), f); |
has_pdelta = strstr(buf, "PDelta") ? 1 : 0; |
|
mslist = (struct masq *) malloc(16 * sizeof(struct masq)); |
if (!mslist) { |
EINTERN("masq_info", "malloc() failed"); |
fclose(f); |
return (-1); |
} |
while ((nread = read_masqinfo(f, &(mslist[ntotal]), 16)) == 16) { |
ntotal += nread; |
mslist = (struct masq *) realloc(mslist, |
(ntotal + 16) * sizeof(struct masq)); |
if (!mslist) { |
EINTERN("masq_info", "realloc() failed"); |
fclose(f); |
return (-1); |
} |
} |
fclose(f); |
|
if (nread < 0) { |
if (mslist) |
free(mslist); |
return (-1); |
} |
ntotal += nread; |
|
if (ntotal > 0) { |
printf(_("IP masquerading entries\n")); |
switch (ext) { |
case 1: |
printf(_("prot expire source destination ports\n")); |
break; |
default: |
printf(_("prot expire initseq delta prevd source destination ports\n")); |
break; |
} |
for (i = 0; i < ntotal; i++) |
print_masq(&(mslist[i]), numeric, ext); |
if (mslist) |
free(mslist); |
|
} |
return 0; |
} |
#endif |
/trunk/uclinux/userland/route/lib/arcnet.c
0,0 → 1,140
/* |
* lib/arcnet.c This file contains an implementation of the "ARCnet" |
* support functions for the NET-2 base distribution. |
* |
* Version: $Id: arcnet.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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_HWARC |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <linux/if_ether.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
extern struct hwtype arcnet_hwtype; |
|
|
/* Display an ARCnet address in readable format. */ |
static char *pr_arcnet(unsigned char *ptr) |
{ |
static char buff[64]; |
|
snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377)); |
return (buff); |
} |
|
|
/* Display an ARCnet socket address. */ |
static char *pr_sarcnet(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (pr_arcnet(sap->sa_data)); |
} |
|
|
/* Input an ARCnet address and convert to binary. */ |
static int in_arcnet(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char c, *orig; |
int i, val; |
|
sap->sa_family = arcnet_hwtype.type; |
ptr = sap->sa_data; |
|
i = 0; |
orig = bufp; |
while ((*bufp != '\0') && (i < 1)) { |
val = 0; |
c = *bufp++; |
if (isdigit(c)) |
val = c - '0'; |
else if (c >= 'a' && c <= 'f') |
val = c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val = c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
val <<= 4; |
c = *bufp++; |
if (isdigit(c)) |
val |= c - '0'; |
else if (c >= 'a' && c <= 'f') |
val |= c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val |= c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) (val & 0377); |
i++; |
|
/* We might get a semicolon here - not required. */ |
if (*bufp == ':') { |
if (i == ETH_ALEN) { |
#ifdef DEBUG |
fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"), |
orig) |
#endif |
; /* nothing */ |
} |
bufp++; |
} |
} |
|
/* That's it. Any trailing junk? */ |
if ((i == ETH_ALEN) && (*bufp != '\0')) { |
#ifdef DEBUG |
fprintf(stderr, _("in_arcnet(%s): trailing junk!\n"), orig); |
errno = EINVAL; |
return (-1); |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data)); |
#endif |
|
return (0); |
} |
|
|
struct hwtype arcnet_hwtype = |
{ |
"arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1, |
pr_arcnet, pr_sarcnet, in_arcnet, NULL |
}; |
|
|
#endif /* HAVE_HWARC */ |
/trunk/uclinux/userland/route/lib/econet.c
0,0 → 1,85
/* |
* lib/econet.c This file contains an implementation of the Econet |
* support functions for the net-tools. |
* (NET-3 base distribution). |
* |
* Version: $Id: econet.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Philip Blundell <philb@gnu.org> |
* |
* Modified: |
* |
* 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_AFECONET |
|
#include <sys/types.h> |
#include <sys/socket.h> |
#include <stdio.h> |
#include <neteconet/ec.h> |
|
#include "version.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
|
/* Display an Econet address */ |
static char * |
ec_print(unsigned char *ptr) |
{ |
static char buff[64]; |
struct ec_addr *ec = (struct ec_addr *) ptr; |
sprintf(buff, "%d.%d", ec->net, ec->station); |
return buff; |
} |
|
|
/* Display an Econet socket address */ |
static char * |
ec_sprint(struct sockaddr *sap, int numeric) |
{ |
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; |
|
if (sap->sa_family != AF_ECONET) |
return _("[NONE SET]"); |
|
return ec_print((unsigned char *) &sec->addr); |
} |
|
static int ec_input(int type, char *bufp, struct sockaddr *sap) |
{ |
struct sockaddr_ec *sec = (struct sockaddr_ec *) sap; |
int net, stn; |
switch (sscanf(bufp, "%d.%d", &net, &stn)) { |
case 2: |
sec->addr.station = stn; |
sec->addr.net = net; |
return 0; |
case 1: |
if (sscanf(bufp, "%d", &stn) == 1) { |
sec->addr.net = 0; |
sec->addr.station = stn; |
return 0; |
} |
} |
return -1; |
} |
|
struct aftype ec_aftype = |
{ |
"ec", NULL, AF_ECONET, 0, |
ec_print, ec_sprint, ec_input, NULL, |
NULL, NULL, NULL, |
-1, |
"/proc/sys/net/econet" |
}; |
|
#endif /* HAVE_AFECONET */ |
/trunk/uclinux/userland/route/lib/hw.c
0,0 → 1,258
/* |
* lib/hw.c This file contains the top-level part of the hardware |
* support functions module. |
* |
* Version: $Id: hw.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
*980701 {1.21} Arnaldo C. Melo GNU gettext instead of catgets |
* |
* 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 <sys/types.h> |
#include <sys/socket.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "config.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
extern struct hwtype unspec_hwtype; |
extern struct hwtype loop_hwtype; |
|
extern struct hwtype slip_hwtype; |
extern struct hwtype cslip_hwtype; |
extern struct hwtype slip6_hwtype; |
extern struct hwtype cslip6_hwtype; |
extern struct hwtype adaptive_hwtype; |
|
extern struct hwtype ether_hwtype; |
extern struct hwtype fddi_hwtype; |
extern struct hwtype hippi_hwtype; |
extern struct hwtype tr_hwtype; |
|
extern struct hwtype ax25_hwtype; |
extern struct hwtype rose_hwtype; |
extern struct hwtype netrom_hwtype; |
extern struct hwtype tunnel_hwtype; |
|
extern struct hwtype ash_hwtype; |
|
extern struct hwtype ppp_hwtype; |
|
extern struct hwtype arcnet_hwtype; |
|
extern struct hwtype dlci_hwtype; |
extern struct hwtype frad_hwtype; |
|
extern struct hwtype hdlc_hwtype; |
extern struct hwtype lapb_hwtype; |
|
extern struct hwtype sit_hwtype; |
|
extern struct hwtype irda_hwtype; |
|
static struct hwtype *hwtypes[] = |
{ |
|
&loop_hwtype, |
|
#if HAVE_HWSLIP |
&slip_hwtype, |
&cslip_hwtype, |
&slip6_hwtype, |
&cslip6_hwtype, |
&adaptive_hwtype, |
#endif |
#if HAVE_HWASH |
&ash_hwtype, |
#endif |
#if HAVE_HWETHER |
ðer_hwtype, |
#endif |
#if HAVE_HWTR |
&tr_hwtype, |
#endif |
#if HAVE_HWAX25 |
&ax25_hwtype, |
#endif |
#if HAVE_HWNETROM |
&netrom_hwtype, |
#endif |
#if HAVE_HWROSE |
&rose_hwtype, |
#endif |
#if HAVE_HWTUNNEL |
&tunnel_hwtype, |
#endif |
#if HAVE_HWPPP |
&ppp_hwtype, |
#endif |
#if HAVE_HWHDLCLAPB |
&hdlc_hwtype, |
&lapb_hwtype, |
#endif |
#if HAVE_HWARC |
&arcnet_hwtype, |
#endif |
#if HAVE_HWFR |
&dlci_hwtype, |
&frad_hwtype, |
#endif |
#if HAVE_HWSIT |
&sit_hwtype, |
#endif |
#if HAVE_HWFDDI |
&fddi_hwtype, |
#endif |
#if HAVE_HWHIPPI |
&hippi_hwtype, |
#endif |
#if HAVE_HWIRDA |
&irda_hwtype, |
#endif |
&unspec_hwtype, |
NULL |
}; |
|
static short sVhwinit = 0; |
|
void hwinit() |
{ |
loop_hwtype.title = _("Local Loopback"); |
unspec_hwtype.title = _("UNSPEC"); |
#if HAVE_HWSLIP |
slip_hwtype.title = _("Serial Line IP"); |
cslip_hwtype.title = _("VJ Serial Line IP"); |
slip6_hwtype.title = _("6-bit Serial Line IP"); |
cslip6_hwtype.title = _("VJ 6-bit Serial Line IP"); |
adaptive_hwtype.title = _("Adaptive Serial Line IP"); |
#endif |
#if HAVE_HWETHER |
ether_hwtype.title = _("Ethernet"); |
#endif |
#if HAVE_HWASH |
ash_hwtype.title = _("Ash"); |
#endif |
#if HAVE_HWFDDI |
fddi_hwtype.title = _("Fiber Distributed Data Interface"); |
#endif |
#if HAVE_HWHIPPI |
hippi_hwtype.title = _("HIPPI"); |
#endif |
#if HAVE_HWAX25 |
ax25_hwtype.title = _("AMPR AX.25"); |
#endif |
#if HAVE_HWROSE |
rose_hwtype.title = _("AMPR ROSE"); |
#endif |
#if HAVE_HWNETROM |
netrom_hwtype.title = _("AMPR NET/ROM"); |
#endif |
#if HAVE_HWTUNNEL |
tunnel_hwtype.title = _("IPIP Tunnel"); |
#endif |
#if HAVE_HWPPP |
ppp_hwtype.title = _("Point-to-Point Protocol"); |
#endif |
#if HAVE_HWHDLCLAPB |
hdlc_hwtype.title = _("(Cisco)-HDLC"); |
lapb_hwtype.title = _("LAPB"); |
#endif |
#if HAVE_HWARC |
arcnet_hwtype.title = _("ARCnet"); |
#endif |
#if HAVE_HWFR |
dlci_hwtype.title = _("Frame Relay DLCI"); |
frad_hwtype.title = _("Frame Relay Access Device"); |
#endif |
#if HAVE_HWSIT |
sit_hwtype.title = _("IPv6-in-IPv4"); |
#endif |
#if HAVE_HWIRDA |
irda_hwtype.title = _("IrLAP"); |
#endif |
sVhwinit = 1; |
} |
|
/* Check our hardware type table for this type. */ |
struct hwtype *get_hwtype(const char *name) |
{ |
struct hwtype **hwp; |
|
if (!sVhwinit) |
hwinit(); |
|
hwp = hwtypes; |
while (*hwp != NULL) { |
if (!strcmp((*hwp)->name, name)) |
return (*hwp); |
hwp++; |
} |
return (NULL); |
} |
|
|
/* Check our hardware type table for this type. */ |
struct hwtype *get_hwntype(int type) |
{ |
struct hwtype **hwp; |
|
if (!sVhwinit) |
hwinit(); |
|
hwp = hwtypes; |
while (*hwp != NULL) { |
if ((*hwp)->type == type) |
return (*hwp); |
hwp++; |
} |
return (NULL); |
} |
|
/* type: 0=all, 1=ARPable */ |
void print_hwlist(int type) { |
int count = 0; |
char * txt; |
struct hwtype **hwp; |
|
if (!sVhwinit) |
hwinit(); |
|
hwp = hwtypes; |
while (*hwp != NULL) { |
if (((type == 1) && ((*hwp)->alen == 0)) || ((*hwp)->type == -1)) { |
hwp++; continue; |
} |
if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); |
txt = (*hwp)->name; if (!txt) txt = ".."; |
fprintf(stderr,"%s (%s) ",txt,(*hwp)->title); |
count++; |
hwp++; |
} |
fprintf(stderr,"\n"); |
} |
|
/* return 1 if address is all zeros */ |
int hw_null_address(struct hwtype *hw, void *ap) |
{ |
unsigned int i; |
unsigned char *address = (unsigned char *)ap; |
for (i = 0; i < hw->alen; i++) |
if (address[i]) |
return 0; |
return 1; |
} |
/trunk/uclinux/userland/route/lib/ax25.c
0,0 → 1,208
/* |
* lib/ax25.c This file contains an implementation of the "AX.25" |
* support functions. |
* |
* Version: $Id: ax25.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* NOTE: I will redo this module as soon as I got the libax25.a |
* library sorted out. This library contains some useful |
* and often used address conversion functions, database |
* lookup stuff, and more of the like. |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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_AFAX25 || HAVE_HWAX25 |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1) |
#include <netax25/ax25.h> |
#else |
#include <linux/ax25.h> |
#endif |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
static char AX25_errmsg[128]; |
|
extern struct aftype ax25_aftype; |
|
static char *AX25_print(unsigned char *ptr) |
{ |
static char buff[8]; |
int i; |
|
for (i = 0; i < 6; i++) { |
buff[i] = ((ptr[i] & 0377) >> 1); |
if (buff[i] == ' ') |
buff[i] = '\0'; |
} |
buff[6] = '\0'; |
i = ((ptr[6] & 0x1E) >> 1); |
if (i != 0) |
sprintf(&buff[strlen(buff)], "-%d", i); |
return (buff); |
} |
|
|
/* Display an AX.25 socket address. */ |
static char * |
AX25_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); |
} |
|
|
static int AX25_input(int type, char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char *orig, c; |
int i; |
|
sap->sa_family = ax25_aftype.af; |
ptr = ((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call; |
|
/* First, scan and convert the basic callsign. */ |
orig = bufp; |
i = 0; |
while ((*bufp != '\0') && (*bufp != '-') && (i < 6)) { |
c = *bufp++; |
if (islower(c)) |
c = toupper(c); |
if (!(isupper(c) || isdigit(c))) { |
safe_strncpy(AX25_errmsg, _("Invalid callsign"), sizeof(AX25_errmsg)); |
#ifdef DEBUG |
fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) ((c << 1) & 0xFE); |
i++; |
} |
|
/* Callsign too long? */ |
if ((i == 6) && (*bufp != '-') && (*bufp != '\0')) { |
strcpy(AX25_errmsg, _("Callsign too long")); |
#ifdef DEBUG |
fprintf(stderr, "ax25_input(%s): %s !\n", AX25_errmsg, orig); |
#endif |
errno = E2BIG; |
return (-1); |
} |
/* Nope, fill out the address bytes with blanks. */ |
while (i++ < sizeof(ax25_address) - 1) { |
*ptr++ = (unsigned char) ((' ' << 1) & 0xFE); |
} |
|
/* See if we need to add an SSID field. */ |
if (*bufp == '-') { |
i = atoi(++bufp); |
*ptr = (unsigned char) ((i << 1) & 0xFE); |
} else { |
*ptr = (unsigned char) '\0'; |
} |
|
/* All done. */ |
#ifdef DEBUG |
fprintf(stderr, "ax25_input(%s): ", orig); |
for (i = 0; i < sizeof(ax25_address); i++) |
fprintf(stderr, "%02X ", sap->sa_data[i] & 0377); |
fprintf(stderr, "\n"); |
#endif |
|
return (0); |
} |
|
|
/* Display an error message. */ |
static void AX25_herror(char *text) |
{ |
if (text == NULL) |
fprintf(stderr, "%s\n", AX25_errmsg); |
else |
fprintf(stderr, "%s: %s\n", text, AX25_errmsg); |
} |
|
|
static char *AX25_hprint(struct sockaddr *sap) |
{ |
static char buf[64]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf)); |
return (AX25_print(((struct sockaddr_ax25 *) sap)->sax25_call.ax25_call)); |
} |
|
|
static int AX25_hinput(char *bufp, struct sockaddr *sap) |
{ |
if (AX25_input(0, bufp, sap) < 0) |
return (-1); |
sap->sa_family = ARPHRD_AX25; |
return (0); |
} |
|
#if 0 |
/* Set the line discipline of a terminal line. */ |
static int KISS_set_disc(int fd, int disc) |
{ |
if (ioctl(fd, TIOCSETD, &disc) < 0) { |
fprintf(stderr, "KISS_set_disc(%d): %s\n", disc, strerror(errno)); |
return (-errno); |
} |
return (0); |
} |
|
|
/* Start the KISS encapsulation on the file descriptor. */ |
static int KISS_init(int fd) |
{ |
if (KISS_set_disc(fd, N_SLIP) < 0) |
return (-1); |
if (ioctl(fd, SIOCSIFENCAP, 4) < 0) |
return (-1); |
return (0); |
} |
#endif |
|
struct hwtype ax25_hwtype = |
{ |
"ax25", NULL, /*"AMPR AX.25", */ ARPHRD_AX25, 7, |
AX25_print, AX25_hprint, AX25_hinput, NULL |
}; |
|
struct aftype ax25_aftype = |
{ |
"ax25", NULL, /*"AMPR AX.25", */ AF_AX25, 7, |
AX25_print, AX25_sprint, AX25_input, AX25_herror, |
NULL, NULL, NULL, |
-1, |
"/proc/net/ax25" |
}; |
|
#endif /* HAVE_xxAX25 */ |
/trunk/uclinux/userland/route/lib/inet6.c
0,0 → 1,164
/* |
* lib/inet6.c This file contains an implementation of the "INET6" |
* support functions for the net-tools. |
* (most of it copied from lib/inet.c 1.26). |
* |
* Version: $Id: inet6.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* Modified: |
*960808 {0.01} Frank Strauss : adapted for IPv6 support |
*980701 {0.02} Arnaldo C. Melo: GNU gettext instead of catgets |
* |
* 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_AFINET6 |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/nameser.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" |
#include "intl.h" |
#include "util.h" |
|
extern int h_errno; /* some netdb.h versions don't export this */ |
|
static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) |
{ |
struct addrinfo req, *ai; |
int s; |
|
req.ai_family = AF_INET6; |
if ((s = getaddrinfo(name, NULL, &req, &ai))) { |
fprintf(stderr, "getaddrinfo: %s: %s\n", name, gai_strerror(s)); |
return -1; |
} |
memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); |
|
freeaddrinfo(ai); |
|
return (0); |
} |
|
|
static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric) |
{ |
int s; |
|
/* Grmpf. -FvK */ |
if (sin6->sin6_family != AF_INET6) { |
#ifdef DEBUG |
fprintf(stderr, _("rresolve: unsupport address family %d !\n"), |
sin6->sin6_family); |
#endif |
errno = EAFNOSUPPORT; |
return (-1); |
} |
if (numeric & 0x7FFF) { |
inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80); |
return (0); |
} |
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
if (numeric & 0x8000) |
strcpy(name, "default"); |
else |
strcpy(name, "*"); |
return (0); |
} |
|
if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), |
name, 255 /* !! */ , NULL, 0, 0))) { |
fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s)); |
return -1; |
} |
return (0); |
} |
|
|
static void INET6_reserror(char *text) |
{ |
herror(text); |
} |
|
|
/* Display an Internet socket address. */ |
static char *INET6_print(unsigned char *ptr) |
{ |
static char name[80]; |
|
inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); |
return name; |
} |
|
|
/* Display an Internet socket address. */ |
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */ |
static char *INET6_sprint(struct sockaddr *sap, int numeric) |
{ |
static char buff[128]; |
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0) |
return (NULL); |
return (buff); |
} |
|
|
static int INET6_getsock(char *bufp, struct sockaddr *sap) |
{ |
struct sockaddr_in6 *sin6; |
|
sin6 = (struct sockaddr_in6 *) sap; |
sin6->sin6_family = AF_INET6; |
sin6->sin6_port = 0; |
|
if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) |
return (-1); |
|
return 16; /* ?;) */ |
} |
|
static int INET6_input(int type, char *bufp, struct sockaddr *sap) |
{ |
switch (type) { |
case 1: |
return (INET6_getsock(bufp, sap)); |
default: |
return (INET6_resolve(bufp, (struct sockaddr_in6 *) sap)); |
} |
} |
|
|
struct aftype inet6_aftype = |
{ |
"inet6", NULL, /*"IPv6", */ AF_INET6, sizeof(struct in6_addr), |
INET6_print, INET6_sprint, INET6_input, INET6_reserror, |
INET6_rprint, INET6_rinput, NULL, |
|
-1, |
"/proc/net/if_inet6" |
}; |
|
|
#endif /* HAVE_AFINET6 */ |
/trunk/uclinux/userland/route/lib/pathnames.h
0,0 → 1,50
|
/* |
* lib/pathnames.h This file contains the definitions of the path |
* names used by the NET-LIB. |
* |
* NET-LIB |
* |
* Version: lib/pathnames.h 1.37 (1997-08-23) |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
*/ |
|
/* pathnames of the procfs files used by NET. */ |
#define _PATH_PROCNET_IGMP "/proc/net/igmp" |
#define _PATH_PROCNET_IGMP6 "/proc/net/igmp6" |
#define _PATH_PROCNET_TCP "/proc/net/tcp" |
#define _PATH_PROCNET_TCP6 "/proc/net/tcp6" |
#define _PATH_PROCNET_UDP "/proc/net/udp" |
#define _PATH_PROCNET_UDP6 "/proc/net/udp6" |
#define _PATH_PROCNET_RAW "/proc/net/raw" |
#define _PATH_PROCNET_RAW6 "/proc/net/raw6" |
#define _PATH_PROCNET_UNIX "/proc/net/unix" |
#define _PATH_PROCNET_ROUTE "/proc/net/route" |
#define _PATH_PROCNET_ROUTE6 "/proc/net/ipv6_route" |
#define _PATH_PROCNET_RTCACHE "/proc/net/rt_cache" |
#define _PATH_PROCNET_AX25_ROUTE "/proc/net/ax25_route" |
#define _PATH_PROCNET_NR "/proc/net/nr" |
#define _PATH_PROCNET_NR_NEIGH "/proc/net/nr_neigh" |
#define _PATH_PROCNET_NR_NODES "/proc/net/nr_nodes" |
#define _PATH_PROCNET_ARP "/proc/net/arp" |
#define _PATH_PROCNET_AX25 "/proc/net/ax25" |
#define _PATH_PROCNET_IPX "/proc/net/ipx" |
#define _PATH_PROCNET_IPX_ROUTE "/proc/net/ipx_route" |
#define _PATH_PROCNET_ATALK "/proc/net/appletalk" |
#define _PATH_PROCNET_IP_BLK "/proc/net/ip_block" |
#define _PATH_PROCNET_IP_FWD "/proc/net/ip_forward" |
#define _PATH_PROCNET_IP_ACC "/proc/net/ip_acct" |
#define _PATH_PROCNET_IP_MASQ "/proc/net/ip_masquerade" |
#define _PATH_PROCNET_NDISC "/proc/net/ndisc" |
#define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" |
#define _PATH_PROCNET_DEV "/proc/net/dev" |
#define _PATH_PROCNET_RARP "/proc/net/rarp" |
#define _PATH_ETHERS "/etc/ethers" |
#define _PATH_PROCNET_ROSE_ROUTE "/proc/net/rose_routes" |
#define _PATH_PROCNET_DEV_MCAST "/proc/net/dev_mcast" |
|
/* pathname for the netlink device */ |
#define _PATH_DEV_ROUTE "/dev/route" |
|
/* End of pathnames.h */ |
/trunk/uclinux/userland/route/lib/tr.c
0,0 → 1,137
/* |
* lib/tr.c This file contains an implementation of the "Tokenring" |
* support functions. |
* |
* Version: $Id: tr.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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_HWTR |
#include <asm/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <linux/if_tr.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
extern struct hwtype tr_hwtype; |
|
static char *pr_tr(unsigned char *ptr) |
{ |
static char buff[64]; |
|
snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", |
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), |
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) |
); |
return (buff); |
} |
|
|
static char *pr_str(struct sockaddr *sap) |
{ |
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
return ("[NONE SET]"); |
return (pr_tr(sap->sa_data)); |
} |
|
|
static int in_tr(char *bufp, struct sockaddr *sap) |
{ |
unsigned char *ptr; |
char c, *orig; |
int i, val; |
|
sap->sa_family = tr_hwtype.type; |
ptr = sap->sa_data; |
|
i = 0; |
orig = bufp; |
while ((*bufp != '\0') && (i < TR_ALEN)) { |
val = 0; |
c = *bufp++; |
if (isdigit(c)) |
val = c - '0'; |
else if (c >= 'a' && c <= 'f') |
val = c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val = c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
val <<= 4; |
c = *bufp++; |
if (isdigit(c)) |
val |= c - '0'; |
else if (c >= 'a' && c <= 'f') |
val |= c - 'a' + 10; |
else if (c >= 'A' && c <= 'F') |
val |= c - 'A' + 10; |
else { |
#ifdef DEBUG |
fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig); |
#endif |
errno = EINVAL; |
return (-1); |
} |
*ptr++ = (unsigned char) (val & 0377); |
i++; |
|
/* We might get a semicolon here - not required. */ |
if (*bufp == ':') { |
if (i == TR_ALEN) { |
#ifdef DEBUG |
fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"), |
orig) |
#endif |
; /* nothing */ |
} |
bufp++; |
} |
} |
|
/* That's it. Any trailing junk? */ |
if ((i == TR_ALEN) && (*bufp != '\0')) { |
#ifdef DEBUG |
fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig); |
errno = EINVAL; |
return (-1); |
#endif |
} |
#ifdef DEBUG |
fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data)); |
#endif |
|
return (0); |
} |
|
|
struct hwtype tr_hwtype = |
{ |
"tr", "16/4 Mbps Token Ring", ARPHRD_IEEE802, TR_ALEN, |
pr_tr, pr_str, in_tr, NULL |
}; |
|
|
#endif /* HAVE_HWTR */ |
/trunk/uclinux/userland/route/lib/af.c
0,0 → 1,323
/* |
* lib/af.c This file contains the top-level part of the protocol |
* support functions module for the NET-2 base distribution. |
* |
* Version: $Id: af.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
* Copyright 1993 MicroWalt Corporation |
* |
* 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 <sys/types.h> |
#include <sys/socket.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <errno.h> |
#include <ctype.h> |
#include <string.h> |
#include <unistd.h> |
#include "config.h" |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
#include "util.h" |
|
int flag_unx = 0; |
int flag_ipx = 0; |
int flag_ax25 = 0; |
int flag_ddp = 0; |
int flag_netrom = 0; |
int flag_inet = 0; |
int flag_inet6 = 0; |
int flag_econet = 0; |
|
|
struct aftrans_t { |
char *alias; |
char *name; |
int *flag; |
} aftrans[] = { |
|
{ |
"ax25", "ax25", &flag_ax25 |
}, |
{ |
"ip", "inet", &flag_inet |
}, |
{ |
"ip6", "inet6", &flag_inet6 |
}, |
{ |
"ipx", "ipx", &flag_ipx |
}, |
{ |
"appletalk", "ddp", &flag_ddp |
}, |
{ |
"netrom", "netrom", &flag_netrom |
}, |
{ |
"inet", "inet", &flag_inet |
}, |
{ |
"inet6", "inet6", &flag_inet6 |
}, |
{ |
"ddp", "ddp", &flag_ddp |
}, |
{ |
"unix", "unix", &flag_unx |
}, |
{ |
"tcpip", "inet", &flag_inet |
}, |
{ |
"econet", "ec", &flag_econet |
}, |
{ |
0, 0, 0 |
} |
}; |
|
char afname[256] = ""; |
|
extern struct aftype unspec_aftype; |
extern struct aftype unix_aftype; |
extern struct aftype inet_aftype; |
extern struct aftype inet6_aftype; |
extern struct aftype ax25_aftype; |
extern struct aftype netrom_aftype; |
extern struct aftype ipx_aftype; |
extern struct aftype ddp_aftype; |
extern struct aftype ec_aftype; |
extern struct aftype rose_aftype; |
|
static short sVafinit = 0; |
|
struct aftype *aftypes[] = |
{ |
#if HAVE_AFUNIX |
&unix_aftype, |
#endif |
#if HAVE_AFINET |
&inet_aftype, |
#endif |
#if HAVE_AFINET6 |
&inet6_aftype, |
#endif |
#if HAVE_AFAX25 |
&ax25_aftype, |
#endif |
#if HAVE_AFNETROM |
&netrom_aftype, |
#endif |
#if HAVE_AFROSE |
&rose_aftype, |
#endif |
#if HAVE_AFIPX |
&ipx_aftype, |
#endif |
#if HAVE_AFATALK |
&ddp_aftype, |
#endif |
#if HAVE_AFECONET |
&ec_aftype, |
#endif |
&unspec_aftype, |
NULL |
}; |
|
void afinit() |
{ |
unspec_aftype.title = _("UNSPEC"); |
#if HAVE_AFUNIX |
unix_aftype.title = _("UNIX Domain"); |
#endif |
#if HAVE_AFINET |
inet_aftype.title = _("DARPA Internet"); |
#endif |
#if HAVE_AFINET6 |
inet6_aftype.title = _("IPv6"); |
#endif |
#if HAVE_AFAX25 |
ax25_aftype.title = _("AMPR AX.25"); |
#endif |
#if HAVE_AFNETROM |
netrom_aftype.title = _("AMPR NET/ROM"); |
#endif |
#if HAVE_AFIPX |
ipx_aftype.title = _("Novell IPX"); |
#endif |
#if HAVE_AFATALK |
ddp_aftype.title = _("Appletalk DDP"); |
#endif |
#if HAVE_AFECONET |
ec_aftype.title = _("Econet"); |
#endif |
#if HAVE_AFROSE |
rose_aftype.title = _("AMPR ROSE"); |
#endif |
sVafinit = 1; |
} |
|
/* set the default AF list from the program name or a constant value */ |
void aftrans_def(char *tool, char *argv0, char *dflt) |
{ |
char *tmp; |
char *buf; |
|
strcpy(afname, dflt); |
|
if (!(tmp = strrchr(argv0, '/'))) |
tmp = argv0; /* no slash?! */ |
else |
tmp++; |
|
if (!(buf = strdup(tmp))) |
return; |
|
if (strlen(tool) >= strlen(tmp)) { |
free(buf); |
return; |
} |
tmp = buf + (strlen(tmp) - strlen(tool)); |
|
if (strcmp(tmp, tool) != 0) { |
free(buf); |
return; |
} |
*tmp = '\0'; |
if ((tmp = strchr(buf, '_'))) |
*tmp = '\0'; |
|
afname[0] = '\0'; |
if (aftrans_opt(buf)) |
strcpy(afname, buf); |
|
free(buf); |
} |
|
|
/* Check our protocol family table for this family. */ |
struct aftype *get_aftype(const char *name) |
{ |
struct aftype **afp; |
|
if (!sVafinit) |
afinit(); |
|
afp = aftypes; |
while (*afp != NULL) { |
if (!strcmp((*afp)->name, name)) |
return (*afp); |
afp++; |
} |
if (index(name, ',')) |
fprintf(stderr, _("Please don't supply more than one address family.\n")); |
return (NULL); |
} |
|
|
/* Check our protocol family table for this family. */ |
struct aftype *get_afntype(int af) |
{ |
struct aftype **afp; |
|
if (!sVafinit) |
afinit(); |
|
afp = aftypes; |
while (*afp != NULL) { |
if ((*afp)->af == af) |
return (*afp); |
afp++; |
} |
return (NULL); |
} |
|
/* Check our protocol family table for this family and return its socket */ |
int get_socket_for_af(int af) |
{ |
struct aftype **afp; |
|
if (!sVafinit) |
afinit(); |
|
afp = aftypes; |
while (*afp != NULL) { |
if ((*afp)->af == af) |
return (*afp)->fd; |
afp++; |
} |
return -1; |
} |
|
int aftrans_opt(const char *arg) |
{ |
struct aftrans_t *paft; |
char *tmp1, *tmp2; |
char buf[256]; |
|
safe_strncpy(buf, arg, sizeof(buf)); |
|
tmp1 = buf; |
|
while (tmp1) { |
|
tmp2 = index(tmp1, ','); |
|
if (tmp2) |
*(tmp2++) = '\0'; |
|
paft = aftrans; |
for (paft = aftrans; paft->alias; paft++) { |
if (strcmp(tmp1, paft->alias)) |
continue; |
if (strlen(paft->name) + strlen(afname) + 1 >= sizeof(afname)) { |
fprintf(stderr, _("Too much address family arguments.\n")); |
return (0); |
} |
if (paft->flag) |
(*paft->flag)++; |
if (afname[0]) |
strcat(afname, ","); |
strcat(afname, paft->name); |
break; |
} |
if (!paft->alias) { |
fprintf(stderr, _("Unknown address family `%s'.\n"), tmp1); |
return (1); |
} |
tmp1 = tmp2; |
} |
|
return (0); |
} |
|
/* type: 0=all, 1=getroute */ |
void print_aflist(int type) { |
int count = 0; |
char * txt; |
struct aftype **afp; |
|
if (!sVafinit) |
afinit(); |
|
afp = aftypes; |
while (*afp != NULL) { |
if ((type == 1 && ((*afp)->rprint == NULL)) || ((*afp)->af == 0)) { |
afp++; continue; |
} |
if ((count % 3) == 0) fprintf(stderr,count?"\n ":" "); |
txt = (*afp)->name; if (!txt) txt = ".."; |
fprintf(stderr,"%s (%s) ",txt,(*afp)->title); |
count++; |
afp++; |
} |
fprintf(stderr,"\n"); |
} |
/trunk/uclinux/userland/route/lib/frame.c
0,0 → 1,59
/* |
* lib/frame.c This file contains the Frame Relay support. |
* |
* Version: $Id: frame.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> |
* |
* Author: Mike McLagan <mike.mclagan@linux.org> |
* |
* Changes: |
* |
*962303 {0.01} Mike McLagan : creation |
*960413 {0.02} Bernd Eckenfels : included in net-lib |
* |
* 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_HWFR |
|
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/socket.h> |
#include <net/if_arp.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <ctype.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <string.h> |
#include <termios.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
|
char *pr_dlci(unsigned char *ptr) |
{ |
static char buf[12]; |
|
snprintf(buf, sizeof(buf), "%i", *(short *) ptr); |
return (buf); |
} |
|
struct hwtype dlci_hwtype = |
{ |
"dlci", NULL, /*"Frame Relay DLCI", */ ARPHRD_DLCI, 3, |
pr_dlci, NULL, NULL, NULL |
}; |
|
struct hwtype frad_hwtype = |
{ |
"frad", NULL, /*"Frame Relay Access Device", */ ARPHRD_FRAD, 0, |
NULL, NULL, NULL, NULL |
}; |
#endif /* HAVE_HWFR */ |
/trunk/uclinux/userland/route/lib/netrom_gr.c
0,0 → 1,79
/* |
* lib/netrom_gr.c This file contains an implementation of the NET/ROM |
* route support functions. |
* |
* Version: $Id: netrom_gr.c,v 1.1 2002-03-17 19:58:53 simons Exp $ |
* |
* Author: Bernd Eckenfels, <ecki@lina.inka.de> |
* Copyright 1999 Bernd Eckenfels, Germany |
* base on Code from Jonathan Naylor <jsn@Cs.Nott.AC.UK> |
* |
* Changes: |
* 980701 {0.02} Arnaldo Carvalho de Melo GNU gettext instead of catgets |
* |
* |
* 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_AFNETROM |
#include <stdlib.h> |
#include <stdio.h> |
#include <unistd.h> |
#include "net-support.h" |
#include "pathnames.h" |
#include "intl.h" |
|
/* UGLY */ |
|
int NETROM_rprint(int options) |
{ |
FILE *f1 = fopen(_PATH_PROCNET_NR_NODES, "r"); |
FILE *f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r"); |
char buffer[256]; |
int qual, n, w; |
/*int ext = options & FLAG_EXT; |
int numeric = options & FLAG_NUM; */ |
|
f1 = fopen(_PATH_PROCNET_NR_NODES, "r"); |
if (!f1) perror(_PATH_PROCNET_NR_NODES); |
f2 = fopen(_PATH_PROCNET_NR_NEIGH, "r"); |
if (!f2) perror(_PATH_PROCNET_NR_NEIGH); |
|
if (f1 == NULL || f2 == NULL) { |
printf(_("NET/ROM not configured in this system.\n")); |
return 1; |
} |
printf(_("Kernel NET/ROM routing table\n")); |
printf(_("Destination Mnemonic Quality Neighbour Iface\n")); |
fgets(buffer, 256, f1); |
while (fgets(buffer, 256, f1)) { |
buffer[9] = 0; |
buffer[17] = 0; |
w = atoi(buffer + 19) - 1; |
printf("%-9s %-7s ", |
buffer, buffer + 10); |
qual = atoi(buffer + 24 + 15 * w); |
n = atoi(buffer + 32 + 15 * w); |
rewind(f2); |
fgets(buffer, 256, f2); |
while (fgets(buffer, 256, f2)) { |
if (atoi(buffer) == n) { |
buffer[15] = 0; |
buffer[20] = 0; |
printf("%3d %-9s %s\n", |
qual, buffer + 6, buffer + 16); |
break; |
} |
} |
} |
fclose(f1); |
fclose(f2); |
return 0; |
} |
|
#endif /* HAVE_AFNETROM */ |
/trunk/uclinux/userland/route/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE |
Version 2, June 1991 |
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc. |
675 Mass Ave, Cambridge, MA 02139, USA |
Everyone is permitted to copy and distribute verbatim copies |
of this license document, but changing it is not allowed. |
|
Preamble |
|
The licenses for most software are designed to take away your |
freedom to share and change it. By contrast, the GNU General Public |
License is intended to guarantee your freedom to share and change free |
software--to make sure the software is free for all its users. This |
General Public License applies to most of the Free Software |
Foundation's software and to any other program whose authors commit to |
using it. (Some other Free Software Foundation software is covered by |
the GNU Library General Public License instead.) You can apply it to |
your programs, too. |
|
When we speak of free software, we are referring to freedom, not |
price. Our General Public Licenses are designed to make sure that you |
have the freedom to distribute copies of free software (and charge for |
this service if you wish), that you receive source code or can get it |
if you want it, that you can change the software or use pieces of it |
in new free programs; and that you know you can do these things. |
|
To protect your rights, we need to make restrictions that forbid |
anyone to deny you these rights or to ask you to surrender the rights. |
These restrictions translate to certain responsibilities for you if you |
distribute copies of the software, or if you modify it. |
|
For example, if you distribute copies of such a program, whether |
gratis or for a fee, you must give the recipients all the rights that |
you have. You must make sure that they, too, receive or can get the |
source code. And you must show them these terms so they know their |
rights. |
|
We protect your rights with two steps: (1) copyright the software, and |
(2) offer you this license which gives you legal permission to copy, |
distribute and/or modify the software. |
|
Also, for each author's protection and ours, we want to make certain |
that everyone understands that there is no warranty for this free |
software. If the software is modified by someone else and passed on, we |
want its recipients to know that what they have is not the original, so |
that any problems introduced by others will not reflect on the original |
authors' reputations. |
|
Finally, any free program is threatened constantly by software |
patents. We wish to avoid the danger that redistributors of a free |
program will individually obtain patent licenses, in effect making the |
program proprietary. To prevent this, we have made it clear that any |
patent must be licensed for everyone's free use or not licensed at all. |
|
The precise terms and conditions for copying, distribution and |
modification follow. |
|
GNU GENERAL PUBLIC LICENSE |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|
0. This License applies to any program or other work which contains |
a notice placed by the copyright holder saying it may be distributed |
under the terms of this General Public License. The "Program", below, |
refers to any such program or work, and a "work based on the Program" |
means either the Program or any derivative work under copyright law: |
that is to say, a work containing the Program or a portion of it, |
either verbatim or with modifications and/or translated into another |
language. (Hereinafter, translation is included without limitation in |
the term "modification".) Each licensee is addressed as "you". |
|
Activities other than copying, distribution and modification are not |
covered by this License; they are outside its scope. The act of |
running the Program is not restricted, and the output from the Program |
is covered only if its contents constitute a work based on the |
Program (independent of having been made by running the Program). |
Whether that is true depends on what the Program does. |
|
1. You may copy and distribute verbatim copies of the Program's |
source code as you receive it, in any medium, provided that you |
conspicuously and appropriately publish on each copy an appropriate |
copyright notice and disclaimer of warranty; keep intact all the |
notices that refer to this License and to the absence of any warranty; |
and give any other recipients of the Program a copy of this License |
along with the Program. |
|
You may charge a fee for the physical act of transferring a copy, and |
you may at your option offer warranty protection in exchange for a fee. |
|
2. You may modify your copy or copies of the Program or any portion |
of it, thus forming a work based on the Program, and copy and |
distribute such modifications or work under the terms of Section 1 |
above, provided that you also meet all of these conditions: |
|
a) You must cause the modified files to carry prominent notices |
stating that you changed the files and the date of any change. |
|
b) You must cause any work that you distribute or publish, that in |
whole or in part contains or is derived from the Program or any |
part thereof, to be licensed as a whole at no charge to all third |
parties under the terms of this License. |
|
c) If the modified program normally reads commands interactively |
when run, you must cause it, when started running for such |
interactive use in the most ordinary way, to print or display an |
announcement including an appropriate copyright notice and a |
notice that there is no warranty (or else, saying that you provide |
a warranty) and that users may redistribute the program under |
these conditions, and telling the user how to view a copy of this |
License. (Exception: if the Program itself is interactive but |
does not normally print such an announcement, your work based on |
the Program is not required to print an announcement.) |
|
These requirements apply to the modified work as a whole. If |
identifiable sections of that work are not derived from the Program, |
and can be reasonably considered independent and separate works in |
themselves, then this License, and its terms, do not apply to those |
sections when you distribute them as separate works. But when you |
distribute the same sections as part of a whole which is a work based |
on the Program, the distribution of the whole must be on the terms of |
this License, whose permissions for other licensees extend to the |
entire whole, and thus to each and every part regardless of who wrote it. |
|
Thus, it is not the intent of this section to claim rights or contest |
your rights to work written entirely by you; rather, the intent is to |
exercise the right to control the distribution of derivative or |
collective works based on the Program. |
|
In addition, mere aggregation of another work not based on the Program |
with the Program (or with a work based on the Program) on a volume of |
a storage or distribution medium does not bring the other work under |
the scope of this License. |
|
3. You may copy and distribute the Program (or a work based on it, |
under Section 2) in object code or executable form under the terms of |
Sections 1 and 2 above provided that you also do one of the following: |
|
a) Accompany it with the complete corresponding machine-readable |
source code, which must be distributed under the terms of Sections |
1 and 2 above on a medium customarily used for software interchange; or, |
|
b) Accompany it with a written offer, valid for at least three |
years, to give any third party, for a charge no more than your |
cost of physically performing source distribution, a complete |
machine-readable copy of the corresponding source code, to be |
distributed under the terms of Sections 1 and 2 above on a medium |
customarily used for software interchange; or, |
|
c) Accompany it with the information you received as to the offer |
to distribute corresponding source code. (This alternative is |
allowed only for noncommercial distribution and only if you |
received the program in object code or executable form with such |
an offer, in accord with Subsection b above.) |
|
The source code for a work means the preferred form of the work for |
making modifications to it. For an executable work, complete source |
code means all the source code for all modules it contains, plus any |
associated interface definition files, plus the scripts used to |
control compilation and installation of the executable. However, as a |
special exception, the source code distributed need not include |
anything that is normally distributed (in either source or binary |
form) with the major components (compiler, kernel, and so on) of the |
operating system on which the executable runs, unless that component |
itself accompanies the executable. |
|
If distribution of executable or object code is made by offering |
access to copy from a designated place, then offering equivalent |
access to copy the source code from the same place counts as |
distribution of the source code, even though third parties are not |
compelled to copy the source along with the object code. |
|
4. You may not copy, modify, sublicense, or distribute the Program |
except as expressly provided under this License. Any attempt |
otherwise to copy, modify, sublicense or distribute the Program is |
void, and will automatically terminate your rights under this License. |
However, parties who have received copies, or rights, from you under |
this License will not have their licenses terminated so long as such |
parties remain in full compliance. |
|
5. You are not required to accept this License, since you have not |
signed it. However, nothing else grants you permission to modify or |
distribute the Program or its derivative works. These actions are |
prohibited by law if you do not accept this License. Therefore, by |
modifying or distributing the Program (or any work based on the |
Program), you indicate your acceptance of this License to do so, and |
all its terms and conditions for copying, distributing or modifying |
the Program or works based on it. |
|
6. Each time you redistribute the Program (or any work based on the |
Program), the recipient automatically receives a license from the |
original licensor to copy, distribute or modify the Program subject to |
these terms and conditions. You may not impose any further |
restrictions on the recipients' exercise of the rights granted herein. |
You are not responsible for enforcing compliance by third parties to |
this License. |
|
7. If, as a consequence of a court judgment or allegation of patent |
infringement or for any other reason (not limited to patent issues), |
conditions are imposed on you (whether by court order, agreement or |
otherwise) that contradict the conditions of this License, they do not |
excuse you from the conditions of this License. If you cannot |
distribute so as to satisfy simultaneously your obligations under this |
License and any other pertinent obligations, then as a consequence you |
may not distribute the Program at all. For example, if a patent |
license would not permit royalty-free redistribution of the Program by |
all those who receive copies directly or indirectly through you, then |
the only way you could satisfy both it and this License would be to |
refrain entirely from distribution of the Program. |
|
If any portion of this section is held invalid or unenforceable under |
any particular circumstance, the balance of the section is intended to |
apply and the section as a whole is intended to apply in other |
circumstances. |
|
It is not the purpose of this section to induce you to infringe any |
patents or other property right claims or to contest validity of any |
such claims; this section has the sole purpose of protecting the |
integrity of the free software distribution system, which is |
implemented by public license practices. Many people have made |
generous contributions to the wide range of software distributed |
through that system in reliance on consistent application of that |
system; it is up to the author/donor to decide if he or she is willing |
to distribute software through any other system and a licensee cannot |
impose that choice. |
|
This section is intended to make thoroughly clear what is believed to |
be a consequence of the rest of this License. |
|
8. If the distribution and/or use of the Program is restricted in |
certain countries either by patents or by copyrighted interfaces, the |
original copyright holder who places the Program under this License |
may add an explicit geographical distribution limitation excluding |
those countries, so that distribution is permitted only in or among |
countries not thus excluded. In such case, this License incorporates |
the limitation as if written in the body of this License. |
|
9. The Free Software Foundation may publish revised and/or new versions |
of the General Public License from time to time. Such new versions will |
be similar in spirit to the present version, but may differ in detail to |
address new problems or concerns. |
|
Each version is given a distinguishing version number. If the Program |
specifies a version number of this License which applies to it and "any |
later version", you have the option of following the terms and conditions |
either of that version or of any later version published by the Free |
Software Foundation. If the Program does not specify a version number of |
this License, you may choose any version ever published by the Free Software |
Foundation. |
|
10. If you wish to incorporate parts of the Program into other free |
programs whose distribution conditions are different, write to the author |
to ask for permission. For software which is copyrighted by the Free |
Software Foundation, write to the Free Software Foundation; we sometimes |
make exceptions for this. Our decision will be guided by the two goals |
of preserving the free status of all derivatives of our free software and |
of promoting the sharing and reuse of software generally. |
|
NO WARRANTY |
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
REPAIR OR CORRECTION. |
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
POSSIBILITY OF SUCH DAMAGES. |
|
END OF TERMS AND CONDITIONS |
|
Appendix: How to Apply These Terms to Your New Programs |
|
If you develop a new program, and you want it to be of the greatest |
possible use to the public, the best way to achieve this is to make it |
free software which everyone can redistribute and change under these terms. |
|
To do so, attach the following notices to the program. It is safest |
to attach them to the start of each source file to most effectively |
convey the exclusion of warranty; and each file should have at least |
the "copyright" line and a pointer to where the full notice is found. |
|
<one line to give the program's name and a brief idea of what it does.> |
Copyright (C) 19yy <name of author> |
|
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. |
|
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
GNU General Public License for more details. |
|
You should have received a copy of the GNU General Public License |
along with this program; if not, write to the Free Software |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
Also add information on how to contact you by electronic and paper mail. |
|
If the program is interactive, make it output a short notice like this |
when it starts in an interactive mode: |
|
Gnomovision version 69, Copyright (C) 19yy name of author |
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
This is free software, and you are welcome to redistribute it |
under certain conditions; type `show c' for details. |
|
The hypothetical commands `show w' and `show c' should show the appropriate |
parts of the General Public License. Of course, the commands you use may |
be called something other than `show w' and `show c'; they could even be |
mouse-clicks or menu items--whatever suits your program. |
|
You should also get your employer (if you work as a programmer) or your |
school, if any, to sign a "copyright disclaimer" for the program, if |
necessary. Here is a sample; alter the names: |
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
`Gnomovision' (which makes passes at compilers) written by James Hacker. |
|
<signature of Ty Coon>, 1 April 1989 |
Ty Coon, President of Vice |
|
This General Public License does not permit incorporating your program into |
proprietary programs. If your program is a subroutine library, you may |
consider it more useful to permit linking proprietary applications with the |
library. If this is what you want to do, use the GNU Library General |
Public License instead of this License. |
/trunk/uclinux/userland/route/version.h
0,0 → 1,339
#define RELEASE "net-tools 1.52" |
/trunk/uclinux/userland/route/Makefile
0,0 → 1,41
|
CC = or32-uclibc-gcc |
LD = or32-uclibc-gcc |
STRIP = or32-uclibc-strip |
|
ROUTE = route |
ROUTEOBJS = route.o |
|
IFCONFIG = ifconfig |
IFCONFIGOBJS = ifconfig.o |
|
ARP = arp |
ARPOBJS = arp.o |
|
CFLAGS += -D_GNU_SOURCE -D__USE_BSD -Wall -Werror-implicit-function-declaration -Ilib/ -Iinclude |
LDFLAGS += -r -d |
|
LIBROUTE = lib/libroute.a |
|
all: $(ROUTE) $(IFCONFIG) $(ARP) |
|
$(ROUTE): $(ROUTEOBJS) $(LIBROUTE) |
$(LD) $(LDFLAGS) -o $@ $(ROUTEOBJS) $(LIBNET) $(LIBROUTE) $(LDLIBS) |
$(STRIP) -g $@ |
|
$(IFCONFIG): $(IFCONFIGOBJS) $(LIBROUTE) |
$(LD) $(LDFLAGS) -o $@ $(IFCONFIGOBJS) $(LIBNET) $(LIBROUTE) $(LDLIBS) |
$(STRIP) -g $@ |
|
$(ARP): $(ARPOBJS) $(LIBROUTE) |
$(LD) $(LDFLAGS) -o $@ $(ARPOBJS) $(LIBNET) $(LIBROUTE) $(LDLIBS) |
$(STRIP) -g $@ |
|
clean: |
-rm -f $(ROUTE) $(IFCONFIG) $(ARP) *.gdb *.o |
$(MAKE) -C lib clean |
|
$(LIBROUTE): |
$(MAKE) -C lib |
|
|