From owner-freebsd-net@FreeBSD.ORG Thu Dec 11 04:59:56 2003 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0A34316A4CF for ; Thu, 11 Dec 2003 04:59:56 -0800 (PST) Received: from cell.sick.ru (cell.sick.ru [217.72.144.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id A497D43D1F for ; Thu, 11 Dec 2003 04:59:51 -0800 (PST) (envelope-from glebius@cell.sick.ru) Received: from cell.sick.ru (glebius@localhost [127.0.0.1]) by cell.sick.ru (8.12.9/8.12.8) with ESMTP id hBBCxnAB038878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 11 Dec 2003 15:59:49 +0300 (MSK) (envelope-from glebius@cell.sick.ru) Received: (from glebius@localhost) by cell.sick.ru (8.12.9/8.12.6/Submit) id hBBCxmkZ038877 for freebsd-net@freebsd.org; Thu, 11 Dec 2003 15:59:48 +0300 (MSK) Date: Thu, 11 Dec 2003 15:59:48 +0300 From: Gleb Smirnoff To: freebsd-net@freebsd.org Message-ID: <20031211125948.GN37784@cell.sick.ru> Mail-Followup-To: Gleb Smirnoff , freebsd-net@freebsd.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="yrj/dFKFPuw6o+aM" Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: incorrect connect() behavior X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Dec 2003 12:59:56 -0000 --yrj/dFKFPuw6o+aM Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Dear sirs, as it is described in connect(2): ERRORS The connect() call fails if: ... [ENETUNREACH] The network is not reachable from this host. [EHOSTUNREACH] The remote host is not reachable from this host. However, this sample program (attached) shows that connect() does not return -1 in case of absence of routing do destination.(One should run test program after "route delete default") Testing FreeBSD-STABLE showed that connect() will return 0, and following getsockname() on same sockaddr will return 127.0.0.1 as source address. What does this break? ntpd(8) will not work after temporary route flapping, or in case when ntpd(8) starts before time servers are reachable. Same problem with ports/net/net-snmp, it freezes after route flapping. In latter case I haven't looked into sources, but I suppose the problem is similar to ntpd's. Testing FreeBSD 5.1-RELEASE showed that connect() will return 0, and following getsockname() on same sockaddr will return same address, as would be returned in presence of default route. Haven't tested on multihomed 5.x boxes. -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE --yrj/dFKFPuw6o+aM Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="no-route-test.c" #include #include #include #include #define SOMEHOST "209.132.205.227" int main() { int s, rtn; struct sockaddr_in saddr; int saddrlen = sizeof(saddr); saddr.sin_family = AF_INET; saddr.sin_addr.s_addr = inet_addr(SOMEHOST); saddr.sin_port = htons(2000); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { printf("Error from socket()\n"); return -1; } rtn = connect(s, (struct sockaddr *)&saddr, sizeof(saddr)); if (rtn < 0) { printf("Error from connect(): %s\n", strerror(errno)); return -1; } rtn = getsockname(s, (struct sockaddr *)&saddr, &saddrlen); if (rtn < 0) { printf("Error from getsockname()\n"); return -1; } close(s); printf("Addr is %s\n", inet_ntoa(saddr.sin_addr)); } --yrj/dFKFPuw6o+aM--