3 * linkaddr.c - link level address parsing
5 * Copyright © 1994 AmiTCP/IP Group,
6 * Network Solutions Development Inc.
9 * Copyright © 1991 Regents of the University of California.
13 static char sccsid
[] = "@(#)linkaddr.c 5.2 (Berkeley) 2/24/91";
16 #include <sys/types.h>
17 #include <sys/socket.h>
19 #include <net/if_dl.h>
35 register const char *addr
;
36 register struct sockaddr_dl
*sdl
;
38 register char *cp
= sdl
->sdl_data
;
39 char *cplim
= sdl
->sdl_len
+ (char *)sdl
;
40 register int byte
= 0, state
= NAMING
, new;
42 bzero((char *)&sdl
->sdl_family
, sdl
->sdl_len
- 1);
43 sdl
->sdl_family
= AF_LINK
;
46 if ((*addr
>= '0') && (*addr
<= '9')) {
48 } else if ((*addr
>= 'a') && (*addr
<= 'f')) {
49 new = *addr
- 'a' + 10;
50 } else if ((*addr
>= 'A') && (*addr
<= 'F')) {
51 new = *addr
- 'A' + 10;
52 } else if (*addr
== 0) {
54 } else if (state
== NAMING
&&
55 (((*addr
>= 'A') && (*addr
<= 'Z')) ||
56 ((*addr
>= 'a') && (*addr
<= 'z'))))
61 switch (state
/* | INPUT */) {
64 *cp
++ = addr
[-1]; continue;
66 state
= RESET
; sdl
->sdl_nlen
= cp
- sdl
->sdl_data
; continue;
68 *cp
++ = byte
; /*FALLTHROUGH*/
70 state
= GOTONE
; byte
= new; continue;
72 state
= GOTTWO
; byte
= new + (byte
<< 4); continue;
73 default: /* | DELIM */
74 state
= RESET
; *cp
++ = byte
; byte
= 0; continue;
77 *cp
++ = byte
; /* FALLTHROUGH */
83 sdl
->sdl_alen
= cp
- LLADDR(sdl
);
84 new = cp
- (char *)sdl
;
85 if (new > sizeof(*sdl
))