Home
Products
Community
Manuals
Contact
Login or Signup

Code archives/Networking/getSubnetMask() & getBroadcastAddress()

This code has been declared by its author to be Public Domain code.

Download source code

getSubnetMask() & getBroadcastAddress() by Jeremy Alessi(Posted 1+ years ago)
This combo adds getSubnetMask() to Blitz3D via a .dll and userlib that I wrote in Visual C++ and additionally adds a getBroadcastAddress() function written in Blitz which can be used to ping a LAN of any network class type.

I originally created this to "fix" BlitzPlay which is limited to a class-C network assumption and additionally doesn't even use the broadcast address for that assumption but instead pings 255 ip addresses. With this code multiplayer LAN searches can be conducted instantly on any network class.

Here's a link to the .dll/userlib
http://www.midnightstatus.com/codeArchives/ipHelper.zip

There's a onesComplement() function included as well which is used in the getBroadcastAddress() function.
Function getBroadcastAddress$( ip$ )

	subnetMask$ = getSubnetMask()

	bank = CreateBank( 4 )
	byte$ = ""
	j = 1
	For i = 0 To 3
		byte = ""
		While Mid( subnetMask$, j, 1 ) <> "." And j < Len( subnetMask$ )
			byte$ = byte$ + Mid( subnetMask$, j, 1 )
			j = j + 1
		Wend
		j = j + 1
		PokeByte( bank, i, byte$ )
	Next
	
	onesComplement( bank, 0, 4 )
		
	bank2 = CreateBank( 4 )
	byte$ = ""
	j = 1
	For i = 0 To 3
		byte$ = ""
		While Mid( ip$, j, 1 ) <> "." And j < Len( ip$ )
			byte$ = byte$ + Mid( ip$, j, 1 )
			j = j + 1
		Wend
		j = j + 1
		PokeByte( bank2, i, byte$ )
	Next
	
	bank3 = CreateBank( 4 )
	For i = 0 To 3
		PokeByte( bank3, i, ( PeekByte( bank, i ) Or PeekByte( bank2, i ) ) )
	Next
	
	broadcastAddress$ = ( PeekByte( bank3, 0 ) + "." + PeekByte( bank3, 1 ) + "." + PeekByte( bank3, 2) + "." + PeekByte( bank3, 3 ) )

	FreeBank( bank )
	FreeBank( bank2 )
	FreeBank( bank3 )
	
	Return broadcastAddress$


End Function

Comments

Ked(Posted 1+ years ago)
Do you have an example for this?


Ked(Posted 1+ years ago)
What do you put in the parameter for getBroadcastAddress(ip$) ?


Etica(Posted 1+ years ago)
Hey this possibly solves what harass me since 1 month!
I'll let you know.

Search my posts on the forum to see what I mean.


Code Archives Forum