On Mon, 12 Jul 2004 12:08:48 +0200, Gershon Geva <[EMAIL PROTECTED]> wrote:


Hi.

I have a server (kernel 2.4.20) with a network card and a
cellular modem. On that server I run an application
That waits for incoming connections on a known port. It is
important to me to know to which Network Interface (in this case ppp0 and eth0) each incoming connection
belongs to. How do I do it? I know the Solution involves the usage of ioctl() , but
the documentation I found about this issue is very scarce. I would appreciate any idea
(sample source code could be
Even better :-)).

Thanks.



I'll suggest the following steps (mind you there are a LOT of small details to cover though):

1. Enumerate all interfaces on your server using ioctl's interface
option SIOCGIFCONF. It's not trivial to cover all aspects of all
interfaces as Stevens clearly shows in his full-blown code that
does this exact thing :)
The code is in UNIX network programming in the ioctl chapter. I'd
suggest AGAINST using it as it's exceedingly long and annoying.
(much to learn from it though).
Once this is done, keep the IP addresses of all your interfaces in
whatever way you prefer. For IPv4 you can just save an array of
in_addr types (along with names if you prefer..)

2. When a new connection is establihed, call getsockname to retrieve
the IP address of the local end of the connection.

3. Look up the IP you got from step 2 in the array from ioctl(). Since
the connection arrived on one of the interfaces, one must match and
that is the interface you were looking for.

Eli


-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Reply via email to