]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/WinPCap/NetworkInterface.c
Fix some build issues in older kernel demo projects.
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / portable / NetworkInterface / WinPCap / NetworkInterface.c
index cca53970ea61a02d2078beef9b123fd339d2b10e..86579ecdbea5703ac8fc1e6d1eb351b19c13b1eb 100644 (file)
@@ -1,28 +1,27 @@
 /*\r
- * FreeRTOS+TCP V2.0.3\r
- * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
+FreeRTOS+TCP V2.0.7\r
+Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
+\r
+Permission is hereby granted, free of charge, to any person obtaining a copy of\r
+this software and associated documentation files (the "Software"), to deal in\r
+the Software without restriction, including without limitation the rights to\r
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
+the Software, and to permit persons to whom the Software is furnished to do so,\r
+subject to the following conditions:\r
+\r
+The above copyright notice and this permission notice shall be included in all\r
+copies or substantial portions of the Software.\r
+\r
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+\r
+ http://aws.amazon.com/freertos\r
+ http://www.FreeRTOS.org\r
+*/\r
 \r
 /* WinPCap includes. */\r
 #define HAVE_REMOTE\r
@@ -80,7 +79,7 @@ static pcap_if_t * prvPrintAvailableNetworkInterfaces( void );
  * by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.\r
  */\r
 static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces );\r
-static void prvOpenInterface( const char *pucName );\r
+static int prvOpenInterface( const char *pucName );\r
 \r
 /*\r
  * Configure the capture filter to allow blocking reads, and to filter out\r
@@ -275,7 +274,7 @@ static BaseType_t xInvalidInterfaceDetected = pdFALSE;
                printf( "\r\nThe interface that will be opened is set by " );\r
                printf( "\"configNETWORK_INTERFACE_TO_USE\", which\r\nshould be defined in FreeRTOSConfig.h\r\n" );\r
 \r
-               if( ( xConfigNextworkInterfaceToUse < 1L ) || ( xConfigNextworkInterfaceToUse >= lInterfaceNumber ) )\r
+               if( ( xConfigNextworkInterfaceToUse < 0L ) || ( xConfigNextworkInterfaceToUse >= lInterfaceNumber ) )\r
                {\r
                        printf( "\r\nERROR:  configNETWORK_INTERFACE_TO_USE is set to %d, which is an invalid value.\r\n", xConfigNextworkInterfaceToUse );\r
                        printf( "Please set configNETWORK_INTERFACE_TO_USE to one of the interface numbers listed above,\r\n" );\r
@@ -300,7 +299,7 @@ static BaseType_t xInvalidInterfaceDetected = pdFALSE;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvOpenInterface( const char *pucName )\r
+static int prvOpenInterface( const char *pucName )\r
 {\r
 static char pucInterfaceName[ 256 ];\r
 \r
@@ -326,6 +325,7 @@ static char pucInterfaceName[ 256 ];
        if ( pxOpenedInterfaceHandle == NULL )\r
        {\r
                printf( "\n%s is not supported by WinPcap and cannot be opened\n", pucInterfaceName );\r
+               return 1;\r
        }\r
        else\r
        {\r
@@ -333,6 +333,7 @@ static char pucInterfaceName[ 256 ];
                out packets that are not of interest to this demo. */\r
                prvConfigureCaptureBehaviour();\r
        }\r
+       return 0;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -343,13 +344,22 @@ int32_t x;
 \r
        /* Walk the list of devices until the selected device is located. */\r
        xInterface = pxAllNetworkInterfaces;\r
-       for( x = 0L; x < ( xConfigNextworkInterfaceToUse - 1L ); x++ )\r
-       {\r
-               xInterface = xInterface->next;\r
+       if (0 == xConfigNextworkInterfaceToUse) {\r
+               while (NULL != xInterface) {\r
+                       xInterface = xInterface->next;\r
+                       if (0 == prvOpenInterface(xInterface->name)) {\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
+       else {\r
+               for (x = 1L; x < xConfigNextworkInterfaceToUse; x++)\r
+               {\r
+                       xInterface = xInterface->next;\r
+               }\r
+               /* Open the selected interface. */\r
+               (void) prvOpenInterface(xInterface->name);\r
        }\r
-\r
-       /* Open the selected interface. */\r
-       prvOpenInterface( xInterface->name );\r
 \r
        /* The device list is no longer required. */\r
        pcap_freealldevs( pxAllNetworkInterfaces );\r
@@ -514,7 +524,16 @@ eFrameProcessingResult_t eResult;
 \r
                        iptraceNETWORK_INTERFACE_RECEIVE();\r
 \r
-                       eResult = ipCONSIDER_FRAME_FOR_PROCESSING( pucPacketData );\r
+            /* Check for minimal size. */\r
+            if( pxHeader->len >= sizeof( EthernetHeader_t ) )\r
+            {\r
+                eResult = ipCONSIDER_FRAME_FOR_PROCESSING( pucPacketData );\r
+            }\r
+            else\r
+            {\r
+                eResult = eReleaseBuffer;\r
+            }\r
+\r
                        if( eResult == eProcessBuffer )\r
                        {\r
                                /* Will the data fit into the frame buffer? */\r