2 * lib/eui64.c This file contains support for generic EUI-64 hw addressing
4 * Version: $Id: eui64.c,v 1.1 2001/11/12 02:12:05 ecki Exp $
6 * Author: Daniel Stodden <stodden@in.tum.de>
7 * Copyright 2001 Daniel Stodden
9 * blueprinted from ether.c
10 * Copyright 1993 MicroWalt Corporation
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.
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <net/if_arp.h>
34 #include "net-support.h"
35 #include "pathnames.h"
45 #define ARPHRD_EUI64 27
46 #warning "ARPHRD_EUI64 not defined in <net/if_arp.h>. Using private value 27"
49 struct hwtype eui64_hwtype
;
51 /* Display an EUI-64 address in readable format. */
52 static char *pr_eui64( unsigned char *ptr
)
56 snprintf(buff
, sizeof(buff
), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
57 (ptr
[0] & 0377), (ptr
[1] & 0377), (ptr
[2] & 0377), (ptr
[3] & 0377),
58 (ptr
[4] & 0377), (ptr
[5] & 0377), (ptr
[6] & 0377), (ptr
[7] & 0377)
63 /* Start the PPP encapsulation on the file descriptor. */
64 static int in_eui64( char *bufp
, struct sockaddr
*sap
)
71 sap
->sa_family
= eui64_hwtype
.type
;
77 while ((*bufp
!= '\0') && (i
< EUI64_ALEN
)) {
82 else if (c
>= 'a' && c
<= 'f')
84 else if (c
>= 'A' && c
<= 'F')
88 fprintf( stderr
, _("in_eui64(%s): invalid eui64 address!\n"),
99 else if (c
>= 'a' && c
<= 'f')
101 else if (c
>= 'A' && c
<= 'F')
103 else if (c
== ':' || c
== 0)
107 fprintf( stderr
, _("in_eui64(%s): invalid eui64 address!\n"),
117 *ptr
++ = (unsigned char) (val
& 0377);
120 /* We might get a semicolon here - not required. */
122 if (i
== EUI64_ALEN
) {
124 fprintf(stderr
, _("in_eui64(%s): trailing : ignored!\n"),
133 /* That's it. Any trailing junk? */
134 if ((i
== EUI64_ALEN
) && (*bufp
!= '\0')) {
136 fprintf(stderr
, _("in_eui64(%s): trailing junk!\n"), orig
);
142 fprintf(stderr
, "in_eui64(%s): %s\n", orig
, pr_eui64(sap
->sa_data
));
148 struct hwtype eui64_hwtype
=
150 "eui64", NULL
, /*"EUI-64 addressing", */ ARPHRD_EUI64
, EUI64_ALEN
,
151 pr_eui64
, in_eui64
, NULL
, 0
155 #endif /* HAVE_EUI64 */