LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2005, 10:50 AM   #1
shadowmas
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
Process ID of a socket


Hi,

I'm trying to write a program which will dyanmically open the firewall for ports open by a specific program (using the libipq library).

for this i need a way to figure out the process id, user id which has created the specific listening socket for a given port (like lsof does). i tried to go through the lsof code but it seems too complicated + since lsof is not gpl i dont have a clear idea what effect it will have on the program that i make (which i plan to make gpl). i realise that i could call lsof from my code but i feel it would give put too much overhead in the process.

can anyone give me some idea as to what i need? this is really my first real linux program so i dont have much of a idea of where to look (google didnt help).

thanks
--MAS
 
Old 06-28-2005, 11:59 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Try the sources of "netstat" instead of lsof. It's probably simpler and also GPL.

Example: netstat -plan
gives all connected and listening sockets (tcp, udp, and filesy sockets) including PID, and process name. (when not run as root, it will give you this info only for the processes of the user running netstat, but there's no way around that anyway)

"netstat" is (on debian) part of the "net-tools" package. One place to get the sources: http://ftp.debian.org/debian/pool/ma...60.orig.tar.gz

Last edited by Hko; 06-28-2005 at 12:01 PM.
 
Old 06-28-2005, 11:13 PM   #3
shadowmas
LQ Newbie
 
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
many thanks. i'll go through the code.
 
  


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
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 08:28 PM
Socket File Descriptors for a process MadCoder77 Linux - Networking 0 05-26-2005 05:19 PM
using a socket decriptor opened by anoter process sudheernair Programming 6 04-19-2004 11:20 AM
using a socket descriptor opened by another process sudheernair Programming 0 04-16-2004 07:29 AM
share socket between two process Vikash Singh Linux - Networking 0 10-10-2003 08:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration