2

This is peculiar. Socket.io version ~1.3

io.sockets.on('connection', function (socket) {
    console.log('Client connected from: ' + socket.handshake.address);
}

Returns

Client connected from: ::1

However

io.sockets.on('connection', function (socket) {
    console.log(socket.handshake);
    console.log('Client connected from: ' + socket.handshake.address);
}

Returns

{ headers:
   { host: 'localhost:8000',
     connection: 'keep-alive',
     origin: 'http://localhost:3000',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTM
L, like Gecko) Chrome/43.0.2357.130 Safari/537.36',
     accept: '*/*',
     dnt: '1',
     referer: 'http://localhost:3000/dev.html',
     'accept-encoding': 'gzip, deflate, sdch',
     'accept-language': 'en-US;q=0.8,en;q=0.6,ko;q=0.4,de;q=0.2,ru;q=0.2,fr;q=0.2,ja;q=0.2,it;q=0.2',
     cookie: 'io=yhyuAabou3GufhzNAAAA' },
  time: 'Wed Jun 24 2015 22:50:19 GMT+0200 (Central European Daylight Time)',
  address: '::ffff:127.0.0.1',
  xdomain: true,
  secure: false,
  issued: 1435179019584,
  url: '/socket.io/?EIO=3&transport=polling&t=1435179017804-3',
  query: { EIO: '3', transport: 'polling', t: '1435179017804-3' } }
Client connected from: ::ffff:127.0.0.1

Why? Is there some ES6 proxy in the way? I thought maybe some weird JS conversion magic was in place, but it doesn't seem like it.

Misiur
  • 5,019
  • 8
  • 38
  • 54

1 Answers1

3

::ffff:127.0.0.1 is an IPv6 version of 127.0.0.1 and ::1 is an IPv6 shortcut for both.

See Express.js req.ip is returning ::ffff:127.0.0.1 for a similar question.

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Thank you. Could you point me as to where the conversion happens, and why it happens only when I dump the whole handshake object? I got as far as https://github.com/joyent/node/blob/master/lib/net.js#L595 , so maybe this is dependent from console.log implementation? – Misiur Jun 25 '15 at 10:49
  • I tracked it further down to https://github.com/joyent/node/blob/master/src/pipe_wrap.cc but my C++ and OS api/pipes knowledge is not enough. – Misiur Jun 25 '15 at 13:30