[Vm-dev] [commit][3500] Fix for Mantis 7837 - Socket connect on a UDP socket does not do the connect ()

commits at squeakvm.org commits at squeakvm.org
Sun Nov 15 23:52:04 UTC 2015


Revision: 3500
Author:   lewis
Date:     2015-11-15 15:52:01 -0800 (Sun, 15 Nov 2015)
Log Message:
-----------
Fix for Mantis 7837 - Socket connect on a UDP socket does not do the connect()
call on Unix VM. This prevents query of a connected UDP socket to find an
address that an external system may use to connect to the local system.

Verify fix by evaluating the following to find a local IPV4 address:

| s local |
s := Socket newUDP setPeer: (NetNameResolver addressForName: '8.8.8.8') port: 0.l.
local := s localAddress.
s close.
local "==> #[172 16 0 10]" 

Modified Paths:
--------------
    trunk/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c

Modified: trunk/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c
===================================================================
--- trunk/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c	2015-11-15 17:33:07 UTC (rev 3499)
+++ trunk/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c	2015-11-15 23:52:01 UTC (rev 3500)
@@ -695,9 +695,12 @@
       /* --- UDP --- */
       if (SOCKET(s) >= 0)
 	{
+	  int result;
 	  memcpy((void *)&SOCKETPEER(s), (void *)&saddr, sizeof(saddr));
 	  SOCKETPEERSIZE(s)= sizeof(struct sockaddr_in);
-	  SOCKETSTATE(s)= Connected;
+	  result= connect(SOCKET(s), (struct sockaddr *)&saddr, sizeof(saddr));
+	  if (result == 0)
+	    SOCKETSTATE(s)= Connected;
 	}
     }
   else
@@ -1978,9 +1981,12 @@
     {
       if (SOCKET(s) >= 0)
 	{
+	  int result;
 	  memcpy((void *)&SOCKETPEER(s), socketAddress(addr), addressSize(addr));
 	  SOCKETPEERSIZE(s)= addressSize(addr);
-	  SOCKETSTATE(s)= Connected;
+	  result= connect(SOCKET(s), socketAddress(addr), addressSize(addr));
+	  if (result == 0)
+	    SOCKETSTATE(s)= Connected;
 	}
     }
   else					/* --- TCP --- */



More information about the Vm-dev mailing list