10cac72f4SYoshinobu Inoue.\" Copyright (C) 1995, 1996, 1997, 1998, 1999, and 2000 WIDE Project. 20cac72f4SYoshinobu Inoue.\" All rights reserved. 30cac72f4SYoshinobu Inoue.\" 40cac72f4SYoshinobu Inoue.\" Redistribution and use in source and binary forms, with or without 50cac72f4SYoshinobu Inoue.\" modification, are permitted provided that the following conditions 60cac72f4SYoshinobu Inoue.\" are met: 70cac72f4SYoshinobu Inoue.\" 1. Redistributions of source code must retain the above copyright 80cac72f4SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer. 90cac72f4SYoshinobu Inoue.\" 2. Redistributions in binary form must reproduce the above copyright 100cac72f4SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer in the 110cac72f4SYoshinobu Inoue.\" documentation and/or other materials provided with the distribution. 120cac72f4SYoshinobu Inoue.\" 3. Neither the name of the project nor the names of its contributors 130cac72f4SYoshinobu Inoue.\" may be used to endorse or promote products derived from this software 140cac72f4SYoshinobu Inoue.\" without specific prior written permission. 150cac72f4SYoshinobu Inoue.\" 160cac72f4SYoshinobu Inoue.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 170cac72f4SYoshinobu Inoue.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 180cac72f4SYoshinobu Inoue.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 190cac72f4SYoshinobu Inoue.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 200cac72f4SYoshinobu Inoue.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 210cac72f4SYoshinobu Inoue.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 220cac72f4SYoshinobu Inoue.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 230cac72f4SYoshinobu Inoue.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 240cac72f4SYoshinobu Inoue.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 250cac72f4SYoshinobu Inoue.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 260cac72f4SYoshinobu Inoue.\" SUCH DAMAGE. 270cac72f4SYoshinobu Inoue.\" 280cac72f4SYoshinobu Inoue.\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 290cac72f4SYoshinobu Inoue.\" All rights reserved. 300cac72f4SYoshinobu Inoue.\" 310cac72f4SYoshinobu Inoue.\" Redistribution and use in source and binary forms, with or without 320cac72f4SYoshinobu Inoue.\" modification, are permitted provided that the following conditions 330cac72f4SYoshinobu Inoue.\" are met: 340cac72f4SYoshinobu Inoue.\" 1. Redistributions of source code must retain the above copyright 350cac72f4SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer. 360cac72f4SYoshinobu Inoue.\" 2. Redistributions in binary form must reproduce the above copyright 370cac72f4SYoshinobu Inoue.\" notice, this list of conditions and the following disclaimer in the 380cac72f4SYoshinobu Inoue.\" documentation and/or other materials provided with the distribution. 390cac72f4SYoshinobu Inoue.\" 400cac72f4SYoshinobu Inoue.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 410cac72f4SYoshinobu Inoue.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 420cac72f4SYoshinobu Inoue.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 430cac72f4SYoshinobu Inoue.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 440cac72f4SYoshinobu Inoue.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 450cac72f4SYoshinobu Inoue.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 460cac72f4SYoshinobu Inoue.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 470cac72f4SYoshinobu Inoue.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 480cac72f4SYoshinobu Inoue.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 490cac72f4SYoshinobu Inoue.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 500cac72f4SYoshinobu Inoue.\" SUCH DAMAGE. 510cac72f4SYoshinobu Inoue.\" 520cac72f4SYoshinobu Inoue.\" $FreeBSD$ 530cac72f4SYoshinobu Inoue.\" 540cac72f4SYoshinobu Inoue.Dd January 11, 2000 550cac72f4SYoshinobu Inoue.Os 560cac72f4SYoshinobu Inoue.Dt REALHOSTNAME_SA 3 570cac72f4SYoshinobu Inoue.Sh NAME 580cac72f4SYoshinobu Inoue.Nm realhostname_sa 590cac72f4SYoshinobu Inoue.Nd "convert an struct sockaddr to the real host name" 600cac72f4SYoshinobu Inoue.Sh SYNOPSIS 610cac72f4SYoshinobu Inoue.Fd #include <sys/types.h> 620cac72f4SYoshinobu Inoue.Fd #include <netinet/in.h> 630cac72f4SYoshinobu Inoue.Fd #include <libutil.h> 640cac72f4SYoshinobu Inoue.Ft int 65cc8ffb11SBruce Evans.Fn realhostname_sa "char *host" "size_t hsize" "struct sockaddr *addr" "int addrlen" 660cac72f4SYoshinobu Inoue.Pp 670cac72f4SYoshinobu InoueLink with 680cac72f4SYoshinobu Inoue.Va -lutil 690cac72f4SYoshinobu Inoueon the 700cac72f4SYoshinobu Inoue.Xr cc 1 710cac72f4SYoshinobu Inouecommand line. 720cac72f4SYoshinobu Inoue.Sh DESCRIPTION 730cac72f4SYoshinobu InoueThe function 740cac72f4SYoshinobu Inoue.Fn realhostname_sa 750cac72f4SYoshinobu Inoueconverts 760cac72f4SYoshinobu Inoue.Ar addr 770cac72f4SYoshinobu Inoueto the corresponding host name. This is done by resolving 780cac72f4SYoshinobu Inoue.Ar addr 790cac72f4SYoshinobu Inoueto a host name and then ensuring that the host name resolves 800cac72f4SYoshinobu Inoueback to 810cac72f4SYoshinobu Inoue.Ar addr . 820cac72f4SYoshinobu Inoue.Pp 830cac72f4SYoshinobu Inoue.Ar host 840cac72f4SYoshinobu Inouemust point to a buffer of at least 850cac72f4SYoshinobu Inoue.Ar hsize 860cac72f4SYoshinobu Inouebytes, and will always be written to by this function. 870cac72f4SYoshinobu Inoue.Pp 880cac72f4SYoshinobu InoueIf the name resolution doesn't work both ways or if the host name is longer 890cac72f4SYoshinobu Inouethan 900cac72f4SYoshinobu Inoue.Ar hsize 910cac72f4SYoshinobu Inouebytes, 920cac72f4SYoshinobu Inoue.Xr getnameinfo 3 930cac72f4SYoshinobu Inouewith NI_NUMERICHOST specified, is used to convert 940cac72f4SYoshinobu Inoue.Ar addr 950cac72f4SYoshinobu Inoueto an ASCII form. 960cac72f4SYoshinobu Inoue.Pp 970cac72f4SYoshinobu InoueIf the string written to 980cac72f4SYoshinobu Inoue.Ar host 990cac72f4SYoshinobu Inoueis 1000cac72f4SYoshinobu Inoue.Ar hsize 1010cac72f4SYoshinobu Inouebytes long, 1020cac72f4SYoshinobu Inoue.Ar host 1030cac72f4SYoshinobu Inouewill not be NUL terminated. 1040cac72f4SYoshinobu Inoue.Sh RETURN VALUES 1050cac72f4SYoshinobu Inoue.Fn realhostname_sa 1060cac72f4SYoshinobu Inouewill return one of the following constants which are defined in 1070cac72f4SYoshinobu Inoue.Pa libutil.h : 1080cac72f4SYoshinobu Inoue.Pp 1090cac72f4SYoshinobu Inoue.Bl -tag -width XXX -offset XXX 1100cac72f4SYoshinobu Inoue.It Li HOSTNAME_FOUND 1110cac72f4SYoshinobu InoueA valid host name was found. 1120cac72f4SYoshinobu Inoue.It Li HOSTNAME_INCORRECTNAME 1130cac72f4SYoshinobu InoueA host name was found, but it did not resolve back to the passed 1140cac72f4SYoshinobu Inoue.Ar ip . 1150cac72f4SYoshinobu Inoue.Ar host 1160cac72f4SYoshinobu Inouenow contains the numeric value of 1170cac72f4SYoshinobu Inoue.Ar ip . 1180cac72f4SYoshinobu Inoue.It Li HOSTNAME_INVALIDADDR 1190cac72f4SYoshinobu Inoue.Ar ip 1200cac72f4SYoshinobu Inouecould not be resolved. 1210cac72f4SYoshinobu Inoue.Ar host 1220cac72f4SYoshinobu Inouenow contains the numeric value of 1230cac72f4SYoshinobu Inoue.Ar ip . 1240cac72f4SYoshinobu Inoue.It Li HOSTNAME_INVALIDNAME 1250cac72f4SYoshinobu InoueA host name was found, but it could not be resolved back to any ip number. 1260cac72f4SYoshinobu Inoue.Ar host 1270cac72f4SYoshinobu Inouenow contains the numeric value of 1280cac72f4SYoshinobu Inoue.Ar ip . 1290cac72f4SYoshinobu Inoue.El 1300cac72f4SYoshinobu Inoue.Sh SEE ALSO 1310cac72f4SYoshinobu Inoue.Xr getaddrinfo 3 , 1320cac72f4SYoshinobu Inoue.Xr getnameinfo 3 , 1330cac72f4SYoshinobu Inoue.Xr realhostname 3 1340cac72f4SYoshinobu Inoue 135