Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Security
User Name
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.


  Search this Thread
Old 05-19-2004, 12:43 PM   #1
LQ Newbie
Registered: May 2004
Posts: 1

Rep: Reputation: 0
C Library for lsof

Hi there,

I am in the process of writing some simple intrusion detection system in linux, and I have reachen a point where I have to, given a port number, return the process using this port, like running lsof -i on the shell. Does any1 know of a function written in c that, given the port number, will return me the same info lsof -i returns???

Thanks in advance...

Last edited by loki.guz_BR; 05-19-2004 at 04:41 PM.
Old 05-19-2004, 03:19 PM   #2
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30

I don't know if there is a library to do this. May very well be. If you don't find one, here's how you could do it yourself in a program:

* read /proc/net/tcp (or udp) and look at the last column of the line concerning the port you want to check (the one that says inode)

* check every /proc/<pid>/fd directory for symlinks pointing to "socket:[<inode>]" where <inode> is this number

I'm not sure if there is an alternative to iterating over all those directories...

Good luck finding a library!

See ya


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What to do when lsof fails.... SpacedCowboy Linux - Security 2 10-29-2005 03:39 PM
Lsof Is Useless?? Philip_38 Linux - Software 3 01-30-2005 10:24 AM
lsof and fuser do not work with /dev/dsp alexrait1 Slackware 4 10-09-2004 05:07 PM
lsof can't identify protocol sock rozeboom Linux - Networking 4 05-21-2004 01:34 PM
lsof: command not found ionian2k Linux - Newbie 1 12-26-2002 09:59 PM > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration