Skip to contentSkip to conversation

linux-user: correct setsockopt() SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

PATCH In review Laurent Vivier 2 participants 4 messages Dec 31, 2012 – Jan 19, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: correct setsockopt() SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

From: Laurent Vivier <[email protected]>

---
 linux-user/syscall.c |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
linux-user/syscall.c +19 -7
index e99adab..1530c8f 100644
@@ -1491,6 +1491,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
+        case TARGET_SO_RCVTIMEO: {
+                struct timeval tv;
+
+		optname = SO_RCVTIMEO;
+
+set_timeout:
+                if (optlen != sizeof(struct target_timeval))
+                    return -TARGET_EINVAL;
+
+                if (copy_from_user_timeval(&tv, optval_addr))
+                    return -TARGET_EFAULT;
+
+		ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                                &tv, sizeof(tv)));
+		return ret;
+        }
+        case TARGET_SO_SNDTIMEO:
+		optname = SO_SNDTIMEO;
+		goto set_timeout;
             /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
 		optname = SO_DEBUG;
@@ -1542,13 +1561,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         case TARGET_SO_RCVLOWAT:
 		optname = SO_RCVLOWAT;
 		break;
-        case TARGET_SO_RCVTIMEO:
-		optname = SO_RCVTIMEO;
-		break;
-        case TARGET_SO_SNDTIMEO:
-		optname = SO_SNDTIMEO;
-		break;
-            break;
         default:
             goto unimplemented;
         }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · Laurent Vivier

From: Laurent Vivier <[email protected]>

Looks about right (though the goto is a little ugly). You have some style issues you need to fix, though.

thanks
-- PMM

#2 lore raw

PATCH v2 1/1 linux-user: correct setsockopt()

In reply to Laurent Vivier

From: Laurent Vivier <[email protected]>

SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

To test this, you can use :

QEMU_STRACE= ping localhost 2>&1 |grep TIMEO 568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0 568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0

---
v2: pass checkpatch.pl

 linux-user/syscall.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
linux-user/syscall.c +22 -6
index e99adab..2b2bd2b 100644
@@ -1491,6 +1491,28 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
+        case TARGET_SO_RCVTIMEO:
+        {
+                struct timeval tv;
+
+                optname = SO_RCVTIMEO;
+
+set_timeout:
+                if (optlen != sizeof(struct target_timeval)) {
+                    return -TARGET_EINVAL;
+                }
+
+                if (copy_from_user_timeval(&tv, optval_addr)) {
+                    return -TARGET_EFAULT;
+                }
+
+                ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                                &tv, sizeof(tv)));
+                return ret;
+        }
+        case TARGET_SO_SNDTIMEO:
+                optname = SO_SNDTIMEO;
+                goto set_timeout;
             /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
 		optname = SO_DEBUG;
@@ -1542,12 +1564,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         case TARGET_SO_RCVLOWAT:
 		optname = SO_RCVLOWAT;
 		break;
-        case TARGET_SO_RCVTIMEO:
-		optname = SO_RCVTIMEO;
-		break;
-        case TARGET_SO_SNDTIMEO:
-		optname = SO_SNDTIMEO;
-		break;
             break;
         default:
             goto unimplemented;
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [Qemu-devel] [PATCH][v2] linux-user: correct setsockopt()

ping ?

Quoted 63 lines · Laurent Vivier

From: Laurent Vivier <[email protected]>

SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

To test this, you can use :

QEMU_STRACE= ping localhost 2>&1 |grep TIMEO 568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0 568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0

---
v2: pass checkpatch.pl

 linux-user/syscall.c |   28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
linux-user/syscall.c +22 -6
index e99adab..2b2bd2b 100644
@@ -1491,6 +1491,28 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         break;
     case TARGET_SOL_SOCKET:
         switch (optname) {
+        case TARGET_SO_RCVTIMEO:
+        {
+                struct timeval tv;
+
+                optname = SO_RCVTIMEO;
+
+set_timeout:
+                if (optlen != sizeof(struct target_timeval)) {
+                    return -TARGET_EINVAL;
+                }
+
+                if (copy_from_user_timeval(&tv, optval_addr)) {
+                    return -TARGET_EFAULT;
+                }
+
+                ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+                                &tv, sizeof(tv)));
+                return ret;
+        }
+        case TARGET_SO_SNDTIMEO:
+                optname = SO_SNDTIMEO;
+                goto set_timeout;
             /* Options with 'int' argument.  */
         case TARGET_SO_DEBUG:
 		optname = SO_DEBUG;
@@ -1542,12 +1564,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
         case TARGET_SO_RCVLOWAT:
 		optname = SO_RCVLOWAT;
 		break;
-        case TARGET_SO_RCVTIMEO:
-		optname = SO_RCVTIMEO;
-		break;
-        case TARGET_SO_SNDTIMEO:
-		optname = SO_SNDTIMEO;
-		break;
             break;
         default:
             goto unimplemented;
Signature · 4 lines
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan