/** @file\r
Data source for network testing.\r
\r
- Copyright (c) 2011, Intel Corporation\r
+ Copyright (c) 2011-2012, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
#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
-struct pollfd PollFd [ MAX_CONNECTIONS ];\r
-DT_PORT Port [ MAX_CONNECTIONS ];\r
+UINT8 Buffer[ DATA_BUFFER_SIZE ];\r
+struct pollfd PollFd[ MAX_CONNECTIONS ];\r
+DT_PORT Port[ MAX_CONNECTIONS ];\r
nfds_t MaxPort;\r
\r
\r
//\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
// Allocate a port\r
//\r
Index = MaxPort++;\r
- 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
+ PollFd[ Index ].fd = ListenSocket;\r
+ PollFd[ Index ].events = POLLRDNORM | POLLHUP;\r
+ PollFd[ Index ].revents = 0;\r
+ ZeroMem ( &Port[ Index ], sizeof ( Port[ Index ]));\r
}\r
}\r
\r
/**\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
// 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
//\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
"0x%08x: Socket created\r\n",\r
ListenSocket ));\r
}\r
- else\r
- {\r
+ else {\r
Status = EFI_NOT_STARTED;\r
}\r
}\r
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
//\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
//\r
// Account for this descriptor\r
//\r
- if ( 0 != PollFd [ Index ].revents ) {\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
\r
//\r
// Check for a broken connection\r
//\r
- if ( 0 != ( PollFd [ Index ].revents & POLLHUP )) {\r
+ if ( 0 != ( PollFd[ Index ].revents & POLLHUP )) {\r
bRemoveSocket = TRUE;\r
- if ( ListenSocket == PollFd [ Index ].fd ) {\r
+ if ( ListenSocket == PollFd[ Index ].fd ) {\r
bListenError = TRUE;\r
DEBUG (( DEBUG_ERROR,\r
"ERROR - Network closed on listen socket, errno: %d\r\n",\r
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
+ ntohs ( 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
+ ntohs ( pPortIpAddress6->sin6_port ),\r
+ errno ));\r
+ }\r
\r
//\r
// Close the socket\r
//\r
- CloseStatus = close ( PollFd [ Index ].fd );\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
+ ntohs ( 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
+ ntohs ( 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
+ ntohs ( 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
+ ntohs ( pPortIpAddress6->sin6_port ),\r
+ errno ));\r
+ }\r
}\r
}\r
}\r
//\r
// Check for a connection or read data\r
//\r
- if ( 0 != ( PollFd [ Index ].revents & POLLRDNORM )) {\r
+ if ( 0 != ( PollFd[ Index ].revents & POLLRDNORM )) {\r
//\r
// Check for a connection\r
//\r
- if ( ListenSocket == PollFd [ Index ].fd ) {\r
+ if ( ListenSocket == PollFd[ Index ].fd ) {\r
//\r
// Another client connection was received\r
//\r
//\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
+ ntohs ( 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
+ ntohs ( pRemoteAddress6->sin6_port ));\r
+ }\r
\r
//\r
// No room for this connection\r
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
+ ntohs ( 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
+ ntohs ( pRemoteAddress6->sin6_port )));\r
+ }\r
}\r
else {\r
DEBUG (( DEBUG_ERROR,\r
"ERROR - Failed to close socket 0x%08x, errno: %d\r\n",\r
- PollFd [ Index ].fd,\r
+ PollFd[ Index ].fd,\r
errno ));\r
}\r
\r
//\r
Status = EFI_SUCCESS;\r
}\r
- else\r
- {\r
+ else {\r
//\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
+ ntohs ( 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
+ ntohs ( 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
- PollFd [ Index ].fd = Socket;\r
- PollFd [ Index ].events = POLLRDNORM | POLLHUP;\r
- PollFd [ Index ].revents = 0;\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
}\r
}\r
}\r
//\r
// Data received\r
//\r
- BytesReceived = read ( PollFd [ Index ].fd,\r
+ BytesReceived = read ( PollFd[ Index ].fd,\r
&Buffer,\r
sizeof ( Buffer ));\r
if ( 0 < BytesReceived ) {\r
//\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
+ ntohs ( 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
+ ntohs ( pPortIpAddress6->sin6_port )));\r
+ }\r
\r
//\r
// Synchronize with the TimerCallback routine\r
//\r
// Account for the data received\r
//\r
- Port [ Index ].BytesTotal += BytesReceived;\r
+ Port[ Index ].BytesTotal += BytesReceived;\r
\r
//\r
// Release the synchronization with the TimerCallback routine\r
//\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
- CloseStatus = close ( PollFd [ Index ].fd );\r
- if ( 0 == CloseStatus ) {\r
- bRemoveSocket = TRUE;\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
- 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
+ "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
+ ntohs ( pPortIpAddress4->sin_port ),\r
+ errno ));\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
+ 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
+ ntohs ( pPortIpAddress6->sin6_port ),\r
errno ));\r
}\r
+ CloseStatus = close ( PollFd[ Index ].fd );\r
+ if ( 0 == CloseStatus ) {\r
+ bRemoveSocket = TRUE;\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
+ ntohs ( 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
+ ntohs ( pPortIpAddress6->sin6_port )));\r
+ }\r
+ }\r
+ else {\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
+ ntohs ( 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
+ ntohs ( pPortIpAddress6->sin6_port ),\r
+ errno ));\r
+ }\r
+ }\r
}\r
\r
//\r
if ( bRemoveSocket ) {\r
DEBUG (( DEBUG_INFO,\r
"0x%08x: Socket removed from polling\r\n",\r
- PollFd [ Index ].fd ));\r
+ PollFd[ Index ].fd ));\r
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
- PollFd [ EntryPrevious ].events = PollFd [ Entry ].events;\r
- PollFd [ EntryPrevious ].fd = PollFd [ Entry ].fd;\r
- PollFd [ EntryPrevious ].revents = PollFd [ Entry ].revents;\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
}\r
- PollFd [ MaxPort ].fd = -1;\r
+ PollFd[ MaxPort ].fd = -1;\r
Index -= 1;\r
}\r
\r
@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
//\r
// Determine if any data was received\r
//\r
- BytesReceived = Port [ Index ].BytesTotal;\r
- if (( ListenSocket != PollFd [ Index ].fd )\r
+ BytesReceived = Port[ Index ].BytesTotal;\r
+ 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
+ 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
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
- for ( ; ; )\r
- {\r
+ for ( ; ; ) {\r
//\r
// Create the timer\r
//\r
//\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
}\r
\r
//\r
- // Send data until the connection breaks\r
+ // Receive data until the connection breaks\r
//\r
do {\r
Status = SocketPoll ( );\r