int shgeodb_host(const char *name, shgeo_t *geo) { struct hostent *host; shdb_t *db; unsigned int a, b, c, d; char *str; int ret_err; int err; int n; int i; n = sscanf(name, "%u.%u.%u.%u", &a, &b, &c, &d); if (n != 4) { struct in_addr *in; char ipaddr[MAXHOSTNAMELEN+1]; host = shresolve((char *)name); if (!host) return (SHERR_NOENT); in = (struct in_addr *)host->h_addr; if (!in) return (SHERR_OPNOTSUPP); memset(ipaddr, 0, sizeof(ipaddr)); strncpy(ipaddr, inet_ntoa(*in), sizeof(ipaddr)-1); n = sscanf(ipaddr, "%u.%u.%u.%u", &a, &b, &c, &d); if (n != 4) return (SHERR_OPNOTSUPP); } ret_err = 0; db = shgeodb_open_sys(); if (db) { err = _shgeodb_host(db, a, b, c, geo); shdb_close(db); if (err == 0) return (0); ret_err = err; } db = shgeodb_open_user(); if (db) { err = _shgeodb_host(db, a, b, c, geo); shdb_close(db); if (err == 0) return (0); ret_err = err; } return (ret_err); }
int shnet_bindsk(int sockfd, char *hostname, unsigned int port) { struct sockaddr_in addr; struct hostent *host; unsigned short sport = (unsigned short)port; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(sport); host = NULL; if (hostname != NULL) host = shresolve(hostname); if (!host) { addr.sin_addr.s_addr = htonl(INADDR_ANY); } else { memcpy(&addr.sin_addr.s_addr, host->h_addr, host->h_length); } return (shnet_bind(sockfd, (struct sockaddr *)&addr, sizeof(addr))); }