added Recv-Q/Send-Q output to netstat.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20819 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,8 +21,10 @@ typedef struct net_stat {
|
||||
int protocol;
|
||||
char state[B_OS_NAME_LENGTH];
|
||||
team_id owner;
|
||||
struct sockaddr_storage address;
|
||||
struct sockaddr_storage peer;
|
||||
struct sockaddr_storage address;
|
||||
struct sockaddr_storage peer;
|
||||
size_t receive_queue_size;
|
||||
size_t send_queue_size;
|
||||
} net_stat;
|
||||
|
||||
#endif // NET_STAT_H
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <net_buffer.h>
|
||||
#include <net_datalink.h>
|
||||
#include <net_stat.h>
|
||||
#include <NetBufferUtilities.h>
|
||||
#include <NetUtilities.h>
|
||||
|
||||
@@ -586,6 +587,19 @@ TCPEndpoint::SendAvailable()
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TCPEndpoint::FillStat(net_stat *stat)
|
||||
{
|
||||
RecursiveLocker _(fLock);
|
||||
|
||||
strlcpy(stat->state, name_for_state(fState), sizeof(stat->state));
|
||||
stat->receive_queue_size = fReceiveQueue.Available();
|
||||
stat->send_queue_size = fSendQueue.Used();
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
TCPEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
|
||||
{
|
||||
|
||||
@@ -60,6 +60,8 @@ class TCPEndpoint : public net_protocol {
|
||||
status_t ReadData(size_t numBytes, uint32 flags, net_buffer **_buffer);
|
||||
ssize_t ReadAvailable();
|
||||
|
||||
status_t FillStat(struct net_stat *stat);
|
||||
|
||||
status_t SetSendBufferSize(size_t length);
|
||||
status_t SetReceiveBufferSize(size_t length);
|
||||
|
||||
|
||||
@@ -457,12 +457,8 @@ tcp_control(net_protocol *_protocol, int level, int option, void *value,
|
||||
TCPEndpoint *protocol = (TCPEndpoint *)_protocol;
|
||||
|
||||
if ((level & LEVEL_MASK) == IPPROTO_TCP) {
|
||||
if (option == NET_STAT_SOCKET) {
|
||||
net_stat *stat = (net_stat *)value;
|
||||
strlcpy(stat->state, name_for_state(protocol->State()),
|
||||
sizeof(stat->state));
|
||||
return B_OK;
|
||||
}
|
||||
if (option == NET_STAT_SOCKET)
|
||||
return protocol->FillStat((net_stat *)value);
|
||||
}
|
||||
|
||||
return protocol->next->module->control(protocol->next, level, option,
|
||||
|
||||
@@ -274,6 +274,8 @@ socket_get_next_stat(uint32 *_cookie, int family, struct net_stat *stat)
|
||||
stat->state[0] = '\0';
|
||||
memcpy(&stat->address, &socket->address, sizeof(struct sockaddr_storage));
|
||||
memcpy(&stat->peer, &socket->peer, sizeof(struct sockaddr_storage));
|
||||
stat->receive_queue_size = 0;
|
||||
stat->send_queue_size = 0;
|
||||
|
||||
// fill in protocol specific data (if supported by the protocol)
|
||||
size_t length = sizeof(net_stat);
|
||||
|
||||
@@ -55,7 +55,7 @@ inet_print_address(sockaddr* _address)
|
||||
sockaddr_in& address = *(sockaddr_in *)_address;
|
||||
|
||||
if (address.sin_family != AF_INET || address.sin_len == 0) {
|
||||
printf("%-30s", "-");
|
||||
printf("%-22s", "-");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ inet_print_address(sockaddr* _address)
|
||||
|
||||
snprintf(buffer + length, sizeof(buffer) - length, ":%s", port);
|
||||
|
||||
printf("%-30s", buffer);
|
||||
printf("%-22s", buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ main(int argc, char** argv)
|
||||
bool printProgram = true;
|
||||
// TODO: add some program options... :-)
|
||||
|
||||
printf("Proto Local Address Foreign Address State Program\n");
|
||||
printf("Proto Recv-Q Send-Q Local Address Foreign Address State Program\n");
|
||||
|
||||
uint32 cookie = 0;
|
||||
int family = -1;
|
||||
@@ -165,6 +165,9 @@ main(int argc, char** argv)
|
||||
else
|
||||
printf("%-6d ", stat.protocol);
|
||||
|
||||
printf("%6lu ", stat.receive_queue_size);
|
||||
printf("%6lu ", stat.send_queue_size);
|
||||
|
||||
inet_print_address((sockaddr*)&stat.address);
|
||||
inet_print_address((sockaddr*)&stat.peer);
|
||||
printf("%-12s ", stat.state);
|
||||
|
||||
Reference in New Issue
Block a user