(09:07:11 PM) Josh Triplett: You want to see something scary?
(09:07:20 PM) Jamey Sharp: Um... lemme think... yes.
(09:07:29 PM) Josh Triplett: Remember Duff's Device?
(09:07:39 PM) Jamey Sharp: I'm frightened already, but yes...

switch(sockname->sa_family)
{
  case AF_INET6:
    addr = (char *) &((struct sockaddr_in6 *)sockname)->sin6_addr;
    addrlen = sizeof(((struct sockaddr_in6 *)sockname)->sin6_addr);
    port = ((struct sockaddr_in6 *)sockname)->sin6_port;
    if(!IN6_IS_ADDR_V4MAPPED(addr))
    {
      if(!IN6_IS_ADDR_LOOPBACK(addr))
        family = XCB_FAMILY_INTERNET_6;
      break;
  case AF_INET:
      addr = (char *) &((struct sockaddr_in *)sockname)->sin_addr;
      port = ((struct sockaddr_in *)sockname)->sin_port;
    }
    else /* if v4-mapped, fall through. */
      addr += 12;
    addrlen = sizeof(((struct sockaddr_in *)sockname)->sin_addr);
    if(*(in_addr_t *) addr != htonl(INADDR_LOOPBACK))
      family = XCB_FAMILY_INTERNET;
    break;
}

(09:13:14 PM) Josh Triplett: Oh $DEITY.
(09:13:37 PM) Josh Triplett: Yes, that works.
(09:13:37 PM) Josh Triplett: Ow.
(09:13:47 PM) Josh Triplett: Let's not.