Add optional method for specifying protocol as part of the service
option. This is similar to how the port number and protocol name are specified in services(5).
This commit is contained in:
parent
5b03462b1b
commit
236104be8e
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: getaddrinfo.1,v 1.3 2014/03/19 18:21:39 riastradh Exp $
|
||||
.\" $NetBSD: getaddrinfo.1,v 1.4 2014/04/22 02:23:03 ginsbach Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2013 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
|
@ -38,7 +38,7 @@
|
|||
.Op Fl cNnP
|
||||
.Op Fl f Ar family
|
||||
.Op Fl p Ar protocol
|
||||
.Op Fl s Ar service
|
||||
.Op Fl s Ar service Ns Op Ns / Ns Ar protocol
|
||||
.Op Fl t Ar socktype
|
||||
.Op Ar hostname
|
||||
.Sh DESCRIPTION
|
||||
|
@ -119,8 +119,11 @@ or
|
|||
Specify a protocol.
|
||||
Protocols may be numeric, or symbolic as listed in
|
||||
.Xr protocols 5 .
|
||||
.It Fl s Ar service
|
||||
.It Fl s Ar service Ns Op Ns / Ns Ar protocol
|
||||
Specify a service to look up.
|
||||
Services may be symbolic or numeric with an optional
|
||||
protocol suffix as listed in
|
||||
.Xr services 5 .
|
||||
If no service is specified, a hostname must be specified.
|
||||
.It Fl t Ar socktype
|
||||
Specify a socket type.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: getaddrinfo.c,v 1.3 2014/03/19 01:24:32 ginsbach Exp $ */
|
||||
/* $NetBSD: getaddrinfo.c,v 1.4 2014/04/22 02:23:03 ginsbach Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2013 The NetBSD Foundation, Inc.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: getaddrinfo.c,v 1.3 2014/03/19 01:24:32 ginsbach Exp $");
|
||||
__RCSID("$NetBSD: getaddrinfo.c,v 1.4 2014/04/22 02:23:03 ginsbach Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -132,6 +132,24 @@ main(int argc, char **argv)
|
|||
if (argc == 1)
|
||||
hostname = argv[0];
|
||||
|
||||
if (service != NULL) {
|
||||
char *p;
|
||||
|
||||
if ((p = strchr(service, '/')) != NULL) {
|
||||
if (hints.ai_protocol != 0) {
|
||||
warnx("protocol already specified");
|
||||
usage();
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
|
||||
if (!parse_protocol(p, &hints.ai_protocol)) {
|
||||
warnx("invalid protocol: %s", p);
|
||||
usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error = getaddrinfo(hostname, service, &hints, &addrinfo);
|
||||
if (error)
|
||||
errx(1, "%s", gai_strerror(error));
|
||||
|
|
Loading…
Reference in New Issue