Networking Forums

Networking Forums > Computer Networking > Linux Networking > linux sockets - connect()

Reply
Thread Tools Display Modes

linux sockets - connect()

 
 
Bilgehan.Balban@gmail.com
Guest
Posts: n/a

 
      02-02-2006, 10:19 AM
Hi,

When a client wants to connect to a server, the connect() call takes
the argument to specify where to connect to, but is there a way to
specify, which interface on the client to use, to connect to the remote
machine?

I'm asking because I have a multi-home client and want it to use a
specific IP to make connections from.

Thanks,
Bahadir

 
Reply With Quote
 
 
 
 
David Schwartz
Guest
Posts: n/a

 
      02-02-2006, 11:02 AM

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

> When a client wants to connect to a server, the connect() call takes
> the argument to specify where to connect to, but is there a way to
> specify, which interface on the client to use, to connect to the remote
> machine?


When you say "which interface" do you mean the source IP address? Or do
you mean what interface the packets go out of? There is a *huge* difference.

> I'm asking because I have a multi-home client and want it to use a
> specific IP to make connections from.


You can specify the source IP address with a 'bind' call before the
'connect'. But that has no affect on which interface is used to transmit
packets or which interface the return packets will wind up at.

DS


 
Reply With Quote
 
manish
Guest
Posts: n/a

 
      02-02-2006, 11:38 AM
i guess both the interface and the ip address are one and the same
thing. Isn't that why a machine having two ip addresses is having two
interfaces.

corrections are welcome.

 
Reply With Quote
 
David Schwartz
Guest
Posts: n/a

 
      02-02-2006, 11:43 AM

"manish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...

>i guess both the interface and the ip address are one and the same
> thing. Isn't that why a machine having two ip addresses is having two
> interfaces.


No. A machine can have two interfaces with the same IP address or two IP
addresses assigned to one interface. While IP addresses are assigned to
interfaces, not machines, an interface can have zero, one, or any number of
IP addresses.

DS


 
Reply With Quote
 
manish
Guest
Posts: n/a

 
      02-03-2006, 02:52 AM
what do you mean by interface...? is the network card an interface or
some logical opening of the system?

 
Reply With Quote
 
Bilgehan.Balban@gmail.com
Guest
Posts: n/a

 
      02-03-2006, 04:59 PM
David Schwartz wrote:
> No. A machine can have two interfaces with the same IP address or two IP
> addresses assigned to one interface. While IP addresses are assigned to
> interfaces, not machines, an interface can have zero, one, or any number of
> IP addresses.
>
> DS


Hi,

I didn't know this. If I have two ethernet interfaces with distinct MAC
addresses, how could I have a single IP address for both? How would
R/ARP and DHCP work then?

In reply to your bind() suggestion, so you mean I should first bind()
my client socket on a particular local IP address, and then connect to
the remote machine?

Thanks,
Bahadir

 
Reply With Quote
 
David Schwartz
Guest
Posts: n/a

 
      02-03-2006, 09:46 PM

"manish" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

> what do you mean by interface...? is the network card an interface or
> some logical opening of the system?


It can be either. Generally, there is one interface for each network
card, whether or not it has any IP addresses assigned to it. There may also
be additional interface generated logically by the system, for example, the
loopback interface or a 'bridge interface' to assign an IP address to
several bridged physical interfaces.

DS


 
Reply With Quote
 
David Schwartz
Guest
Posts: n/a

 
      02-03-2006, 09:47 PM

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

> I didn't know this. If I have two ethernet interfaces with distinct MAC
> addresses, how could I have a single IP address for both? How would
> R/ARP and DHCP work then?


It's not easy to do this with ethernet interfaces, it's much more common
with point-to-point interfaces.

> In reply to your bind() suggestion, so you mean I should first bind()
> my client socket on a particular local IP address, and then connect to
> the remote machine?


Yes, that's correct.

DS


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Some C language examples of linux raw sockets for IPv4 and IPv6 pdbuchan@yahoo.com Linux Networking 0 12-17-2011 03:30 AM
Can't connect W2K Box To Linux Box Snoopy :-)) Linux Networking 2 06-08-2006 03:01 PM
Can't get the exact message using sockets in 64-bit Linux? LaBird Linux Networking 1 03-12-2006 07:12 PM
Real-Time UDP non-blocking sockets in Linux Michael Drew Linux Networking 14 02-18-2004 11:56 PM
Linux Box (Red Hat 9 Can't Connect to Internet DavidNoack Linux Networking 0 07-08-2003 01:04 AM



1 2 3 4 5 6 7 8 9 10 11