Unix Network Programming Manual
Prev Page Next Page

Socket Utilities

There are a number of Unix socket utilities that are useful in creating communication programs.

getsockname

In many cases, you don't need to explicitly select a port for a socket. Instead, you set the port value to zero, and this causes the bind function to select an unused port and assign it. However, you may then need to query the operating system and get the port number. This can be done as follows by using getsockname which returns the address structure for the socket.

getsockopt

In some cases, you will need to query a socket to determine what its properties are, and that can be done with the getsockopt function. The syntax is:
The option names include the following: