Can a network client specify an IP on the source side?



When I initiate a network connection to a remote server, is there a
way to specify an IP address on the source side? Take a Perl snippet
as an example (modified from "Programming Perl"):

#!/usr/local/bin/perl -w
require 5.002;
use Socket;

$remote = shift || 'locahost';
$port = shift || 2345;
$iaddr = inet_aton($remote) or die "No host: $remote";
$paddr = sockaddr_in($port, $iaddr);
$proto = getprotobyname("tcp");
socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";

#Does it make sense to bind the socket with an IP on the source? How?
bind(SOCK, sockaddr_in(0, "10.6.143.111")) or die "bind: $!";

connect(SOCK, $paddr) or die "connect: $!";
print while <SOCK>;
close SOCK or die "close: $!";
exit;

I've never seen a bind() call on a client. I added it because I want
to designate a specific IP on a multihomed server. But it throws
error:

$ client.pl some.destination.example.com 22
bind: Cannot assign requested address at client.pl line <line number
pointing to the bind() line>.

That IP does exist as shown in ifconfig output. I suspect the first
argument to sockaddr() should not be 0. Any help is appreacited.

Yong Huang
[This message was posted to another group without a definitive answer]

.



Relevant Pages

  • Can a network client specify an IP on the source side?
    ... When I initiate a network connection to a remote server, ... Take a Perl snippet ... #Does it make sense to bind the socket with an IP on the source? ... I've never seen a bind() call on a client. ...
    (comp.unix.solaris)
  • Windows XP/SP2 DHCP provided IP address does not bind.
    ... Installed Client XP/SP2, installed QOS. ... DHCP, does not bind and as a result no connection to remote server, with ...
    (microsoft.public.windowsxp.network_web)
  • BIND 9.5.2rc1 is now available.
    ... BIND 9.5.2rc1 is now available. ... triggering an assertion failure in ... API and glibc hides parts of the IPv6 Advanced Socket ... need to tweak ISC_SOCKET_MAXSOCKETS at compilation time ...
    (comp.protocols.dns.bind)
  • BIND 9.5.2 is now available.
    ... BIND 9.5.2 is now available. ... triggering an assertion failure in ... API and glibc hides parts of the IPv6 Advanced Socket ... need to tweak ISC_SOCKET_MAXSOCKETS at compilation time ...
    (comp.protocols.dns.bind)
  • BIND 9.4-ESVb1 is now available.
    ... BIND 9.4-ESVb1 is a extended release version beta for BIND 9.4. ... API and glibc hides parts of the IPv6 Advanced Socket ... WARNING: API CHANGE: over memory callback ... If allow-recursion is not set in named.conf then ...
    (comp.protocols.dns.bind)