Skip to content

Commit 767f5c9

Browse files
committed
PR/57953: Attaullah Ansari: Add getnameinfo program
1 parent 4048e18 commit 767f5c9

4 files changed

Lines changed: 415 additions & 2 deletions

File tree

usr.bin/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $NetBSD: Makefile,v 1.241 2024/10/28 17:55:12 nia Exp $
1+
# $NetBSD: Makefile,v 1.242 2025/01/27 18:30:19 christos Exp $
22
# from: @(#)Makefile 8.3 (Berkeley) 1/7/94
33

44
.include <bsd.own.mk>
@@ -12,7 +12,7 @@ SUBDIR= aiomixer apply asa at audio audiocfg \
1212
eject elf2aout elf2ecoff env error expand extattr \
1313
false fdformat fgen fincore find finger flock fmt fold fpr from \
1414
fsplit fstat ftp gcore genassym gencat getaddrinfo getconf getent \
15-
getopt gettext gprof \
15+
getnameinfo getopt gettext gprof \
1616
head hexdump iconv id indent infocmp innetgr ipcrm ipcs join jot \
1717
kdump ktrace ktruss lam last lastcomm ldd leave \
1818
locale locate lock logger login logname look lorder m4 \

usr.bin/getnameinfo/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# $NetBSD: Makefile,v 1.1 2025/01/27 18:30:19 christos Exp $
2+
3+
.include <bsd.own.mk>
4+
5+
PROG = getnameinfo
6+
7+
WARNS = 5
8+
9+
.include <bsd.prog.mk>

usr.bin/getnameinfo/getnameinfo.1

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
.\" $NetBSD: getnameinfo.1,v 1.1 2025/01/27 18:30:19 christos Exp $
2+
.\"
3+
.\" Copyright (c) 2025 The NetBSD Foundation, Inc.
4+
.\" All rights reserved.
5+
.\"
6+
.\" This documentation is derived from text contributed to The NetBSD
7+
.\" Foundation by Attaullah Ansari.
8+
.\"
9+
.\" Redistribution and use in source and binary forms, with or without
10+
.\" modification, are permitted provided that the following conditions
11+
.\" are met:
12+
.\" 1. Redistributions of source code must retain the above copyright
13+
.\" notice, this list of conditions and the following disclaimer.
14+
.\" 2. Redistributions in binary form must reproduce the above copyright
15+
.\" notice, this list of conditions and the following disclaimer in the
16+
.\" documentation and/or other materials provided with the distribution.
17+
.\"
18+
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19+
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20+
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21+
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22+
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
.\" POSSIBILITY OF SUCH DAMAGE.
29+
.\"
30+
.Dd January 16, 2025
31+
.Dt GETNAMEINFO 1
32+
.Os
33+
.Sh NAME
34+
.Nm getnameinfo
35+
.Nd resolve IP addresses and ports to host and service names
36+
.Sh SYNOPSIS
37+
.Nm
38+
.Op Fl 46rufnNHS
39+
.Op Fl p Ar port
40+
.Ar IP-address
41+
.Sh DESCRIPTION
42+
The
43+
.Nm
44+
utility resolves IP addresses and port numbers to hostnames and service names
45+
as if with the
46+
.Xr getnameinfo 3
47+
library routine and formats them to standard output.
48+
.Pp
49+
The output is a single line of space-separated fields:
50+
.Pp
51+
.Dl hostname service
52+
.Pp
53+
Depending on the flags specified, the output may consist only of the hostname
54+
or service name, or their numeric representations.
55+
By default, both are shown.
56+
.Pp
57+
Although
58+
.Nm
59+
may query the DNS or other sources for name resolution depending on the
60+
system's
61+
.Xr nsswitch.conf 5
62+
configuration, it is not intended to replace DNS-specific tools like
63+
.Xr dig 1 .
64+
.Pp
65+
The following options are available:
66+
.Bl -tag -width Ds
67+
.It Fl 4
68+
Restrict the lookup to IPv4 addresses only.
69+
.It Fl 6
70+
Restrict the lookup to IPv6 addresses only.
71+
.It Fl r
72+
Ensure that a name is returned.
73+
If no name can be resolved, an error is reported.
74+
This is equivalent to the
75+
.Dv NI_NAMEREQD
76+
flag in
77+
.Xr getnameinfo 3 .
78+
.It Fl u
79+
Use UDP instead of the default TCP.
80+
This is equivalent to the
81+
.Dv NI_DGRAM
82+
flag in
83+
.Xr getnameinfo 3 .
84+
.It Fl f
85+
Suppress the fully-qualified domain name (FQDN).
86+
This is equivalent to the
87+
.Dv NI_NOFQDN
88+
flag in
89+
.Xr getnameinfo 3 .
90+
.It Fl n
91+
Display the numeric host address instead of resolving to a hostname.
92+
This is equivalent to the
93+
.Dv NI_NUMERICHOST
94+
flag in
95+
.Xr getnameinfo 3 .
96+
.It Fl N
97+
Display the numeric service name instead of resolving to a service name.
98+
This is equivalent to the
99+
.Dv NI_NUMERICSERV
100+
flag in
101+
.Xr getnameinfo 3 .
102+
.It Fl H
103+
Display only the hostname, omitting the service name.
104+
.It Fl S
105+
Display only the service name, omitting the hostname.
106+
.It Fl p Ar port
107+
Specify the port number to be used in the lookup.
108+
.El
109+
.Sh EXIT STATUS
110+
.Ex -std getnameinfo
111+
.Sh EXAMPLES
112+
Look up the hostname and service name for an IPv4 address:
113+
.Bd -literal -offset indent
114+
$ getnameinfo -4 -p 80 93.184.216.34
115+
example.com http
116+
.Ed
117+
.Pp
118+
Look up the numeric host and service for an IPv6 address:
119+
.Bd -literal -offset indent
120+
$ getnameinfo -nN -p 443 2606:2800:220:1:248:1893:25c8:1946
121+
2606:2800:220:1:248:1893:25c8:1946 443
122+
.Ed
123+
.Pp
124+
Resolve an address to its hostname but suppress the service name:
125+
.Bd -literal -offset indent
126+
$ getnameinfo -H -p 22 192.0.2.1
127+
example-host
128+
.Ed
129+
.Pp
130+
Resolve a hostname and service for a UDP connection:
131+
.Bd -literal -offset indent
132+
$ getnameinfo -u -p 53 198.51.100.2
133+
example-dns-server domain
134+
.Ed
135+
.Sh SEE ALSO
136+
.Xr dig 1 ,
137+
.Xr getaddrinfo 1 ,
138+
.Xr getaddrinfo 3 ,
139+
.Xr getnameinfo 3 ,
140+
.Xr inet 3 ,
141+
.Xr hosts 5 ,
142+
.Xr nsswitch.conf 5

0 commit comments

Comments
 (0)