So I am pretty new to sockets and C++ in general. I am trying to set a socket up on one computer that takes the IP address of that computer so I can connect to it from another. I am setting the IP address and the Port. However when it come to bind it always fails.
So I set the IP address to that of my computer and I set a port.
#define DEFAULT_PORT "8080"
#define DEFAULT_IP "165.120.216.66"
I then call WSAStartup which all seems to go fine. I then Resolver the server address and port.
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_IP;
hints.ai_flags = AI_PASSIVE;
Followed by getaddrinfo and create the socket. All of which goes fine
status = getaddrinfo(DEFAULT_IP, DEFAULT_PORT, &hints, &data);
MySocket = socket(data->ai_family, data->ai_socktype, data->ai_protocol);
However when it comes to bind it always fails, and I just don't know why.
status = bind(MySocket, data->ai_addr, (int)data->ai_addrlen);
Also is there any way I can get the IP address of the machine it is running on instead of coding the IP?