Make host resolver call __connect() rather than connect() so mark isn't cleared.

Calling connect() will erase the mark set by the host resolver code because the
explicitlySelected bit of the Fwmark isn't set.  It's by design that the
explicitlySelected bit isn't set as this facilitates falling through to other
routing rules if the selected network doesn't provide a route to the DNS server
as may be the case with VPNs.

Change-Id: I60ba7c754194ead97df3ac6a6c5b3db1f446dac8
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 8914fae..bea16d4 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -494,6 +494,16 @@
 void res_setmark(res_state, unsigned);
 u_int  res_randomid(void);
 
+#ifdef __i386__
+# define __socketcall extern __attribute__((__cdecl__))
+#else
+# define __socketcall extern
+#endif
+
+__socketcall int __connect(int, const struct sockaddr*, socklen_t);
+
+#undef __socketcall
+
 __END_DECLS
 
 #endif /* !_RESOLV_PRIVATE_H_ */
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index be692e3..32d946c 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -369,7 +369,7 @@
 		return 0;
 	int ret;
 	do {
-		ret = connect(s, addr, addrlen);
+		ret = __connect(s, addr, addrlen);
 	} while (ret < 0 && errno == EINTR);
 	int success = (ret == 0);
 	do {
@@ -1803,7 +1803,7 @@
 	if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
 		return 0;
 	do {
-		ret = connect(sock, addr, len);
+		ret = __connect(sock, addr, len);
 	} while (ret == -1 && errno == EINTR);
 
 	if (ret == -1) {
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
index 972e143..e64ccde 100644
--- a/libc/dns/resolv/res_send.c
+++ b/libc/dns/resolv/res_send.c
@@ -946,7 +946,7 @@
 	origflags = fcntl(sock, F_GETFL, 0);
 	fcntl(sock, F_SETFL, origflags | O_NONBLOCK);
 
-	res = connect(sock, nsap, salen);
+	res = __connect(sock, nsap, salen);
 	if (res < 0 && errno != EINPROGRESS) {
                 res = -1;
                 goto done;
@@ -1103,7 +1103,7 @@
 			res_nclose(statp);
 			return (0);
 		}
-		if (connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
+		if (__connect(EXT(statp).nssocks[ns], nsap, (socklen_t)nsaplen) < 0) {
 			Aerror(statp, stderr, "connect(dg)", errno, nsap,
 			    nsaplen);
 			res_nclose(statp);