本文整理汇总了C++中RES_SET_H_ERRNO函数的典型用法代码示例。如果您正苦于以下问题:C++ RES_SET_H_ERRNO函数的具体用法?C++ RES_SET_H_ERRNO怎么用?C++ RES_SET_H_ERRNO使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RES_SET_H_ERRNO函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gethostent_r
int
gethostent_r(struct hostent* hptr, char* buffer, size_t buflen,
struct hostent** result, int* h_errnop) {
struct hostent_data* hed;
struct hostent he;
res_state statp;
statp = __res_state();
if ((statp->options & RES_INIT) == 0 && res_ninit(statp) == -1) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (-1);
}
if ((hed = __hostent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (-1);
}
if (gethostent_p(&he, hed, statp->options & RES_USE_INET6, statp) != 0) {
return (-1);
}
if (__copy_hostent(&he, hptr, buffer, buflen) != 0) {
return (-1);
}
*result = hptr;
return (0);
}
示例2: _ht_gethostbyaddr
int
_ht_gethostbyaddr(void *rval, void *cb_data, va_list ap)
{
const void *addr;
socklen_t len;
int af;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct hostent *hptr, he;
struct hostent_data *hed;
res_state statp;
int error;
addr = va_arg(ap, const void *);
len = va_arg(ap, socklen_t);
af = va_arg(ap, int);
hptr = va_arg(ap, struct hostent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
*((struct hostent **)rval) = NULL;
statp = __res_state();
if ((hed = __hostent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
_sethosthtent(0, hed);
while ((error = gethostent_p(&he, hed, 0, statp)) == 0)
if (he.h_addrtype == af && !bcmp(he.h_addr, addr, len)) {
if (he.h_addrtype == AF_INET &&
statp->options & RES_USE_INET6) {
_map_v4v6_address(he.h_addr, he.h_addr);
he.h_length = IN6ADDRSZ;
he.h_addrtype = AF_INET6;
}
break;
}
_endhosthtent(hed);
if (error != 0)
return (NS_NOTFOUND);
if (__copy_hostent(&he, hptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct hostent **)rval) = hptr;
return (NS_SUCCESS);
}
示例3: fakeaddr
static struct netent *
fakeaddr(const char *name, int af, struct net_data *net_data) {
struct pvt *pvt;
const char *cp;
u_long tmp;
if (af != AF_INET) {
/* XXX should support IPv6 some day */
errno = EAFNOSUPPORT;
RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
return (NULL);
}
if (!isascii((unsigned char)(name[0])) ||
!isdigit((unsigned char)(name[0])))
return (NULL);
for (cp = name; *cp; ++cp)
if (!isascii(*cp) || (!isdigit((unsigned char)*cp) && *cp != '.'))
return (NULL);
if (*--cp == '.')
return (NULL);
/* All-numeric, no dot at the end. */
tmp = inet_network(name);
if (tmp == INADDR_NONE) {
RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
return (NULL);
}
/* Valid network number specified.
* Fake up a netent as if we'd actually
* done a lookup.
*/
freepvt(net_data);
net_data->nw_data = malloc(sizeof (struct pvt));
if (!net_data->nw_data) {
errno = ENOMEM;
RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
return (NULL);
}
pvt = net_data->nw_data;
strncpy(pvt->name, name, MAXDNAME);
pvt->name[MAXDNAME] = '\0';
pvt->netent.n_name = pvt->name;
pvt->netent.n_addrtype = AF_INET;
pvt->netent.n_aliases = pvt->aliases;
pvt->aliases[0] = NULL;
pvt->netent.n_net = tmp;
return (&pvt->netent);
}
示例4: _ht_getnetbyname
int
_ht_getnetbyname(void *rval, void *cb_data, va_list ap)
{
const char *name;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct netent *nptr, ne;
struct netent_data *ned;
char **cp;
res_state statp;
int error;
name = va_arg(ap, const char *);
nptr = va_arg(ap, struct netent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
statp = __res_state();
if ((ned = __netent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_UNAVAIL);
}
_setnethtent(ned->stayopen, ned);
while ((error = getnetent_p(&ne, ned)) == 0) {
if (strcasecmp(ne.n_name, name) == 0)
break;
for (cp = ne.n_aliases; *cp != 0; cp++)
if (strcasecmp(*cp, name) == 0)
goto found;
}
found:
if (!ned->stayopen)
_endnethtent(ned);
if (error != 0) {
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (__copy_netent(&ne, nptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct netent **)rval) = nptr;
return (NS_SUCCESS);
}
示例5: _nis_gethostbyaddr
int
_nis_gethostbyaddr(void *rval, void *cb_data, va_list ap)
{
#ifdef YP
const void *addr;
socklen_t len;
int af;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct hostent *hptr, he;
struct hostent_data *hed;
res_state statp;
addr = va_arg(ap, const void *);
len = va_arg(ap, socklen_t);
af = va_arg(ap, int);
hptr = va_arg(ap, struct hostent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
*((struct hostent **)rval) = NULL;
statp = __res_state();
if ((hed = __hostent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (_gethostbynisaddr_r(addr, len, af, &he, hed) != 0) {
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (__copy_hostent(&he, hptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct hostent **)rval) = hptr;
return (NS_SUCCESS);
#else
*((struct hostent **)rval) = NULL;
return (NS_UNAVAIL);
#endif
}
示例6: _gethostbynisaddr
struct hostent *
_gethostbynisaddr(const void *addr, socklen_t len, int af)
{
#ifdef YP
struct hostent *he;
struct hostent_data *hed;
u_long oresopt;
int error;
res_state statp;
statp = __res_state();
if ((he = __hostent_init()) == NULL ||
(hed = __hostent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
return (NULL);
}
oresopt = statp->options;
statp->options &= ~RES_USE_INET6;
error = _gethostbynisaddr_r(addr, len, af, he, hed);
statp->options = oresopt;
return (error == 0) ? he : NULL;
#else
return (NULL);
#endif
}
示例7: _ht_getnetbyaddr
int
_ht_getnetbyaddr(void *rval, void *cb_data, va_list ap)
{
uint32_t net;
int type;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct netent *nptr, ne;
struct netent_data *ned;
res_state statp;
int error;
net = va_arg(ap, uint32_t);
type = va_arg(ap, int);
nptr = va_arg(ap, struct netent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
statp = __res_state();
if ((ned = __netent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_UNAVAIL);
}
_setnethtent(ned->stayopen, ned);
while ((error = getnetent_p(&ne, ned)) == 0)
if (ne.n_addrtype == type && ne.n_net == net)
break;
if (!ned->stayopen)
_endnethtent(ned);
if (error != 0) {
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (__copy_netent(&ne, nptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct netent **)rval) = nptr;
return (NS_SUCCESS);
}
示例8: _nis_getnetbyname
int
_nis_getnetbyname(void *rval, void *cb_data, va_list ap)
{
#ifdef YP
const char *name;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct netent *nptr, ne;
struct netent_data *ned;
res_state statp;
name = va_arg(ap, const char *);
nptr = va_arg(ap, struct netent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
statp = __res_state();
if ((ned = __netent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_UNAVAIL);
}
if (_getnetbynis(name, "networks.byname", AF_INET, &ne, ned) != 0) {
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (__copy_netent(&ne, nptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct netent **)rval) = nptr;
return (NS_SUCCESS);
#else
return (NS_UNAVAIL);
#endif
}
示例9: getnetent_r
int
getnetent_r(struct netent *nptr, char *buffer, size_t buflen,
struct netent **result, int *h_errnop)
{
struct netent_data *ned;
struct netent ne;
res_state statp;
statp = __res_state();
if ((ned = __netent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (-1);
}
if (getnetent_p(&ne, ned) != 0)
return (-1);
if (__copy_netent(&ne, nptr, buffer, buflen) != 0) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return ((errno != 0) ? errno : -1);
}
*result = nptr;
return (0);
}
示例10: init
static struct net_data *
init() {
struct net_data *net_data;
if (!(net_data = net_data_init(NULL)))
goto error;
if (!net_data->ho) {
net_data->ho = (*net_data->irs->ho_map)(net_data->irs);
if (!net_data->ho || !net_data->res) {
error:
errno = EIO;
if (net_data && net_data->res)
RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
return (NULL);
}
(*net_data->ho->res_set)(net_data->ho, net_data->res, NULL);
}
return (net_data);
}
示例11: nw_to_net
static struct netent *
nw_to_net(struct nwent *nwent, struct net_data *net_data) {
struct pvt *pvt;
u_long addr = 0;
int i;
int msbyte;
if (!nwent || nwent->n_addrtype != AF_INET)
return (NULL);
freepvt(net_data);
net_data->nw_data = malloc(sizeof (struct pvt));
if (!net_data->nw_data) {
errno = ENOMEM;
RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
return (NULL);
}
pvt = net_data->nw_data;
pvt->netent.n_name = nwent->n_name;
pvt->netent.n_aliases = nwent->n_aliases;
pvt->netent.n_addrtype = nwent->n_addrtype;
/*
* What this code does: Converts net addresses from network to host form.
*
* msbyte: the index of the most significant byte in the n_addr array.
*
* Shift bytes in significant order into addr. When all signicant
* bytes are in, zero out bits in the LSB that are not part of the network.
*/
msbyte = nwent->n_length / 8 +
((nwent->n_length % 8) != 0 ? 1 : 0) - 1;
for (i = 0; i <= msbyte; i++)
addr = (addr << 8) | ((unsigned char *)nwent->n_addr)[i];
i = (32 - nwent->n_length) % 8;
if (i != 0)
addr &= ~((1 << (i + 1)) - 1);
pvt->netent.n_net = addr;
return (&pvt->netent);
}
示例12: _getnetbynis
static int
_getnetbynis(const char *name, char *map, int af, struct netent *ne,
struct netent_data *ned)
{
char *p, *bp, *ep;
char *cp, **q;
char *result;
int resultlen, len;
char ypbuf[YPMAXRECORD + 2];
switch(af) {
case AF_INET:
break;
default:
case AF_INET6:
errno = EAFNOSUPPORT;
return (-1);
}
if (ned->yp_domain == (char *)NULL)
if (yp_get_default_domain (&ned->yp_domain))
return (-1);
if (yp_match(ned->yp_domain, map, name, strlen(name), &result,
&resultlen))
return (-1);
bcopy((char *)result, (char *)&ypbuf, resultlen);
ypbuf[resultlen] = '\0';
free(result);
result = (char *)&ypbuf;
if ((cp = index(result, '\n')))
*cp = '\0';
cp = strpbrk(result, " \t");
*cp++ = '\0';
bp = ned->netbuf;
ep = ned->netbuf + sizeof ned->netbuf;
len = strlen(result) + 1;
if (ep - bp < len) {
RES_SET_H_ERRNO(__res_state(), NO_RECOVERY);
return (-1);
}
strlcpy(bp, result, ep - bp);
ne->n_name = bp;
bp += len;
while (*cp == ' ' || *cp == '\t')
cp++;
ne->n_net = inet_network(cp);
ne->n_addrtype = AF_INET;
q = ne->n_aliases = ned->net_aliases;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q > &ned->net_aliases[_MAXALIASES - 1])
break;
p = strpbrk(cp, " \t");
if (p != NULL)
*p++ = '\0';
len = strlen(cp) + 1;
if (ep - bp < len)
break;
strlcpy(bp, cp, ep - bp);
*q++ = bp;
bp += len;
cp = p;
}
*q = NULL;
return (0);
}
示例13: _nis_getnetbyaddr
int
_nis_getnetbyaddr(void *rval, void *cb_data, va_list ap)
{
#ifdef YP
uint32_t addr;
int af;
char *buffer;
size_t buflen;
int *errnop, *h_errnop;
struct netent *nptr, ne;
struct netent_data *ned;
char *str, *cp;
uint32_t net2;
int nn;
unsigned int netbr[4];
char buf[MAXDNAME];
res_state statp;
addr = va_arg(ap, uint32_t);
af = va_arg(ap, int);
nptr = va_arg(ap, struct netent *);
buffer = va_arg(ap, char *);
buflen = va_arg(ap, size_t);
errnop = va_arg(ap, int *);
h_errnop = va_arg(ap, int *);
statp = __res_state();
if ((ned = __netent_data_init()) == NULL) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_UNAVAIL);
}
if (af != AF_INET) {
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
errno = EAFNOSUPPORT;
return (NS_UNAVAIL);
}
for (nn = 4, net2 = addr; net2; net2 >>= 8) {
netbr[--nn] = net2 & 0xff;
}
switch (nn) {
case 3: /* Class A */
sprintf(buf, "%u", netbr[3]);
break;
case 2: /* Class B */
sprintf(buf, "%u.%u", netbr[2], netbr[3]);
break;
case 1: /* Class C */
sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
break;
case 0: /* Class D - E */
sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
netbr[2], netbr[3]);
break;
}
str = (char *)&buf;
cp = str + (strlen(str) - 2);
while(!strcmp(cp, ".0")) {
*cp = '\0';
cp = str + (strlen(str) - 2);
}
if (_getnetbynis(str, "networks.byaddr", af, &ne, ned) != 0) {
*h_errnop = statp->res_h_errno;
return (NS_NOTFOUND);
}
if (__copy_netent(&ne, nptr, buffer, buflen) != 0) {
*errnop = errno;
RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
*h_errnop = statp->res_h_errno;
return (NS_RETURN);
}
*((struct netent **)rval) = nptr;
return (NS_SUCCESS);
#else
return (NS_UNAVAIL);
#endif /* YP */
}
示例14: res_nupdate
int
res_nupdate(res_state statp, ns_updrec *rrecp_in, ns_tsig_key *key) {
ns_updrec *rrecp;
u_char answer[PACKETSZ];
u_char *packet;
struct zonegrp *zptr, tgrp;
LIST(struct zonegrp) zgrps;
int nzones = 0, nscount = 0, n;
union res_sockaddr_union nsaddrs[MAXNS];
packet = malloc(NS_MAXMSG);
if (packet == NULL) {
DPRINTF(("malloc failed"));
return (0);
}
/* Thread all of the updates onto a list of groups. */
INIT_LIST(zgrps);
memset(&tgrp, 0, sizeof (tgrp));
for (rrecp = rrecp_in; rrecp;
rrecp = LINKED(rrecp, r_link) ? NEXT(rrecp, r_link) : NULL) {
int nscnt;
/* Find the origin for it if there is one. */
tgrp.z_class = rrecp->r_class;
nscnt = res_findzonecut2(statp, rrecp->r_dname, tgrp.z_class,
RES_EXHAUSTIVE, tgrp.z_origin,
sizeof tgrp.z_origin,
tgrp.z_nsaddrs, MAXNS);
if (nscnt <= 0) {
DPRINTF(("res_findzonecut failed (%d)", nscnt));
goto done;
}
tgrp.z_nscount = nscnt;
/* Find the group for it if there is one. */
for (zptr = HEAD(zgrps); zptr != NULL; zptr = NEXT(zptr, z_link))
if (ns_samename(tgrp.z_origin, zptr->z_origin) == 1 &&
tgrp.z_class == zptr->z_class)
break;
/* Make a group for it if there isn't one. */
if (zptr == NULL) {
zptr = malloc(sizeof *zptr);
if (zptr == NULL) {
DPRINTF(("malloc failed"));
goto done;
}
*zptr = tgrp;
zptr->z_flags = 0;
INIT_LINK(zptr, z_link);
INIT_LIST(zptr->z_rrlist);
APPEND(zgrps, zptr, z_link);
}
/* Thread this rrecp onto the right group. */
APPEND(zptr->z_rrlist, rrecp, r_glink);
}
for (zptr = HEAD(zgrps); zptr != NULL; zptr = NEXT(zptr, z_link)) {
/* Construct zone section and prepend it. */
rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
zptr->z_class, ns_t_soa, 0);
if (rrecp == NULL) {
DPRINTF(("res_mkupdrec failed"));
goto done;
}
PREPEND(zptr->z_rrlist, rrecp, r_glink);
zptr->z_flags |= ZG_F_ZONESECTADDED;
/* Marshall the update message. */
n = res_nmkupdate(statp, HEAD(zptr->z_rrlist),
packet, NS_MAXMSG);
DPRINTF(("res_mkupdate -> %d", n));
if (n < 0)
goto done;
/* Temporarily replace the resolver's nameserver set. */
nscount = res_getservers(statp, nsaddrs, MAXNS);
res_setservers(statp, zptr->z_nsaddrs, zptr->z_nscount);
/* Send the update and remember the result. */
if (key != NULL) {
#ifdef _LIBC
DPRINTF(("TSIG is not supported\n"));
RES_SET_H_ERRNO(statp, NO_RECOVERY);
goto done;
#else
n = res_nsendsigned(statp, packet, n, key,
answer, sizeof answer);
#endif
} else
n = res_nsend(statp, packet, n, answer, sizeof answer);
if (n < 0) {
DPRINTF(("res_nsend: send error, n=%d (%s)\n",
n, strerror(errno)));
goto done;
}
if (((HEADER *)answer)->rcode == NOERROR)
nzones++;
/* Restore resolver's nameserver set. */
res_setservers(statp, nsaddrs, nscount);
nscount = 0;
}
//.........这里部分代码省略.........
示例15: getnetent_p
static int
getnetent_p(struct netent *ne, struct netent_data *ned)
{
char *p, *bp, *ep;
char *cp, **q;
int len;
char line[BUFSIZ + 1];
if (ned->netf == NULL &&
(ned->netf = fopen(_PATH_NETWORKS, "r")) == NULL)
return (-1);
again:
p = fgets(line, sizeof line, ned->netf);
if (p == NULL)
return (-1);
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
if (cp != NULL)
*cp = '\0';
bp = ned->netbuf;
ep = ned->netbuf + sizeof ned->netbuf;
ne->n_name = bp;
cp = strpbrk(p, " \t");
if (cp == NULL)
goto again;
*cp++ = '\0';
len = strlen(p) + 1;
if (ep - bp < len) {
RES_SET_H_ERRNO(__res_state(), NO_RECOVERY);
return (-1);
}
strlcpy(bp, p, ep - bp);
bp += len;
while (*cp == ' ' || *cp == '\t')
cp++;
p = strpbrk(cp, " \t");
if (p != NULL)
*p++ = '\0';
ne->n_net = inet_network(cp);
ne->n_addrtype = AF_INET;
q = ne->n_aliases = ned->net_aliases;
if (p != NULL) {
cp = p;
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q >= &ned->net_aliases[_MAXALIASES - 1])
break;
p = strpbrk(cp, " \t");
if (p != NULL)
*p++ = '\0';
len = strlen(cp) + 1;
if (ep - bp < len)
break;
strlcpy(bp, cp, ep - bp);
*q++ = bp;
bp += len;
cp = p;
}
}
*q = NULL;
return (0);
}