xref: /openbsd-src/usr.sbin/dhcpd/print.c (revision 837cddff4b95f9432151663c8b92d709c11482aa)
1*837cddffSkrw /*	$OpenBSD: print.c,v 1.11 2016/02/06 23:50:10 krw Exp $ */
2e853bc5dShenning 
362767975Shshoexer /* Turn data structures into printable text. */
4e853bc5dShenning 
5e853bc5dShenning /*
6e853bc5dShenning  * Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
7e853bc5dShenning  * All rights reserved.
8e853bc5dShenning  *
9e853bc5dShenning  * Redistribution and use in source and binary forms, with or without
10e853bc5dShenning  * modification, are permitted provided that the following conditions
11e853bc5dShenning  * are met:
12e853bc5dShenning  *
13e853bc5dShenning  * 1. Redistributions of source code must retain the above copyright
14e853bc5dShenning  *    notice, this list of conditions and the following disclaimer.
15e853bc5dShenning  * 2. Redistributions in binary form must reproduce the above copyright
16e853bc5dShenning  *    notice, this list of conditions and the following disclaimer in the
17e853bc5dShenning  *    documentation and/or other materials provided with the distribution.
18e853bc5dShenning  * 3. Neither the name of The Internet Software Consortium nor the names
19e853bc5dShenning  *    of its contributors may be used to endorse or promote products derived
20e853bc5dShenning  *    from this software without specific prior written permission.
21e853bc5dShenning  *
22e853bc5dShenning  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23e853bc5dShenning  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24e853bc5dShenning  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25e853bc5dShenning  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26e853bc5dShenning  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27e853bc5dShenning  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28e853bc5dShenning  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29e853bc5dShenning  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30e853bc5dShenning  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31e853bc5dShenning  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32e853bc5dShenning  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33e853bc5dShenning  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34e853bc5dShenning  * SUCH DAMAGE.
35e853bc5dShenning  *
36e853bc5dShenning  * This software has been written for the Internet Software Consortium
37e853bc5dShenning  * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
38e853bc5dShenning  * Enterprises.  To learn more about the Internet Software Consortium,
39e853bc5dShenning  * see ``http://www.vix.com/isc''.  To learn more about Vixie
40e853bc5dShenning  * Enterprises, see ``http://www.vix.com''.
41e853bc5dShenning  */
42e853bc5dShenning 
43*837cddffSkrw #include <sys/types.h>
44*837cddffSkrw #include <sys/socket.h>
45*837cddffSkrw 
46*837cddffSkrw #include <net/if.h>
47*837cddffSkrw 
48*837cddffSkrw #include <netinet/in.h>
49*837cddffSkrw 
50*837cddffSkrw #include <stdio.h>
51*837cddffSkrw #include <string.h>
52*837cddffSkrw 
53*837cddffSkrw #include "dhcp.h"
54*837cddffSkrw #include "tree.h"
55e853bc5dShenning #include "dhcpd.h"
56e853bc5dShenning 
5762767975Shshoexer char *
print_hw_addr(int htype,int hlen,unsigned char * data)5862767975Shshoexer print_hw_addr(int htype, int hlen, unsigned char *data)
59e853bc5dShenning {
60e853bc5dShenning 	static char	habuf[49];
61fd395675Sderaadt 	int		i, j, slen = sizeof(habuf);
62fd395675Sderaadt 	char		*s = habuf;
63e853bc5dShenning 
64e853bc5dShenning 	if (htype == 0 || hlen == 0) {
65e853bc5dShenning bad:
66e853bc5dShenning 		strlcpy(habuf, "<null>", sizeof habuf);
67e853bc5dShenning 		return habuf;
68fd395675Sderaadt 	}
69e853bc5dShenning 
70fd395675Sderaadt 	for (i = 0; i < hlen; i++) {
71fd395675Sderaadt 		j = snprintf(s, slen, "%02x", data[i]);
72fd395675Sderaadt 		if (j <= 0 || j >= slen)
73fd395675Sderaadt 			goto bad;
74fd395675Sderaadt 		j = strlen(s);
75fd395675Sderaadt 		s += j;
76fd395675Sderaadt 		slen -= (j + 1);
77fd395675Sderaadt 		*s++ = ':';
78fd395675Sderaadt 	}
79fd395675Sderaadt 	*--s = '\0';
80fd395675Sderaadt 	return habuf;
81e853bc5dShenning }
82