zhhyu7 opened a new pull request, #17735:
URL: https://github.com/apache/nuttx/pull/17735

   ## Summary
   fix the issue where acquiring the lock gets stuck due to the sconn lock not 
being initialized.
   provides support for s|getsockopt(IPPROTO_IP|IPPROTO_IPV6) through the 
SOCK_CTRL socket.
   
   ## Impact
   
   *Update this section, where applicable, on how change affects users,
    build process, hardware, documentation, security, compatibility, etc.*
   
   ## Testing
   sim:matter with test code:
   ```
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <unistd.h>
   #include <errno.h>
   #include <sys/socket.h>
   #include <sys/types.h>
   #include <netinet/in.h>
   #include <arpa/inet.h>
   
   int main(void) {
       int sock_fd;
       int ret;
       int tos_value_to_set;
       int tos_value_read;
       socklen_t optlen;
   
       // 1. Create a CTRL socket (SOCK_CTRL)
       sock_fd = socket(AF_INET, SOCK_CTRL, 0);
       if (sock_fd < 0) {
           perror("socket() failed");
           return EXIT_FAILURE;
       }
       printf("CTRL socket created successfully. FD: %d\n", sock_fd);
   
       // 2. Define the IP_TOS value we want to set
       // IP_TOS is a byte (0-255). Common values:
       // Low Delay (0x10): 16 decimal - for interactive traffic
       // High Throughput (0x08): 8 decimal - for bulk data
       // High Reliability (0x04): 4 decimal
       // We'll set it to "Low Delay" (0x10 = 16 decimal)
       tos_value_to_set = 0x10; // Low Delay
       printf("Attempting to set IP_TOS to: 0x%02x (%d decimal)\n", 
              tos_value_to_set, tos_value_to_set);
   
       // 3. Set the IP_TOS socket option using setsockopt()
       ret = setsockopt(sock_fd,            // socket file descriptor
                        IPPROTO_IP,         // level: IP protocol level
                        IP_TOS,             // option name: Type of Service
                        &tos_value_to_set,  // pointer to the option value
                        sizeof(tos_value_to_set)); // size of the option value
   
       if (ret < 0) {
           perror("setsockopt(IP_TOS) failed");
           close(sock_fd);
           return EXIT_FAILURE;
       }
       printf("Successfully set IP_TOS option.\n");
   
       // 4. Prepare to read back the IP_TOS value
       tos_value_read = 0;
       optlen = sizeof(tos_value_read);
   
       // 5. Read the IP_TOS socket option using getsockopt()
       ret = getsockopt(sock_fd,    // socket file descriptor
                        IPPROTO_IP, // level: IP protocol level
                        IP_TOS,     // option name: Type of Service
                        &tos_value_read, // buffer to store the retrieved value
                        &optlen);   // size of the buffer (in/out parameter)
   
       if (ret < 0) {
           perror("getsockopt(IP_TOS) failed");
           close(sock_fd);
           return EXIT_FAILURE;
       }
   
       // Note: The kernel may modify/round the TOS value you set.
       // It typically only uses the 6 most significant bits (DSCP field).
       printf("Successfully read back IP_TOS option.\n");
       printf("Read value: 0x%02x (%d decimal)\n", 
              tos_value_read, tos_value_read);
   
       // 6. Clean up: close the socket
       close(sock_fd);
       printf("\nSocket closed. Program finished.\n");
   
       return EXIT_SUCCESS;
   }
   ```
   NuttX log:
   ```
   Starting program: /home/zhhyu/source/upstream/nuttx/nuttx 
   [Thread debugging using libthread_db enabled]
   Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
   
   NuttShell (NSH) NuttX-12.12.0-RC0
   MOTD: username=admin password=Administrator
   nsh> hello
   CTRL socket created successfully. FD: 3
   Attempting to set IP_TOS to: 0x10 (16 decimal)
   Successfully set IP_TOS option.
   Successfully read back IP_TOS option.
   Read value: 0x10 (16 decimal)
   
   Socket closed. Program finished.
   nsh>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to