xref: /freebsd/crypto/openssl/doc/man3/BIO_parse_hostserv.pod (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimBIO_hostserv_priorities,
6e71b7053SJung-uk KimBIO_parse_hostserv
7e71b7053SJung-uk Kim- utility routines to parse a standard host and service string
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim=head1 SYNOPSIS
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim #include <openssl/bio.h>
12e71b7053SJung-uk Kim
13e71b7053SJung-uk Kim enum BIO_hostserv_priorities {
14e71b7053SJung-uk Kim     BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV
15e71b7053SJung-uk Kim };
16e71b7053SJung-uk Kim int BIO_parse_hostserv(const char *hostserv, char **host, char **service,
17e71b7053SJung-uk Kim                        enum BIO_hostserv_priorities hostserv_prio);
18e71b7053SJung-uk Kim
19e71b7053SJung-uk Kim=head1 DESCRIPTION
20e71b7053SJung-uk Kim
21e71b7053SJung-uk KimBIO_parse_hostserv() will parse the information given in B<hostserv>,
22e71b7053SJung-uk Kimcreate strings with the hostname and service name and give those
23e71b7053SJung-uk Kimback via B<host> and B<service>.  Those will need to be freed after
24e71b7053SJung-uk Kimthey are used.  B<hostserv_prio> helps determine if B<hostserv> shall
25e71b7053SJung-uk Kimbe interpreted primarily as a hostname or a service name in ambiguous
26e71b7053SJung-uk Kimcases.
27e71b7053SJung-uk Kim
28e71b7053SJung-uk KimThe syntax the BIO_parse_hostserv() recognises is:
29e71b7053SJung-uk Kim
30e71b7053SJung-uk Kim host + ':' + service
31e71b7053SJung-uk Kim host + ':' + '*'
32e71b7053SJung-uk Kim host + ':'
33e71b7053SJung-uk Kim        ':' + service
34e71b7053SJung-uk Kim '*'  + ':' + service
35e71b7053SJung-uk Kim host
36e71b7053SJung-uk Kim service
37e71b7053SJung-uk Kim
38e71b7053SJung-uk KimThe host part can be a name or an IP address.  If it's a IPv6
39e71b7053SJung-uk Kimaddress, it MUST be enclosed in brackets, such as '[::1]'.
40e71b7053SJung-uk Kim
41*b077aed3SPierre ProncheryThe service part can be a service name or its port number.  A service name
42*b077aed3SPierre Proncherywill be mapped to a port number using the system function getservbyname().
43e71b7053SJung-uk Kim
44e71b7053SJung-uk KimThe returned values will depend on the given B<hostserv> string
45e71b7053SJung-uk Kimand B<hostserv_prio>, as follows:
46e71b7053SJung-uk Kim
47e71b7053SJung-uk Kim host + ':' + service  => *host = "host", *service = "service"
48e71b7053SJung-uk Kim host + ':' + '*'      => *host = "host", *service = NULL
49e71b7053SJung-uk Kim host + ':'            => *host = "host", *service = NULL
50e71b7053SJung-uk Kim        ':' + service  => *host = NULL, *service = "service"
51e71b7053SJung-uk Kim  '*' + ':' + service  => *host = NULL, *service = "service"
52e71b7053SJung-uk Kim
53e71b7053SJung-uk Kim in case no ':' is present in the string, the result depends on
54e71b7053SJung-uk Kim hostserv_prio, as follows:
55e71b7053SJung-uk Kim
56e71b7053SJung-uk Kim when hostserv_prio == BIO_PARSE_PRIO_HOST
57e71b7053SJung-uk Kim host                 => *host = "host", *service untouched
58e71b7053SJung-uk Kim
59e71b7053SJung-uk Kim when hostserv_prio == BIO_PARSE_PRIO_SERV
60e71b7053SJung-uk Kim service              => *host untouched, *service = "service"
61e71b7053SJung-uk Kim
62e71b7053SJung-uk Kim=head1 RETURN VALUES
63e71b7053SJung-uk Kim
64e71b7053SJung-uk KimBIO_parse_hostserv() returns 1 on success or 0 on error.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk Kim=head1 SEE ALSO
67e71b7053SJung-uk Kim
68e71b7053SJung-uk KimL<BIO_ADDRINFO(3)>
69e71b7053SJung-uk Kim
70e71b7053SJung-uk Kim=head1 COPYRIGHT
71e71b7053SJung-uk Kim
72*b077aed3SPierre ProncheryCopyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
73e71b7053SJung-uk Kim
74*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
75e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
76e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
77e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
78e71b7053SJung-uk Kim
79e71b7053SJung-uk Kim=cut
80