DottedIP$ ( IP )

Parameters

IP - an IP address as a packed integer

Description

Converts a packed integer IP address into the dotted "a.b.c.d" text form.

Blitz3D+ networking commands trade IP addresses as single integers: the four parts of a.b.c.d packed one per byte, highest first, so 127.0.0.1 becomes (127 Shl 24) Or 1 = 2130706433. Efficient for the engine, unreadable for people - DottedIP is the translation back, ready for a lobby list, a "player joined from ..." message or a debug log.

Everything that hands you an address hands you one of these integers: HostIP after a name lookup, RecvUDPMsg and UDPMsgIP for UDP senders, TCPStreamIP for the far end of a TCP connection. They all feed straight into DottedIP.

There is no reverse command, and you rarely need one: the commands that accept text names (OpenTCPStream, CountHostIPs) happily take a dotted string like "192.168.1.42" directly, and CountHostIPs plus HostIP is the route from any text to the integer form.

See also: HostIP, CountHostIPs, UDPMsgIP, TCPStreamIP, RecvUDPMsg.

Example

; DottedIP Example
; ----------------

; Blitz3D+ handles IP addresses as packed integers: one byte per
; part, highest byte first. DottedIP formats them for humans.

; Build 192.168.1.42 by packing its four parts into one integer
ip=(192 Shl 24) Or (168 Shl 16) Or (1 Shl 8) Or 42
Print "Packed integer "+ip+" is "+DottedIP$(ip)

; The loopback address 127.0.0.1 packs down to 2130706433
loopback=(127 Shl 24) Or 1
Print "Packed integer "+loopback+" is "+DottedIP$(loopback)

; Every networking command that returns an address returns these
; integers - HostIP, RecvUDPMsg, UDPMsgIP, TCPStreamIP...
count=CountHostIPs("localhost")
If count>0 Then
    Print "HostIP for 'localhost' = "+HostIP(1)+"  ->  "+DottedIP$(HostIP(1))
EndIf

Print ""
Print "Press any key to close the example"
WaitKey

End

Index