示例#1
0
static int
hostent_add_alias(struct hostent *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];
	size_t	i;

	for (i = 0; i < MAXALIASES - 1; i++)
		if (h->h_aliases[i] == NULL)
			break;
	if (i == MAXALIASES - 1)
		return (0);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf)-1] = '\0';
		name = buf;
	}
	if (strlen(name) + 1 >= HOSTENT_LEFT(h))
		return (1);

	strlcpy(HOSTENT_POS(h), name, HOSTENT_LEFT(h));
	h->h_aliases[i] = HOSTENT_POS(h);
	HOSTENT_POS(h) += strlen(name) + 1;

	return (0);
}
示例#2
0
static int
hostent_add_alias(struct hostent_ext *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];
	size_t	i, n;

	for (i = 0; i < MAXALIASES; i++)
		if (h->aliases[i] == NULL)
			break;
	if (i == MAXALIASES)
		return (-1);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf)-1] = '\0';
		name = buf;
	}

	n = strlen(name) + 1;
	if (h->pos + n >= h->end)
		return (-1);

	h->aliases[i] = h->pos;
	memmove(h->pos, name, n);
	h->pos += n;
	return (0);
}
示例#3
0
static int
addrinfo_from_pkt(struct asr_query *as, char *pkt, size_t pktlen)
{
	struct asr_unpack	 p;
	struct asr_dns_header	 h;
	struct asr_dns_query	 q;
	struct asr_dns_rr	 rr;
	int			 i;
	union {
		struct sockaddr		sa;
		struct sockaddr_in	sain;
		struct sockaddr_in6	sain6;
	} u;
	char		 buf[MAXDNAME], *c;

	asr_unpack_init(&p, pkt, pktlen);
	asr_unpack_header(&p, &h);
	for (; h.qdcount; h.qdcount--)
		asr_unpack_query(&p, &q);

	for (i = 0; i < h.ancount; i++) {
		asr_unpack_rr(&p, &rr);
		if (rr.rr_type != q.q_type ||
		    rr.rr_class != q.q_class)
			continue;

		memset(&u, 0, sizeof u);
		if (rr.rr_type == T_A) {
			u.sain.sin_len = sizeof u.sain;
			u.sain.sin_family = AF_INET;
			u.sain.sin_addr = rr.rr.in_a.addr;
			u.sain.sin_port = 0;
		} else if (rr.rr_type == T_AAAA) {
			u.sain6.sin6_len = sizeof u.sain6;
			u.sain6.sin6_family = AF_INET6;
			u.sain6.sin6_addr = rr.rr.in_aaaa.addr6;
			u.sain6.sin6_port = 0;
		} else
			continue;

		if (as->as.ai.hints.ai_flags & AI_CANONNAME) {
			asr_strdname(rr.rr_dname, buf, sizeof buf);
			buf[strlen(buf) - 1] = '\0';
			c = res_hnok(buf) ? buf : NULL;
		} else if (as->as.ai.hints.ai_flags & AI_FQDN)
			c = as->as.ai.fqdn;
		else
			c = NULL;

		if (addrinfo_add(as, &u.sa, c))
			return (-1); /* errno set */
	}
	return (0);
}
static int
hostent_set_cname(struct hostent *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];

	if (h->h_name)
		return (0);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf) - 1] = '\0';
		h->h_name = strdup(buf);
	} else {
		h->h_name = strdup(name);
	}
	if (h->h_name == NULL)
		return (-1);

	return (0);
}
示例#5
0
static int
hostent_set_cname(struct hostent *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];

	if (h->h_name)
		return (0);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf) - 1] = '\0';
		name = buf;
	}
	if (strlen(name) + 1 >= HOSTENT_LEFT(h))
		return (1);

	strlcpy(HOSTENT_POS(h), name, HOSTENT_LEFT(h));
	h->h_name = HOSTENT_POS(h);
	HOSTENT_POS(h) += strlen(name) + 1;

	return (0);
}
static int
hostent_add_alias(struct hostent *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];
	size_t	i;

	for (i = 0; i < MAXALIASES; i++)
		if (h->h_aliases[i] == NULL)
			break;
	if (i == MAXALIASES)
		return (0);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf)-1] = '\0';
		h->h_aliases[i] = strdup(buf);
	} else {
		h->h_aliases[i] = strdup(name);
	}
	if (h->h_aliases[i] == NULL)
		return (-1);

	return (0);
}
示例#7
0
static int
hostent_set_cname(struct hostent_ext *h, const char *name, int isdname)
{
	char	buf[MAXDNAME];
	size_t	n;

	if (h->h.h_name)
		return (-1);

	if (isdname) {
		asr_strdname(name, buf, sizeof buf);
		buf[strlen(buf) - 1] = '\0';
		name = buf;
	}

	n = strlen(name) + 1;
	if (h->pos + n >= h->end)
		return (-1);

	h->h.h_name = h->pos;
	memmove(h->pos, name, n);
	h->pos += n;
	return (0);
}
示例#8
0
文件: asr_debug.c 项目: bingos/bitrig
static const char *
print_dname(const char *_dname, char *buf, size_t max)
{
	return (asr_strdname(_dname, buf, max));
}