1998-05-03 04:11:49 +00:00
|
|
|
/*
|
1999-11-30 02:43:11 +00:00
|
|
|
* Copyright (c) 1996,1999 by Internet Software Consortium.
|
1998-05-03 04:11:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(LINT) && !defined(CODECENTER)
|
1999-11-30 02:43:11 +00:00
|
|
|
static const char rcsid[] = "$Id: getprotoent.c,v 1.15 1999/10/13 16:39:31 vixie Exp $";
|
1998-05-03 04:11:49 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Imports */
|
|
|
|
|
|
|
|
#include "port_before.h"
|
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
#if !defined(__BIND_NOSTATIC)
|
|
|
|
|
1998-05-03 04:11:49 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/nameser.h>
|
|
|
|
|
1998-05-03 04:11:49 +00:00
|
|
|
#include <errno.h>
|
1999-11-30 02:43:11 +00:00
|
|
|
#include <resolv.h>
|
1998-05-03 04:11:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <irs.h>
|
|
|
|
|
|
|
|
#include "port_after.h"
|
|
|
|
|
|
|
|
#include "irs_data.h"
|
|
|
|
|
|
|
|
/* Forward */
|
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
static struct net_data *init(void);
|
1998-05-03 04:11:49 +00:00
|
|
|
|
|
|
|
/* Public */
|
|
|
|
|
|
|
|
struct protoent *
|
|
|
|
getprotoent() {
|
1999-11-30 02:43:11 +00:00
|
|
|
struct net_data *net_data = init();
|
|
|
|
|
|
|
|
return (getprotoent_p(net_data));
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct protoent *
|
|
|
|
getprotobyname(const char *name) {
|
1999-11-30 02:43:11 +00:00
|
|
|
struct net_data *net_data = init();
|
|
|
|
|
|
|
|
return (getprotobyname_p(name, net_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct protoent *
|
|
|
|
getprotobynumber(int proto) {
|
|
|
|
struct net_data *net_data = init();
|
|
|
|
|
|
|
|
return (getprotobynumber_p(proto, net_data));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setprotoent(int stayopen) {
|
|
|
|
struct net_data *net_data = init();
|
|
|
|
|
|
|
|
setprotoent_p(stayopen, net_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
endprotoent() {
|
|
|
|
struct net_data *net_data = init();
|
|
|
|
|
|
|
|
endprotoent_p(net_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shared private. */
|
|
|
|
|
|
|
|
struct protoent *
|
|
|
|
getprotoent_p(struct net_data *net_data) {
|
|
|
|
struct irs_pr *pr;
|
|
|
|
|
|
|
|
if (!net_data || !(pr = net_data->pr))
|
|
|
|
return (NULL);
|
|
|
|
net_data->pr_last = (*pr->next)(pr);
|
|
|
|
return (net_data->pr_last);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct protoent *
|
|
|
|
getprotobyname_p(const char *name, struct net_data *net_data) {
|
|
|
|
struct irs_pr *pr;
|
1998-05-03 04:11:49 +00:00
|
|
|
char **pap;
|
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
if (!net_data || !(pr = net_data->pr))
|
1998-05-03 04:11:49 +00:00
|
|
|
return (NULL);
|
1999-11-30 02:43:11 +00:00
|
|
|
if (net_data->pr_stayopen && net_data->pr_last) {
|
|
|
|
if (!strcmp(net_data->pr_last->p_name, name))
|
|
|
|
return (net_data->pr_last);
|
|
|
|
for (pap = net_data->pr_last->p_aliases; pap && *pap; pap++)
|
1998-05-03 04:11:49 +00:00
|
|
|
if (!strcmp(name, *pap))
|
1999-11-30 02:43:11 +00:00
|
|
|
return (net_data->pr_last);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
1999-11-30 02:43:11 +00:00
|
|
|
net_data->pr_last = (*pr->byname)(pr, name);
|
|
|
|
if (!net_data->pr_stayopen)
|
1998-05-03 04:11:49 +00:00
|
|
|
endprotoent();
|
1999-11-30 02:43:11 +00:00
|
|
|
return (net_data->pr_last);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct protoent *
|
1999-11-30 02:43:11 +00:00
|
|
|
getprotobynumber_p(int proto, struct net_data *net_data) {
|
|
|
|
struct irs_pr *pr;
|
1998-05-03 04:11:49 +00:00
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
if (!net_data || !(pr = net_data->pr))
|
1998-05-03 04:11:49 +00:00
|
|
|
return (NULL);
|
1999-11-30 02:43:11 +00:00
|
|
|
if (net_data->pr_stayopen && net_data->pr_last)
|
|
|
|
if (net_data->pr_last->p_proto == proto)
|
|
|
|
return (net_data->pr_last);
|
|
|
|
net_data->pr_last = (*pr->bynumber)(pr, proto);
|
|
|
|
if (!net_data->pr_stayopen)
|
1998-05-03 04:11:49 +00:00
|
|
|
endprotoent();
|
1999-11-30 02:43:11 +00:00
|
|
|
return (net_data->pr_last);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-30 02:43:11 +00:00
|
|
|
setprotoent_p(int stayopen, struct net_data *net_data) {
|
|
|
|
struct irs_pr *pr;
|
1998-05-03 04:11:49 +00:00
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
if (!net_data || !(pr = net_data->pr))
|
1998-05-03 04:11:49 +00:00
|
|
|
return;
|
|
|
|
(*pr->rewind)(pr);
|
1999-11-30 02:43:11 +00:00
|
|
|
net_data->pr_stayopen = (stayopen != 0);
|
|
|
|
if (stayopen == 0)
|
|
|
|
net_data_minimize(net_data);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-11-30 02:43:11 +00:00
|
|
|
endprotoent_p(struct net_data *net_data) {
|
|
|
|
struct irs_pr *pr;
|
1998-05-03 04:11:49 +00:00
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
if ((net_data != NULL) && ((pr = net_data->pr) != NULL))
|
1998-05-03 04:11:49 +00:00
|
|
|
(*pr->minimize)(pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Private */
|
|
|
|
|
1999-11-30 02:43:11 +00:00
|
|
|
static struct net_data *
|
1998-05-03 04:11:49 +00:00
|
|
|
init() {
|
1999-11-30 02:43:11 +00:00
|
|
|
struct net_data *net_data;
|
|
|
|
|
|
|
|
if (!(net_data = net_data_init(NULL)))
|
1998-05-03 04:11:49 +00:00
|
|
|
goto error;
|
1999-11-30 02:43:11 +00:00
|
|
|
if (!net_data->pr) {
|
|
|
|
net_data->pr = (*net_data->irs->pr_map)(net_data->irs);
|
|
|
|
|
|
|
|
if (!net_data->pr || !net_data->res) {
|
1998-05-03 04:11:49 +00:00
|
|
|
error:
|
1999-11-30 02:43:11 +00:00
|
|
|
errno = EIO;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
(*net_data->pr->res_set)(net_data->pr, net_data->res, NULL);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
1999-11-30 02:43:11 +00:00
|
|
|
|
|
|
|
return (net_data);
|
1998-05-03 04:11:49 +00:00
|
|
|
}
|
1999-11-30 02:43:11 +00:00
|
|
|
|
|
|
|
#endif /*__BIND_NOSTATIC*/
|