Operating System - HP-UX
1833341 Members
3799 Online
110051 Solutions
New Discussion

need help understanding netstat -a output

 
Byron Myers
Trusted Contributor

need help understanding netstat -a output

Example netstat -a output record header: "Proto Recv-Q Send-Q Local Address Foreign Address (state)". I need help with the "Local Address" and "Foreign Address" fields. An example netstat -a output with two records are: "tcp4 0 0 myhost.sapgw81 myhost2.33555 ESTABLISHED" and "tcp4 0 0 *.sapgw81 *.* LISTEN". From these two records I believe there is a process listening on the *.sapgw81 socket that corresponds a "sapgw81 4800/tcp" record in the /etc/services file. So the first record indicates that a connection has been established - but what does the "myhost.sapgw81" field mean, and what does the "myhost2.33555" field mean for the first record? My guess is that "myhost2.3355" means that "myhost2" has successfully connected to the *.sapgw81 socket and that the socket used for communication on the myhost side to myhost2 is 33555 - yes/no?
Also, is there any limit on the number of connections spawned by a listening socket?
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
5 REPLIES 5
Ron Kinner
Honored Contributor

Re: need help understanding netstat -a output

look at netstat -an for a slightly different view but essentially (when you add in the info from /etc/services) it tells you that the sapgw81 process (I think this is a SAP GateWay)is listening on port 4800 and that there is already an existing TCP connection between port 33555 on myhost2 and port 4800 on myhost. Both ends of the connection may be the same PC. It is common for a process to use TCP/IP to communicate with another process on the same box. In this case the netstat -an will show 127.0.0.1 as the IP address for each end of the connection.

When you write software for sockets you have the option of reusing the socket. If you do not allow socket reuse then the maximum is 1. If you do then your maximum can vary depending on the OS and the application and the amount of memory available on the system. Often an application will have a flexible limit on the maximum number of connections allowed in its config file.


Ron
Byron Myers
Trusted Contributor

Re: need help understanding netstat -a output

How does the amout of available memory affect socket connections?
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
Ron Kinner
Honored Contributor

Re: need help understanding netstat -a output

Byron,

Each connection requires some amount of memory for buffers, stacks etc. The application will also need to reserve some memory for each connection.

Ron
Sridhar Bhaskarla
Honored Contributor

Re: need help understanding netstat -a output

Hi,

sapgw81 is the service name as defined in your /etc/services file. If you do a netstat -an, you would see it as a corresponding port number. If it is in LISTEN state, then there is a corresponding process associated with the port that will respond to the connections to it.

When a connection is made to this port (for ex., myhost2 , the socket will spawn a new socket with it's properties and returns a new file descriptor that will be used during the connection with myhost2 through the arbitrary port 33555. The original socket (*.sapgw81) will remain open for incoming requests and that goes on.

Since this involves creation of file descriptors, all the file parameters such as maxfiles, nfile limit the number of socket connections.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: need help understanding netstat -a output

Hi (again),

Look at this tutorial on socket programming. You don't need to understand the "code" part of it but theory part of it gives a good explanation of how the sockets work.

http://www.scit.wlv.ac.uk/~jphb/comms/sockets.html

-Sri
You may be disappointed if you fail, but you are doomed if you don't try