Fix reporting of IPv6 multicast addresses.
[oss-qm-packages.git] / lib / hippi.c
blob308db00c3363e49a59df775ec91cf7da6798c3a8
1 /*
2 * lib/hippi.c This file contains an implementation of the "HIPPI"
3 * support functions for the NET-2 base distribution.
5 * Version: $Id$
7 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
8 * Copyright 1993 MicroWalt Corporation
10 * Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch>
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software
15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version.
18 #include "config.h"
20 #if HAVE_HWHIPPI
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <net/if_arp.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <errno.h>
27 #include <ctype.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include "net-support.h"
31 #include "pathnames.h"
32 #include "intl.h"
33 #include "util.h"
36 * HIPPI magic constants.
39 #define HIPPI_ALEN 6 /* Bytes in one HIPPI hw-addr */
40 #ifndef ARPHRD_HIPPI
41 #define ARPHRD_HIPPI 780
42 #warning "ARPHRD_HIPPI is not defined in <net/if_arp.h>. Using private value 708"
43 #endif
45 extern struct hwtype hippi_hwtype;
48 /* Display an HIPPI address in readable format. */
49 static char *pr_hippi(unsigned char *ptr)
51 static char buff[64];
53 sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
54 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
55 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
57 return (buff);
61 /* Input an HIPPI address and convert to binary. */
62 static int in_hippi(char *bufp, struct sockaddr *sap)
64 unsigned char *ptr;
65 char c, *orig;
66 int i, val;
68 sap->sa_family = hippi_hwtype.type;
69 ptr = sap->sa_data;
71 i = 0;
72 orig = bufp;
73 while ((*bufp != '\0') && (i < HIPPI_ALEN)) {
74 val = 0;
75 c = *bufp++;
76 if (isdigit(c))
77 val = c - '0';
78 else if (c >= 'a' && c <= 'f')
79 val = c - 'a' + 10;
80 else if (c >= 'A' && c <= 'F')
81 val = c - 'A' + 10;
82 else {
83 #ifdef DEBUG
84 fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
85 #endif
86 errno = EINVAL;
87 return (-1);
89 val <<= 4;
90 c = *bufp++;
91 if (isdigit(c))
92 val |= c - '0';
93 else if (c >= 'a' && c <= 'f')
94 val |= c - 'a' + 10;
95 else if (c >= 'A' && c <= 'F')
96 val |= c - 'A' + 10;
97 else {
98 #ifdef DEBUG
99 fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
100 #endif
101 errno = EINVAL;
102 return (-1);
104 *ptr++ = (unsigned char) (val & 0377);
105 i++;
107 /* We might get a semicolon here - not required. */
108 if (*bufp == ':') {
109 if (i == HIPPI_ALEN) {
110 #ifdef DEBUG
111 fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig)
112 #endif
113 ; /* nothing */
115 bufp++;
119 /* That's it. Any trailing junk? */
120 if ((i == HIPPI_ALEN) && (*bufp != '\0')) {
121 #ifdef DEBUG
122 fprintf(stderr, _("in_hippi(%s): trailing junk!\n"), orig);
123 errno = EINVAL;
124 return (-1);
125 #endif
127 #ifdef DEBUG
128 fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data));
129 #endif
131 return (0);
135 struct hwtype hippi_hwtype =
137 "hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN,
138 pr_hippi, in_hippi, NULL, 0
142 #endif /* HAVE_HWHIPPI */