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/
How low in the protocol stack are you going? If you use an IP raw socket with
IP_HDRINCL and just leave the sending address filled with zeros, then it will be
filled in with the default address for the link used to send to the destination
address. See the man page on raw(4) for more details.
> If a port number is not allocated with the above connect(),
> how do I manually allocate a source port, bind()?
Yes, bind() works.
Why do you care about source address? I would suspect that most of the time you
want to either a) use the default, in which case you let the IP stack fill it
in, or b) use some wierd source address, in which case you're usually better off
using a config file or commandline parm.
Chris Friesen | MailStop: 043/33/F10
Nortel Networks | work: (613) 765-0557
3500 Carling Avenue | fax: (613) 765-2986
Nepean, ON K2H 8E9 Canada | email: cfriesen@xxxxxxxxxxxxxxxxxx