Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
The noticing will continue
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Arbitrary CONST values Unseen Machine 31 2,879 10-29-2025, 05:44 AM
Last Post: bplus
  QB64PE programming challenge? auto-convert image to photoreal etch-a-sketch drawing madscijr 9 1,864 02-14-2025, 05:49 PM
Last Post: madscijr
  suggestion: initialize array values within the DIM statement bobalooie 19 3,355 12-22-2022, 06:46 PM
Last Post: Kernelpanic
  String math: Whole # powers easy, decimal powers!!! Pete 0 507 09-12-2022, 08:58 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)