Convert IPv4 dotted quad into four decimal values
#1
A trivially easy way to enter an IPv4 address into qb64, and extract the four decimals values 0-255 which make up the address, is to use commas as delimiters for each byte of the address. I've done that, and my program (to convert an IP multicast address into its derived MAC group address, per RFC 1112) works fine that way.

What would be even better is to be able to enter the IP address in its conventional form, with . instead of , for delimiters. So for example, given the multicast address

239.255.128.1

I'm now entering it as

239,255,128,1

It's okay, super easy to parse, but not really nice.

So far, I have this. It inputs the dotted quad as a single string variable, then changes the dots into commas, so that hopefully the four decimal numbers can be easily parsed by qb64. Just trying to figure out an easy way to make the ASCII list of numbers and commas, which you see in the output, into four separate decimal numbers. I'm not proficient in all the niceties of how numbers and characters can be converted in qb64. Any super clever ideas out there? There usually are.

Code: (Select All)
Dim num(100), char$(100)
Input "Enter quad decimal IP multicast group ->", addr$
Print addr$
length = Len(addr$)
i = 0
Do
    i = i + 1
    num(i) = Asc(addr$, i)
    If num(i) = 46 Then num(i) = 44
    If i = length Then Exit Do
Loop
For i = 1 To length
    char$(i) = Chr$(num(i))
    Print num(i), char$(i)
Next i
Reply


Messages In This Thread
Convert IPv4 dotted quad into four decimal values - by bert22306 - 09-01-2022, 08:58 PM



Users browsing this thread: 2 Guest(s)