i was a bit surprised today when i saw that i got connected to one WebRTC peer with a IPv6 in the browser.
You hardcode the family to IPv4
https://github.com/feross/simple-peer/blob/605960271fb80b596ef3a94bfd46e4b9629bde44/index.js#L183
https://github.com/feross/simple-peer/blob/605960271fb80b596ef3a94bfd46e4b9629bde44/index.js#L780
This line is from 2015 - well before IPv6 was standard. Definitely needs to be updated. 馃憤
Can't find anything about address families in the spec, is there any way to access this beyond counting the bit length?
Dose not look like there is something in the spec about ip families
looking around in the web i found this solution:
const ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/
const ipv6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i
const isV4Format = ip => ipv4Regex.test(ip)
const isV6Format = ip => ipv6Regex.test(ip)
We know the string is an IP, so tests for arbitrary strings seems like overkill.
Maybe the fact that IPV6 always uses colon separators while IPV4 never does is enough?
const family = ip.indexOf(':') === -1 ? 'IPv4' : 'IPv6'
Most helpful comment
We know the string is an IP, so tests for arbitrary strings seems like overkill.
Maybe the fact that IPV6 always uses colon separators while IPV4 never does is enough?