Simple-peer: ip family is always IPv4

Created on 20 Jan 2019  路  3Comments  路  Source: feross/simple-peer

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

bug

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?

const family = ip.indexOf(':') === -1 ? 'IPv4' : 'IPv6'

All 3 comments

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'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sahil-devzila picture sahil-devzila  路  3Comments

contra picture contra  路  6Comments

onel picture onel  路  5Comments

Applicafroguy picture Applicafroguy  路  3Comments

mmorainville picture mmorainville  路  4Comments