LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
Search this Thread
Old 05-19-2004, 11:43 AM   #1
loki.guz_BR
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 03:41 PM.
 
Old 05-19-2004, 02:19 PM   #2
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
Hi,

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
nukkel
 
  


Reply


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 02:39 PM
Lsof Is Useless?? Philip_38 Linux - Software 3 01-30-2005 09:24 AM
lsof and fuser do not work with /dev/dsp alexrait1 Slackware 4 10-09-2004 04:07 PM
lsof can't identify protocol sock rozeboom Linux - Networking 4 05-21-2004 12:34 PM
lsof: command not found ionian2k Linux - Newbie 1 12-26-2002 08:59 PM


All times are GMT -5. The time now is 11:12 AM.

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