Fix the errors detected by the GCC compiler:
[mirror_edk2.git] / AppPkg / Applications / Sockets / DataSink / DataSink.c
index 8223ead118079e3b652eb7d7f32c7d4ea122a4c2..dcf4b59f303436c2d7b649526f0307d537a38877 100644 (file)
 #include <sys/socket.h>\r
 \r
 \r
-#define MAX_CONNECTIONS       ( 1 + 16 )  ///<  Maximum number of client connections\r
-#define RANGE_SWITCH                2048  ///<  Switch display ranges\r
-#define DATA_RATE_UPDATE_SHIFT      2     ///<  2n seconds between updates\r
+#define DATA_SAMPLE_SHIFT           5       ///<  Shift for number of samples\r
+#define MAX_CONNECTIONS       ( 1 + 16 )    ///<  Maximum number of client connections\r
+#define RANGE_SWITCH        ( 1024 * 1024 ) ///<  Switch display ranges\r
+#define DATA_RATE_UPDATE_SHIFT      2       ///<  2n seconds between updates\r
 #define AVERAGE_SHIFT_COUNT ( 6 - DATA_RATE_UPDATE_SHIFT )  ///<  2n samples in average\r
+#define DATA_SAMPLES        ( 1 << DATA_SAMPLE_SHIFT )      ///<  Number of samples\r
 \r
 #define TPL_DATASINK        TPL_CALLBACK  ///<  Synchronization TPL\r
 \r
 #define DATA_BUFFER_SIZE    (( 65536 / PACKET_SIZE ) * PACKET_SIZE )  ///<  Buffer size in bytes\r
 \r
 typedef struct _DT_PORT {\r
-  UINT64 BytesAverage;\r
-  UINT64 BytesPrevious;\r
   UINT64 BytesTotal;\r
-  struct sockaddr_in RemoteAddress;\r
-  UINT64 Samples;\r
+  struct sockaddr_in6 IpAddress;\r
+  UINT32 In;\r
+  UINT32 Samples;\r
+  UINT64 BytesReceived[ DATA_SAMPLES ];\r
 } DT_PORT;\r
 \r
 volatile BOOLEAN bTick;\r
 BOOLEAN bTimerRunning;\r
-struct sockaddr_in LocalAddress;\r
+struct sockaddr_in6 LocalAddress;\r
 EFI_EVENT pTimer;\r
 int ListenSocket;\r
 UINT8 Buffer[ DATA_BUFFER_SIZE ];\r
@@ -120,7 +122,7 @@ SocketAccept (
   //\r
   SocketStatus = bind ( ListenSocket,\r
                         (struct sockaddr *) &LocalAddress,\r
-                        LocalAddress.sin_len );\r
+                        LocalAddress.sin6_len );\r
   if ( 0 == SocketStatus ) {\r
     //\r
     //  Start listening on the local socket\r
@@ -139,14 +141,7 @@ SocketAccept (
       PollFd[ Index ].fd = ListenSocket;\r
       PollFd[ Index ].events = POLLRDNORM | POLLHUP;\r
       PollFd[ Index ].revents = 0;\r
-      Port[ Index ].BytesAverage = 0;\r
-      Port[ Index ].BytesPrevious = 0;\r
-      Port[ Index ].BytesTotal = 0;\r
-      Port[ Index ].Samples = 0;\r
-      Port[ Index ].RemoteAddress.sin_len = 0;\r
-      Port[ Index ].RemoteAddress.sin_family = 0;\r
-      Port[ Index ].RemoteAddress.sin_port = 0;\r
-      Port[ Index ].RemoteAddress.sin_addr.s_addr= 0;\r
+      ZeroMem ( &Port[ Index ], sizeof ( Port[ Index ]));\r
     }\r
   }\r
 \r
@@ -203,11 +198,14 @@ SocketClose (
 /**\r
   Create the socket\r
 \r
+  @param [in] Family    Network family, AF_INET or AF_INET6\r
+\r
   @retval  EFI_SUCCESS  The application is running normally\r
   @retval  Other        The user stopped the application\r
 **/\r
 EFI_STATUS\r
 SocketNew (\r
+  sa_family_t Family\r
   )\r
 {\r
   EFI_STATUS Status;\r
@@ -216,9 +214,9 @@ SocketNew (
   //  Get the port number\r
   //\r
   ZeroMem ( &LocalAddress, sizeof ( LocalAddress ));\r
-  LocalAddress.sin_len = sizeof ( LocalAddress );\r
-  LocalAddress.sin_family = AF_INET;\r
-  LocalAddress.sin_port = htons ( PcdGet16 ( DataSource_Port ));\r
+  LocalAddress.sin6_len = sizeof ( LocalAddress );\r
+  LocalAddress.sin6_family = Family;\r
+  LocalAddress.sin6_port = htons ( PcdGet16 ( DataSource_Port ));\r
   \r
   //\r
   //  Loop creating the socket\r
@@ -234,7 +232,7 @@ SocketNew (
     //\r
     //  Attempt to create the socket\r
     //\r
-    ListenSocket = socket ( AF_INET,\r
+    ListenSocket = socket ( LocalAddress.sin6_family,\r
                             SOCK_STREAM,\r
                             IPPROTO_TCP );\r
     if ( -1 != ListenSocket ) {\r
@@ -274,7 +272,11 @@ SocketPoll (
   int FdCount;\r
   nfds_t Index;\r
   socklen_t LengthInBytes;\r
-  struct sockaddr_in RemoteAddress;\r
+  struct sockaddr_in * pPortIpAddress4;\r
+  struct sockaddr_in6 * pPortIpAddress6;\r
+  struct sockaddr_in * pRemoteAddress4;\r
+  struct sockaddr_in6 * pRemoteAddress6;\r
+  struct sockaddr_in6 RemoteAddress;\r
   int Socket;\r
   EFI_STATUS Status;\r
   EFI_TPL TplPrevious;\r
@@ -282,6 +284,8 @@ SocketPoll (
   //\r
   //  Check for control-C\r
   //\r
+  pRemoteAddress4 = (struct sockaddr_in *)&RemoteAddress;\r
+  pRemoteAddress6 = (struct sockaddr_in6 *)&RemoteAddress;\r
   bListenError = FALSE;\r
   Status = ControlCCheck ( );\r
   if ( !EFI_ERROR ( Status )) {\r
@@ -311,6 +315,8 @@ SocketPoll (
         //\r
         //  Account for this descriptor\r
         //\r
+        pPortIpAddress4 = (struct sockaddr_in *)&Port[ Index ].IpAddress;\r
+        pPortIpAddress6 = (struct sockaddr_in6 *)&Port[ Index ].IpAddress;\r
         if ( 0 != PollFd[ Index ].revents ) {\r
           FdCount -= 1;\r
         }\r
@@ -327,14 +333,38 @@ SocketPoll (
                       errno ));\r
           }\r
           else {\r
-            DEBUG (( DEBUG_ERROR,\r
-                      "ERROR - Network closed on socket %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                      Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                      htons ( Port[ Index ].RemoteAddress.sin_port ),\r
-                      errno ));\r
+            if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+              DEBUG (( DEBUG_ERROR,\r
+                        "ERROR - Network closed on socket %d.%d.%d.%d:%d, errno: %d\r\n",\r
+                        pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                        ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                        ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                        ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                        htons ( pPortIpAddress4->sin_port ),\r
+                        errno ));\r
+            }\r
+            else {\r
+              DEBUG (( DEBUG_ERROR,\r
+                        "ERROR - Network closed on socket [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d, errno: %d\r\n",\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                        pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                        htons ( pPortIpAddress6->sin6_port ),\r
+                        errno ));\r
+            }\r
 \r
             //\r
             //  Close the socket\r
@@ -342,25 +372,74 @@ SocketPoll (
             CloseStatus = close ( PollFd[ Index ].fd );\r
             if ( 0 == CloseStatus ) {\r
               bRemoveSocket = TRUE;\r
-              DEBUG (( DEBUG_INFO,\r
-                        "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                        PollFd[ Index ].fd,\r
-                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port[ Index ].RemoteAddress.sin_port )));\r
+              if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pPortIpAddress4->sin_port )));\r
+              }\r
+              else {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "0x%08x: Socket closed for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pPortIpAddress6->sin6_port )));\r
+              }\r
             }\r
             else {\r
-              DEBUG (( DEBUG_ERROR,\r
-                        "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                        PollFd[ Index ].fd,\r
-                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port[ Index ].RemoteAddress.sin_port ),\r
-                        errno ));\r
+              if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                DEBUG (( DEBUG_ERROR,\r
+                          "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pPortIpAddress4->sin_port ),\r
+                          errno ));\r
+              }\r
+              else {\r
+                DEBUG (( DEBUG_ERROR,\r
+                          "ERROR - Failed to close socket 0x%08x for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d, errno: %d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pPortIpAddress6->sin6_port ),\r
+                          errno ));\r
+              }\r
             }\r
           }\r
         }\r
@@ -399,12 +478,34 @@ SocketPoll (
                 //\r
                 //  Display the connection\r
                 //\r
-                Print ( L"Rejecting connection to remote system %d.%d.%d.%d:%d\r\n",\r
-                        RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( RemoteAddress.sin_port ));\r
+                if ( AF_INET == pRemoteAddress4->sin_family ) {\r
+                  Print ( L"Rejecting connection to remote system %d.%d.%d.%d:%d\r\n",\r
+                          pRemoteAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pRemoteAddress4->sin_port ));\r
+                }\r
+                else {\r
+                  Print ( L"Rejecting connection to remote system [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pRemoteAddress6->sin6_port ));\r
+                }\r
 \r
                 //\r
                 //  No room for this connection\r
@@ -413,14 +514,38 @@ SocketPoll (
                 CloseStatus = close ( Socket );\r
                 if ( 0 == CloseStatus ) {\r
                   bRemoveSocket = TRUE;\r
-                  DEBUG (( DEBUG_INFO,\r
-                            "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                            PollFd[ Index ].fd,\r
-                            RemoteAddress.sin_addr.s_addr & 0xff,\r
-                            ( RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                            ( RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                            ( RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                            htons ( RemoteAddress.sin_port )));\r
+                  if ( AF_INET == pRemoteAddress4->sin_family ) {\r
+                    DEBUG (( DEBUG_INFO,\r
+                              "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
+                              PollFd[ Index ].fd,\r
+                              pRemoteAddress4->sin_addr.s_addr & 0xff,\r
+                              ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                              ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                              ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                              htons ( pRemoteAddress4->sin_port )));\r
+                  }\r
+                  else {\r
+                    DEBUG (( DEBUG_INFO,\r
+                              "0x%08x: Socket closed for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                              PollFd[ Index ].fd,\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                              pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                              htons ( pRemoteAddress6->sin6_port )));\r
+                  }\r
                 }\r
                 else {\r
                   DEBUG (( DEBUG_ERROR,\r
@@ -439,25 +564,41 @@ SocketPoll (
                 //\r
                 //  Display the connection\r
                 //\r
-                Print ( L"Connected to remote system %d.%d.%d.%d:%d\r\n",\r
-                        RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( RemoteAddress.sin_port ));\r
+                if ( AF_INET == pRemoteAddress4->sin_family ) {\r
+                  Print ( L"Connected to remote system %d.%d.%d.%d:%d\r\n",\r
+                          pRemoteAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pRemoteAddress4->sin_port ));\r
+                }\r
+                else {\r
+                  Print ( L"Connected to remote system [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pRemoteAddress6->sin6_port ));\r
+                }\r
 \r
                 //\r
                 //  Allocate the client connection\r
                 //\r
                 Index = MaxPort++;\r
-                Port[ Index ].BytesAverage = 0;\r
-                Port[ Index ].BytesPrevious = 0;\r
-                Port[ Index ].BytesTotal = 0;\r
-                Port[ Index ].Samples = 0;\r
-                Port[ Index ].RemoteAddress.sin_len = RemoteAddress.sin_len;\r
-                Port[ Index ].RemoteAddress.sin_family = RemoteAddress.sin_family;\r
-                Port[ Index ].RemoteAddress.sin_port = RemoteAddress.sin_port;\r
-                Port[ Index ].RemoteAddress.sin_addr = RemoteAddress.sin_addr;\r
+                ZeroMem ( &Port[ Index ], sizeof ( Port[ Index ]));\r
+                CopyMem ( pPortIpAddress6, pRemoteAddress6, sizeof ( *pRemoteAddress6 ));\r
                 PollFd[ Index ].fd = Socket;\r
                 PollFd[ Index ].events = POLLRDNORM | POLLHUP;\r
                 PollFd[ Index ].revents = 0;\r
@@ -475,15 +616,40 @@ SocketPoll (
               //\r
               //  Display the amount of data received\r
               //\r
-              DEBUG (( DEBUG_INFO,\r
-                        "0x%08x: Socket received 0x%08x bytes from %d.%d.%d.%d:%d\r\n",\r
-                        PollFd[ Index ].fd,\r
-                        BytesReceived,\r
-                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port[ Index ].RemoteAddress.sin_port )));\r
+              if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "0x%08x: Socket received 0x%08x bytes from %d.%d.%d.%d:%d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          BytesReceived,\r
+                          pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pPortIpAddress4->sin_port )));\r
+              }\r
+              else {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "0x%08x: Socket received 0x%08x bytes from [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                          PollFd[ Index ].fd,\r
+                          BytesReceived,\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pPortIpAddress6->sin6_port )));\r
+              }\r
 \r
               //\r
               //  Synchronize with the TimerCallback routine\r
@@ -504,36 +670,109 @@ SocketPoll (
               //\r
               //  Close the socket\r
               //\r
-              DEBUG (( DEBUG_INFO,\r
-                        "ERROR - Receive failure for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port[ Index ].RemoteAddress.sin_port ),\r
-                        errno ));\r
+              if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "ERROR - Receive failure for %d.%d.%d.%d:%d, errno: %d\r\n",\r
+                          pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( pPortIpAddress4->sin_port ),\r
+                          errno ));\r
+              }\r
+              else {\r
+                DEBUG (( DEBUG_INFO,\r
+                          "ERROR - Receive failure for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d, errno: %d\r\n",\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                          pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                          htons ( pPortIpAddress6->sin6_port ),\r
+                          errno ));\r
+              }\r
               CloseStatus = close ( PollFd[ Index ].fd );\r
               if ( 0 == CloseStatus ) {\r
                 bRemoveSocket = TRUE;\r
-                DEBUG (( DEBUG_INFO,\r
-                          "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                          PollFd[ Index ].fd,\r
-                          Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( Port[ Index ].RemoteAddress.sin_port )));\r
+                if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                  DEBUG (( DEBUG_INFO,\r
+                            "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
+                            PollFd[ Index ].fd,\r
+                            pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                            htons ( pPortIpAddress4->sin_port )));\r
+                }\r
+                else {\r
+                  DEBUG (( DEBUG_INFO,\r
+                            "0x%08x: Socket closed for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
+                            PollFd[ Index ].fd,\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                            htons ( pPortIpAddress6->sin6_port )));\r
+                }\r
               }\r
               else {\r
-                DEBUG (( DEBUG_ERROR,\r
-                          "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                          PollFd[ Index ].fd,\r
-                          Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( Port[ Index ].RemoteAddress.sin_port ),\r
-                          errno ));\r
+                if ( AF_INET == pPortIpAddress4->sin_family ) {\r
+                  DEBUG (( DEBUG_ERROR,\r
+                            "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
+                            PollFd[ Index ].fd,\r
+                            pPortIpAddress4->sin_addr.s_addr & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
+                            ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
+                            htons ( pPortIpAddress4->sin_port ),\r
+                            errno ));\r
+                }\r
+                else {\r
+                  DEBUG (( DEBUG_ERROR,\r
+                            "ERROR - Failed to close socket 0x%08x for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d, errno: %d\r\n",\r
+                            PollFd[ Index ].fd,\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 0 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 1 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 2 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 3 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 4 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 5 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 6 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 7 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 8 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 9 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 10 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 11 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 12 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
+                            pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
+                            htons ( pPortIpAddress6->sin6_port ),\r
+                            errno ));\r
+                }\r
               }\r
             }\r
 \r
@@ -555,14 +794,9 @@ SocketPoll (
           MaxPort -= 1;\r
           for ( Entry = Index + 1; MaxPort >= Entry; Entry++ ) {\r
             EntryPrevious = Entry;\r
-            Port[ EntryPrevious ].BytesAverage = Port[ Entry ].BytesAverage;\r
-            Port[ EntryPrevious ].BytesPrevious = Port[ Entry ].BytesPrevious;\r
-            Port[ EntryPrevious ].BytesTotal = Port[ Entry ].BytesTotal;\r
-            Port[ EntryPrevious ].RemoteAddress.sin_len = Port[ Entry ].RemoteAddress.sin_len;\r
-            Port[ EntryPrevious ].RemoteAddress.sin_family = Port[ Entry ].RemoteAddress.sin_family;\r
-            Port[ EntryPrevious ].RemoteAddress.sin_port = Port[ Entry ].RemoteAddress.sin_port;\r
-            Port[ EntryPrevious ].RemoteAddress.sin_addr.s_addr = Port[ Entry ].RemoteAddress.sin_addr.s_addr;\r
-            Port[ EntryPrevious ].Samples = Port[ Entry ].Samples;\r
+            CopyMem ( &Port[ EntryPrevious ],\r
+                      &Port[ Entry ],\r
+                      sizeof ( Port[ Entry ]));\r
             PollFd[ EntryPrevious ].events = PollFd[ Entry ].events;\r
             PollFd[ EntryPrevious ].fd = PollFd[ Entry ].fd;\r
             PollFd[ EntryPrevious ].revents = PollFd[ Entry ].revents;\r
@@ -600,16 +834,18 @@ SocketPoll (
   @param [in] pContext  Context for this routine\r
 **/\r
 VOID\r
+EFIAPI\r
 TimerCallback (\r
   IN EFI_EVENT Event,\r
   IN VOID * pContext\r
   )\r
 {\r
-  UINT64 Average;\r
+  UINT32 Average;\r
+  UINT64 BitsPerSecond;\r
   UINT64 BytesReceived;\r
-  UINT32 Delta;\r
-  UINT64 DeltaBytes;\r
+  UINT32 Count;\r
   nfds_t Index;\r
+  UINT64 TotalBytes;\r
 \r
   //\r
   //  Notify the other code of the timer tick\r
@@ -627,65 +863,84 @@ TimerCallback (
     if (( ListenSocket != PollFd[ Index ].fd )\r
       && ( 0 != BytesReceived )) {\r
       //\r
-      //  Update the average bytes per second\r
+      //  Update the received data samples\r
       //\r
-      DeltaBytes = Port[ Index ].BytesAverage >> AVERAGE_SHIFT_COUNT;\r
-      Port[ Index ].BytesAverage -= DeltaBytes;\r
-      DeltaBytes = BytesReceived - Port[ Index ].BytesPrevious;\r
-      Port[ Index ].BytesPrevious = BytesReceived;\r
-      Port[ Index ].BytesAverage += DeltaBytes;\r
-\r
+      Port[ Index ].BytesTotal = 0;\r
+      Port[ Index ].BytesReceived [ Port[ Index ].In ] = BytesReceived;\r
+      Port[ Index ].In += 1;\r
+      if ( DATA_SAMPLES <= Port[ Index ].In ) {\r
+        Port[ Index ].In = 0;\r
+      }\r
+      \r
       //\r
       //  Separate the samples\r
       //\r
-      if (( 2 << AVERAGE_SHIFT_COUNT ) == Port[ Index ].Samples ) {\r
+      if ( DATA_SAMPLES == Port[ Index ].Samples ) {\r
         Print ( L"---------- Stable average ----------\r\n" );\r
       }\r
       Port[ Index ].Samples += 1;\r
 \r
+      //\r
+      //  Compute the data rate\r
+      //\r
+      TotalBytes = 0;\r
+      for ( Count = 0; DATA_SAMPLES > Count; Count++ )\r
+      {\r
+          TotalBytes += Port[ Index ].BytesReceived[ Count ];\r
+      }\r
+      Average = (UINT32)RShiftU64 ( TotalBytes, DATA_SAMPLE_SHIFT );\r
+      BitsPerSecond = Average * 8;\r
+\r
       //\r
       //  Display the data rate\r
       //\r
-      Delta = (UINT32)( DeltaBytes >> DATA_RATE_UPDATE_SHIFT );\r
-      Average = Port[ Index ].BytesAverage >> ( AVERAGE_SHIFT_COUNT + DATA_RATE_UPDATE_SHIFT );\r
-      if ( Average < RANGE_SWITCH ) {\r
-        Print ( L"%d Bytes/sec, Ave: %d Bytes/Sec\r\n",\r
-                Delta,\r
-                (UINT32) Average );\r
+      if (( RANGE_SWITCH >> 10 ) > Average ) {\r
+        Print ( L"Ave: %d Bytes/Sec, %Ld Bits/sec\r\n",\r
+                Average,\r
+                BitsPerSecond );\r
       }\r
       else {\r
-        Average >>= 10;\r
-        if ( Average < RANGE_SWITCH ) {\r
-          Print ( L"%d Bytes/sec, Ave: %d KiBytes/Sec\r\n",\r
-                  Delta,\r
-                  (UINT32) Average );\r
+        BitsPerSecond /= 1000;\r
+        if ( RANGE_SWITCH > Average ) {\r
+          Print ( L"Ave: %d.%03d KiBytes/Sec, %Ld KBits/sec\r\n",\r
+                  Average >> 10,\r
+                  (( Average & 0x3ff ) * 1000 ) >> 10,\r
+                  BitsPerSecond );\r
         }\r
         else {\r
+          BitsPerSecond /= 1000;\r
           Average >>= 10;\r
-          if ( Average < RANGE_SWITCH ) {\r
-            Print ( L"%d Bytes/sec, Ave: %d MiBytes/Sec\r\n",\r
-                    Delta,\r
-                    (UINT32) Average );\r
+          if ( RANGE_SWITCH > Average ) {\r
+            Print ( L"Ave: %d.%03d MiBytes/Sec, %Ld MBits/sec\r\n",\r
+                    Average >> 10,\r
+                    (( Average & 0x3ff ) * 1000 ) >> 10,\r
+                    BitsPerSecond );\r
           }\r
           else {\r
+            BitsPerSecond /= 1000;\r
             Average >>= 10;\r
-            if ( Average < RANGE_SWITCH ) {\r
-              Print ( L"%d Bytes/sec, Ave: %d GiBytes/Sec\r\n",\r
-                      Delta,\r
-                      (UINT32) Average );\r
+            if ( RANGE_SWITCH > Average ) {\r
+              Print ( L"Ave: %d.%03d GiBytes/Sec, %Ld GBits/sec\r\n",\r
+                      Average >> 10,\r
+                      (( Average & 0x3ff ) * 1000 ) >> 10,\r
+                      BitsPerSecond );\r
             }\r
             else {\r
+              BitsPerSecond /= 1000;\r
               Average >>= 10;\r
-              if ( Average < RANGE_SWITCH ) {\r
-                Print ( L"%d Bytes/sec, Ave: %d TiBytes/Sec\r\n",\r
-                        Delta,\r
-                        Average );\r
+              if ( RANGE_SWITCH > Average ) {\r
+                Print ( L"Ave: %d.%03d TiBytes/Sec, %Ld TBits/sec\r\n",\r
+                        Average >> 10,\r
+                        (( Average & 0x3ff ) * 1000 ) >> 10,\r
+                        BitsPerSecond );\r
               }\r
               else {\r
+                BitsPerSecond /= 1000;\r
                 Average >>= 10;\r
-                Print ( L"%d Bytes/sec, Ave: %d PiBytes/Sec\r\n",\r
-                        Delta,\r
-                        (UINT32) Average );\r
+                Print ( L"Ave: %d.%03d PiBytes/Sec, %Ld PBits/sec\r\n",\r
+                        Average >> 10,\r
+                        (( Average & 0x3ff ) * 1000 ) >> 10,\r
+                        BitsPerSecond );\r
               }\r
             }\r
           }\r
@@ -909,11 +1164,17 @@ main (
   IN char **Argv\r
   )\r
 {\r
+  sa_family_t Family;\r
   EFI_STATUS Status;\r
 \r
   DEBUG (( DEBUG_INFO,\r
             "DataSink starting\r\n" ));\r
 \r
+  //\r
+  //  Determine the family to use\r
+  //\r
+  Family = ( 1 < Argc ) ? AF_INET6 : AF_INET;\r
+\r
   //\r
   //  Use for/break instead of goto\r
   //\r
@@ -966,7 +1227,7 @@ main (
       //\r
       //  Wait for the network layer to initialize\r
       //\r
-      Status = SocketNew ( );\r
+      Status = SocketNew ( Family );\r
       if ( EFI_ERROR ( Status )) {\r
         continue;\r
       }\r
@@ -987,7 +1248,7 @@ main (
       }\r
 \r
       //\r
-      //  Send data until the connection breaks\r
+      //  Receive data until the connection breaks\r
       //\r
       do {\r
         Status = SocketPoll ( );\r