Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2760
  • Last Modified:

How to find subnet mask

I'm trying to send a broadcast on a TCP/IP LAN. I'm going to use the subnet mask to build a broadcast address.
Is there a function in Win32 (or MFC) to find out the subnet mask? Or if not, how do I make a broadcast?
0
zingo
Asked:
zingo
  • 2
  • 2
1 Solution
 
connexCommented:
Well there is no direct function to get the subnetmask, but you can read it from the registry *yuck*.
Maybe it's easier simply to make a socket broadcasting .)
See the documentation of SetSocketOpt and/or
the Chatter Samples which use broadcasting.

connex


0
 
alexoCommented:
* Check the bindings in HKLM\Enum\Root\Net\xxxx\Bindings for a MSTCP binding
* The driver for the binding is found in HKLM\Enum\Network\MSTCP\yyyy
* The driver points to System\CurrentControlSet\Services\Class\nettrans\zzzz

0
 
zingoAuthor Commented:
The chatter example does not use broadcast, it just connects to a server. The server then forwards all messages to all connected clients.

I've looked at the SetSockOpt SO_BROADCAST thing, but one question remains then: What do I use as address when calling SendTo(...) (CAsyncSocket).
0
 
connexCommented:
Well the sample that I have here uses broadcasting to find a server.

Anyway, following is taken from the SendTo help:

To send a broadcast (on a SOCK_DGRAM only), the address in the lpSockAddr parameter should be constructed using the special IP address INADDR_BROADCAST (defined in the Windows Sockets header file WINSOCK.H) together with the intended port number. Or, if the lpszHostAddress parameter is NULL, the socket is configured for broadcast. It is generally inadvisable for a broadcast datagram to exceed the size at which fragmentation can occur, which implies that the data portion of the datagram (excluding headers) should not exceed 512 bytes.

What's unclear about that?


0
 
zingoAuthor Commented:
Nothing is unclear, anymore. I tried it and it works. The problem was that I didn't read all the way down in the help text. Real silly.

Thanks,

              Zingo
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now