[erlang-questions] subnet masking with binary matching

Per Hedeland <>
Fri Jan 19 08:46:59 CET 2007


Just a side note,

>jm wrote:
>> Using binary matching to perform subnet masking with the following code, 
>> which should work with both IPv4 and IPv6 as far as I can tell,
>> 
>> mask_address(Addr, Maskbits) ->
>>    B = list_to_binary(tuple_to_list(Addr)),

It will actually *not* work for IPv6, as each tuple element there holds
two address octets. You'd typically get a badarg from list_to_binary/1,
but if you're really unlucky the thing could end up silently doing
something completely wrong.

--Per Hedeland



More information about the erlang-questions mailing list