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