Aiee :)
Hello!
On Tue, Sep 11, 2001 at 06:47:07PM +0100, Padraig Brady wrote:
> >>Padraig Brady wrote:
> >>
> >>>I'm writing a network app (currently on linux 2.2.18,
> >>>but soon moving to 2.4) that needs to build up ip &
> >>>tcp packets manually. So my question is how do I determine
> >>>the source ip address to use for a given destination
> >>>ip address. I.E. take account of multiple interfaces/routes/
> >>>aliases/...
> >>>
> Chris, I'm only filling in the TCP header, and I realise the IP header
> will be
> filled appropriately when sent. However I need to calculate the checksum for
> the TCP header which is actually calculated for the pseudo header:
>
> struct pseudo_header {
> unsigned int src_address; /* <==-- */
> unsigned int dest_address; > unsigned char placeholder;
> unsigned char protocol;
> unsigned short tcp_length;
> struct tcphdr tcp;
> } pseudo_header;
>
> So I need to determine the source address before sending...
When sending IP datagram, source IP address is choosen by the
kernel just picking up the one bound to the outgoing interface
(actually I never thought about this could work when multiple
addresses are assigned to one interface).
So, what you have to do is just this;
look at destination IP address, use the kernel routing table to
get the outgoing interface, retrieve the IP address associated with
it.
You can achieve all this just using AF_NETLINK socket(2) or by playing
with /proc/net/route and doing a few ioctl(2) calls (SIOCGIFADDR))
If I misenderstood something, I apologize; point me out to the
beginning thread then, thanks! :)
> Thanks,
> Padraig.
bye bye
-- gg sullivan
--
Lorenzo Cavallaro `Gigi Sullivan' <sullivan@xxxxxxxxxxxxx>
Until I loved, life had no beauty;
I did not know I lived until I had loved. (Theodor Korner)
|