On Sun, Feb 25, 2018 at 03:33:06PM -0500, Jan Schaumann wrote: > Hi, > > I just encountered something that befuddles me: > > On an AWS EC2 instance (ami-d0b520b8, FreeBSD 10.1-RELEASE), I noticed > that 'telnet www.google.com 80' first opens a UDP socket to google's > addresses on port 1, then closes it without sending any data before > opening the TCP socket. > > Sample (trimmed) ktrace output: > > 1098 telnet RET socket 3 > 1098 telnet CALL connect(0x3,0xbfbfe8c8,0x1c) > 1098 telnet STRU struct sockaddr { AF_INET6, > [2607:f8b0:4004:807::2004]:1 } > 1098 telnet RET connect -1 errno 65 No route to host > 1098 telnet CALL close(0x3) > 1098 telnet RET close 0 > 1098 telnet CALL socket(PF_INET,SOCK_CLOEXEC|SOCK_DGRAM,IPPROTO_UDP) > 1098 telnet RET socket 3 > 1098 telnet CALL connect(0x3,0xbfbfe8c8,0x10) > 1098 telnet STRU struct sockaddr { AF_INET, 172.217.12.228:1 } > 1098 telnet RET connect 0 > 1098 telnet CALL getsockname(0x3,0x28c311dc,0xbfbfe8c4) > 1098 telnet STRU struct sockaddr { AF_INET, 10.234.105.225:22661 } > 1098 telnet RET getsockname 0 > 1098 telnet CALL close(0x3) > [...] > 1098 telnet GIO fd 1 wrote 25 bytes > "Trying 172.217.12.228... > " > 1098 telnet RET write 25/0x19 > 1098 telnet CALL socket(PF_INET,SOCK_STREAM,IPPROTO_TCP) > 1098 telnet RET socket 3 > [...] > 1098 telnet CALL connect(0x3,0x28c0f0f0,0x10) > 1098 telnet STRU struct sockaddr { AF_INET, 172.217.12.228:80 } > 1098 telnet RET connect 0 > > > I don't see this happening when the destination host in question has > either only an IPv6 record or only an IPv4 record. In those cases, > telnet will try to open the TCP socket to port 80. In the case of > dual-stack addresses, however, I see the above behaviour. > > (I also see the same behavior in e.g. nc(1), so this is not a telnet(1) > specific thing.) > > Anybody have any idea why this is done?
This is getaddrinfo(3) using fake connect(2) to get appropriate source address for the requested destination. They are used to order the result set when there is more that one element, which somewhat explains why do you need inet and inet6 addresses to see this. Note that created socket is not only to port 1 but also UDP. _______________________________________________ freebsd-net@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"