1

Candidate attribute in a SDP provides connection address of the candidate. Which looks like this:

a=candidate:4022866446 1 udp 2113937151 192.168.0.197 36768 typ host

I want to know how does sdp collects information about my local ip.

It'd be great help if there's any specific webrtc code to look at. And, if it is possible to look at local IP, can sdp know my default gateway ?

Community
  • 1
  • 1
Anirban
  • 343
  • 3
  • 14

3 Answers3

2

WebRTC provides you some APIs. You can not see whats going on underneath. You call specific APIs and internally the SDK does its job which in this case gathering your ip information.

There are 3 types of candidates Host, Server Reflexive(public address) and relay address.

Host candidate is your interface address. The interface addresses are gathered through some system API calls and also a socket is created and bound for each interface to get the port.

As WebRTC internally uses ICE, STUN and TURN protocol, the server reflexive and relay candidate gathering has specific rule to follow.

To gather Server Reflexive candidate(NAT's public IP:Port) internally a STUN message is sent to STUN server and the response message contains mapped/XOR mapped address. This how your server reflexive address is gathered.

To gather Relay candidate a TURN allocate request is sent to TURN server and the response message contains relay address. TURN message response contains the server reflexive address also. So if you have TURN server then you don't need STUN server.

Edit:

I dont think there are WebRTC APIs that can help you with this.

You dont need WebRTC for finding out your default gateway. You can programmatically find that out by yourself. There are some system calls which will give your devices routing table entries. Or in some platform you need to read a specific configuration file to get those entries. You can parse these entries to find out the default gateway. See the following questions fie some examples.

How to get the WIFI gateway address on the iPhone?

Default Gateway in C on Linux

Community
  • 1
  • 1
Tahlil
  • 2,680
  • 6
  • 43
  • 84
  • Can gateway address be achieved from those API calls ? Though Alex said it's not possible but i was thinking if anyone has tried to find out how API calls results in interface addresses. – Anirban Sep 21 '15 at 18:19
  • I needed WebRTC as I was trying to find the default gateway from browser. WebRTC has been used to find out [public](http://ipcalf.com/) and [local](http://net.ipcalf.com/) IP from browser. The second link you provided (default gateway through C) seems promising though links specified in the accepted answer are dead. And, as you've suggested, I am thinking, if C can find out IP information and can be complied from browser using something like [asm.js](http://programmers.stackexchange.com/questions/197940/how-to-run-c-code-in-browser-using-asm-js) then WebRTC won't be needed. – Anirban Sep 22 '15 at 13:58
1

Whenever you create a PeerConnection object, it collects all the possible ice candidates( addresses through which the remote peer could reach you), you have to gather them using PeerConnection.onicecandiate event handler and pass them on the remote peer through signalling server.

Some of these candidates would reflect on the locally generated sdp, they are not mandatory part of the sdp, the main purpose of the sdp is to describe the mediasteam you are sharing.

mido
  • 24,198
  • 15
  • 92
  • 117
  • Okay. I wanted to know how candidate's IP is gathered. I have mentioned SDP as we only have SDP displaying it to us. How PeerConnection object learns about it ? I wanted to collect my IP information through browser. So, it'd be good to know how browsers normally collect them. Which IP information onicecandidate event handler can provide us ? – Anirban Sep 21 '15 at 05:46
  • 1
    @Anirban like Alex said, the candidates are collected through browser, you have no control over that, you can just gather it using `onicecandidate` event, you can easily find free stun servers, just add it to the configuration when creating new PeerConnection, then some of the ice candidates gathered would be of type **srflx**, these are got from STUN, which basically is sort of your external ip – mido Sep 21 '15 at 08:47
0

It s called "ice gathering" and it s done internally in the browsers.

The browser does NOT know about your gateway, but if you use a STUN server, it will know your public IP.

Dr. Alex Gouaillard
  • 2,078
  • 14
  • 13
  • Also, it can infer your likely Gateway addresses, as 99% of networks put the gateways at x.x.x.1 or a few other "likely" and well-known addresses. In addition, it's possible (without WebRTC) to infer what addresses are in-use on your network, though that doesn't tell you if it's the Gateway or not (though per above, that can be guessed, and you can use certain types of IMG/etc requests to check that guess, at least in home networks) – jesup Sep 21 '15 at 16:24
  • We shouldn't guess an interface information. Can you describe the requests please? It'd be good to confirm that guess. – Anirban Sep 21 '15 at 18:23