Deleted Added
full compact
linkaddr.c (309633) linkaddr.c (309692)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
32#endif /* LIBC_SCCS and not lint */
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
32#endif /* LIBC_SCCS and not lint */
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: releng/11.0/lib/libc/net/linkaddr.c 309633 2016-12-06 18:49:38Z glebius $");
34__FBSDID("$FreeBSD: releng/11.0/lib/libc/net/linkaddr.c 309692 2016-12-07 23:29:42Z glebius $");
35
36#include <sys/types.h>
37#include <sys/socket.h>
38#include <net/if.h>
39#include <net/if_dl.h>
40#include <string.h>
41
42/* States*/

--- 77 unchanged lines hidden (view full) ---

120static const char hexlist[] = "0123456789abcdef";
121
122char *
123link_ntoa(const struct sockaddr_dl *sdl)
124{
125 static char obuf[64];
126 _Static_assert(sizeof(obuf) >= IFNAMSIZ + 20, "obuf is too small");
127 char *out;
35
36#include <sys/types.h>
37#include <sys/socket.h>
38#include <net/if.h>
39#include <net/if_dl.h>
40#include <string.h>
41
42/* States*/

--- 77 unchanged lines hidden (view full) ---

120static const char hexlist[] = "0123456789abcdef";
121
122char *
123link_ntoa(const struct sockaddr_dl *sdl)
124{
125 static char obuf[64];
126 _Static_assert(sizeof(obuf) >= IFNAMSIZ + 20, "obuf is too small");
127 char *out;
128 const char *in, *inlim;
128 const u_char *in, *inlim;
129 int namelen, i, rem;
130
131 namelen = (sdl->sdl_nlen <= IFNAMSIZ) ? sdl->sdl_nlen : IFNAMSIZ;
132
133 out = obuf;
134 rem = sizeof(obuf);
135 if (namelen > 0) {
136 bcopy(sdl->sdl_data, out, namelen);
137 out += namelen;
138 rem -= namelen;
139 if (sdl->sdl_alen > 0) {
140 *out++ = ':';
141 rem--;
142 }
143 }
144
129 int namelen, i, rem;
130
131 namelen = (sdl->sdl_nlen <= IFNAMSIZ) ? sdl->sdl_nlen : IFNAMSIZ;
132
133 out = obuf;
134 rem = sizeof(obuf);
135 if (namelen > 0) {
136 bcopy(sdl->sdl_data, out, namelen);
137 out += namelen;
138 rem -= namelen;
139 if (sdl->sdl_alen > 0) {
140 *out++ = ':';
141 rem--;
142 }
143 }
144
145 in = (const char *)sdl->sdl_data + sdl->sdl_nlen;
145 in = (const u_char *)sdl->sdl_data + sdl->sdl_nlen;
146 inlim = in + sdl->sdl_alen;
147
148 while (in < inlim && rem > 1) {
146 inlim = in + sdl->sdl_alen;
147
148 while (in < inlim && rem > 1) {
149 if (in != (const char *)sdl->sdl_data + sdl->sdl_nlen) {
149 if (in != (const u_char *)sdl->sdl_data + sdl->sdl_nlen) {
150 *out++ = '.';
151 rem--;
152 }
153 i = *in++;
154 if (i > 0xf) {
155 if (rem < 3)
156 break;
150 *out++ = '.';
151 rem--;
152 }
153 i = *in++;
154 if (i > 0xf) {
155 if (rem < 3)
156 break;
157 *out++ = hexlist[i >> 4];
157 *out++ = hexlist[i & 0xf];
158 *out++ = hexlist[i & 0xf];
158 i >>= 4;
159 *out++ = hexlist[i];
160 rem -= 2;
161 } else {
162 if (rem < 2)
163 break;
164 *out++ = hexlist[i];
159 rem -= 2;
160 } else {
161 if (rem < 2)
162 break;
163 *out++ = hexlist[i];
165 rem++;
164 rem--;
166 }
167 }
168 *out = 0;
169 return (obuf);
170}
165 }
166 }
167 *out = 0;
168 return (obuf);
169}