}; {endcode} +{section: Memo on conversion} + +Remember that socket() does accept AF_INET and AF_INET6. You should change appropriately as well. If the user's intention is obvious like following code, I could write a wrapper function that deals automatically. However, I must consider more complicated situations like calling socket() at one site and passing the socket descriptor to elsewhere. And then calls connect() or accept() on it. + +{code} +static SOCKET +tcp_connect( const char *host, int port ) +{ + struct hostent *h; + struct sockaddr_in address; + int success; + SOCKET fd; + + if(!initialize_sockets()) + return INVALID_SOCKET; + + h = gethostbyname(host); + if(!h) return INVALID_SOCKET; + + address.sin_port = htons((unsigned short)port); + address.sin_family = h->h_addrtype; + memcpy(&address.sin_addr.s_addr,h->h_addr_list[0],sizeof(address.sin_addr.s_addr)); + +#if defined(WIN32) + // Create the socket with no overlapped I/0 so we can later associate the socket + // with a valid file descripter using _open_osfhandle. + fd = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0); +#else + fd = socket( AF_INET, SOCK_STREAM, 0 ); +#endif + if(fd == INVALID_SOCKET) return INVALID_SOCKET; + + success = connect( fd, (struct sockaddr *) &address, sizeof(address) ); + if(success == SOCKET_ERROR) { + closesocket(fd); + return INVALID_SOCKET; + } + + return fd; +} +{endcode} + {section: IPv6 support in External Libraries} {subsection: Unsupported}