CSE312 — Web Development
{"candidate":"candidate:2382557538 1 udp 2122260223 192.168.1.19 54090 typ host generation 0 ufrag FGP/ network-id 1 network-cost 10","sdpMid":"0","sdpMLineIndex":0}| Bytes | Field |
|---|---|
| 2 | Message type: 0x0001 Binding Request, 0x0101 Binding Success Response |
| 2 | Message length: the number of bytes after the 20-byte header |
| 4 | Magic cookie: always 0x2112A442 |
| 12 | Transaction ID: random, chosen by the client, copied into the response |
0x0020)| Bytes | Field |
|---|---|
| 1 | 0x00 |
| 1 | Family: 0x01 for IPv4, 0x02 for IPv6 |
| 2 | X-Port: the port XOR 0x2112 (the first 2 bytes of the magic cookie) |
| 4 | X-Address: the IPv4 address XOR 0x2112A442 |
23.34.59.30, port 56705670 XOR 0x2112 = 0x1626 XOR 0x2112 = 0x37340x17223B1E XOR 0x2112A442 = 0x36309F5C01 01 00 0C 21 12 A4 42 <the request's 12-byte transaction ID> Header
00 20 00 08 00 01 37 34 36 30 9F 5C XOR-MAPPED-ADDRESS0x000C = 12: the attribute's 4-byte type and length, plus its 8-byte valueconn, err := net.ListenPacket("udp", ":3478")
// handle err
buffer := make([]byte, 1500)
for {
n, addr, err := conn.ReadFrom(buffer)
// addr is the IP and port this packet came from: the answer to "What's my IP?"
// Verify buffer[:n] is a Binding Request, then build the response
conn.WriteTo(response, addr)
}0x0001, the cookie is 0x2112A442, and the length matches the bytes you read"3478:3478/udp"
typ srflx candidates in the ice_candidate messages passing through your signaling serverchrome://webrtc-internals shows every candidate the browser gathered| Type | Address |
|---|---|
host |
The device's own address on its local network |
srflx |
Server reflexive: the public address a STUN server reported |
relay |
An address on a TURN server that relays the traffic |
ice-ufrag and ice-pwd from the offer and answerhost candidate contains your local IP address