get the IP adress of the bind socket WINSOCK

Started by
2 comments, last by hplus0603 10 years, 5 months ago

I have this code using winsock that creates a socket and binds it using the IP of the computer I am


    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_protocol = IPPROTO_UDP;
    hints.ai_flags = AI_PASSIVE;

    iResult = getaddrinfo(NULL, DEFAULT_PORT, &hints, &result);
    if( iResult != 0 ){printf("getaddrinfo failed with error: %d\n", iResult);WSACleanup();return -1;}

	for(soketList = result; soketList != NULL; soketList = soketList->ai_next) 
    {
		ConnectSocket = socket(soketList->ai_family, soketList->ai_socktype,soketList->ai_protocol);
        if(ConnectSocket == INVALID_SOCKET) 
		{
            printf("socket failed with error: %ld\n", WSAGetLastError());
            continue;
        }
		iResult = bind(ConnectSocket, soketList->ai_addr, soketList->ai_addrlen);
        if (iResult == SOCKET_ERROR) 
		{
			printf("bind failed with error: %d\n", WSAGetLastError());
            closesocket(ConnectSocket);
            continue;
        }

        break;
    } 

then I want to see with my own eyes the IP of that socket


InetNtop(soketList->ai_addr->sa_family,soketList->ai_addr->sa_data,(PWSTR)myIP,80)

and the IP is like this... 6354:: not exactly those numbers

Is that IP correct? I was expecting 32 numbers

if I create another application that creates a socket and sends data to that EXACT IP will it work?

Advertisement

and the IP is like this... 6354:: not exactly those numbers


IPv6 shortens sequences of zeros to double-colons.

if I create another application that creates a socket and sends data to that EXACT IP will it work?


If it is a routable address, and the machine is listening for connections, yes.
enum Bool { True, False, FileNotFound };

my code should always produce a routable IP, no?

There are a number of non-routable interface addresses defined in IPv6, similar to 127.0.0.1 and the 10.x and 192.168.x subnets in IPv4.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement