One way works other doesn't
-
The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }
-
The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }
the 'aorh' is your flag to go with gethostbyaddr but it doesn´t work. So you should check if your are allowed to use gethostbyaddr in this context/parameters. The error is poiting that you haven´t started the WSA properly to do this. X| Try this @ home. (B&B)
-
the 'aorh' is your flag to go with gethostbyaddr but it doesn´t work. So you should check if your are allowed to use gethostbyaddr in this context/parameters. The error is poiting that you haven´t started the WSA properly to do this. X| Try this @ home. (B&B)
KarstenK wrote: The error is poiting that you haven´t started the WSA properly to do this. Which is what
WSANOTINITIALISED
is used for.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
The part under the (if aorh == 0) works great :). The part in the else{} brackets dosn't and causes a fatal error in my program when I run it as well as a WSAEPROTONOSUPPORT error :(. I don't understand. I must be doing something screwy. void CSSPingDlg::Ping(LPCSTR pstrHost, int aorh) { SOCKET rawSocket; LPHOSTENT lpHost; rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (rawSocket == SOCKET_ERROR) { AfxMessageBox("Raw socket initialization failed.",MB_OK); return; } if (aorh == 0) { lpHost = gethostbyname(pstrHost); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; } else { lpHost = gethostbyaddr(pstrHost,4,AF_INET); saDest.sin_addr.s_addr = *((u_long FAR *) (lpHost->h_addr)); saDest.sin_family = AF_INET; saDest.sin_port = 0; }
This should work just fine:
ULONG ulAddr = inet_addr("192.168.200.100");
if (INADDR_NONE != ulAddr)
{
LPHOSTENT hostinfo = gethostbyaddr((char *) &ulAddr, sizeof(ulAddr), AF_INET);
if (NULL != hostinfo)
{
....
}
}I'm not sure what your code is doing after assigning values to the
saDest
structure, but have you ruled out that as a potential problem? In other words, do you really want port 0, or should you be using a port in the range 1024–49151? You can also use 49152–65535, but no services are registered on them, which you may not even care about. What islpHost->h_addr
? Shouldn't that belpHost->h_addr_list
?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
KarstenK wrote: The error is poiting that you haven´t started the WSA properly to do this. Which is what
WSANOTINITIALISED
is used for.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?