Can not take my own IP address (Windows Server 2003)
-
Hi, I cann't take my own IP address on Windows Server 2003. This is the code i'm using, it works fine in Windows 2000 (Professional and Server) and Windows XP, but DOESN'T WORK IN Windows Server 2003. I'm getting crazy, Why it doesn't work only in Windows 2003?
int iSockErr = 0; HANDLE hnd = 0; WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; try { //Inicializar los sockets if ((iSockErr = WSAStartup(wVersionRequested, &wsaData)) != 0) { throw 1; } DWORD dw; GUID guid = SVCID\_HOSTNAME; struct AUX{ WSAQUERYSET qsRestrictions; BYTE byte\[500\]; }aux; memset(&aux.qsRestrictions, 0, sizeof(WSAQUERYSET)); aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET); aux.qsRestrictions.lpServiceClassId = &guid; if (WSALookupServiceBegin(&aux.qsRestrictions, LUP\_RETURN\_ADDR, &hnd)) { throw 2; } dw = sizeof(aux); memset(&aux, 0, sizeof(aux)); aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET); while ( !WSALookupServiceNext(hnd, LUP\_RETURN\_ADDR, &dw, &aux.qsRestrictions) ) {
//IN WINDOWS 2003 aux.qsRestrictions.lpcsaBuffer IS ALWAYS NULL
ptyIP->d0 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[2\]; ptyIP->d1 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[3\]; ptyIP->d2 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[4\]; ptyIP->d3 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[5\]; } ...
Thank you very much.
-
Hi, I cann't take my own IP address on Windows Server 2003. This is the code i'm using, it works fine in Windows 2000 (Professional and Server) and Windows XP, but DOESN'T WORK IN Windows Server 2003. I'm getting crazy, Why it doesn't work only in Windows 2003?
int iSockErr = 0; HANDLE hnd = 0; WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; try { //Inicializar los sockets if ((iSockErr = WSAStartup(wVersionRequested, &wsaData)) != 0) { throw 1; } DWORD dw; GUID guid = SVCID\_HOSTNAME; struct AUX{ WSAQUERYSET qsRestrictions; BYTE byte\[500\]; }aux; memset(&aux.qsRestrictions, 0, sizeof(WSAQUERYSET)); aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET); aux.qsRestrictions.lpServiceClassId = &guid; if (WSALookupServiceBegin(&aux.qsRestrictions, LUP\_RETURN\_ADDR, &hnd)) { throw 2; } dw = sizeof(aux); memset(&aux, 0, sizeof(aux)); aux.qsRestrictions.dwSize = sizeof(WSAQUERYSET); while ( !WSALookupServiceNext(hnd, LUP\_RETURN\_ADDR, &dw, &aux.qsRestrictions) ) {
//IN WINDOWS 2003 aux.qsRestrictions.lpcsaBuffer IS ALWAYS NULL
ptyIP->d0 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[2\]; ptyIP->d1 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[3\]; ptyIP->d2 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[4\]; ptyIP->d3 = aux.qsRestrictions.lpcsaBuffer\[0\].RemoteAddr.lpSockaddr->sa\_data\[5\]; } ...
Thank you very much.
alejandrofuchs wrote:
Why it doesn't work only in Windows 2003?
Why don't you tell us? What does
WSAGetLastError()
return?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
alejandrofuchs wrote:
Why it doesn't work only in Windows 2003?
Why don't you tell us? What does
WSAGetLastError()
return?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Thanks, It returns 0, indicating there is no error, but no data is returned. alejandrofuchs@yahoo.com
-
alejandrofuchs wrote:
Why it doesn't work only in Windows 2003?
Why don't you tell us? What does
WSAGetLastError()
return?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com
-
Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com
alejandrofuchs wrote:
WSAGetLastError() returns 10110...
Which resolves to
WSA_E_NO_MORE
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Thanks! First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name. Second (again i'm sorry), i responded wrong, the rigth answer is: WSAGetLastError() returns 10110, WSALookupServiceNext is returning 0 the second time it is called. alejandrofuchs@yahoo.com
alejandrofuchs wrote:
First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.
hmmm...split personality? ;P If you try getaddrinfo(), does that work on Server 2003? Something like:
char szHostName[256];
if (0 == ::gethostname(szHostName, sizeof(szHostName)))
{
char* port = "80";
addrinfo aiHints;
addrinfo *aiList = NULL;
int retVal;memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;if ((retVal = ::getaddrinfo(szHostName, port, &aiHints, &aiList)) == 0)
{
addrinfo *pAddrInfo = aiList;
while (pAddrInfo)
{
//examine pAddrInfo->ai_addr here for local IP address(es)
pAddrInfo = pAddrInfo->ai\_next; } `::freeaddrinfo(aiList); //*EDIT*`
}
}-- modified at 14:41 Friday 8th June, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
alejandrofuchs wrote:
First, i'm sorry, someone else (joseaxy) was already signed in codeproject in this machine, so my later response had that name.
hmmm...split personality? ;P If you try getaddrinfo(), does that work on Server 2003? Something like:
char szHostName[256];
if (0 == ::gethostname(szHostName, sizeof(szHostName)))
{
char* port = "80";
addrinfo aiHints;
addrinfo *aiList = NULL;
int retVal;memset(&aiHints, 0, sizeof(aiHints));
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;if ((retVal = ::getaddrinfo(szHostName, port, &aiHints, &aiList)) == 0)
{
addrinfo *pAddrInfo = aiList;
while (pAddrInfo)
{
//examine pAddrInfo->ai_addr here for local IP address(es)
pAddrInfo = pAddrInfo->ai\_next; } `::freeaddrinfo(aiList); //*EDIT*`
}
}-- modified at 14:41 Friday 8th June, 2007
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com
-
Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com
alejandrofuchs wrote:
I still have the doubt about why it doesn't work only on Windows 2003
I couldn't find any reason it wouldn't work in the Platform SDK for Server 2003...it's a mystery to me! :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Yes, this works. I will change my code. I still have the doubt about why it doesn't work only on Windows 2003, but as this code works fine i prefer this new aproach. :)Thank you to you all for your help! PD. Only for curiosity :confused:, if somebody find out what's wrong on the original code under 2003, please write. :)alejandrofuchs@yahoo.com
p.s. Don't forget to call freeaddrinfo() - I left that out of the code sample. Cheers :beer: Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder