Gets service entry by port.
Standard C Library (libc.a)
The getservbyport subroutine is threadsafe in AIX® 4.3 and later. However, the return value points to static data that is overwritten by subsequent calls. This data must be copied to be saved for use by subsequent calls.
The getservbyport subroutine retrieves an entry from the /etc/services file using a port number as a search key.
An application program can use the getservbyport subroutine to access a service, service aliases, the protocol for the service, and a protocol port number for the service.
The getservbyport subroutine searches the services file sequentially from the beginning of the file until it finds one of the following:
Upon locating a matching protocol and port number or upon locating a matching protocol only if the Port parameter value equals 0, the getservbyport subroutine returns a pointer to a servent structure, which contains fields for a line of information in the /etc/services file. The netdb.h file defines the servent structure and structure fields.
Use the endservent subroutine to close the /etc/services file.
All applications containing the getservbyport subroutine must be compiled with the _BSD macro set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.
Item | Description |
---|---|
Port | Specifies the port where a service resides. |
Protocol | Specifies a protocol for use with the service. |
Upon successful completion, the getservbyport subroutine returns a pointer to a servent structure.
If an error occurs or the end of the file is reached, the getservbyport subroutine returns a null pointer.
Item | Description |
---|---|
/etc/services | Contains service names. |