The problem I have is that 'getservbyname()' always fails with error code
11004
returned from 'WSAGetLastError()'.
I am not quite sure what the first argument to getservbyname() should be...
but whatever
I try, the call always fails.
What am I missing here?
What does 'getservbyname()' actually do on NT?
Any help appreciated.
SOCKADDR_IN sa;
WSADATA WSAData;
char szMyName[256];
HOSTENT* pHostEnt;
SERVENT* pServEnt;
SOCKET sListen = INVALID_SOCKET;
WORD wVersionRequested = MAKEWORD( 2, 0 );
if (WSAStartup(wVersionRequested, &WSAData) != 0) {
printf("\nWSAStartup() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
if ((sListen = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
printf("\nsocket() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
if (gethostname(szMyName, sizeof(szMyName)) != 0) {
printf("\ngethostname() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
if ((pHostEnt = gethostbyname(szMyName)) == NULL) {
printf("\ngethostbyname() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
sa.sin_family = AF_INET;
memcpy(&sa.sin_addr, pHostEnt->h_addr_list[0], pHostEnt->h_length);
if ((pServEnt = getservbyname( "some service", "tcp")) == NULL) {
printf("\ngetservbyname() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
sa.sin_port = pServEnt->s_port;
if (bind(sListen, (SOCKADDR*)&sa, sizeof (SOCKADDR)) != 0) {
printf("\nbind() failed, err = %d\n", WSAGetLastError());
goto cleanup;
}
--
Dave
Amsterdam
da...@smallplanet.nl
Error 11004 is WSANO_DATA according to WINSOCK.H, which probably means
there is no entry for this service in your SERVICES file
(%SystemRoot%\System32\DRIVERS\ETC).
David Cross <da...@smallplanet.nl> wrote in article
<01bc5b9c$ec7249b0$67f10bc3@athena>...