Unix Network Programming Manual
Prev Page Next Page

Getting Services Data

Another category of information that you need to manipulate is that for services. Again, it is inconvenient to always know what port number to use and to hard code it into a program. Services have names, ports and protocols, as defined by the structure: You can specify either a name or a port and obtain this service structure for a particular service using getservbyname or getservbyport. For example, if you had a stream server that could by known by several different service names (ports-protocol pairs), you might pass in the service name that you want it to use. The server could find the appropriate port number for the bind as follows: In this case, you have to know that the server is written for streams and that the protocol for Internet streams is tcp.

getservbyport is used less frequently but might be used to determine the service name being used from the port number, since the service name will probably have more meaning to the humans than a port number.


Prev Page Next Page