2 * IPX protocol output functions.
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.
13 * 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets,
14 * snprintf instead of sprintf
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>
33 #include <netinet/in.h>
35 #include "net-support.h"
36 #include "pathnames.h"
40 #if (IPX_NODE_LEN != 6)
41 #error "IPX_NODE_LEN != 6"
44 /* Display a ipx domain address. */
45 static char *IPX_print(unsigned char *ptr
)
48 struct sockaddr_ipx
*sipx
= (struct sockaddr_ipx
*) (ptr
- 2);
52 for (t
= IPX_NODE_LEN
; t
; t
--)
53 if (sipx
->sipx_node
[t
- 1])
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]);
75 /* Display a ipx domain address. */
76 static char *IPX_sprint(struct sockaddr
*sap
, int numeric
)
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
)
91 struct sockaddr_ipx
*sipx
= (struct sockaddr_ipx
*) sap
;
96 bp
= (char *) sipx
->sipx_node
;
97 for (i
= 0; i
< sizeof(sipx
->sipx_node
); i
++) {
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');
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');
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))
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
;
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';
152 netnum
= strtoul(bufp
, &ep
, 16);
153 if ((netnum
== 0xffffffffL
) || (netnum
== 0L))
156 sai
->sipx_network
= netnum
;
158 sai
->sipx_network
= htonl(netnum
);
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
,