getservbyport

Returns information about a service, given its port number and protocol.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <netdb.h> 
   
  struct servent *getservbyport (
     int           port,
     const char   *proto);
  

Parameters

port

(IN) Specifies the port number at which the service resides (in network order).

proto

(IN) Points to the name of the protocol, such as "TCP" or "tcp". The matching is case insensitive.

Return Values

If successful, returns a pointer to a structure of type servent. Otherwise, returns NULL.

Remarks

The getservbyport function returns a pointer to a servent structure in the services file.

The function accepts a pointer to a character string representing the protocol name and an integer representing the port number. The function searches from the beginning of the sys:\etc\services file and continues until it reaches end-of-file or finds a service matching the port number. If a protocol name is also specified, then the searches must also match the protocol name. (The numeric protocol number is expressed in network byte order). If the protocol name is NULL, the first matching entry with the given port number is returned.

NOTE:Calling any database routine overwrites the results of the last call to getservbyport.

See Also