/* * NAME: inet_ptohn * USAGE: Convert a "presentation address" (p-addr) into a Hostname * PLAIN ENGLISH: Convert "foo.bar.com" into "A.B.C.D" * ARGS: family - The family whose presesentation address format to use * ip - The presentation-address to look up * retval - A string to store the hostname (RETURN VALUE) * size - The length of 'retval' in bytes * RETURN VALUE: "retval" is returned upon success * "empty_string" is returned for any error. */ char * inet_ptohn (int family, const char *ip, char *retval, int size) { int err; SS buffer; ((SA *)&buffer)->sa_family = family; if ((err = inet_strton(ip, NULL, (SA *)&buffer, AI_NUMERICHOST))) return empty_string; if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NAMEREQD)) return empty_string; return retval; }
/* * NAME: inet_remotesockaddr * USAGE: Get a sockaddr of the specified host and port. * ARGS: family - The family whose sockaddr info is to be retrieved * host - The host whose address shall be put in the sockaddr * port - The port to put into the sockaddr -- MUST BE IN HOST ORDER! * storage - Pointer to a sockaddr structure appropriate for family. */ static int inet_remotesockaddr (int family, const char *host, const char *port, SS *storage, socklen_t *len) { int err; ((SA *)storage)->sa_family = family; if ((err = inet_strton(host, port, (SA *)storage, 0))) return err; if ((*len = socklen((SA *)storage)) == 0) return -2; return 0; }
/* * NAME: inet_hntop * USAGE: Convert a Hostname into a "presentation address" (p-addr) * PLAIN ENGLISH: Convert "A.B.C.D" into "foo.bar.com" * ARGS: family - The family whose presesentation address format to use * host - The hostname to convert * retval - A string to store the p-addr (RETURN VALUE) * size - The length of 'retval' in bytes * RETURN VALUE: "retval" is returned upon success * "empty_string" is returned for any error. */ char * inet_hntop (int family, const char *host, char *retval, int size) { int err; SS buffer; ((SA *)&buffer)->sa_family = family; if ((err = inet_strton(host, NULL, (SA *)&buffer, 0))) return empty_string; if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NUMERICHOST)) return empty_string; return retval; }
/* * NAME: inet_hntop * USAGE: Convert a Hostname into a "presentation address" (p-addr) * PLAIN ENGLISH: Convert "A.B.C.D" into "foo.bar.com" * ARGS: family - The family whose presesentation address format to use * host - The hostname to convert * retval - A string to store the p-addr (RETURN VALUE) * size - The length of 'retval' in bytes * RETURN VALUE: "retval" is returned upon success * "empty_string" is returned for any error. */ int inet_hntop (int family, const char *host, char *retval, int size) { SS buffer; ((SA *)&buffer)->sa_family = family; if (inet_strton(host, NULL, (SA *)&buffer, AI_ADDRCONFIG)) { syserr(-1, "inet_hntop: inet_strton(%d,%s) failed", family, host); return -1; } if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NUMERICHOST)) { syserr(-1, "inet_hntop: inet_ntostr(%d,%s) failed", family, host); return -1; } return 0; }
/* * NAME: inet_ptohn * USAGE: Convert a "presentation address" (p-addr) into a Hostname * PLAIN ENGLISH: Convert "foo.bar.com" into "A.B.C.D" * ARGS: family - The family whose presesentation address format to use * ip - The presentation-address to look up * retval - A string to store the hostname (RETURN VALUE) * size - The length of 'retval' in bytes * RETURN VALUE: "retval" is returned upon success * "empty_string" is returned for any error. */ int inet_ptohn (int family, const char *ip, char *retval, int size) { SS buffer; ((SA *)&buffer)->sa_family = family; if (inet_strton(ip, NULL, (SA *)&buffer, AI_NUMERICHOST)) { syserr(-1, "inet_ptohn: inet_strton(%d,%s) failed", family, ip); return -1; } if (inet_ntostr((SA *)&buffer, retval, size, NULL, 0, NI_NAMEREQD)) { syserr(-1, "inet_ptohn: inet_ntostr(%d,%s) failed", family, ip); return -1; } return 0; }