LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   getting ports (tcp, udp) from /proc (https://www.linuxquestions.org/questions/linux-software-2/getting-ports-tcp-udp-from-proc-714590/)

kbarani 03-26-2009 09:16 AM

getting ports (tcp, udp) from /proc
 
Hi all,
How to get the list of TCP , UDP ports running in the linux machine
from /proc/net/tcp ,/proc/net/udp through C program. Anyone have this program pls send me.

Thanks,
Barani

robel 03-27-2009 04:00 AM

Quote:

Originally Posted by kbarani (Post 3488438)
Hi all,
How to get the list of TCP , UDP ports running in the linux machine
from /proc/net/tcp ,/proc/net/udp through C program. Anyone have this program pls send me.

I do not have a program, but you can check out the source for netstat

http://www.tazenda.demon.co.uk/phil/net-tools/

It's a matter of sscanf() I guess.

Code:

    num = sscanf(line,
                "%d: %64[0-9A-Fa-f]:%X %64[0-9A-Fa-f]:%X %X %lX:%lX %X:%lX %lX %d %d %ld %512s\n",
                &d, local_addr, &local_port,
                rem_addr, &rem_port, &state,
          &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);

This code is from netstat.c around line 720

-Bob-


All times are GMT -5. The time now is 01:43 AM.