2

I am working on a Windows service that uses ports to discuss with client applications.

I have seen that the ports used by Windows are registered in the C:\Windows\System32\drivers\etc\services file, as well as ports used by some applications not developed by Windows.

Should I append the ports my service use in that file? Is it in anyway useful, or just informational?

1 Answer 1

3

This file is mostly just a copy of /etc/services from an old version of BSD – since Windows uses the same "BSD sockets" API and even brought in various client programs (ftp, telnet, rsh, finger commands) from it, it needs an services file in order for the getservbyname() function to work.

On Unix, various Internet servers and clients used to call getservbyname() to find out what port they should listen to; getservbyname("finger", "tcp") would return port 79. But when /etc/hosts was replaced by DNS, /etc/services was not – so it would quickly get out of date as the number of sites grew.

I'm guessing it's because of this that programs stopped using getservbyname() and started using their own config files, or hardcoded port numbers, instead. I think only the inetd daemon (and its xinetd successor) still uses service names as part of its configuration. And only legacy clients like telnet or ftp use the service names to connect.

These days, the file is mostly informational – for example, the netstat program can translate ports to service names, just like it translates IP addresses to hostnames.

$ netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 *:pulse-native          *:*                     LISTEN     
tcp6       0      0 [::]:mpd                [::]:*                  LISTEN     
tcp6       0      0 [::]:pulse-native       [::]:*                  LISTEN     
tcp6       0      0 [::]:netbios-ssn        [::]:*                  LISTEN     
tcp6       0      0 [::]:finger             [::]:*                  LISTEN     
tcp6       0      0 [::]:auth               [::]:*                  LISTEN     

On Windows, I'm sure, the file is used even less – I can't remember any program that uses it, other than the same ftp and telnet tools.

1
  • SAP NetWeaver RFC C++ SDK uses services file for reading its spagw ports associated to SAP instances.
    – thersch
    Apr 30, 2018 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .