minor fix to return E_USAGE on -V instead of exit(0);
[oss-qm-packages.git] / lib / arcnet.c
blobeb0f46ef58203b0399454b7ebf36c8d4d3603db1
1 /*
2 * lib/arcnet.c This file contains an implementation of the "ARCnet"
3 * support functions for the NET-2 base distribution.
5 * Version: $Id: arcnet.c,v 1.6 2000/03/05 11:26:02 philip Exp $
7 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
8 * Copyright 1993 MicroWalt Corporation
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 #include "config.h"
18 #if HAVE_HWARC
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <net/if_arp.h>
22 #include <linux/if_ether.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <errno.h>
26 #include <ctype.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include "net-support.h"
30 #include "pathnames.h"
31 #include "intl.h"
32 #include "util.h"
34 extern struct hwtype arcnet_hwtype;
37 /* Display an ARCnet address in readable format. */
38 static char *pr_arcnet(unsigned char *ptr)
40 static char buff[64];
42 snprintf(buff, sizeof(buff), "%02X", (ptr[0] & 0377));
43 return (buff);
47 /* Input an ARCnet address and convert to binary. */
48 static int in_arcnet(char *bufp, struct sockaddr *sap)
50 unsigned char *ptr;
51 char c, *orig;
52 int i, val;
54 sap->sa_family = arcnet_hwtype.type;
55 ptr = sap->sa_data;
57 i = 0;
58 orig = bufp;
59 while ((*bufp != '\0') && (i < 1)) {
60 val = 0;
61 c = *bufp++;
62 if (isdigit(c))
63 val = c - '0';
64 else if (c >= 'a' && c <= 'f')
65 val = c - 'a' + 10;
66 else if (c >= 'A' && c <= 'F')
67 val = c - 'A' + 10;
68 else {
69 #ifdef DEBUG
70 fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
71 #endif
72 errno = EINVAL;
73 return (-1);
75 val <<= 4;
76 c = *bufp++;
77 if (isdigit(c))
78 val |= c - '0';
79 else if (c >= 'a' && c <= 'f')
80 val |= c - 'a' + 10;
81 else if (c >= 'A' && c <= 'F')
82 val |= c - 'A' + 10;
83 else {
84 #ifdef DEBUG
85 fprintf(stderr, _("in_arcnet(%s): invalid arcnet address!\n"), orig);
86 #endif
87 errno = EINVAL;
88 return (-1);
90 *ptr++ = (unsigned char) (val & 0377);
91 i++;
93 /* We might get a semicolon here - not required. */
94 if (*bufp == ':') {
95 if (i == ETH_ALEN) {
96 #ifdef DEBUG
97 fprintf(stderr, _("in_arcnet(%s): trailing : ignored!\n"),
98 orig)
99 #endif
100 ; /* nothing */
102 bufp++;
106 /* That's it. Any trailing junk? */
107 if ((i == ETH_ALEN) && (*bufp != '\0')) {
108 #ifdef DEBUG
109 fprintf(stderr, _("in_arcnet(%s): trailing junk!\n"), orig);
110 errno = EINVAL;
111 return (-1);
112 #endif
114 #ifdef DEBUG
115 fprintf(stderr, "in_arcnet(%s): %s\n", orig, pr_arcnet(sap->sa_data));
116 #endif
118 return (0);
122 struct hwtype arcnet_hwtype =
124 "arcnet", NULL, /*"2.5Mbps ARCnet", */ ARPHRD_ARCNET, 1,
125 pr_arcnet, in_arcnet, NULL
129 #endif /* HAVE_HWARC */