1

I'm currently writing a simple socket server on Windows 8 using VS 2013 and want it to listen on both 0.0.0.0 and [::] with the following socket initialization code:

int sock;
struct sockaddr_in6 addr;

memset(&addr, 0x0, sizeof(struct sockaddr_in6));
addr.sin6_family = AF_INET6;
addr.sin6_addr = in6addr_any;
addr.sin6_port = htons((uint16_t) myPort);

sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if (sock == -1) {
    fprintf(stderr, "\nsocket call failed\n");
    WSACleanup();
    return(1);
}

int off= 0;
setsockopt(sock, SOL_SOCKET, IPV6_V6ONLY, (void *)&off, sizeof(off));
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&on, sizeof(on));

ioctlsocket(sock, FIONBIO, &iMode);

rc = bind(sock, (const struct sockaddr*)&addr, sizeof(addr))

However, when I startup my application it appears to only be listening on [::] with the port I specify and not on 0.0.0.0.

EDIT: When I start a client application on the same host and tell it connect to my socket server application using the IP address of 127.0.0.1 I get a connection refused error. If I specify ::1, then I am able to connect to my server application.

Is there any additional configuration required to make a dual stack socket?

Peter
  • 11
  • 2
  • How did you check it only binds `[::]`? If you only used TcpView or netstat, you might be missing it. Try connecting using IPv4. According to [this](http://stackoverflow.com/questions/1618240/how-to-support-both-ipv4-and-ipv6-connections), an IPv4 connection will appear as an IPv6 address but will still work. – kichik Feb 03 '16 at 22:41
  • I used netstat to check and saw that the binding was only on [::]. I have a client application on the same host that I start up and tell to connect the server application. In this client application I give it "127.0.0.1" as the host to connect to but I receive a 10061 Connection Refused error. – Peter Feb 04 '16 at 00:46

0 Answers0