Example #1
0
struct hostent *
netsnmp_gethostbyname(const char *name)
{
#if HAVE_GETHOSTBYNAME
#ifdef DNSSEC_LOCAL_VALIDATION
    val_status_t val_status;
#endif
    struct hostent *hp = NULL;

    if (NULL == name)
        return NULL;

    DEBUGMSGTL(("dns:gethostbyname", "looking up %s\n", name));

#ifdef DNSSEC_LOCAL_VALIDATION
    hp  = val_gethostbyname(netsnmp_validator_context(), name, &val_status);
    DEBUGMSGTL(("dns:sec:val", "val_status %d / %s; trusted: %d\n",
                val_status, p_val_status(val_status),
                val_istrusted(val_status)));
    if (!val_istrusted(val_status)) {
        snmp_log(LOG_WARNING,
                 "The authenticity of DNS response is not trusted (%s)\n",
                 p_val_status(val_status));
        /** continue anyways if DNSSEC_WARN_ONLY is set */
        if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, 
                                    NETSNMP_DS_LIB_DNSSEC_WARN_ONLY))
            hp = NULL;
    }
    else if (val_does_not_exist(val_status) && hp)
        hp = NULL;
#else
    hp = gethostbyname(name);
#endif
    if (hp == NULL) {
        DEBUGMSGTL(("dns:gethostbyname",
                    "couldn't resolve %s\n", name));
    } else if (hp->h_addrtype != AF_INET) {
        DEBUGMSGTL(("dns:gethostbyname",
                    "warning: response for %s not AF_INET!\n", name));
    } else {
        DEBUGMSGTL(("dns:gethostbyname",
                    "%s resolved okay\n", name));
    }
    return hp;
#else
    NETSNMP_LOGONCE((LOG_ERR, "gethostbyname not available"));
    return NULL;
#endif /* HAVE_GETHOSTBYNAME */
}
Example #2
0
struct hostent *
dnssec_gethostbyname(const char *name) {
  	val_status_t          val_status;
  	struct hostent *      res;

  	if (dnssec_init_context())
    	return NULL;

  	LOG(L_INFO, " gethostbyname(%s) called: wrapper\n", name);

  	res = val_gethostbyname(libval_ctx, name, &val_status);

  	if (val_istrusted(val_status) && !val_does_not_exist(val_status)) {
   		return res;
  	}
  	return NULL;
}
Example #3
0
int
AddrStrToAddr(const char * const s, struct sockaddr_in * const sa, const int defaultport)
{
    char portstr[128];
    unsigned int ipnum;
    unsigned int port;
    struct hostent *hp;
    char *hostcp, *atsign, *colon, *cp, *p2;

    memset(sa, 0, sizeof(struct sockaddr_in));
    strncpy(portstr, s, sizeof(portstr));
    portstr[sizeof(portstr) - 1] = '\0';

    if ((colon = strchr(portstr, ':')) != NULL)
    {
        /* Does it look like a URL?  http://host ? */
        if ((colon[1] == '/') && (colon[2] == '/'))
        {
            *colon = '\0';
            port = 0;
            hostcp = colon + 3;
            for (cp = hostcp; *cp != '\0'; cp++)
            {
                if ((!ISALNUM(*cp)) && (*cp != '.'))
                {
                    /* http://host:port */
                    if ((*cp == ':') && (isdigit((int) cp[1])))
                    {
                        *cp++ = '\0';
                        p2 = cp;
                        while (isdigit((int) *cp))
                            cp++;
                        *cp = '\0';
                        port = atoi(p2);
                    }
                    *cp = '\0';
                    break;
                }
            }
            if (port == 0)
                port = ServiceNameToPortNumber(portstr, 0);
        }
        else
        {
            /* Look for host.name.domain:port */
            *colon = '\0';
            hostcp = portstr;
            port = (unsigned int) atoi(colon + 1);
        }
    }
    else if ((atsign = strchr(portstr, '@')) != NULL)
    {
        /* Look for [email protected] */
        *atsign = '\0';
        hostcp = atsign + 1;
        port = (unsigned int) atoi(portstr);
    }
    else if (defaultport > 0)
    {
        /* Have just host.name.domain, use that w/ default port. */
        port = (unsigned int) defaultport;
        hostcp = portstr;
    }
    else
    {
        /* If defaultport <= 0, they must supply a port number
         * in the host/port string.
         */
        errno = EADDRNOTAVAIL;
        return (kAddrStrToAddrMiscErr);
    }

    sa->sin_port = htons((short) port);

    ipnum = inet_addr(hostcp);
    if (ipnum != INADDR_NONE)
    {
        sa->sin_family = AF_INET;
        sa->sin_addr.s_addr = ipnum;
    }
    else
    {
#ifdef DNSSEC_LOCAL_VALIDATION
        val_status_t val_status;
        errno = 0;
        hp = val_gethostbyname(NULL,hostcp,&val_status);
        if ((hp != NULL) && (!val_istrusted(val_status)))
            hp = NULL;
#else
        errno = 0;
        hp = gethostbyname(hostcp);
#endif
        if (hp == NULL)
        {
            if (errno == 0)
                errno = ENOENT;
            return (kAddrStrToAddrBadHost);
        }
        sa->sin_family = hp->h_addrtype;
        memcpy(&sa->sin_addr.s_addr, hp->h_addr_list[0],
               (size_t) hp->h_length);
    }
    return (0);
}	/* AddrStrToAddr */