I hope it is possible to get the necessary details of each network port from /etc/services. If I have to develop a C++ program to get the status of each port how should I start it?  I am not allowed to call netstat, ss or anything similar from my program. Is there some files in the filesystem from which I can get the information?
Status of network ports
networking;c++;netstat
It's still not clear to me whether you want to implement netstat -a -t -u or the outer join of /etc/services and netstat -a -t -u, or something else, but here are some ideas that may help:TCP and UDP port numbers range from 1 to 65536. The /etc/services file that you mentioned lists a subset of the well-known ports and registered ports. A larger list is at the IANA Service Name and Transport Protocol Port Number Registry. You can use getservent() to retrieve each record listed in /etc/services.On Linux, you can get a list of all the sockets that are in listen, connecting, connected, or partially closed state, and their local and remote addresses and ports, by reading the files /proc/net/tcp, /proc/net/tcp6, /proc/net/udp, and /proc/net/udp6. The output of netstat -a -t -u -n is almost exactly the same as these files, just a lot prettier. The addresses, port numbers, and states are in hex. The pretty version of the state field can be produced by using the names in /usr/include/netinet/tcp.h:    enum    {      TCP_ESTABLISHED = 1,      TCP_SYN_SENT,      TCP_SYN_RECV,      TCP_FIN_WAIT1,      TCP_FIN_WAIT2,      TCP_TIME_WAIT,      TCP_CLOSE,      TCP_CLOSE_WAIT,      TCP_LAST_ACK,      TCP_LISTEN,      TCP_CLOSING    };On FreeBSD, you would call sysctlbyname(net.inet.tcp.pcblist,...), which retrieves an array of xtcpcb structs. It's probably best to look at the netstat source code to see how to interpret those structures.