[PATCH] ws2_32: Add support to disable networking with envvar WINENONET=1

Bruno Jesus 00cpxxx at gmail.com
Wed Dec 7 00:27:25 CST 2016


I have used this in some situations to check how network enabled applications react to not having network access. IMO it is useful but if nobody cares I don't mind it being rejected.

Signed-off-by: Bruno Jesus <00cpxxx at gmail.com>
---
 dlls/ws2_32/socket.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index d863b3e..1b8635e 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -182,6 +182,8 @@
 WINE_DEFAULT_DEBUG_CHANNEL(winsock);
 WINE_DECLARE_DEBUG_CHANNEL(winediag);
 
+static int network_disabled;
+
 /* names of the protocols */
 static const WCHAR NameIpxW[]   = {'I', 'P', 'X', '\0'};
 static const WCHAR NameSpxW[]   = {'S', 'P', 'X', '\0'};
@@ -1186,6 +1188,9 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID fImpLoad)
     TRACE("%p 0x%x %p\n", hInstDLL, fdwReason, fImpLoad);
     switch (fdwReason) {
     case DLL_PROCESS_ATTACH:
+        network_disabled = GetEnvironmentVariableA("WINENONET", NULL, 0);
+        if (network_disabled)
+            WARN("Running without support to connect or send data\n");
         break;
     case DLL_PROCESS_DETACH:
         if (fImpLoad) break;
@@ -2433,6 +2438,12 @@ static int WS2_send( int fd, struct ws2_async *wsa, int flags )
     union generic_unix_sockaddr unix_addr;
     int n, ret;
 
+    if (network_disabled)
+    {
+        errno = EHOSTUNREACH;
+        return -1;
+    }
+
     hdr.msg_name = NULL;
     hdr.msg_namelen = 0;
 
@@ -3326,6 +3337,9 @@ static int do_connect(int fd, const struct WS_sockaddr* name, int namelen)
     if (!uaddrlen)
         return WSAEFAULT;
 
+    if (network_disabled)
+        return WSAEHOSTUNREACH;
+
     if (name->sa_family == WS_AF_INET)
     {
         struct sockaddr_in *in4 = (struct sockaddr_in*) &uaddr;
-- 
2.9.3




More information about the wine-patches mailing list