Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

get the IP adress of the bind socket WINSOCK

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 lomateron   Members   

491
Like
0Likes
Like

Posted 11 November 2013 - 08:36 AM

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, 11 November 2013 - 08:40 AM.


#2 hplus0603   Moderators   

11106
Like
1Likes
Like

Posted 11 November 2013 - 10:14 AM

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 };

#3 lomateron   Members   

491
Like
0Likes
Like

Posted 11 November 2013 - 07:36 PM

my code should always produce a routable IP, no?


Edited by lomateron, 11 November 2013 - 07:39 PM.


#4 hplus0603   Moderators   

11106
Like
1Likes
Like

Posted 11 November 2013 - 07:58 PM

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 };




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.