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

   ## Summary
   Some third-party network libraries use PACKET_ADD_MEMBERSHIP to add MAC 
addresses to devices, and this patch can add support for this.
   
   ## Impact
   net/pkt: setsockopt
   
   ## Testing
   sim:matter with below test code:
   ```
   #include <nuttx/config.h>
   #include <net/if.h>
   #include <netinet/if_ether.h>
   #include <netpacket/packet.h>
   #include <string.h>
   #include <stdio.h>
   
   int main(int argc, FAR char *argv[])
   {
       int fd;
       int res;
       struct packet_mreq mreq;
       char macaddr[ETH_ALEN] = {0x91, 0xe0, 0xf0, 0x00, 0x0e, 0x01};
   
       fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
       if (fd < 0) {
           perror("Failed to open socket");
           return -1;
       }
       mreq.mr_ifindex = 1; // eth0
       mreq.mr_type = PACKET_MR_MULTICAST;
       mreq.mr_alen = ETH_ALEN;
       memcpy(&mreq.mr_address, macaddr, ETH_ALEN);
   
       res = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
                       &mreq, sizeof(struct packet_mreq));
       if (res < 0) {
           perror("Couldn't set PACKET_ADD_MEMBERSHIP");
       } else {
           printf("Successfully set PACKET_ADD_MEMBERSHIP\n");
       }
   
       close(fd);
       return res;
   }
   ```
   
   NuttX test log
   ```
   NuttShell (NSH) NuttX-12.11.0
   MOTD: username=admin password=Administrator
   nsh> ifconfig
   eth0 Link encap:Ethernet HWaddr 42:e1:c4:3f:48:dd at RUNNING mtu 1500
        inet addr:10.0.1.2 DRaddr:10.0.0.1 Mask:255.255.255.0
        inet6 addr: fe80::40e1:c4ff:fe3f:48dd/64
        inet6 DRaddr: ::
   
   nsh> hello
   Successfully set PACKET_ADD_MEMBERSHIP
   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