Logo Search packages:      
Sourcecode: leafnode version File versions

char* masock_sa2name ( const struct sockaddr *  sa,
int *  h_e 

Look up the host name belonging to the socket address. If compiled with IPv6 support, use IPv6 lookup unless the address is actually an IPv6-mapped IPv4 address.

strdup'ed string containing the host name or NULL in case of trouble.
Linux glibc has broken IN6_IS_ADDR_* macros that do not cast to const.
sa  socket address to convert
h_e  variable to place h_errno into

Definition at line 39 of file masock_sa2name.c.

    struct hostent *he;
    char *ret;

    switch (sa->sa_family) {
#ifdef HAVE_IPV6
    case AF_INET6:
      /* any warnings issued here are the fault of broken system
         includes */
      if (IN6_IS_ADDR_V4MAPPED(&((const struct sockaddr_in6 *)sa)->sin6_addr)) {
          /* do IPv4 lookup on mapped addresses */
          /* see RFC-2553 section 6.2 for "12" */
          he = gethostbyaddr(12 + (const char *)
                         &((const struct sockaddr_in6 *)sa)
                         ->sin6_addr, sizeof(struct in_addr), AF_INET);
      } else {
          /* real IPv6 */
          he = gethostbyaddr((const char *)
                         &((const struct sockaddr_in6 *)sa)
                         sizeof(struct in6_addr), sa->sa_family);
      if (!he)
          errno = 0, *h_e = h_errno;
    case AF_INET:
      he = gethostbyaddr((const char *)
                     &((const struct sockaddr_in *)sa)
                     sizeof(struct in_addr), sa->sa_family);
      if (!he)
          errno = 0, *h_e = h_errno;
      errno = EAFNOSUPPORT;
      *h_e = 0;
      he = 0;

    ret = he && he->h_name ? critstrdup(he->h_name, "masock_sa2name") : 0;
    return ret;

Generated by  Doxygen 1.6.0   Back to index