diff options
-rw-r--r-- | src/lib/libc/net/Makefile.inc | 5 | ||||
-rw-r--r-- | src/lib/libc/net/link_ntoa.3 (renamed from src/lib/libc/net/link_addr.3) | 59 | ||||
-rw-r--r-- | src/lib/libc/net/linkaddr.c | 80 |
3 files changed, 8 insertions, 136 deletions
diff --git a/src/lib/libc/net/Makefile.inc b/src/lib/libc/net/Makefile.inc index b063c4a1fa..b4d99987c5 100644 --- a/src/lib/libc/net/Makefile.inc +++ b/src/lib/libc/net/Makefile.inc | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.56 2014/08/31 02:27:37 guenther Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.57 2015/09/10 08:55:03 mpi Exp $ |
2 | 2 | ||
3 | # net sources | 3 | # net sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/net ${LIBCSRCDIR}/net |
@@ -32,7 +32,7 @@ MAN+= byteorder.3 ethers.3 gai_strerror.3 getaddrinfo.3 gethostbyname.3 \ | |||
32 | getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ | 32 | getifaddrs.3 getnameinfo.3 getnetent.3 getpeereid.3 getprotoent.3 \ |
33 | getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ | 33 | getrrsetbyname.3 getservent.3 htonl.3 if_indextoname.3 \ |
34 | inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ | 34 | inet_addr.3 inet_lnaof.3 inet_net.3 inet_ntop.3 \ |
35 | inet6_opt_init.3 inet6_rth_space.3 link_addr.3 \ | 35 | inet6_opt_init.3 inet6_rth_space.3 link_ntoa.3 \ |
36 | rcmd.3 rcmdsh.3 resolver.3 sockatmark.3 | 36 | rcmd.3 rcmdsh.3 resolver.3 sockatmark.3 |
37 | 37 | ||
38 | MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \ | 38 | MLINKS+=byteorder.3 htobe16.3 byteorder.3 htobe32.3 byteorder.3 htobe64.3 \ |
@@ -70,7 +70,6 @@ MLINKS+=inet_addr.3 inet_aton.3 inet_addr.3 inet_network.3 \ | |||
70 | MLINKS+=inet_lnaof.3 inet_makeaddr.3 inet_lnaof.3 inet_netof.3 | 70 | MLINKS+=inet_lnaof.3 inet_makeaddr.3 inet_lnaof.3 inet_netof.3 |
71 | MLINKS+=inet_ntop.3 inet_pton.3 | 71 | MLINKS+=inet_ntop.3 inet_pton.3 |
72 | MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 | 72 | MLINKS+=inet_net.3 inet_net_ntop.3 inet_net.3 inet_net_pton.3 |
73 | MLINKS+=link_addr.3 link_ntoa.3 | ||
74 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ | 73 | MLINKS+=rcmd.3 iruserok.3 rcmd.3 rresvport.3 rcmd.3 ruserok.3 \ |
75 | rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 | 74 | rcmd.3 rresvport_af.3 rcmd.3 rcmd_af.3 rcmd.3 iruserok_sa.3 |
76 | MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ | 75 | MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ |
diff --git a/src/lib/libc/net/link_addr.3 b/src/lib/libc/net/link_ntoa.3 index f234fe84cc..67a412dbc8 100644 --- a/src/lib/libc/net/link_addr.3 +++ b/src/lib/libc/net/link_ntoa.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: link_addr.3,v 1.13 2013/06/05 03:39:23 tedu Exp $ | 1 | .\" $OpenBSD: link_ntoa.3,v 1.1 2015/09/10 08:55:03 mpi Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1993 | 3 | .\" Copyright (c) 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -30,29 +30,22 @@ | |||
30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
32 | .\" | 32 | .\" |
33 | .Dd $Mdocdate: June 5 2013 $ | 33 | .Dd $Mdocdate: September 10 2015 $ |
34 | .Dt LINK_ADDR 3 | 34 | .Dt LINK_NTOA 3 |
35 | .Os | 35 | .Os |
36 | .Sh NAME | 36 | .Sh NAME |
37 | .Nm link_addr , | ||
38 | .Nm link_ntoa | 37 | .Nm link_ntoa |
39 | .Nd elementary address specification routines for link level access | 38 | .Nd elementary address specification routines for link level access |
40 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
41 | .In sys/types.h | 40 | .In sys/types.h |
42 | .In sys/socket.h | 41 | .In sys/socket.h |
43 | .In net/if_dl.h | 42 | .In net/if_dl.h |
44 | .Ft void | ||
45 | .Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" | ||
46 | .Ft char * | 43 | .Ft char * |
47 | .Fn link_ntoa "const struct sockaddr_dl *sdl" | 44 | .Fn link_ntoa "const struct sockaddr_dl *sdl" |
48 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
49 | The | 46 | The |
50 | .Fn link_addr | ||
51 | function interprets character strings representing | ||
52 | link-level addresses, returning binary information suitable | ||
53 | for use in system calls. | ||
54 | .Fn link_ntoa | 47 | .Fn link_ntoa |
55 | takes | 48 | function takes |
56 | a link-level | 49 | a link-level |
57 | address and returns an | 50 | address and returns an |
58 | .Tn ASCII | 51 | .Tn ASCII |
@@ -61,59 +54,21 @@ including the link level address itself, and the interface name | |||
61 | or number, if present. | 54 | or number, if present. |
62 | This facility is experimental and is | 55 | This facility is experimental and is |
63 | still subject to change. | 56 | still subject to change. |
64 | .Pp | ||
65 | For | ||
66 | .Fn link_addr , | ||
67 | the string | ||
68 | .Fa addr | ||
69 | may contain | ||
70 | an optional network interface identifier of the form | ||
71 | .Dq name unit-number , | ||
72 | suitable for the first argument to | ||
73 | .Xr ifconfig 8 , | ||
74 | followed in all cases by a colon and | ||
75 | an interface address in the form of | ||
76 | groups of hexadecimal digits | ||
77 | separated by periods. | ||
78 | Each group represents a byte of address; | ||
79 | address bytes are filled left to right from | ||
80 | low order bytes through high order bytes. | ||
81 | .Pp | ||
82 | .\" A regular expression may make this format clearer: | ||
83 | .\" .Bd -literal -offset indent | ||
84 | .\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* | ||
85 | .\" .Ed | ||
86 | .\" .Pp | ||
87 | Thus | ||
88 | .Li le0:8.0.9.13.d.30 | ||
89 | represents an Ethernet address | ||
90 | to be transmitted on the first Lance Ethernet interface. | ||
91 | .Sh RETURN VALUES | 57 | .Sh RETURN VALUES |
92 | .Fn link_ntoa | 58 | .Fn link_ntoa |
93 | always returns a NUL-terminated string. | 59 | always returns a NUL-terminated string. |
94 | .Fn link_addr | ||
95 | has no return value. | ||
96 | (See | ||
97 | .Sx BUGS . ) | ||
98 | .Sh SEE ALSO | 60 | .Sh SEE ALSO |
99 | .Xr ifconfig 8 | 61 | .Xr ifconfig 8 |
100 | .Sh HISTORY | 62 | .Sh HISTORY |
101 | The | 63 | The |
102 | .Fn link_addr | ||
103 | and | ||
104 | .Fn link_ntoa | 64 | .Fn link_ntoa |
105 | functions appeared in | 65 | function appeared in |
106 | .Bx 4.3 Reno . | 66 | .Bx 4.3 Reno . |
107 | .Sh BUGS | 67 | .Sh BUGS |
108 | The returned values for | 68 | The returned values for |
109 | .Fn link_ntoa | 69 | .Fn link_ntoa |
110 | reside in a static memory area. | 70 | reside in a static memory area. |
111 | .Pp | 71 | .Pp |
112 | The function | ||
113 | .Fn link_addr | ||
114 | should diagnose improperly formed input, and there should be an unambiguous | ||
115 | way to recognize this. | ||
116 | .Pp | ||
117 | If the | 72 | If the |
118 | .Fa sdl_len | 73 | .Fa sdl_len |
119 | field of the link socket address | 74 | field of the link socket address |
@@ -121,7 +76,3 @@ field of the link socket address | |||
121 | is 0, | 76 | is 0, |
122 | .Fn link_ntoa | 77 | .Fn link_ntoa |
123 | will not insert a colon before the interface address bytes. | 78 | will not insert a colon before the interface address bytes. |
124 | If this translated address is given to | ||
125 | .Fn link_addr | ||
126 | without inserting an initial colon, | ||
127 | the latter will not interpret it correctly. | ||
diff --git a/src/lib/libc/net/linkaddr.c b/src/lib/libc/net/linkaddr.c index ac96f3acdf..8f90aca8f5 100644 --- a/src/lib/libc/net/linkaddr.c +++ b/src/lib/libc/net/linkaddr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: linkaddr.c,v 1.5 2005/08/06 20:30:03 espie Exp $ */ | 1 | /* $OpenBSD: linkaddr.c,v 1.6 2015/09/10 08:55:03 mpi Exp $ */ |
2 | /*- | 2 | /*- |
3 | * Copyright (c) 1990, 1993 | 3 | * Copyright (c) 1990, 1993 |
4 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -33,84 +33,6 @@ | |||
33 | #include <net/if_dl.h> | 33 | #include <net/if_dl.h> |
34 | #include <string.h> | 34 | #include <string.h> |
35 | 35 | ||
36 | /* States*/ | ||
37 | #define NAMING 0 | ||
38 | #define GOTONE 1 | ||
39 | #define GOTTWO 2 | ||
40 | #define RESET 3 | ||
41 | /* Inputs */ | ||
42 | #define DIGIT (4*0) | ||
43 | #define END (4*1) | ||
44 | #define DELIM (4*2) | ||
45 | #define LETTER (4*3) | ||
46 | |||
47 | void | ||
48 | link_addr(const char *addr, struct sockaddr_dl *sdl) | ||
49 | { | ||
50 | char *cp = sdl->sdl_data; | ||
51 | char *cplim = sdl->sdl_len + (char *)sdl; | ||
52 | int byte = 0, state = NAMING, new; | ||
53 | |||
54 | bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); | ||
55 | sdl->sdl_family = AF_LINK; | ||
56 | do { | ||
57 | state &= ~LETTER; | ||
58 | if ((*addr >= '0') && (*addr <= '9')) { | ||
59 | new = *addr - '0'; | ||
60 | } else if ((*addr >= 'a') && (*addr <= 'f')) { | ||
61 | new = *addr - 'a' + 10; | ||
62 | } else if ((*addr >= 'A') && (*addr <= 'F')) { | ||
63 | new = *addr - 'A' + 10; | ||
64 | } else if (*addr == 0) { | ||
65 | state |= END; | ||
66 | } else if (state == NAMING && | ||
67 | (((*addr >= 'A') && (*addr <= 'Z')) || | ||
68 | ((*addr >= 'a') && (*addr <= 'z')))) | ||
69 | state |= LETTER; | ||
70 | else | ||
71 | state |= DELIM; | ||
72 | addr++; | ||
73 | switch (state /* | INPUT */) { | ||
74 | case NAMING | DIGIT: | ||
75 | case NAMING | LETTER: | ||
76 | *cp++ = addr[-1]; | ||
77 | continue; | ||
78 | case NAMING | DELIM: | ||
79 | state = RESET; | ||
80 | sdl->sdl_nlen = cp - sdl->sdl_data; | ||
81 | continue; | ||
82 | case GOTTWO | DIGIT: | ||
83 | *cp++ = byte; | ||
84 | /* FALLTHROUGH */ | ||
85 | case RESET | DIGIT: | ||
86 | state = GOTONE; | ||
87 | byte = new; | ||
88 | continue; | ||
89 | case GOTONE | DIGIT: | ||
90 | state = GOTTWO; | ||
91 | byte = new + (byte << 4); | ||
92 | continue; | ||
93 | default: /* | DELIM */ | ||
94 | state = RESET; | ||
95 | *cp++ = byte; | ||
96 | byte = 0; | ||
97 | continue; | ||
98 | case GOTONE | END: | ||
99 | case GOTTWO | END: | ||
100 | *cp++ = byte; | ||
101 | /* FALLTHROUGH */ | ||
102 | case RESET | END: | ||
103 | break; | ||
104 | } | ||
105 | break; | ||
106 | } while (cp < cplim); | ||
107 | sdl->sdl_alen = cp - LLADDR(sdl); | ||
108 | new = cp - (char *)sdl; | ||
109 | if (new > sizeof(*sdl)) | ||
110 | sdl->sdl_len = new; | ||
111 | return; | ||
112 | } | ||
113 | |||
114 | static char hexlist[] = "0123456789abcdef"; | 36 | static char hexlist[] = "0123456789abcdef"; |
115 | 37 | ||
116 | char * | 38 | char * |