Skip to content

Handling IPv6 #162

@fedd

Description

@fedd

Despite me trying to get rid of IPv6 in my systems where possible, Linphone sometimes decides to register with an IPc6-looking IPv4 address (that looks like this: [::ffff:192.0.2.128]), which breaks my proxy.

I've hacked the parseUri function to look like below in case an IPv6 is encountered, but I suspect this is not enough, what do you think?

function parseUri(s) {
if(typeof s === 'object')
return s;

  //var re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?([\w\-\.]+)(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
  let re = /^(sips?):(?:([^\s>:@]+)(?::([^\s@>]+))?@)?(([\w\-\.]+)|(\[[0-9A-Fa-f:\.]+\]))(?::(\d+))?((?:;[^\s=\?>;]+(?:=[^\s?\;]+)?)*)(?:\?(([^\s&=>]+=[^\s&=>]+)(&[^\s&=>]+=[^\s&=>]+)*))?$/;
  var r = re.exec(s);

  if(r) {
    return {
      schema: r[1],
      user: r[2],
      password: r[3],
      host: r[6]?r[6]:r[4],  <== this is just a remainder of experimentations, the 4th bracket should contain the address
      port: +r[7],
      params: (r[8].match(/([^;=]+)(=([^;=]+))?/g) || [])
        .map(function(s) { return s.split('='); })
        .reduce(function(params, x) { params[x[0]]=x[1] || null; return params;}, {}),
      headers: ((r[9] || '').match(/[^&=]+=[^&=]+/g) || [])
        .map(function(s){ return s.split('=') })
        .reduce(function(params, x) { params[x[0]]=x[1]; return params; }, {})
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions