static void prvOpenInterface( const char *pucName ) { static char pucInterfaceName[ 256 ]; if( pucName != NULL ) { strncpy( pucInterfaceName, pucName, sizeof( pucInterfaceName ) ); } pxOpenedInterfaceHandle = pcap_open( pucInterfaceName, /* The name of the selected interface. */ ipTOTAL_ETHERNET_FRAME_SIZE, /* The size of the packet to capture. */ PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscuous mode as the MAC and IP address is going to be "simulated", and not be the real MAC and IP address. This allows traffic to the simulated IP address to be routed to uIP, and traffic to the real IP address to be routed to the Windows TCP/IP stack. */ 100, NULL, /* No authentication is required as this is not a remote capture session. */ cErrorBuffer ); if ( pxOpenedInterfaceHandle == NULL ) { printf( "\n%s is not supported by WinPcap and cannot be opened\n", pucInterfaceName ); } else { /* Configure the capture filter to allow blocking reads, and to filter out packets that are not of interest to this demo. */ prvConfigureCaptureBehaviour(); } }
static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces ) { pcap_if_t *xInterface; long x; /* Walk the list of devices until the selected device is located. */ xInterface = pxAllNetworkInterfaces; for( x = 0L; x < ( configNETWORK_INTERFACE_TO_USE - 1L ); x++ ) { xInterface = xInterface->next; } /* Open the selected interface. */ pxOpenedInterfaceHandle = pcap_open( xInterface->name, /* The name of the selected interface. */ UIP_CONF_BUFFER_SIZE, /* The size of the packet to capture. */ PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscious mode as the MAC and IP address is going to be "simulated", and not be the real MAC and IP address. This allows trafic to the simulated IP address to be routed to uIP, and trafic to the real IP address to be routed to the Windows TCP/IP stack. */ 0xfffffffL, /* The read time out. This is going to block until data is available. */ NULL, /* No authentication is required as this is not a remote capture session. */ cErrorBuffer ); if ( pxOpenedInterfaceHandle == NULL ) { printf( "\r\n%s is not supported by WinPcap and cannot be opened\r\n", xInterface->name ); } else { /* Configure the capture filter to allow blocking reads, and to filter out packets that are not of interest to this demo. */ prvConfigureCaptureBehaviour(); } /* The device list is no longer required. */ pcap_freealldevs( pxAllNetworkInterfaces ); }