how to set lwip interface to promiscuous mode by raw socket

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to set lwip interface to promiscuous mode by raw socket

Jump to solution
1,923 Views
Changhawn
Contributor III

Hi

I am using S32K3 Design studio with FreeRTOS, LWIP component.

Question) By raw socket , can I make promiscuous mode like below?

PF_PACKET, SIOCGIFFLAGS, IFF_PROMISC is not defined.

But SW32K3_TCPIP_STACK_1_0_4 / 1_0_3 doesn't support it.

Is there any other method?

~~~~

/* Open PF_PACKET socket, listening for EtherType ETHER_TYPE */
if ((sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETHER_TYPE))) == -1)
{
perror("listener: socket");
return -1;
}
 
/* Set interface to promiscuous mode - do we need to do this every time? */
strncpy(ifopts.ifr_name, ifName, IFNAMSIZ - 1);
ioctl(sockfd, SIOCGIFFLAGS, &ifopts);
ifopts.ifr_flags |= IFF_PROMISC;
ioctl(sockfd, SIOCSIFFLAGS, &ifopts);
/* Allow the socket to be reused - incase connection is closed prematurely */
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof sockopt) == -1)
~~~
0 Kudos
Reply
1 Solution
1,896 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Changhawn,

You can set promiscuous mode by writing a 1 to MAC_Packet_Filter[PR]:

Julin_AragnM_0-1716247251134.png

See chapter 76.17.4 (MAC_Packet_Filter) from the reference manual.

Also, promiscuous mode is set as

    GMAC_PKT_FILTER_PROMISCUOUS_MODE = GMAC_MAC_PACKET_FILTER_PR_MASK,               /*!< Passes all incoming packets irrespective of the destination or source address. */

In the Gmac_Ip_Types.h file from the RTD include directory.

Best regards,
Julián

View solution in original post

0 Kudos
Reply
2 Replies
1,897 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Changhawn,

You can set promiscuous mode by writing a 1 to MAC_Packet_Filter[PR]:

Julin_AragnM_0-1716247251134.png

See chapter 76.17.4 (MAC_Packet_Filter) from the reference manual.

Also, promiscuous mode is set as

    GMAC_PKT_FILTER_PROMISCUOUS_MODE = GMAC_MAC_PACKET_FILTER_PR_MASK,               /*!< Passes all incoming packets irrespective of the destination or source address. */

In the Gmac_Ip_Types.h file from the RTD include directory.

Best regards,
Julián

0 Kudos
Reply
1,888 Views
Changhawn
Contributor III

Thank u for your support.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1868702%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3Ehow%20to%20set%20lwip%20interface%20to%20promiscuous%20mode%20by%20raw%20socket%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1868702%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI%20am%20using%20S32K3%20Design%20studio%20with%20FreeRTOS%2C%20LWIP%20component.%3C%2FP%3E%3CP%3EQuestion)%20By%20raw%20socket%20%2C%20can%20I%20make%20promiscuous%20mode%20like%20below%3F%3C%2FP%3E%3CP%3E%3CSPAN%3EPF_PACKET%2C%26nbsp%3BSIOCGIFFLAGS%2C%26nbsp%3BIFF_PROMISC%20is%20not%20defined.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EBut%26nbsp%3BSW32K3_TCPIP_STACK_1_0_4%20%2F%201_0_3%20doesn't%20support%20it.%3C%2FP%3E%3CP%3EIs%20there%20any%20other%20method%3F%3C%2FP%3E%3CP%3E~~~~%3C%2FP%3E%3CDIV%3E%3CSPAN%3E%2F*%20Open%20PF_PACKET%20socket%2C%20listening%20for%20EtherType%20ETHER_TYPE%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif%20((sockfd%20%3D%20socket(PF_PACKET%2C%20SOCK_RAW%2C%20htons(ETHER_TYPE)))%20%3D%3D%20-1)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eperror(%22listener%3A%20socket%22)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ereturn%20-1%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Set%20interface%20to%20promiscuous%20mode%20-%20do%20we%20need%20to%20do%20this%20every%20time%3F%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Estrncpy(ifopts.ifr_name%2C%20ifName%2C%20IFNAMSIZ%20-%201)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eioctl(sockfd%2C%20SIOCGIFFLAGS%2C%20%26amp%3Bifopts)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eifopts.ifr_flags%20%7C%3D%20IFF_PROMISC%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eioctl(sockfd%2C%20SIOCSIFFLAGS%2C%20%26amp%3Bifopts)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%20Allow%20the%20socket%20to%20be%20reused%20-%20incase%20connection%20is%20closed%20prematurely%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eif%20(setsockopt(sockfd%2C%20SOL_SOCKET%2C%20SO_REUSEADDR%2C%20%26amp%3Bsockopt%2C%20sizeof%20sockopt)%20%3D%3D%20-1)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E~~~%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1869194%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20how%20to%20set%20lwip%20interface%20to%20promiscuous%20mode%20by%20raw%20socket%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1869194%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EThank%20u%20for%20your%20support.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1869180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20how%20to%20set%20lwip%20interface%20to%20promiscuous%20mode%20by%20raw%20socket%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1869180%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F232520%22%20target%3D%22_blank%22%3E%40Changhawn%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EYou%20can%20set%20promiscuous%20mode%20by%20writing%20a%201%20to%26nbsp%3BMAC_Packet_Filter%5BPR%5D%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Julin_AragnM_0-1716247251134.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Julin_AragnM_0-1716247251134.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279703i27F49DF9F96A34ED%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Julin_AragnM_0-1716247251134.png%22%20alt%3D%22Julin_AragnM_0-1716247251134.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESee%20chapter%26nbsp%3B%3CSTRONG%3E76.17.4%3C%2FSTRONG%3E%20(MAC_Packet_Filter)%20from%20the%20reference%20manual.%3C%2FP%3E%0A%3CP%3EAlso%2C%20promiscuous%20mode%20is%20set%20as%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3E%20%20%20%20GMAC_PKT_FILTER_PROMISCUOUS_MODE%20%3D%20GMAC_MAC_PACKET_FILTER_PR_MASK%2C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F*!%26lt%3B%20Passes%20all%20incoming%20packets%20irrespective%20of%20the%20destination%20or%20source%20address.%20*%2F%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIn%20the%20Gmac_Ip_Types.h%20file%20from%20the%20RTD%20include%20directory.%3C%2FP%3E%0A%3CP%3EBest%20regards%2C%3CBR%20%2F%3EJuli%C3%A1n%3C%2FP%3E%3C%2FLINGO-BODY%3E