delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/10/13/01:40:13

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <416CC006.3D4ECDEF@dessent.net>
Date: Tue, 12 Oct 2004 22:41:26 -0700
From: Brian Dessent <brian AT dessent DOT net>
Organization: My own little world...
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: other services ok, ftp not (was 1.5.11 - tcp problems)
References: <4745850620 DOT 20040921112624 AT scenta DOT co DOT uk> <416B3A95 DOT 4010506 AT hq DOT astra DOT ph> <Pine DOT GSO DOT 4 DOT 61 DOT 0410121150090 DOT 24643 AT slinky DOT cs DOT nyu DOT edu> <416C92BD DOT 90100 AT hq DOT astra DOT ph>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019