Networking Forums

Networking Forums > Computer Networking > Linux Networking > Determining Originator of TCP Connection?

Reply
Thread Tools Display Modes

Determining Originator of TCP Connection?

 
 
gg-csf@dmztest.vsr.ambisys.net
Guest
Posts: n/a

 
      05-18-2005, 03:36 AM
Given a socket which is being used for an established TCP connection,
is there any way to determine from user space under Linux 2.4/2.6 which
side originated the connection? I'm working on some low-level code, so
all I get is the socket. The solution doesn't have to be portable, so I
could use, say, data from the tcp_info structure, but unfortunately
none of those fields seem to indicate the originator.

Thanks!

G

 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a

 
      05-18-2005, 05:04 PM
gg-(E-Mail Removed) wrote:
> Given a socket which is being used for an established TCP connection,
> is there any way to determine from user space under Linux 2.4/2.6 which
> side originated the connection? I'm working on some low-level code, so
> all I get is the socket. The solution doesn't have to be portable, so I
> could use, say, data from the tcp_info structure, but unfortunately
> none of those fields seem to indicate the originator.
>
> Thanks!
>
> G
>


You may be able to infer it from the port numbers. The originator
always calls from port numbers above 1024. And you may happen to
know which port the server is listening on. Otherwise, I think
you are out of luck - an open TCP connection is symmetrical.

Steve
 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a

 
      05-18-2005, 06:48 PM
Steve Horsley <(E-Mail Removed)> said:
>gg-(E-Mail Removed) wrote:
>> Given a socket which is being used for an established TCP connection,
>> is there any way to determine from user space under Linux 2.4/2.6 which
>> side originated the connection? I'm working on some low-level code, so
>> all I get is the socket. The solution doesn't have to be portable, so I
>> could use, say, data from the tcp_info structure, but unfortunately
>> none of those fields seem to indicate the originator.
>>
>> Thanks!
>>
>> G
>>

>
>You may be able to infer it from the port numbers. The originator
>always calls from port numbers above 1024.


No, not always. It is possible for the originating application to
bind to a given socket number before connecting. This isn't often
used (any more), but was favored by some programs (the r* things,
as far as I recall, did behave like this).

>And you may happen to know which port the server is listening on.


This is the other possibility.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
Menno Duursma
Guest
Posts: n/a

 
      05-18-2005, 07:06 PM
On Wed, 18 May 2005 18:48:42 +0000, Juha Laiho wrote:
> Steve Horsley <(E-Mail Removed)> said:


>>You may be able to infer it from the port numbers. The originator
>>always calls from port numbers above 1024.

>
> No, not always. It is possible for the originating application to
> bind to a given socket number before connecting. This isn't often
> used (any more),


NFS, NTP

> but was favored by some programs (the r* things,
> as far as I recall, did behave like this).


Indeed, ssh used to do that as well (if installed setuid.)

--
-Menno.

 
Reply With Quote
 
gg-csf@dmztest.vsr.ambisys.net
Guest
Posts: n/a

 
      05-19-2005, 05:53 AM
Hello!

Good idea! I was hoping to find a bit flag somewhere that I could
check, but failing that, this should handle 90% of the cases.

Thanks!

G

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining who operates which APs Gonzago Wireless Internet 3 03-22-2012 05:39 AM
Determining the lifespan of a process Jurgen Haan Linux Networking 2 04-09-2008 09:36 AM
Determining IP Address Neil Cameron Broadband 1 01-03-2006 03:38 PM
Determining OS language Cfm Windows Networking 1 06-20-2004 02:29 AM
Determining IP address? mpierce Linux Networking 6 01-01-2004 12:29 PM



1 2 3 4 5 6 7 8 9 10 11