Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with bind UDP socket in sample application compiled under Windows (with MinGw) #21

Open
owbeg opened this issue Mar 21, 2021 · 3 comments

Comments

@owbeg
Copy link

owbeg commented Mar 21, 2021

Sample application compiled successfully with MinGw-64 under Windows.
Now identified 2 issue when I tried to run sample application (in both cases raised error "OSError: [WinError 10049] The requested address is not valid in its context"):

  1. bind UDP socket for "global broadcast listener", file networkhandler.cc (at line about 680 - attempt to bind to address INADDR_BROADCAST, i.e. 255.255.255.255):
    if( bind( s_sockets.udp_global_broadcast_listener, address, SADDRZ ) )
  2. bind UDP socket for "local broadcast listener", file networkhandler.cc (at line about 710 - attempt to bind to address x.x.x.255, in my case it was 192.168.2.255):
    if( bind( s_sockets.udp_local_broadcast_listener, address, SADDRZ ) )

I don't know but maybe it is Windows specific issue.

I tried to change address to bind (but I am not sure that it is correct modification, at least sample application starts)

  1. for "global broadcast listener" address to bind from INET_BROADCAST to INET_ANY
  2. for "local broadcast listener" - removed "~c.network_mask" from expression, now address definition looks like
    SockAddr address( kEIP_Reserved_Port, ntohl( c.ip_address ) );
@liftoff-sr
Copy link
Owner

liftoff-sr commented Mar 22, 2021 via email

@owbeg
Copy link
Author

owbeg commented Mar 22, 2021

I tried to run application as administrator with same effect.

Here described similar problem with Python - bind to "<broadcast>" works under Linux but doesn';t work under Windows
https://python-list.python.narkive.com/bTCj6wTw/problems-using-magic-broadcast-socket-address-on-different-platforms

The most probably it is Windows specific issue

@liftoff-sr
Copy link
Owner

In your 18 year old link, I extract the following comment and then wonder if Windows would accept a broadcast address if it was correct. Perhaps the computed value is not correct for your network only. Maybe you are supplying an incorrect network subnet parameter to the CIPster library?

Hi,
The broadcast address is dependant upon the ip address and subnet mask.
255.255.255.255 is a generalization much like 0.0.0.0 for "default gateway".
If I remember correctly you can calculate it using
network addr xor (subnet mask xor 255.255.255.255)
example:
192.168.1.0 (network addr)
subnet mask 255.255.255.0 (standard class c)
yields
192.168.1.0 xor (255.255.255.0 xor 255.255.255.255)
yields
192.168.1.0 xor 0.0.0.255
yields
192.168.1.255 which is the proper broadcast address.

Regards,
Cecil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants