minor fix to return E_USAGE on -V instead of exit(0);
[oss-qm-packages.git] / lib / fddi.c
blobf6bf5ca1852cbb13025e4c3b063562db254feb64
1 /*
2 * lib/fddi.c This file contains an implementation of the "FDDI"
3 * support functions.
5 * Version: $Id: fddi.c,v 1.7 2000/03/05 11:26:02 philip Exp $
7 * Author: Lawrence V. Stefani, <stefani@lkg.dec.com>
9 * 1998-07-01 - Arnaldo Carvalho de Melo <acme@conectiva.com.br> GNU gettext
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 #include "config.h"
19 #include <features.h>
21 #if HAVE_HWFDDI
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <net/if_arp.h>
25 #ifndef ARPHRD_FDDI
26 #error "No FDDI Support in your current Kernelsource Tree."
27 #error "Disable HW Type FDDI"
28 #endif
29 #if __GLIBC__ >= 2
30 #include <netinet/if_fddi.h>
31 #else
32 #include <linux/if_fddi.h>
33 #endif
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <errno.h>
37 #include <ctype.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include "net-support.h"
41 #include "pathnames.h"
42 #include "intl.h"
43 #include "util.h"
45 extern struct hwtype fddi_hwtype;
48 /* Display an FDDI address in readable format. */
49 static char *pr_fddi(unsigned char *ptr)
51 static char buff[64];
53 snprintf(buff, sizeof(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 FDDI address and convert to binary. */
62 static int in_fddi(char *bufp, struct sockaddr *sap)
64 unsigned char *ptr;
65 char c, *orig;
66 int i, val;
68 sap->sa_family = fddi_hwtype.type;
69 ptr = sap->sa_data;
71 i = 0;
72 orig = bufp;
73 while ((*bufp != '\0') && (i < FDDI_K_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_fddi(%s): invalid fddi 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_fddi(%s): invalid fddi 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 == FDDI_K_ALEN) {
110 #ifdef DEBUG
111 fprintf(stderr, _("in_fddi(%s): trailing : ignored!\n"),
112 orig)
113 #endif
114 ; /* nothing */
116 bufp++;
120 /* That's it. Any trailing junk? */
121 if ((i == FDDI_K_ALEN) && (*bufp != '\0')) {
122 #ifdef DEBUG
123 fprintf(stderr, _("in_fddi(%s): trailing junk!\n"), orig);
124 errno = EINVAL;
125 return (-1);
126 #endif
128 #ifdef DEBUG
129 fprintf(stderr, "in_fddi(%s): %s\n", orig, pr_fddi(sap->sa_data));
130 #endif
132 return (0);
136 struct hwtype fddi_hwtype =
138 "fddi", NULL, /*"Fiber Distributed Data Interface (FDDI)", */ ARPHRD_FDDI, FDDI_K_ALEN,
139 pr_fddi, in_fddi, NULL
143 #endif /* HAVE_HWFDDI */