comp.lang.ada
 help / color / mirror / Atom feed
* UDP Send gets NETWORK_IS_UNREACHABLE
@ 2018-07-03 10:43 Petter Fryklund
  2018-07-03 12:07 ` alby.gamper
  2018-07-03 12:16 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 19+ messages in thread
From: Petter Fryklund @ 2018-07-03 10:43 UTC (permalink / raw)


Hi all,

We have a need to send a broadcast message. In the test environment on Windows everything is fine. But in the productional environment on Linux we receive Socket Error NETWORK_IS_UNREACHABLE. I have searched the net a bit and it seems like we should use so_bindtodev, but that is not available on GNAT. Does anybody have some advice? 

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-03 10:43 UDP Send gets NETWORK_IS_UNREACHABLE Petter Fryklund
@ 2018-07-03 12:07 ` alby.gamper
  2018-07-04  9:53   ` Petter Fryklund
  2018-07-03 12:16 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 19+ messages in thread
From: alby.gamper @ 2018-07-03 12:07 UTC (permalink / raw)


On Tuesday, July 3, 2018 at 8:43:34 PM UTC+10, Petter Fryklund wrote:
> Hi all,
> 
> We have a need to send a broadcast message. In the test environment on Windows everything is fine. But in the productional environment on Linux we receive Socket Error NETWORK_IS_UNREACHABLE. I have searched the net a bit and it seems like we should use so_bindtodev, but that is not available on GNAT. Does anybody have some advice? 
> 
> Regards,
> Petter

Hi Petter

You may need to bind to a specific interface before doing broadcast/multicast
I recall on windows server with multiple NIC's it was required to bind to
the specific NIC that was expected to receive the broadcast/multicast.

I appreciate this may be the reverse of you situation, But maybe this helps

Alex

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-03 10:43 UDP Send gets NETWORK_IS_UNREACHABLE Petter Fryklund
  2018-07-03 12:07 ` alby.gamper
@ 2018-07-03 12:16 ` Dmitry A. Kazakov
  2018-07-04  9:50   ` Petter Fryklund
  1 sibling, 1 reply; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-03 12:16 UTC (permalink / raw)


On 2018-07-03 12:43, Petter Fryklund wrote:

> We have a need to send a broadcast message. In the test environment on Windows everything is fine. But in the productional environment on Linux we receive Socket Error NETWORK_IS_UNREACHABLE. I have searched the net a bit and it seems like we should use so_bindtodev, but that is not available on GNAT. Does anybody have some advice?

You do not need so_bindtodev, that is for sure.

You could do something like this:

    Create_Socket (Socket, Family_Inet, Socket_Datagram);
    Set_Socket_Option
    (  Socket,
       Socket_Level,
       (Reuse_Address, True)
    );
    Set_Socket_Option
    (  Socket,
       Socket_Level,
       (Broadcast, True)
    );
    Set_Socket_Option
    (  Socket,
       Socket_Level,
       (Receive_Timeout, <some reasonable value if responses expected>)
    );
    Address.Addr := Addresses (Get_Host_By_Name (<my host name>), 1);
    Address.Port := <port>;
    Bind_Socket (Socket, Address);
    Address.Addr := Broadcast_Inet_Addr;
    Address.Port := <port>;
    Send_Socket (Socket, <announce>, Last, Address'Access);
    loop -- Gathering responses
       begin
          Receive_Socket (Socket, <response>, Last, <who is there>);
       exception
         when Socket_Error =>
            null;
       end;
    end loop;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-03 12:16 ` Dmitry A. Kazakov
@ 2018-07-04  9:50   ` Petter Fryklund
  2018-07-04 10:23     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-04  9:50 UTC (permalink / raw)


Thanks for answering, Dmitry.

The wording isn't exactly like yours (we use GNAT Sockets), but it is similar to the code we use. It works fine in Windows, but not in Linux. The embedded Linux system has several network devices, that is why I think we need so_bindtodev.

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-03 12:07 ` alby.gamper
@ 2018-07-04  9:53   ` Petter Fryklund
  0 siblings, 0 replies; 19+ messages in thread
From: Petter Fryklund @ 2018-07-04  9:53 UTC (permalink / raw)


Thanks for answering. I think you are right and I think that it might have been accomplished with so_bindtodev if it had been available. 

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04  9:50   ` Petter Fryklund
@ 2018-07-04 10:23     ` Dmitry A. Kazakov
  2018-07-04 11:11       ` Petter Fryklund
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-04 10:23 UTC (permalink / raw)


On 2018-07-04 11:50, Petter Fryklund wrote:

> The wording isn't exactly like yours (we use GNAT Sockets), but it is similar to the code we use. It works fine in Windows, but not in Linux. The embedded Linux system has several network devices, that is why I think we need so_bindtodev.

It is GNAT.Sockets and it works under Linux, AFAIK.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 10:23     ` Dmitry A. Kazakov
@ 2018-07-04 11:11       ` Petter Fryklund
  2018-07-04 13:07         ` Petter Fryklund
  2018-07-04 13:31         ` Dmitry A. Kazakov
  0 siblings, 2 replies; 19+ messages in thread
From: Petter Fryklund @ 2018-07-04 11:11 UTC (permalink / raw)


GNAT works fine on Linux except for broadcast with many network interfaces.

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 11:11       ` Petter Fryklund
@ 2018-07-04 13:07         ` Petter Fryklund
  2018-07-04 13:42           ` Dmitry A. Kazakov
  2018-07-04 13:31         ` Dmitry A. Kazakov
  1 sibling, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-04 13:07 UTC (permalink / raw)


Maybe GNAT.Sockets.Thin can be used to set SO_BINDTODEVICE, but I cannot find a copy of sys/sockets.h that includes the numerical value for SO_BINDTODEV. Also, I've come across both SO_BINDTODEV and SO_BINDTODEVICE. Which is more commonly used?

Regards,
Petter 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 11:11       ` Petter Fryklund
  2018-07-04 13:07         ` Petter Fryklund
@ 2018-07-04 13:31         ` Dmitry A. Kazakov
  1 sibling, 0 replies; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-04 13:31 UTC (permalink / raw)


On 2018-07-04 13:11, Petter Fryklund wrote:
> GNAT works fine on Linux except for broadcast with many network interfaces.

You should bind the socket to the host's network address corresponding 
to the interface where you want to broadcast instead of

    Addresses (Get_Host_By_Name (<my host name>), 1)

which is the first interface found. You might have the interface of 
interest second or third in the Addresses list.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 13:07         ` Petter Fryklund
@ 2018-07-04 13:42           ` Dmitry A. Kazakov
  2018-07-06  5:31             ` Petter Fryklund
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-04 13:42 UTC (permalink / raw)


On 2018-07-04 15:07, Petter Fryklund wrote:

> Maybe GNAT.Sockets.Thin can be used to set SO_BINDTODEVICE, but I cannot find a copy of sys/sockets.h that includes the numerical value for SO_BINDTODEV. Also, I've come across both SO_BINDTODEV and SO_BINDTODEVICE. Which is more commonly used?

When I had to use Linux raw sockets I too used GNAT.Thin and defined 
missing constants like IPPROTO_RAW. It worked OK.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 13:42           ` Dmitry A. Kazakov
@ 2018-07-06  5:31             ` Petter Fryklund
  2018-07-06  7:23               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-06  5:31 UTC (permalink / raw)


This is getting weirder. Get_Host_By_Name returns two addresses, 127.0.0.1 and 127.0.0.1. The broadcasts are going to a very narrow network ;-) 

I'm going to try to set the interface with Thin.Set_Socket_Option but I cannot find the numerical value for SO_BINDTODEV sometimes called SO_BINDTODEVICE.

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  5:31             ` Petter Fryklund
@ 2018-07-06  7:23               ` Dmitry A. Kazakov
  2018-07-06  8:10                 ` Petter Fryklund
                                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-06  7:23 UTC (permalink / raw)


On 2018-07-06 07:31, Petter Fryklund wrote:
> This is getting weirder. Get_Host_By_Name returns two addresses, 127.0.0.1 and 127.0.0.1. The broadcasts are going to a very narrow network ;-)

You have the network setting broken. I believe I had such a problem with 
a Linux box and resolved it. I forgot what was it.

But you can always set the address manually instead of Get_Host_By_Name, 
e.g. Inet_Addr ("192.168.2.100") etc.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  7:23               ` Dmitry A. Kazakov
@ 2018-07-06  8:10                 ` Petter Fryklund
  2018-07-08 15:28                   ` Simon Wright
  2018-07-06  8:12                 ` Petter Fryklund
  2018-07-06  8:24                 ` Petter Fryklund
  2 siblings, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-06  8:10 UTC (permalink / raw)


Den fredag 6 juli 2018 kl. 09:23:47 UTC+2 skrev Dmitry A. Kazakov:
> On 2018-07-06 07:31, Petter Fryklund wrote:
> > This is getting weirder. Get_Host_By_Name returns two addresses, 127.0.0.1 and 127.0.0.1. The broadcasts are going to a very narrow network ;-)
> 
> You have the network setting broken. I believe I had such a problem with 
> a Linux box and resolved it. I forgot what was it.
> 
> But you can always set the address manually instead of Get_Host_By_Name, 
> e.g. Inet_Addr ("192.168.2.100") etc.

This is similar to what we did from the beginning, 192.168.255.255, getting NETWORK_IS_UNREACHABLE (or in fact still do).
 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Regards,
Petter

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  7:23               ` Dmitry A. Kazakov
  2018-07-06  8:10                 ` Petter Fryklund
@ 2018-07-06  8:12                 ` Petter Fryklund
  2018-07-06  8:28                   ` Dmitry A. Kazakov
  2018-07-06  8:24                 ` Petter Fryklund
  2 siblings, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-06  8:12 UTC (permalink / raw)


Den fredag 6 juli 2018 kl. 09:23:47 UTC+2 skrev Dmitry A. Kazakov:
> On 2018-07-06 07:31, Petter Fryklund wrote:
> > This is getting weirder. Get_Host_By_Name returns two addresses, 127.0.0.1 and 127.0.0.1. The broadcasts are going to a very narrow network ;-)
> 
> You have the network setting broken. I believe I had such a problem with 
> a Linux box and resolved it. I forgot what was it.
> 
> But you can always set the address manually instead of Get_Host_By_Name, 
> e.g. Inet_Addr ("192.168.2.100") etc.

This is related to what we do, setting the broadcast address to 192.168.255.255, which results in NETWORK_IS_UNREACHABLE.

> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Regards,
Petter


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  7:23               ` Dmitry A. Kazakov
  2018-07-06  8:10                 ` Petter Fryklund
  2018-07-06  8:12                 ` Petter Fryklund
@ 2018-07-06  8:24                 ` Petter Fryklund
  2 siblings, 0 replies; 19+ messages in thread
From: Petter Fryklund @ 2018-07-06  8:24 UTC (permalink / raw)


Now I've studied the case a little more and I've found out that in our unit that interfaces with GNAT.Sockets we also uses Get_Host_By_Name. That maybe explains the problem. It's hard to choose interface if both are localhost. We will have to solve this differently somewhere in the 5 deep call-chain. 

Thanks for all the help Dmitry.

Regards,
Petter

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  8:12                 ` Petter Fryklund
@ 2018-07-06  8:28                   ` Dmitry A. Kazakov
  2018-07-06  8:48                     ` Petter Fryklund
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-06  8:28 UTC (permalink / raw)


On 2018-07-06 10:12, Petter Fryklund wrote:
> Den fredag 6 juli 2018 kl. 09:23:47 UTC+2 skrev Dmitry A. Kazakov:
>> On 2018-07-06 07:31, Petter Fryklund wrote:
>>> This is getting weirder. Get_Host_By_Name returns two addresses, 127.0.0.1 and 127.0.0.1. The broadcasts are going to a very narrow network ;-)
>>
>> You have the network setting broken. I believe I had such a problem with
>> a Linux box and resolved it. I forgot what was it.
>>
>> But you can always set the address manually instead of Get_Host_By_Name,
>> e.g. Inet_Addr ("192.168.2.100") etc.
> 
> This is related to what we do, setting the broadcast address to 192.168.255.255, which results in NETWORK_IS_UNREACHABLE.

Do you try to bind the socket to a broadcast address? That won't go. You 
bind it to the host's address in the network you want to broadcast to. 
E.g. in the network 192.168.1.0 your machine has the address 
192.168.1.100. You bind socket to this address. Then you can broadcast 
to the broadcast address of the network 192.168.1.255.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  8:28                   ` Dmitry A. Kazakov
@ 2018-07-06  8:48                     ` Petter Fryklund
  2018-07-06 18:46                       ` Simon Clubley
  0 siblings, 1 reply; 19+ messages in thread
From: Petter Fryklund @ 2018-07-06  8:48 UTC (permalink / raw)


Sorry, I got all mixed up. The socket that will send is created by getting it's IP from Get_Host_By_Name index 1. In this case 127.0.0.1:33333. Then when we try to broadcast to 192.168.255.255 we get the NETWORK_IS_UNREACHABLE, maybe because Linux doesn't know which interface to use. So we need to supply the correct IP, 192.168.0.20 somewhere in our class hierarchy, some 5 levels deep.

Regards,
Petter

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  8:48                     ` Petter Fryklund
@ 2018-07-06 18:46                       ` Simon Clubley
  0 siblings, 0 replies; 19+ messages in thread
From: Simon Clubley @ 2018-07-06 18:46 UTC (permalink / raw)


On 2018-07-06, Petter Fryklund <petter.fryklund@atero.se> wrote:
> Sorry, I got all mixed up. The socket that will send is created by
> getting it's IP from Get_Host_By_Name index 1. In this case
> 127.0.0.1:33333. Then when we try to broadcast to 192.168.255.255 we get
> the NETWORK_IS_UNREACHABLE, maybe because Linux doesn't know which
> interface to use. So we need to supply the correct IP, 192.168.0.20
> somewhere in our class hierarchy, some 5 levels deep.
>

Are you sure that 192.168.255.255 is correct ?

192.168.x.y is by default a class C network (or maybe even smaller
if CIDR is active), not a class B. As such, I wonder if 192.168.0.255
is the correct broadcast address, given the IP address you give above ?

It may be possible to turn 192.168.x.y into a class B, but I have never
seen it done.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-06  8:10                 ` Petter Fryklund
@ 2018-07-08 15:28                   ` Simon Wright
  0 siblings, 0 replies; 19+ messages in thread
From: Simon Wright @ 2018-07-08 15:28 UTC (permalink / raw)


Petter Fryklund <petter.fryklund@atero.se> writes:

> This is similar to what we did from the beginning, 192.168.255.255,
> getting NETWORK_IS_UNREACHABLE (or in fact still do).

It'd be very unusual (legal, of course) to have a 192.168.255/24
network.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-07-08 15:28 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 10:43 UDP Send gets NETWORK_IS_UNREACHABLE Petter Fryklund
2018-07-03 12:07 ` alby.gamper
2018-07-04  9:53   ` Petter Fryklund
2018-07-03 12:16 ` Dmitry A. Kazakov
2018-07-04  9:50   ` Petter Fryklund
2018-07-04 10:23     ` Dmitry A. Kazakov
2018-07-04 11:11       ` Petter Fryklund
2018-07-04 13:07         ` Petter Fryklund
2018-07-04 13:42           ` Dmitry A. Kazakov
2018-07-06  5:31             ` Petter Fryklund
2018-07-06  7:23               ` Dmitry A. Kazakov
2018-07-06  8:10                 ` Petter Fryklund
2018-07-08 15:28                   ` Simon Wright
2018-07-06  8:12                 ` Petter Fryklund
2018-07-06  8:28                   ` Dmitry A. Kazakov
2018-07-06  8:48                     ` Petter Fryklund
2018-07-06 18:46                       ` Simon Clubley
2018-07-06  8:24                 ` Petter Fryklund
2018-07-04 13:31         ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox