Hi all,
I am now trying to send data from a Mac to two different
network.
My Mac has two ips.
192.168.0.234 (LAN)
192.168.1.56 (Wireless)
==============> some place 192.168.1.33
My code is listed below partially:
sin.sin_family = AF_INET;
sin.sin_addr.s_addr =
inet_addr("192.168.1.56"); //If I use INADDR_ANY, it didn't
send using both NIC. Why?
sin.sin_port = htons(1234);
s = socket(AF_INET, SOCK_DGRAM,
IPPROTO_UDP);
setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const void
*)&opt, sizeof(opt));
bind(s, (struct sockaddr *)&sin,
sizeof(sin));
send_sin.sin_family = AF_INET;
send_sin.sin_addr.s_addr =
inet_addr("255.255.255.255");
send_sin.sin_port = htons(1234);
mydata.data1=2;
mydata.data2=3;
int sendtoResult;
sendtoResult = sendto(s, (const void *)&mydata,
sizeof(mydata), 0, (struct sockaddr *)&send_sin,
sizeof(send_sin) );
while(1)
{
if (recvfrom(s, buff, sizeof(buff), 0, (struct
sockaddr *)&recv_sin, &recvlen) < 0)
{
printf("Receive
error!!!\n");
}
}
My problems are:
1. In binding, I use
sin.sin_addr.s_addr = inet_addr("192.168.1.56");
However, this is not working. It
didn't receive any data. I have to change to sin.sin_addr.s_addr =
INADDR_ANY;
What I want to achieve is
that
A. Since I
have two cards, sometimes I only want to use the wireless card or
LAN to receive and send packet.
B. I want to
send data on both card.
So, how?? What's wrong with my code?
2. When I send data, only the LAN side will broadcast.
The wireless side didn't send any data. I know that because the "192.168.1.33"
didn't receive any packet from 192.168.1.56
DATA = ""
192.168.0.234(LAN)
=====Broadcast=====> ok
=
> 192.168.1.56(Wireless)
===============X Why??? 192.168.1.33
Any suggestions?
How should I write it?
Thank you.
Pei-Yuan
@KCodes
|