2 * lib/ether.c This file contains an implementation of the "Ethernet"
5 * Version: $Id: ether.c,v 1.8 2002/07/30 05:17:29 ecki 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.
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <net/if_arp.h>
22 #include <linux/if_ether.h>
29 #include "net-support.h"
30 #include "pathnames.h"
34 extern struct hwtype ether_hwtype;
37 /* Display an Ethernet address in readable format. */
38 static char *pr_ether(unsigned char *ptr)
42 snprintf(buff, sizeof(buff), "%02x:%02x:%02x:%02x:%02x:%02x",
43 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
44 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
50 /* Input an Ethernet address and convert to binary. */
51 static int in_ether(char *bufp, struct sockaddr *sap)
58 sap->sa_family = ether_hwtype.type;
63 while ((*bufp != '\0') && (i < ETH_ALEN)) {
68 else if (c >= 'a' && c <= 'f')
70 else if (c >= 'A' && c <= 'F')
74 fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
83 else if (c >= 'a' && c <= 'f')
85 else if (c >= 'A' && c <= 'F')
87 else if (c == ':' || c == 0)
91 fprintf(stderr, _("in_ether(%s): invalid ether address!\n"), orig);
98 *ptr++ = (unsigned char) (val & 0377);
101 /* We might get a semicolon here - not required. */
105 fprintf(stderr, _("in_ether(%s): trailing : ignored!\n"),
114 /* That's it. Any trailing junk? */
115 if ((i == ETH_ALEN) && (*bufp != '\0')) {
117 fprintf(stderr, _("in_ether(%s): trailing junk!\n"), orig);
123 fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data));
130 struct hwtype ether_hwtype =
132 "ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN,
133 pr_ether, in_ether, NULL
137 #endif /* HAVE_HWETHER */