man/pt_BR/ifconfig.8: remove untranslated paragraph
[platform/upstream/net-tools.git] / lib / ash.c
1 /*
2  * lib/ash.c  This file contains an implementation of the Ash
3  *              support functions for the NET-2 base distribution.
4  * $Id: ash.c,v 1.11 1999/09/27 11:00:45 philip Exp $
5  */
6
7 #include "config.h"
8
9 #if HAVE_HWASH || HAVE_AFASH
10
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <net/if_arp.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <errno.h>
17 #include <ctype.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include "net-support.h"
21 #include "pathnames.h"
22 #include "intl.h"
23 #include "util.h"
24
25 #define ASH_ALEN                64
26
27 static unsigned char hamming[16] =
28 {
29     0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f,
30     0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea
31 };
32
33 /* Display an Ash address in readable format. */
34 static const char *
35 pr_ash(const char *ptr)
36 {
37     static char buff[128];
38     char *p = buff;
39     unsigned int i = 0;
40
41     p[0] = '[';
42     p++;
43     while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN))
44         sprintf(p++, "%1x", ptr[i++]);
45     *(p++) = ']';
46     *p = 0;
47
48     return buff;
49 }
50
51 #if HAVE_HWASH
52
53 #ifndef ARPHRD_ASH
54 #warning "No definition of ARPHRD_ASH in <net/if_arp.h>, using private value 517"
55 #define ARPHRD_ASH 517
56 #endif
57
58 struct hwtype ash_hwtype;
59
60 static int 
61 in_ash(char *bufp, struct sockaddr *sap)
62 {
63     char *ptr;
64     unsigned int i = 0;
65
66     sap->sa_family = ash_hwtype.type;
67     ptr = sap->sa_data;
68
69     while (bufp && i < ASH_ALEN) {
70         char *next;
71         int hop = strtol(bufp, &next, 16);
72         ptr[i++] = hamming[hop];
73         switch (*next) {
74         case ':':
75             bufp = next + 1;
76             break;
77         case 0:
78             bufp = NULL;
79             break;
80         default:
81             fprintf(stderr, _("Malformed Ash address"));
82             memset(ptr, 0xc9, ASH_ALEN);
83             return -1;
84         }
85     }
86
87     while (i < ASH_ALEN)
88         ptr[i++] = 0xc9;
89
90     return 0;
91 }
92
93 struct hwtype ash_hwtype =
94 {
95     "ash", NULL, ARPHRD_ASH, ASH_ALEN,
96     pr_ash, in_ash, NULL,
97     1
98 };
99
100 #endif  /* HAVE_HWASH */
101
102 #if HAVE_AFASH
103
104 /* Display an Ash socket address. */
105 static const char *
106 pr_sash(struct sockaddr *sap, int numeric)
107 {
108     static char buf[64];
109
110     if (sap->sa_family != AF_ASH)
111         return safe_strncpy(buf, "[NONE SET]", 64);
112     return pr_ash(sap->sa_data);
113 }
114
115 struct aftype ash_aftype =
116 {
117     "ash", NULL, AF_ASH, 0,
118     pr_ash, pr_sash, NULL, NULL,
119     NULL, NULL, NULL,
120     -1,
121     "/proc/sys/net/ash"
122 };
123
124 #endif  /* HAVE_AFASH */
125
126 #endif  /* HAVE_AFASH || HAVE_HWASH */