Binding to specific IP address

I’m testing the usage of multicasting via TCP/IP under RTP. Our system is
configured with redundant LAN cards, both running TCP/IP and qnet. I’m
trying to multicast via TCP/IP on both LAN cards simulataneously.

According to my limited knowledge, one would create two sockets (s1/s2), and
then bind these sockets to the IP address specific to the cards you want to
transmit on (IP1/IP2):

/* create socket */
s1 = socket( AF_INET, SOCK_DGRAM, 0 );
if( s1 < 0 )
{
printf("%s : cannot open socket\n",argv[0]);
exit(1);
}

s2 = socket( AF_INET, SOCK_DGRAM, 0 );
if( s2 < 0 )
{
printf("%s : cannot open socket\n",argv[0]);
exit(1);
}

/* bind any port number /
cliAddr.sin_family = AF_INET;
inet_aton( IP1, &cliAddr.sin_addr );
cliAddr.sin_port = htons( 0 );
if( bind( s1,( struct sockaddr * ) &cliAddr, sizeof( cliAddr ) )<0)
{
perror( “bind” );
exit( 1 );
}
/
bind any port number */
cliAddr.sin_family = AF_INET;
inet_aton( IP2, &cliAddr.sin_addr );
cliAddr.sin_port = htons( 0 );
if( bind( s2,( struct sockaddr * ) &cliAddr, sizeof( cliAddr ) )<0)
{
perror( “bind” );
exit( 1 );
}


This code works, sort of. I would expect the packets sent via s2 to be
transmitted on the secondary LAN card (en1). However, this is not the case;
they are transmitted on en0 using IP2 address. What gives?

Never mind. It was a routing issue…

“Richard Doucet” <doucetr@aecl.ca> wrote in message
news:d6i6mj$p3h$1@inn.qnx.com

I’m testing the usage of multicasting via TCP/IP under RTP. Our system is
configured with redundant LAN cards, both running TCP/IP and qnet. I’m
trying to multicast via TCP/IP on both LAN cards simulataneously.

According to my limited knowledge, one would create two sockets (s1/s2),
and
then bind these sockets to the IP address specific to the cards you want
to
transmit on (IP1/IP2):

/* create socket */
s1 = socket( AF_INET, SOCK_DGRAM, 0 );
if( s1 < 0 )
{
printf("%s : cannot open socket\n",argv[0]);
exit(1);
}

s2 = socket( AF_INET, SOCK_DGRAM, 0 );
if( s2 < 0 )
{
printf("%s : cannot open socket\n",argv[0]);
exit(1);
}

/* bind any port number /
cliAddr.sin_family = AF_INET;
inet_aton( IP1, &cliAddr.sin_addr );
cliAddr.sin_port = htons( 0 );
if( bind( s1,( struct sockaddr * ) &cliAddr, sizeof( cliAddr ) )<0)
{
perror( “bind” );
exit( 1 );
}
/
bind any port number */
cliAddr.sin_family = AF_INET;
inet_aton( IP2, &cliAddr.sin_addr );
cliAddr.sin_port = htons( 0 );
if( bind( s2,( struct sockaddr * ) &cliAddr, sizeof( cliAddr ) )<0)
{
perror( “bind” );
exit( 1 );
}
.
.
.

This code works, sort of. I would expect the packets sent via s2 to be
transmitted on the secondary LAN card (en1). However, this is not the
case;
they are transmitted on en0 using IP2 address. What gives?

As far as i know, binding in combination with UDP sockets is only
relevant for getting errors related to the transmission, but has no
relevance w.r.t. selecting the the interface.

If i’d have to transmit to two LAN interfaces, i would use one socket,
and use INET_ADDR_ANY as destination for that socket, with the port i
want to broadcast to. I would not be inclined to bind anything: UDP
broadcast is not likely to result in reported errors anyway. With a
‘point-to-point’ UDP connction something like ‘destination IP and or
port cannot be reached’ could happen, but with broadcast that error
is not generated…