Sumit Das
Sumit Das

Reputation: 1017

prefix length calculation for ipv6 addresses

I want to calculate the prefix length for Ipv4 and Ipv6 addresses . The subnet mask can be in the form of a string(1 , 32 ,97 etc) or in the dotted format(255.255.0.0) . I want to impose the following conditions. 1)For ipv4 , both the formats should be allowed . But when we cast from the string to an unsigned , the prefix length should not be more than 31 2)For ipv6 only the prefix length is allowed . It should not be more than 127

Although I can do the above calculations pretty easily by passing a sub routine , I have been asked to use boost defined classes and methods for the same .

Can anyone suggest the appropriate boost methods for the above . I've tried to do some searching , but unable to do so.

The paramaters can be the mask in the prefix length string format (16 , 97) or in the dotted format , and maybe the address(string) . The boost methods should be able to determine the prefix length as an unsigned based on the restrictions already mentioned.

Upvotes: 2

Views: 880

Answers (1)

MSalters
MSalters

Reputation: 179779

Useful boost parts are regex, to analyze what you got, and lexical_cast to turn a string into a number.

Upvotes: 0

Related Questions