fixes for man page bugs reported by Hugh Redelmeier.
[oss-qm-packages.git] / lib / ipx.c
blob13d2761daaafe3d5a17c3b0e4ba98f7c5fae135b
1 /*
2 * IPX protocol output functions.
3 * [Not yet input]
5 * Alan Cox <Alan.Cox@linux.org>
7 * This program is free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General
9 * Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 * Modifications:
13 * 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
14 * snprintf instead of sprintf
16 #include "config.h"
18 #if HAVE_AFIPX
19 #include <asm/types.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
23 #include <netipx/ipx.h>
24 #else
25 #include "ipx.h"
26 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <ctype.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <netinet/in.h>
34 #include "version.h"
35 #include "net-support.h"
36 #include "pathnames.h"
37 #include "intl.h"
38 #include "util.h"
40 #if (IPX_NODE_LEN != 6)
41 #error "IPX_NODE_LEN != 6"
42 #endif
44 /* Display a ipx domain address. */
45 static char *IPX_print(unsigned char *ptr)
47 static char buff[64];
48 struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2);
49 int t;
52 for (t = IPX_NODE_LEN; t; t--)
53 if (sipx->sipx_node[t - 1])
54 break;
56 if (t && ntohl(sipx->sipx_network))
57 snprintf(buff, sizeof(buff), "%08lX:%02X%02X%02X%02X%02X%02X",
58 (long int) ntohl(sipx->sipx_network),
59 (int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
60 (int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
61 (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
62 else if (!t && ntohl(sipx->sipx_network))
63 snprintf(buff, sizeof(buff), "%08lX", (long int) ntohl(sipx->sipx_network));
64 else if (t && !ntohl(sipx->sipx_network))
65 snprintf(buff, sizeof(buff), "%02X%02X%02X%02X%02X%02X",
66 (int) sipx->sipx_node[0], (int) sipx->sipx_node[1],
67 (int) sipx->sipx_node[2], (int) sipx->sipx_node[3],
68 (int) sipx->sipx_node[4], (int) sipx->sipx_node[5]);
69 else
70 buff[0] = '\0';
71 return (buff);
75 /* Display a ipx domain address. */
76 static char *IPX_sprint(struct sockaddr *sap, int numeric)
78 static char buf[64];
80 if (sap->sa_family != AF_IPX)
81 return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
82 return (IPX_print(sap->sa_data));
86 static int IPX_getsock(char *bufp, struct sockaddr *sap)
88 char *sp = bufp, *bp;
89 unsigned int i;
90 unsigned char val;
91 struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap;
93 sipx->sipx_port = 0;
95 val = 0;
96 bp = (char *) sipx->sipx_node;
97 for (i = 0; i < sizeof(sipx->sipx_node); i++) {
98 *sp = toupper(*sp);
100 if ((*sp >= 'A') && (*sp <= 'F'))
101 bp[i] |= (int) (*sp - 'A') + 10;
102 else if ((*sp >= '0') && (*sp <= '9'))
103 bp[i] |= (int) (*sp - '0');
104 else
105 return (-1);
107 bp[i] <<= 4;
108 sp++;
109 *sp = toupper(*sp);
111 if ((*sp >= 'A') && (*sp <= 'F'))
112 bp[i] |= (int) (*sp - 'A') + 10;
113 else if ((*sp >= '0') && (*sp <= '9'))
114 bp[i] |= (int) (*sp - '0');
115 else
116 return (-1);
118 sp++;
120 if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) ||
121 (memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
122 return (-1);
124 return (0);
127 /* XXX define type which makes verbose format checks AF_input */
129 static int IPX_input(int type, char *bufp, struct sockaddr *sap)
131 struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap;
132 unsigned long netnum;
133 char *ep;
134 int nbo;
136 if (!sai)
137 return (-1);
139 sai->sipx_family = AF_IPX;
140 sai->sipx_network = htonl(0);
141 sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] =
142 sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0';
143 sai->sipx_port = 0;
145 if (type & 4)
146 nbo = 1;
147 else
148 nbo = 0;
150 type &= 3;
151 if (type <= 1) {
152 netnum = strtoul(bufp, &ep, 16);
153 if ((netnum == 0xffffffffL) || (netnum == 0L))
154 return (-1);
155 if (nbo)
156 sai->sipx_network = netnum;
157 else
158 sai->sipx_network = htonl(netnum);
160 if (type == 1) {
161 if (*ep != '\0')
162 return (-2);
163 return (0);
165 if (type == 0) {
166 if (*ep != ':')
167 return (-3);
168 bufp = ep + 1;
170 return (IPX_getsock(bufp, sap));
174 struct aftype ipx_aftype =
176 "ipx", NULL, /*"IPX", */ AF_IPX, 0,
177 IPX_print, IPX_sprint, IPX_input, NULL,
178 NULL /*IPX_rprint */ , NULL, NULL,
180 "/proc/net/ipx"
183 #endif