Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinSock getservbyname() error 11004

401 views
Skip to first unread message

David Cross

unread,
May 8, 1997, 3:00:00 AM5/8/97
to

I am trying to write a simple WinSock server (NT4 SP2 MSVC5) that client
applications can connect over TCP/IP.
The code below is about where I am at.

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


Michael Vaserman

unread,
May 17, 1997, 3:00:00 AM5/17/97
to


Basically, according to the KB article Q130024, all getservbyname() does is
look for the entry in the SERVICES file that corresponds to the requested
service name.

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>...

0 new messages