netstat -p + how it works? - Linux
This is a discussion on netstat -p + how it works? - Linux ; hi
i m working on FC4, FC5 and RH9 of Linux OS. i want to build a program
such as like netstat. In this program i have to gather local port,
local ip, protocol and the program or file name ...
-
netstat -p + how it works?
hi
i m working on FC4, FC5 and RH9 of Linux OS. i want to build a program
such as like netstat. In this program i have to gather local port,
local ip, protocol and the program or file name on which particular
port a particular file is running.
for that i have read the netstat command help. i know that it reads
from the "proc" file system. But i m not able to know from where it
will find out PID/program name for that particular port number.
i want to implement all this using C programming language. i have local
port and local ip but unable to find the PID/program name on that port.
plz help me.
if there is any structure or if from which proc file it will read the
binary/file name, or which technique the "netstat -p" command use.
Thanking you
Chandrakant Solanki
-
Re: netstat -p + how it works?
solanki.chandrakant@gmail.com wrote:
> hi
>
>
> i m working on FC4, FC5 and RH9 of Linux OS. i want to build a program
> such as like netstat. In this program i have to gather local port,
> local ip, protocol and the program or file name on which particular
> port a particular file is running.
>
> for that i have read the netstat command help. i know that it reads
> from the "proc" file system. But i m not able to know from where it
> will find out PID/program name for that particular port number.
>
> i want to implement all this using C programming language. i have local
> port and local ip but unable to find the PID/program name on that port.
> plz help me.
>
> if there is any structure or if from which proc file it will read the
> binary/file name, or which technique the "netstat -p" command use.
If you look into /proc/net/{tcp,udp,unix,tcp6,udp6 maybe raw,raw6},
you'll find the "inode" number (e.g. in column 9 in tcp). If you then
look at /proc//fd, you'll find that network connections are denoted
as a symbolic link to "socket[]". This number is the inode
number, so if you relate the contents of the abovementioned files with
the symbolic links, you get the necessary information.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
-
Re: netstat -p + how it works?
In article <1166598431.625756.11140@f1g2000cwa.googlegroups.co m>,
solanki.chandrakant@gmail.com wrote:
>if there is any structure or if from which proc file it will read the
>binary/file name, or which technique the "netstat -p" command use.
Have you consider just looking at the netstat source to see what it
does?
--
http://www.spinics.net/lists/kernel/