This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 40c9f52f763b8a30a20efc335f50ef168284794e
Author: Yongrong Wang <[email protected]>
AuthorDate: Fri Nov 13 17:02:02 2026 +0800

    examples/vsock: accept a cid given as a name
    
    A NuttX vsock cid set from a cpu name holds the first four bytes of
    the name. Let "-c" take either a number or such a name, e.g.
    "-c prox".
    
    Signed-off-by: Yongrong Wang <[email protected]>
---
 examples/vsock/vsock_main.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/examples/vsock/vsock_main.c b/examples/vsock/vsock_main.c
index ff0b14963..01536f4fd 100644
--- a/examples/vsock/vsock_main.c
+++ b/examples/vsock/vsock_main.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <unistd.h>
 
@@ -114,7 +115,7 @@ static int safe_recv(int s, char *buf, size_t len, int 
flags)
  ****************************************************************************/
 
 static int vsock_client(unsigned int port, size_t size,
-                        size_t count, int cid)
+                        size_t count, unsigned int cid)
 {
   struct sockaddr_vm addr;
   size_t sendlen = 0;
@@ -194,7 +195,7 @@ out:
   return ret;
 }
 
-static int vsock_server(unsigned int port, size_t size, int cid)
+static int vsock_server(unsigned int port, size_t size, unsigned int cid)
 {
   struct sockaddr_vm peer_addr;
   struct sockaddr_vm addr;
@@ -426,9 +427,10 @@ static int vsock_server_conn(unsigned int port, int cid)
 
 int main(int argc, char *argv[])
 {
-  int cid = VMADDR_CID_ANY;
+  unsigned int cid = VMADDR_CID_ANY;
   unsigned int port = 9999;
-  const char *type = NULL;
+  FAR const char *type = NULL;
+  FAR char *endptr;
   size_t count = 100;
   size_t size = 64;
   int is_server = 1;
@@ -459,7 +461,13 @@ int main(int argc, char *argv[])
         {
           case 'c':
             is_server = 0;
-            cid = strtoul(optarg, NULL, 0);
+            cid = strtoul(optarg, &endptr, 0);
+            if (errno != 0 || *endptr != '\0')
+              {
+                cid = 0;
+                strncpy((FAR char *)&cid, optarg,
+                        MIN(sizeof(cid), strlen(optarg)));
+              }
             break;
 
           case 't':

Reply via email to