Gets information on the specified port from the services database that is referenced by the TCPIP$SERVICE logical name. If the specified port is not found, this function may invoke the BIND resolver to search TCPIP$ETC:SERVICES.DAT. Format #include <netdb.h> struct servent *getservbyport ( int port, char *proto );
1 – Arguments
port The port number for which to search. This port number should be specified in network byte order. You can use the htons() function to convert the port number to network byte order. proto A pointer to a string containing the name of the protocol (TCP or UDP) for which to search.
2 – Description
This function searches the services database until a matching port is found, or until end of file is encountered. If a protocol name is also supplied, searches must also match the protocol. This function returns a pointer to a servent structure containing the broken-out fields of the requested line in the network services database. For information about the servent structure, refer to servent Structure. All information is contained in a static area, so it must be copied to be saved. Related Functions See also getservbyname().
3 – Return Values
NULL Indicates end of file or an error. x A pointer to a servent structure.
4 – Errors
EPERM Not owner. Indicates that the wrong port number was specified.