May 23rd, 2005, 03:29 PM
Problem when Creating AsyncSocket
I have two network cards on my machine and I retrieve their info by the following code, mainly their IP addresses:
Later I user this address in setting up some sockets:
hostent *host = NULL;
char hostName = "";
host = gethostbyname(hostName);
AfxMessageBox("Error getting local IP address", MB_OK);
//set IPs for both network cards
for (int i = 0; host->h_addr_list[i]; i++)
memcpy(&sockAddr.sin_addr, host->h_addr_list[i], host->h_length);
tempIP = inet_ntoa(sockAddr.sin_addr);
m_UIWIp = tempIP
The problem was one of the network cards wasn't connected to anything and so the IP address being returned was "". So when I tried creating the socket, I was getting the error of WSAEADDRNOTAVAIL which isn't on the list of valid returns for the Create function.
for (i = 0; i < 2; i++)
if (!m_WrTCMSockFd[i].Create(WRITE_PORT,SOCK_DGRAM , FD_WRITE, m_UIWIp[i]))
nLastError = m_WrTCMSockFd[i].GetLastError(); // Obtain the error code
MidOutMsg,"Address family is not supported\n";
MidOutMsg="No more file descriptors available\n";
MidOutMsg="No buffer space is available\n";
MidOutMsg="Specified port not supported\n";
MidOutMsg="Specified port is the wrong type for this socket\n";
MidOutMsg="Specified socket type is not supported in this address family\n";
The problem that I was having was the bad address was the first ip address and when I tried creating the second ip address, nothing could be created.
Now if the valid address was first, I was able to create it, but not if it was second.
I know I can solve the problem of making sure that the address is valid, but why was the second Create failing if the first Create had a "" for an address
May 23rd, 2005, 05:02 PM
Re: Problem when Creating AsyncSocket
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.