LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 08-18-2004, 01:42 PM   #1
WhiteDevel
LQ Newbie
 
Registered: Jun 2004
Location: Nepal
Distribution: Slackware 10.2
Posts: 15

Rep: Reputation: 0
Port Addressess...........


i have sniffed all the packets of a network using a c program in fedora core 1. And i also know which port number is initiating the packets. Ofcourse if the port numbers are defined like 23 or 80 etc than i can say that it is initiating from a telnet application or a http application. But if the port numbers are not known than how can i know which application inititated the packets. Can anyone help me out here i am really in trouble. Or there is any other theory except port address to know which application is initiating the packets.
 
Old 08-18-2004, 01:46 PM   #2
ToniT
Senior Member
 
Registered: Oct 2003
Location: Zurich, Switzerland
Distribution: Debian/unstable
Posts: 1,357

Rep: Reputation: 47
lsof -i
and
cat /proc/net/tcp
 
Old 08-19-2004, 07:31 PM   #3
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
To see what ports are used by various applications, you can look at /etc/services

--Tony
 
Old 08-20-2004, 12:56 PM   #4
WhiteDevel
LQ Newbie
 
Registered: Jun 2004
Location: Nepal
Distribution: Slackware 10.2
Posts: 15

Original Poster
Rep: Reputation: 0
Actually i need some programmatic approach. Hope ya people understand. I am using C language to develop my program.
 
Old 08-20-2004, 01:02 PM   #5
Xagafinelle
LQ Newbie
 
Registered: Aug 2004
Distribution: SlackWare
Posts: 11

Rep: Reputation: 0
Using C it's a sinch, like ToniT said, lsof -i and cat /proc/net/tcp, although a little differently.

You can read in /proc/net/tcp using a standard file open command in C, and the formatting, in case it eludes you, is all defined in the proc man and info pages.

lsof -i, though, is really a spiffy one, I'd never used that before, if you want to capture it's functionality, simply open a pipe to it, popen, look it up in the man pages as well. Then just scan in it's output and format however you'd like.
 
Old 08-20-2004, 01:52 PM   #6
WhiteDevel
LQ Newbie
 
Registered: Jun 2004
Location: Nepal
Distribution: Slackware 10.2
Posts: 15

Original Poster
Rep: Reputation: 0
Actually, what i want to do is know the applications that are initiating different packets (using the port numbers) and then giving those packets high priority which are generated by real time applications such as voice application or most specifically VOIP i.e voice over IP which need consistent bandwidth and minimal delay.
For the priority purpose i chose CBQ i.e. class based queueing. Also if you people can give me some information i.e. implementation specific about CBQ then i will be very grateful to you.
 
Old 08-21-2004, 01:35 PM   #7
WhiteDevel
LQ Newbie
 
Registered: Jun 2004
Location: Nepal
Distribution: Slackware 10.2
Posts: 15

Original Poster
Rep: Reputation: 0
hey is there nobody to solve my problems or no one is interested. I hope ya people will soon find a solution. What'd you think...
 
Old 08-21-2004, 02:04 PM   #8
cracauer
Member
 
Registered: Jul 2004
Location: Boston, MA, USA
Distribution: FreeBSD, Debian/AMD64, Ubuntu/i386
Posts: 59

Rep: Reputation: 15
There is no high-level C interface for what you want.

The only way to get the information which program is sending the packets is to use netstat(1). The netstat program has a lot of functionality to figure this out coded in. Short of taking netstat and writing your own variant you cannot gain the information about the program without using it. Alternatively, you could write a kernel module to do what you want.

So if you see a packet then you have top loock at the address/port tuples and then call netstat to find the line corrosponding to these tuples.

There is an obvious race condition that the connection might end after you see a packet and before your call through netstat is through, or, worse, that the connection ended and a new one is already in place by the time you read the netstat output.

If this is security related, also take into account that programs can fake the string that appears in ps(1) so you need some /proc sniffing to figure out which executable on disk exactly this was called from.
 
  


Reply



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
PLESK [Solution] Change port to 23 (telnet) instead of default port 8443 x5452 Linux - Software 6 05-10-2009 05:58 AM
Using serial port card(PCMCIA) with IPAQ running Linux, can't find ttyS0 port d2army Linux - Laptop and Netbook 0 11-12-2005 08:07 PM
ip addressess configuration in squid proxy server raju_dhakar2002 Linux - Networking 0 05-09-2005 12:52 AM
Proxy server flodded by requests on port 53 & port 25 saurabh_sahni Linux - Security 5 04-26-2005 10:35 PM
--destination-ports port[,port[,port...]] KevinGuy Linux - Networking 1 03-16-2004 06:06 PM

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

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

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