fixes for man page bugs reported by Hugh Redelmeier.
[oss-qm-packages.git] / lib / ash.c
blobc64667c1f7b0b9a6afeb8d59bab025cc5d7d6682
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 */
7 #include "config.h"
9 #if HAVE_HWASH || HAVE_AFASH
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"
25 #define ASH_ALEN 64
27 static unsigned char hamming[16] =
29 0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f,
30 0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea
33 /* Display an Ash address in readable format. */
34 static char *
35 pr_ash(unsigned char *ptr)
37 static char buff[128];
38 char *p = buff;
39 unsigned int i = 0;
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;
48 return buff;
51 #if HAVE_HWASH
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
58 struct hwtype ash_hwtype;
60 static int
61 in_ash(char *bufp, struct sockaddr *sap)
63 unsigned char *ptr;
64 unsigned int i = 0;
66 sap->sa_family = ash_hwtype.type;
67 ptr = sap->sa_data;
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;
87 while (i < ASH_ALEN)
88 ptr[i++] = 0xc9;
90 return 0;
93 struct hwtype ash_hwtype =
95 "ash", NULL, ARPHRD_ASH, ASH_ALEN,
96 pr_ash, in_ash, NULL,
100 #endif /* HAVE_HWASH */
102 #if HAVE_AFASH
104 /* Display an Ash socket address. */
105 static char *
106 pr_sash(struct sockaddr *sap, int numeric)
108 static char buf[64];
110 if (sap->sa_family != AF_ASH)
111 return safe_strncpy(buf, "[NONE SET]", 64);
112 return pr_ash(sap->sa_data);
115 struct aftype ash_aftype =
117 "ash", NULL, AF_ASH, 0,
118 pr_ash, pr_sash, NULL, NULL,
119 NULL, NULL, NULL,
121 "/proc/sys/net/ash"
124 #endif /* HAVE_AFASH */
126 #endif /* HAVE_AFASH || HAVE_HWASH */