LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-16-2012, 08:58 AM   #1
pologuy
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Rep: Reputation: Disabled
How to get service name(process name) by port number in kernel?


Hi all,

I need to know how to get service name(process name) by port number in kernel. Does anyone can help me?

I know function of "getserbyport" can get service by port number in userspace, but don't know the similar way in kernel.

Thanks a lot.
 
Old 04-17-2012, 02:22 AM   #2
jklaverstijn
LQ Newbie
 
Registered: Jan 2011
Posts: 15

Rep: Reputation: 0
I use lsof. For example: lsof -i :<portnumber>. This gives the pid of the process accessing the port. From this you can use ps to get th eprocess name.

There is bound to be a way by going through /proc but I do not know by heart.

Good luck, Jan.
 
Old 04-17-2012, 07:00 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by pologuy View Post
I know function of "getserbyport" can get service by port number in userspace, but don't know the similar way in kernel.
This function parses /etc/services. The more "current" userspace method is getnameinfo. I don't know where it gets info from, but I assume it's from the same place. I don't think there's any built-in way to get that information in kernel space.
Kevin Barry
 
Old 04-17-2012, 08:05 PM   #4
waltinator
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Rep: Reputation: 1
Port number and service aren't connected!

If a process has a port open, the kernel knows about it. Reading the lsof source might give you a hint. However, knowing that PID ### has TCP Port ## open, plus all the information you can get from /proc/### will NOT let you know what service the process is providing. One can write a simple program, call it "telnetd", run it on port 8080 (or port 80, if you're root).
 
  


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
How to get service name(process name) by port number in kernel? pologuy Linux - Networking 1 04-16-2012 10:40 AM
Retrieve client ip address and port number in kernel udp socket yethish Linux - Newbie 4 09-08-2011 09:59 PM
how to get the port number of the "ajp13" service running on host master? atirasatiras Linux - Server 1 04-01-2011 04:32 AM
LXer: Linux Kernel Ext3 Invalid Inode Number Denial of Service LXer Syndicated Linux News 0 08-08-2006 08:33 PM
need all service port number !!! hitesh_linux Linux - General 4 03-19-2003 07:32 PM

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

All times are GMT -5. The time now is 07:12 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