~ubuntu-branches/ubuntu/edgy/net-tools/edgy

« back to all changes in this revision

Viewing changes to lib/ipx.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Eckenfels
  • Date: 2001-11-24 06:26:37 UTC
  • Revision ID: james.westby@ubuntu.com-20011124062637-1y96kzx03e8dbi55
Tags: upstream-1.60
ImportĀ upstreamĀ versionĀ 1.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *            IPX protocol output functions.
 
3
 *              [Not yet input]
 
4
 *
 
5
 *                      Alan Cox  <Alan.Cox@linux.org>
 
6
 *
 
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
 
15
 */
 
16
#include "config.h"
 
17
 
 
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"
 
39
 
 
40
#if (IPX_NODE_LEN != 6)
 
41
#error "IPX_NODE_LEN != 6"
 
42
#endif
 
43
 
 
44
/* Display a ipx domain address. */
 
45
static char *IPX_print(unsigned char *ptr)
 
46
{
 
47
    static char buff[64];
 
48
    struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) (ptr - 2);
 
49
    int t;
 
50
 
 
51
 
 
52
    for (t = IPX_NODE_LEN; t; t--)
 
53
        if (sipx->sipx_node[t - 1])
 
54
            break;
 
55
 
 
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);
 
72
}
 
73
 
 
74
 
 
75
/* Display a ipx domain address. */
 
76
static char *IPX_sprint(struct sockaddr *sap, int numeric)
 
77
{
 
78
    static char buf[64];
 
79
 
 
80
    if (sap->sa_family != AF_IPX)
 
81
        return safe_strncpy(buf, _("[NONE SET]"), sizeof(buf));
 
82
    return (IPX_print(sap->sa_data));
 
83
}
 
84
 
 
85
 
 
86
static int IPX_getsock(char *bufp, struct sockaddr *sap)
 
87
{
 
88
    char *sp = bufp, *bp;
 
89
    unsigned int i;
 
90
    unsigned char val;
 
91
    struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) sap;
 
92
 
 
93
    sipx->sipx_port = 0;
 
94
 
 
95
    val = 0;
 
96
    bp = (char *) sipx->sipx_node;
 
97
    for (i = 0; i < sizeof(sipx->sipx_node); i++) {
 
98
        *sp = toupper(*sp);
 
99
 
 
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);
 
106
 
 
107
        bp[i] <<= 4;
 
108
        sp++;
 
109
        *sp = toupper(*sp);
 
110
 
 
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);
 
117
 
 
118
        sp++;
 
119
    }
 
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);
 
123
 
 
124
    return (0);
 
125
}
 
126
 
 
127
/* XXX define type which makes verbose format checks AF_input */
 
128
 
 
129
static int IPX_input(int type, char *bufp, struct sockaddr *sap)
 
130
{
 
131
    struct sockaddr_ipx *sai = (struct sockaddr_ipx *) sap;
 
132
    unsigned long netnum;
 
133
    char *ep;
 
134
    int nbo;
 
135
 
 
136
    sai->sipx_family = AF_IPX;
 
137
    sai->sipx_network = htonl(0);
 
138
    sai->sipx_node[0] = sai->sipx_node[1] = sai->sipx_node[2] =
 
139
        sai->sipx_node[3] = sai->sipx_node[4] = sai->sipx_node[5] = '\0';
 
140
    sai->sipx_port = 0;
 
141
 
 
142
    if (type & 4)
 
143
        nbo = 1;
 
144
    else
 
145
        nbo = 0;
 
146
 
 
147
    type &= 3;
 
148
    if (type <= 1) {
 
149
        netnum = strtoul(bufp, &ep, 16);
 
150
        if ((netnum == 0xffffffffL) || (netnum == 0L))
 
151
            return (-1);
 
152
        if (nbo)
 
153
            sai->sipx_network = netnum;
 
154
        else
 
155
            sai->sipx_network = htonl(netnum);
 
156
    }
 
157
    if (type == 1) {
 
158
        if (*ep != '\0')
 
159
            return (-2);
 
160
        return (0);
 
161
    }
 
162
    if (type == 0) {
 
163
        if (*ep != ':')
 
164
            return (-3);
 
165
        bufp = ep + 1;
 
166
    }
 
167
    return (IPX_getsock(bufp, sap));
 
168
}
 
169
 
 
170
 
 
171
struct aftype ipx_aftype =
 
172
{
 
173
    "ipx", NULL, /*"IPX", */ AF_IPX, 0,
 
174
    IPX_print, IPX_sprint, IPX_input, NULL,
 
175
    NULL /*IPX_rprint */ , NULL, NULL,
 
176
    -1,
 
177
    "/proc/net/ipx"
 
178
};
 
179
 
 
180
#endif