Convert IPv4 dotted quad into four decimal values
#6
@bert22306 Hi! Here is some Win32 code you can use to convert a string IPv4 address to a 4 byte representation:

Code: (Select All)
Option Explicit
$NoPrefix
$Console:Only

Type in_addr
    As Unsigned Byte b1, b2, b3, b4
End Type

Declare Dynamic Library "ntdll"
    Sub RtlIpv4StringToAddress Alias "RtlIpv4StringToAddressA" (ByVal S As Offset, Byval Strict As Byte, Byval Terminator As Offset, Byval Addr As Offset)
End Declare

'Dim As Unsigned Byte ipv4(0 To 3)   'you can also just pass in the offset to this array and just iterate through it
Dim As in_addr ipv4
Dim As String Terminator

Dim As String ip: ip = "192.168.0.1" + Chr$(0)
RtlIpv4StringToAddress Offset(ip), 0, Offset(Terminator), Offset(ipv4)

'Dim As Unsigned Long i 'if you plan on iterating through the array
'For i = 0 to 3
'Print ipv4(i),
'Next

Print ipv4.b1, ipv4.b2, ipv4.b3, ipv4.b4
Ask me about Windows API and maybe some Linux stuff
Reply


Messages In This Thread
RE: Convert IPv4 dotted quad into four decimal values - by SpriggsySpriggs - 09-15-2022, 06:24 PM



Users browsing this thread: 3 Guest(s)