xref: /netbsd-src/sys/lib/libsa/ether_sprintf.c (revision 2f39df062cf815ccfe77379eba43fa6197713601)
1*2f39df06Sjakllsch /*	$NetBSD: ether_sprintf.c,v 1.7 2014/03/29 14:20:14 jakllsch Exp $	*/
268edf0e5Sdrochner 
368edf0e5Sdrochner /*
468edf0e5Sdrochner  * Copyright (c) 1992 Regents of the University of California.
568edf0e5Sdrochner  * All rights reserved.
668edf0e5Sdrochner  *
768edf0e5Sdrochner  * This software was developed by the Computer Systems Engineering group
868edf0e5Sdrochner  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
968edf0e5Sdrochner  * contributed to Berkeley.
1068edf0e5Sdrochner  *
1168edf0e5Sdrochner  * Redistribution and use in source and binary forms, with or without
1268edf0e5Sdrochner  * modification, are permitted provided that the following conditions
1368edf0e5Sdrochner  * are met:
1468edf0e5Sdrochner  * 1. Redistributions of source code must retain the above copyright
1568edf0e5Sdrochner  *    notice, this list of conditions and the following disclaimer.
1668edf0e5Sdrochner  * 2. Redistributions in binary form must reproduce the above copyright
1768edf0e5Sdrochner  *    notice, this list of conditions and the following disclaimer in the
1868edf0e5Sdrochner  *    documentation and/or other materials provided with the distribution.
1968edf0e5Sdrochner  * 3. All advertising materials mentioning features or use of this software
2068edf0e5Sdrochner  *    must display the following acknowledgement:
2168edf0e5Sdrochner  *	This product includes software developed by the University of
2268edf0e5Sdrochner  *	California, Lawrence Berkeley Laboratory and its contributors.
2368edf0e5Sdrochner  * 4. Neither the name of the University nor the names of its contributors
2468edf0e5Sdrochner  *    may be used to endorse or promote products derived from this software
2568edf0e5Sdrochner  *    without specific prior written permission.
2668edf0e5Sdrochner  *
2768edf0e5Sdrochner  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2868edf0e5Sdrochner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2968edf0e5Sdrochner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3068edf0e5Sdrochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3168edf0e5Sdrochner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3268edf0e5Sdrochner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3368edf0e5Sdrochner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3468edf0e5Sdrochner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3568edf0e5Sdrochner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3668edf0e5Sdrochner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3768edf0e5Sdrochner  * SUCH DAMAGE.
3868edf0e5Sdrochner  *
3968edf0e5Sdrochner  * @(#) Header: net.c,v 1.9 93/08/06 19:32:15 leres Exp  (LBL)
4068edf0e5Sdrochner  */
4168edf0e5Sdrochner 
4268edf0e5Sdrochner #include <sys/param.h>
4368edf0e5Sdrochner #include <sys/socket.h>
4468edf0e5Sdrochner #ifdef _STANDALONE
4568edf0e5Sdrochner #include <lib/libkern/libkern.h>
4668edf0e5Sdrochner #else
4768edf0e5Sdrochner #include <string.h>
4868edf0e5Sdrochner #endif
4968edf0e5Sdrochner 
50*2f39df06Sjakllsch #include <net/if_ether.h>
5168edf0e5Sdrochner 
5268edf0e5Sdrochner #include "stand.h"
5368edf0e5Sdrochner #include "net.h"
5468edf0e5Sdrochner 
5568edf0e5Sdrochner /*
5668edf0e5Sdrochner  * Convert Ethernet address to printable (loggable) representation.
5768edf0e5Sdrochner  */
5868edf0e5Sdrochner char *
ether_sprintf(const u_char * ap)598f67218aSchristos ether_sprintf(const u_char *ap)
6068edf0e5Sdrochner {
6168edf0e5Sdrochner 	int i;
62*2f39df06Sjakllsch 	static char etherbuf[3*ETHER_ADDR_LEN];
6368edf0e5Sdrochner 	char *cp = etherbuf;
6468edf0e5Sdrochner 
65*2f39df06Sjakllsch 	for (i = 0; i < ETHER_ADDR_LEN; i++) {
66362a4a0bSchristos 		*cp++ = hexdigits[*ap >> 4];
67362a4a0bSchristos 		*cp++ = hexdigits[*ap++ & 0xf];
6868edf0e5Sdrochner 		*cp++ = ':';
6968edf0e5Sdrochner 	}
7068edf0e5Sdrochner 	*--cp = 0;
711c038e68Sisaki 	return etherbuf;
7268edf0e5Sdrochner }
73