Tim Gessner
|
broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Tim Gessner
09/23/2008 5:27 PM
post13908
|
broadcast using 255.255.255.255 actually sends 192.168.0.255
Ok, I really need help on this one. I have two nics and I want to broadcast to "255.255.255.255". What happens is that
when I use INADDR_BROADCAST I get 192.168.0.255, which is en0. The source address is 192.168.0.29.
I can deliberately broadcast using en1 in sendto with the broadcast address of en1, 192.168.75.255. But that is not
what I want to do.
What I want is to have a source IP of 192.168.75.80 (en1) and dest IP of 255.255.255.255. At least that is what I think
I want.
I have tried binding and IP_MULTICAST_IF. Nothing seems to change the source to en1 and nothing seems to make any
difference to the dest IP with the exception of changing sendto to the specific subnet. I have tried to sendto "255.255
.255.255" and it still sends to 192.168.0.255. This does not seem correct to me at all.
Can anyone help? Thanx
Tim
|
|
|
Tim Gessner
|
Re: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Tim Gessner
09/23/2008 5:52 PM
post13909
|
Re: broadcast using 255.255.255.255 actually sends 192.168.0.255
If I ping 192.168.0.255 (en0 broadcast) I get responses for all devices on that subnet.
If I ping 192.168.75.255 (en1 broadcast) I don't get any responses except from en1 (there are more devices on that
subnet).
If I ping 255.255.255.255 I get no route to host.
Please Help!
Thanx
Tim
|
|
|
Robert Craig
|
Re: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Robert Craig
09/23/2008 6:10 PM
post13910
|
Re: broadcast using 255.255.255.255 actually sends 192.168.0.255
Can you post the ouput from ifconfig so that we can see your overall network configuration?
R.
----- Original Message -----
From: Tim Gessner <community-noreply@qnx.com>
To: technology-networking <post13909@community.qnx.com>
Sent: Tue Sep 23 17:52:16 2008
Subject: Re: broadcast using 255.255.255.255 actually sends 192.168.0.255
If I ping 192.168.0.255 (en0 broadcast) I get responses for all devices on that subnet.
If I ping 192.168.75.255 (en1 broadcast) I don't get any responses except from en1 (there are more devices on that
subnet).
If I ping 255.255.255.255 I get no route to host.
Please Help!
Thanx
Tim
_______________________________________________
Technology
http://community.qnx.com/sf/go/post13909
|
|
|
Tim Gessner
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Tim Gessner
09/23/2008 6:33 PM
post13911
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
Sure, ifconfig below... Problem solved. I added a route for
255.255.255.255 to 192.168.75.80 I also used SO_BINDTODEVICE and
MSG_DONTROUTE and it seems to work. If I understand correctly, QNX
following some linux distros don't handle 255.255.255.255 correctly,
instead they treat change it to the subnet broadcast of the first
interface which supports broadcast. To get around this, a route needs
to be added and the stack told to not route and use the ip address as
bound in the sendto. Do I understand that correctly?
#ifconfig
lo0: flags=8009<UP, LOOPBACK, MULTICAST>
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
inet 127.0.0.1 netmask 0xff000000
en0: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:d0:c9:a9:44:59
inet 192.168.0.29 netmask 0xffffff00 broadcast 192.168.0.255
en1: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
enabled=0<>
address: 00:d0:c9:a9:44:5a
inet 192.168.75.80 netmask 0xffffff00 broadcast 192.168.75.255
-----Original Message-----
From: Robert Craig [mailto:community-noreply@qnx.com]
Sent: Tuesday, September 23, 2008 3:11 PM
To: technology-networking
Subject: Re: broadcast using 255.255.255.255 actually sends
192.168.0.255
Can you post the ouput from ifconfig so that we can see your overall
network configuration?
R.
----- Original Message -----
From: Tim Gessner <community-noreply@qnx.com>
To: technology-networking <post13909@community.qnx.com>
Sent: Tue Sep 23 17:52:16 2008
Subject: Re: broadcast using 255.255.255.255 actually sends
192.168.0.255
If I ping 192.168.0.255 (en0 broadcast) I get responses for all devices
on that subnet.
If I ping 192.168.75.255 (en1 broadcast) I don't get any responses
except from en1 (there are more devices on that subnet).
If I ping 255.255.255.255 I get no route to host.
Please Help!
Thanx
Tim
_______________________________________________
Technology
http://community.qnx.com/sf/go/post13909
_______________________________________________
Technology
http://community.qnx.com/sf/go/post13910
|
|
|
Dave Brown
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Dave Brown
09/24/2008 9:29 AM
post13932
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
You should not need the manual route setting if using SO_BINDTODEVICE
with MSG_DONTROUTE. It is an alternative to using these options. Take a
look at the tech-note Sean posted earlier in the thread which describes
how broadcasting works.
Dave
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 23, 2008 6:34 PM
> To: technology-networking
> Subject: RE: broadcast using 255.255.255.255 actually sends
192.168.0.255
>
> Sure, ifconfig below... Problem solved. I added a route for
> 255.255.255.255 to 192.168.75.80 I also used SO_BINDTODEVICE and
> MSG_DONTROUTE and it seems to work. If I understand correctly, QNX
> following some linux distros don't handle 255.255.255.255 correctly,
> instead they treat change it to the subnet broadcast of the first
> interface which supports broadcast. To get around this, a route needs
> to be added and the stack told to not route and use the ip address as
> bound in the sendto. Do I understand that correctly?
>
> #ifconfig
>
> lo0: flags=8009<UP, LOOPBACK, MULTICAST>
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> inet 127.0.0.1 netmask 0xff000000
>
> en0: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> address: 00:d0:c9:a9:44:59
> inet 192.168.0.29 netmask 0xffffff00 broadcast 192.168.0.255
>
> en1: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> address: 00:d0:c9:a9:44:5a
> inet 192.168.75.80 netmask 0xffffff00 broadcast 192.168.75.255
>
>
> -----Original Message-----
> From: Robert Craig [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 23, 2008 3:11 PM
> To: technology-networking
> Subject: Re: broadcast using 255.255.255.255 actually sends
> 192.168.0.255
>
> Can you post the ouput from ifconfig so that we can see your overall
> network configuration?
>
> R.
>
> ----- Original Message -----
> From: Tim Gessner <community-noreply@qnx.com>
> To: technology-networking <post13909@community.qnx.com>
> Sent: Tue Sep 23 17:52:16 2008
> Subject: Re: broadcast using 255.255.255.255 actually sends
> 192.168.0.255
>
> If I ping 192.168.0.255 (en0 broadcast) I get responses for all
devices
> on that subnet.
>
> If I ping 192.168.75.255 (en1 broadcast) I don't get any responses
> except from en1 (there are more devices on that subnet).
>
> If I ping 255.255.255.255 I get no route to host.
>
> Please Help!
>
> Thanx
> Tim
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13909
>
>
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13910
>
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13911
|
|
|
Tim Gessner
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Tim Gessner
09/24/2008 10:11 AM
post13939
|
RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
Thanx
-----Original Message-----
From: Dave Brown [mailto:community-noreply@qnx.com]
Sent: Wednesday, September 24, 2008 6:30 AM
To: technology-networking
Subject: RE: broadcast using 255.255.255.255 actually sends
192.168.0.255
You should not need the manual route setting if using SO_BINDTODEVICE
with MSG_DONTROUTE. It is an alternative to using these options. Take a
look at the tech-note Sean posted earlier in the thread which describes
how broadcasting works.
Dave
> -----Original Message-----
> From: Tim Gessner [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 23, 2008 6:34 PM
> To: technology-networking
> Subject: RE: broadcast using 255.255.255.255 actually sends
192.168.0.255
>
> Sure, ifconfig below... Problem solved. I added a route for
> 255.255.255.255 to 192.168.75.80 I also used SO_BINDTODEVICE and
> MSG_DONTROUTE and it seems to work. If I understand correctly, QNX
> following some linux distros don't handle 255.255.255.255 correctly,
> instead they treat change it to the subnet broadcast of the first
> interface which supports broadcast. To get around this, a route needs
> to be added and the stack told to not route and use the ip address as
> bound in the sendto. Do I understand that correctly?
>
> #ifconfig
>
> lo0: flags=8009<UP, LOOPBACK, MULTICAST>
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> inet 127.0.0.1 netmask 0xff000000
>
> en0: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> address: 00:d0:c9:a9:44:59
> inet 192.168.0.29 netmask 0xffffff00 broadcast 192.168.0.255
>
> en1: flags=8843<UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
> capabilities=7<IP4CSUM,TCP4CSUM,UDP4CSUM>
> enabled=0<>
> address: 00:d0:c9:a9:44:5a
> inet 192.168.75.80 netmask 0xffffff00 broadcast 192.168.75.255
>
>
> -----Original Message-----
> From: Robert Craig [mailto:community-noreply@qnx.com]
> Sent: Tuesday, September 23, 2008 3:11 PM
> To: technology-networking
> Subject: Re: broadcast using 255.255.255.255 actually sends
> 192.168.0.255
>
> Can you post the ouput from ifconfig so that we can see your overall
> network configuration?
>
> R.
>
> ----- Original Message -----
> From: Tim Gessner <community-noreply@qnx.com>
> To: technology-networking <post13909@community.qnx.com>
> Sent: Tue Sep 23 17:52:16 2008
> Subject: Re: broadcast using 255.255.255.255 actually sends
> 192.168.0.255
>
> If I ping 192.168.0.255 (en0 broadcast) I get responses for all
devices
> on that subnet.
>
> If I ping 192.168.75.255 (en1 broadcast) I don't get any responses
> except from en1 (there are more devices on that subnet).
>
> If I ping 255.255.255.255 I get no route to host.
>
> Please Help!
>
> Thanx
> Tim
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13909
>
>
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13910
>
>
> _______________________________________________
> Technology
> http://community.qnx.com/sf/go/post13911
_______________________________________________
Technology
http://community.qnx.com/sf/go/post13932
|
|
|
Yao Zhao(deleted)
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Yao Zhao(deleted)
09/24/2008 11:22 AM
post13949
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
You must understand how route works, then you will know how to do it.
you have 2 interfaces and 2 different subnets, if you don't bind src to an interface then just want to send dst=
0xffffffff, is this possible? It is possible but you have to add code to stack to let it bind a device because stack
doesn't know src addr so stack doesn't know which interface it should send out. if you send to subnet broadcast, it then
possible to know output interface.
based on this you can
1.so add a route(0xffffffff) is an option to let stack know which interface it should go if you don't bind.
2.bind src
3.bind to interface
4.specify pktinfo...
5.modify stack to let it go anywhere you want
|
|
|
Yao Zhao(deleted)
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Yao Zhao(deleted)
09/24/2008 2:27 PM
post13963
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
I copied some code from dhcp and it works for QNX.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <net/if.h>
int main(void) {
struct sockaddr_in name;
int sock;
int flag;
struct ifreq ifr;
char buf[80] = " broadcast layer2 + layer3 testing\n";
short rport=3000, lport= 3000;
struct sockaddr_in to;
int result;
memset (&name, 0, sizeof (name));
name.sin_family = AF_INET;
name.sin_port = htons(lport);
name.sin_addr.s_addr = INADDR_ANY;
if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
perror("can't create socket:");
if ( setsockopt (sock, SOL_SOCKET, SO_BROADCAST,
(char *)&flag, sizeof flag) < 0)
perror ("Can't set SO_BROADCAST option on socket: ");
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, "en0", sizeof("en0"));
if ( setsockopt (sock, SOL_SOCKET, SO_BINDTODEVICE,
(char *)&ifr, sizeof ifr) < 0)
perror ("setsockopt: SO_BINDTODEVICE: ");
memset (&to, 0, sizeof (to));
to.sin_family = AF_INET;
to.sin_port = htons(rport);
to.sin_addr.s_addr = INADDR_BROADCAST;
while(1) {
result = sendto (sock, buf, strlen(buf), 0,
(struct sockaddr *)&to, sizeof to);
if (result < 0)
printf("send to result:%d errno:%d\n", result, errno);
sleep(2);
}
}
|
|
|
Zavvio Mok(deleted)
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
|
Zavvio Mok(deleted)
09/24/2021 4:10 PM
post121600
|
Re: RE: broadcast using 255.255.255.255 actually sends 192.168.0.255
Thank you for the post.
Using SO_BINDTODEVICE option to bind socket to network interface is proved to be necessary to bypass QNX's broadcast
limitation.
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, "en0", sizeof("en0"));
setsockopt (sock, SOL_SOCKET, SO_BINDTODEVICE, (char *)&ifr, sizeof ifr)
Also had to explicitly add a route for 255.255.255.255 to QNX's current IP address, and thus its current network interface's up-link, e.g. "route add 255.255.255.255 <current IP address>".
# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33192
inet 127.0.0.1 netmask 0xff000000
fec0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
address: 00:10:ea:92:79:d7
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 192.168.250.100 netmask 0xffffff00 broadcast 192.168.250.255
# route show
Routing tables
Internet:
Destination Gateway Flags
localhost.localdom 127.0.0.1 UH
192.168.250.0/24 link#2 U
192.168.250.100 00:10:ea:92:79:d7 UHL
255.255.255.255 192.168.250.100 UGH
|
|
|
|