Jump to content
  • Advertisement
Sign in to follow this  
lomateron

get the IP adress of the bind socket WINSOCK

This topic is 2078 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Edited by lomateron

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!