Jump to content

convert Ipv4 and IpV6 to netmask


edotom

Recommended Posts

Then you'll probably have to make your own function to deal with it. Since the problem is simply finding the number of leading 1 bits I'd just go with a function to do both IPv4 and IPv6 that gives you exactly the result you need. Means you don't have to parse the address for real, simply count how many 1 bits you find until the first 0.

"Simply". Thing is that there are a few valid formats you'd have to account for: pieces not having all four hex digits, omitted zeroes with a ::, a trailing IPv4 address... Unless you can restrict the input.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.