This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: other services ok, ftp not (was 1.5.11 - tcp problems)


Carlo Florendo wrote:

> File:  inetutils-1.3.2-28 /ftp/main.c  (line numbers preceed each line)
> 
> 147     sp = getservbyname("ftp", "tcp");
> 148     if (sp == 0)
> 149         errx(1, "ftp/tcp: unknown service");

Okay, so the 'SYSTEM' thing was a red herring, and you're just running
this from a normal command prompt.  Your SYSTEMROOT is set and nothing
seems odd in your cygcheck, and permissions on the "services" file seem
okay.  Although I think your reasoning there is a little off-base:
Cygwin itself does not attempt to access that file at all.  Cygwin's
getservbyname() just a straight passthru to the Winsock function of the
same name which does the actual lookup.

Try the following and see what happens:

cat <<ENDL >getservbyname.c && \
    gcc getservbyname.c -o getservbyname && ./getservbyname
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>

int main(int argc, char *argv[])
{
    struct servent *sv = getservbyname("ftp", "tcp");
    
    if(sv)
        printf( "getservbyname() returned port %hu\n",
            ntohs(sv->s_port));    
    else
        printf( "getservbyname() returned NULL: %s\n",
            strerror(errno));    
}
ENDL

Also try the following variant that will create a mingw version of the
same test:


cat <<ENDL >getservbyname-mingw.c && gcc -mno-cygwin \
 getservbyname-mingw.c -o getservbyname-mingw && ./getservbyname-mingw
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <winsock2.h>

int main(int argc, char *argv[])
{
    struct servent *sv;
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
 
    wVersionRequested = MAKEWORD( 2, 2 );
 
    err = WSAStartup( wVersionRequested, &wsaData );
    if( err != 0 ) {
        printf( "Unable to load ws2_32.dll: error %u\n", err);
      	exit(1);
    }
    if( ( sv = getservbyname("ftp", "tcp") ) )
        printf( "getservbyname() returned port %hu\n",
            ntohs(sv->s_port));    
    else
        printf( "getservbyname() returned NULL: win32 error %u\n",
            WSAGetLastError());
}
ENDL

Both of those should say "getservbyname() returned port 21".  If either
fails, paste the output.  I suppose it's remotely possible that
something's wrong with wsock32.dll or ws2_32.dll on your system, but if
that was the case you'd have many more problems I'd think.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]