Beispiel #1
0
/* Return values:
 * 	0 : host found listed in dnsbl
 * 	1 : host not found listed in dnsbl
 */
int
check_dnsbl(int a, int b, int c, int d, char *dnsbl)
{
	char *name;
	int l, herr;
	struct hostent *he;

	/* An IPv4 address is max 15 chars long (xxx.xxx.xxx.xxx) */
	l = 18 + strlen(dnsbl);
	name = (char *)malloc(l);
	if (name == NULL) {
		syslog(LOG_INFO, "check_dnsbl(): malloc() error: aborting");
		return(0);
	}
	memset(name, '\0', l);
	if (*dnsbl == '.') {
		sprintf(name, "%d.%d.%d.%d%s", d, c, b, a, dnsbl);
	} else {
		sprintf(name, "%d.%d.%d.%d.%s", d, c, b, a, dnsbl);
	}

	he = lwres_getipnodebyname(name, AF_INET, 0, &herr);
	free(name);
	if (he == NULL) {
		return(1);
	}

	lwres_freehostent(he);
	return(0);
}
Beispiel #2
0
/*% Looks for either an IPv4 or IPv6 address. */
struct hostent *
lwres_gethostbyname2(const char *name, int af) {
	if (he != NULL)
		lwres_freehostent(he);

	he = lwres_getipnodebyname(name, af, 0, &lwres_h_errno);
	return (he);
}
Beispiel #3
0
/*% Always looks for an IPv4 address. */
struct hostent *
lwres_gethostbyname(const char *name) {

	if (he != NULL)
		lwres_freehostent(he);

	he = lwres_getipnodebyname(name, AF_INET, 0, &lwres_h_errno);
	return (he);
}
Beispiel #4
0
/*% Thread-safe function for forward lookups. */
struct hostent *
lwres_gethostbyname_r(const char *name, struct hostent *resbuf,
		char *buf, int buflen, int *error)
{
	struct hostent *he;
	int res;

	he = lwres_getipnodebyname(name, AF_INET, 0, error);
	if (he == NULL)
		return (NULL);
	res = copytobuf(he, resbuf, buf, buflen);
	lwres_freehostent(he);
	if (res != 0) {
		errno = ERANGE;
		return (NULL);
	}
	return (resbuf);
}