Unix Programming - Obtaining my own address

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2004 > Obtaining my own address





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Obtaining my own address
Brieuc Jeunhomme

2004-11-18, 7:47 am

Hello,

I am implementing a UDP based protocol whose specifications require the
client to send its own IP address in the UDP payload (ie. this information
is duplicated: it appears both in the IP header and in the UDP payload).

I am thus looking for a portable way to determine the source IP address
that will be placed by the kernel in the IP header of a UDP datagram. This
means that the routing tables will have to be inspected, as the
application may run on a multi interfaces system.

Any ideas ?

--
BBP

Lőrinczy Zsigmond

2004-11-18, 5:52 pm

Brieuc Jeunhomme wrote:
> Hello,
>
> I am implementing a UDP based protocol whose specifications require the
> client to send its own IP address in the UDP payload (ie. this information
> is duplicated: it appears both in the IP header and in the UDP payload).


What protocol is this?
If a local (homemade) one then try to remove this field from the protocol.
Brieuc Jeunhomme

2004-11-18, 5:52 pm

> What protocol is this?

SNMP

> If a local (homemade) one then try to remove this field from the protocol.


The entire protocol should be removed

--
BBP

Alex Fraser

2004-11-19, 2:48 am

"Brieuc Jeunhomme" <bbp@via.ecp.fr> wrote in message
news:pan.2004.11.18.11.23.56.935501@frtest.org...
> I am thus looking for a portable way to determine the source IP address
> that will be placed by the kernel in the IP header of a UDP datagram.


Call connect() on an unbound socket, followed by getsockname().

Alex


David Schwartz

2004-11-24, 6:28 pm


"Brieuc Jeunhomme" <bbp@via.ecp.fr> wrote in message
news:pan.2004.11.18.11.23.56.935501@frtest.org...

> I am thus looking for a portable way to determine the source IP address
> that will be placed by the kernel in the IP header of a UDP datagram. This
> means that the routing tables will have to be inspected, as the
> application may run on a multi interfaces system.


You should probably just select the source IP address yourself by
binding the UDP socket to whichever IP address you want. This is the only
way to guarantee that the source address is the one you think it should be.

DS


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com