4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1991-1994 Sun Microsystems, Inc
25 * lib/libsocket/inet/getservbyname_r.c
27 * getservbyname_r() is defined in this file. It is implemented on top of
28 * _get_hostserv_inetnetdir_byname() which is also used to implement
29 * netdir_getbyname() for inet family transports. In turn the common code
30 * uses the name service switch policy for "hosts" and "services" unless
31 * the administrator chooses to bypass the name service switch by
32 * specifying third-party supplied nametoaddr libs for inet transports
35 * getservbyport_r() is similarly related to _get_hostserv_inetnetdir_byaddr()
36 * and netdir_getbyaddr();
38 * The common code lives in lib/libnsl/nss/netdir_inet.c.
40 * getservent_r(), setservent() and endservent() are *not* implemented on top
41 * of the common interface; they go straight to the switch and are
42 * defined in getservent_r.c.
44 * There is absolutely no data sharing, not even the stayopen flag or
45 * enumeration state, between getservbyYY_r() and getservent_r();
48 #pragma ident "%Z%%M% %I% %E% SMI"
52 #include <sys/types.h>
53 #include <nss_netdir.h>
55 extern int str2servent(const char *, int, void *, char *, int);
56 extern struct netconfig
*__rpc_getconfip();
59 getservbyname_r(const char *name
, const char *proto
, struct servent
*result
,
60 char *buffer
, int buflen
)
62 struct netconfig
*nconf
;
63 struct nss_netdirbyname_in nssin
;
64 union nss_netdirbyname_out nssout
;
67 if ((nconf
= __rpc_getconfip("udp")) == NULL
&&
68 (nconf
= __rpc_getconfip("tcp")) == NULL
) {
69 return ((struct servent
*)NULL
);
71 nssin
.op_t
= NSS_SERV
;
72 nssin
.arg
.nss
.serv
.name
= name
;
73 nssin
.arg
.nss
.serv
.proto
= proto
;
74 nssin
.arg
.nss
.serv
.buf
= buffer
;
75 nssin
.arg
.nss
.serv
.buflen
= buflen
;
77 nssout
.nss
.serv
= result
;
80 * We pass in nconf and let the implementation of the long-named func
81 * decide whether to use the switch based on nc_nlookups.
83 neterr
= _get_hostserv_inetnetdir_byname(nconf
, &nssin
, &nssout
);
85 (void) freenetconfigent(nconf
);
86 if (neterr
!= ND_OK
) {
87 return ((struct servent
*)NULL
);
89 return (nssout
.nss
.serv
);
93 getservbyport_r(int port
, const char *proto
, struct servent
*result
,
94 char *buffer
, int buflen
)
96 struct netconfig
*nconf
;
97 struct nss_netdirbyaddr_in nssin
;
98 union nss_netdirbyaddr_out nssout
;
101 if ((nconf
= __rpc_getconfip("udp")) == NULL
&&
102 (nconf
= __rpc_getconfip("tcp")) == NULL
) {
103 return ((struct servent
*)NULL
);
105 nssin
.op_t
= NSS_SERV
;
106 nssin
.arg
.nss
.serv
.port
= port
;
107 nssin
.arg
.nss
.serv
.proto
= proto
;
108 nssin
.arg
.nss
.serv
.buf
= buffer
;
109 nssin
.arg
.nss
.serv
.buflen
= buflen
;
111 nssout
.nss
.serv
= result
;
114 * We pass in nconf and let the implementation of this long-named func
115 * decide whether to use the switch based on nc_nlookups.
117 neterr
= _get_hostserv_inetnetdir_byaddr(nconf
, &nssin
, &nssout
);
119 (void) freenetconfigent(nconf
);
120 if (neterr
!= ND_OK
) {
121 return ((struct servent
*)NULL
);
123 return (nssout
.nss
.serv
);