How to Selecte a Service Port?

Answer

The protocol specifications of the protocols used in the AF_INET domain require specification of a port. The port number is used to determine which process on the remote machine to talk to.

Certain network services have been assigned Well Known Ports. The port assignments to network services can be found in the file /etc/services. Selection of a Well Known Port involves searching this file and is done with the following functions:

#include <netdb.h>

struct servent *getservbyname(char *name,char *proto)

struct servent *getservbyport(int port,char *proto)

The two options for proto in each call are tcp for stream oriented communications, and udp for datagram oriented communications. port is the (known) port number when the service name is requested, while name is the character string containing the service name when the port number is requested.
The return value for each function is a pointer to a structure with the following form:

struct servent {
char *s_name; /* official name of service */
char **s_aliases; /* alias service name list */
long s_port; /* port service resides at */
char *s_proto; /* protocol to use */
};

If a program does not need to communicate with a Well Known Port it is possible to choose an unused port for use by a program. 

All sockets Questions

Ask your interview questions on sockets

Write Your comment or Questions if you want the answers on sockets from sockets Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---