[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] how do i set interface for tcp client socket etc.
From: |
Hans Bulfone |
Subject: |
Re: [Chicken-users] how do i set interface for tcp client socket etc. |
Date: |
Fri, 16 Mar 2007 21:49:02 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
hi,
On Fri, Mar 16, 2007 at 08:46:43AM +0100, felix winkelmann wrote:
> >I think the idea is to be able to connect *from* a specific address
> >when you are on a box with multiple IP addresses.
>
> Sorry, but I have no idea how that is done. Anybody around who
> knows more about socket programming?
this can be done by calling bind() on the socket before calling
connect().
if you set the address to INADDR_ANY the system decides
the source address (and normally uses the address of the
interface where the packet is going to be sent, but i don't
know if this is required)
if you set the port to 0, the system chooses a free port
number for the local end of the connection.
(actually, i didn't find anything about that in the docs
that i've read, but i just tried it on linux and it works.
also, i can't think of any other way of specifying the
source address but letting the system decide the source port)
not calling bind() before calling connect() is imho the
same as calling bind() with INADDR_ANY and port 0.
(but as i'm not 100% sure about the port 0 thing, i'd
probably not call bind() if neither a specific source
address nor port is requested).
hth & bye,
hans.
Re: [Chicken-users] how do i set interface for tcp client socket etc., foobar, 2007/03/16