inet_ntoa.c revision 139815
1139815Simp/*- 27088Swollman * Copyright 1994, 1995 Massachusetts Institute of Technology 37088Swollman * 47088Swollman * Permission to use, copy, modify, and distribute this software and 57088Swollman * its documentation for any purpose and without fee is hereby 67088Swollman * granted, provided that both the above copyright notice and this 77088Swollman * permission notice appear in all copies, that both the above 87088Swollman * copyright notice and this permission notice appear in all 97088Swollman * supporting documentation, and that the name of M.I.T. not be used 107088Swollman * in advertising or publicity pertaining to distribution of the 117088Swollman * software without specific, written prior permission. M.I.T. makes 127088Swollman * no representations about the suitability of this software for any 137088Swollman * purpose. It is provided "as is" without express or implied 147088Swollman * warranty. 158876Srgrimes * 167088Swollman * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 177088Swollman * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 187088Swollman * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 197088Swollman * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 207088Swollman * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217088Swollman * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227088Swollman * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 237088Swollman * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 247088Swollman * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 257088Swollman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 267088Swollman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 277088Swollman * SUCH DAMAGE. 287088Swollman */ 297088Swollman 30116189Sobrien#include <sys/cdefs.h> 31116189Sobrien__FBSDID("$FreeBSD: head/sys/libkern/inet_ntoa.c 139815 2005-01-07 00:24:33Z imp $"); 32116189Sobrien 337088Swollman#include <sys/param.h> 347088Swollman#include <sys/systm.h> 357088Swollman 367088Swollman#include <netinet/in.h> 377088Swollman 387088Swollmanchar * 397088Swollmaninet_ntoa(struct in_addr ina) 407088Swollman{ 417088Swollman static char buf[4*sizeof "123"]; 427088Swollman unsigned char *ucp = (unsigned char *)&ina; 437088Swollman 447088Swollman sprintf(buf, "%d.%d.%d.%d", 457088Swollman ucp[0] & 0xff, 467088Swollman ucp[1] & 0xff, 477088Swollman ucp[2] & 0xff, 487088Swollman ucp[3] & 0xff); 497088Swollman return buf; 507088Swollman} 517088Swollman 5269134Salfredchar * 5369134Salfredinet_ntoa_r(struct in_addr ina, char *buf) 5469134Salfred{ 5569134Salfred unsigned char *ucp = (unsigned char *)&ina; 5669134Salfred 5769134Salfred sprintf(buf, "%d.%d.%d.%d", 5869134Salfred ucp[0] & 0xff, 5969134Salfred ucp[1] & 0xff, 6069134Salfred ucp[2] & 0xff, 6169134Salfred ucp[3] & 0xff); 6269134Salfred return buf; 6369134Salfred} 6469134Salfred 6569134Salfred 66