4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1996,1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid
[] = "Id: getprotoent.c,v 1.4 2005/04/27 04:56:26 sra Exp";
26 #include "port_before.h"
28 #if !defined(__BIND_NOSTATIC)
30 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <arpa/nameser.h>
42 #include "port_after.h"
48 static struct net_data
*init(void);
54 struct net_data
*net_data
= init();
56 return (getprotoent_p(net_data
));
60 getprotobyname(const char *name
) {
61 struct net_data
*net_data
= init();
63 return (getprotobyname_p(name
, net_data
));
67 getprotobynumber(int proto
) {
68 struct net_data
*net_data
= init();
70 return (getprotobynumber_p(proto
, net_data
));
74 setprotoent(int stayopen
) {
75 struct net_data
*net_data
= init();
77 setprotoent_p(stayopen
, net_data
);
82 struct net_data
*net_data
= init();
84 endprotoent_p(net_data
);
90 getprotoent_p(struct net_data
*net_data
) {
93 if (!net_data
|| !(pr
= net_data
->pr
))
95 net_data
->pr_last
= (*pr
->next
)(pr
);
96 return (net_data
->pr_last
);
100 getprotobyname_p(const char *name
, struct net_data
*net_data
) {
104 if (!net_data
|| !(pr
= net_data
->pr
))
106 if (net_data
->pr_stayopen
&& net_data
->pr_last
) {
107 if (!strcmp(net_data
->pr_last
->p_name
, name
))
108 return (net_data
->pr_last
);
109 for (pap
= net_data
->pr_last
->p_aliases
; pap
&& *pap
; pap
++)
110 if (!strcmp(name
, *pap
))
111 return (net_data
->pr_last
);
113 net_data
->pr_last
= (*pr
->byname
)(pr
, name
);
114 if (!net_data
->pr_stayopen
)
116 return (net_data
->pr_last
);
120 getprotobynumber_p(int proto
, struct net_data
*net_data
) {
123 if (!net_data
|| !(pr
= net_data
->pr
))
125 if (net_data
->pr_stayopen
&& net_data
->pr_last
)
126 if (net_data
->pr_last
->p_proto
== proto
)
127 return (net_data
->pr_last
);
128 net_data
->pr_last
= (*pr
->bynumber
)(pr
, proto
);
129 if (!net_data
->pr_stayopen
)
131 return (net_data
->pr_last
);
135 setprotoent_p(int stayopen
, struct net_data
*net_data
) {
138 if (!net_data
|| !(pr
= net_data
->pr
))
141 net_data
->pr_stayopen
= (stayopen
!= 0);
143 net_data_minimize(net_data
);
147 endprotoent_p(struct net_data
*net_data
) {
150 if ((net_data
!= NULL
) && ((pr
= net_data
->pr
) != NULL
))
156 static struct net_data
*
158 struct net_data
*net_data
;
160 if (!(net_data
= net_data_init(NULL
)))
163 net_data
->pr
= (*net_data
->irs
->pr_map
)(net_data
->irs
);
165 if (!net_data
->pr
|| !net_data
->res
) {
170 (*net_data
->pr
->res_set
)(net_data
->pr
, net_data
->res
, NULL
);
176 #endif /*__BIND_NOSTATIC*/