From 3df919a7a02eb4f70d591f735b7c5b0490313206 Mon Sep 17 00:00:00 2001 From: Hugo Santos Date: Mon, 30 Apr 2007 12:31:57 +0000 Subject: [PATCH] added 'ipv4_multicast' debugger command. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20922 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/network/protocols/ipv4/ipv4.cpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp index 8ae233e597..413722c540 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp +++ b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -143,6 +144,8 @@ public: { return &group->fLink; } }; + void DumpInternalState() const; + private: // for g++ 2.95 friend class HashDefinition; @@ -208,6 +211,18 @@ static net_protocol_module_info *sReceivingProtocol[256]; static benaphore sReceivingProtocolLock; +static const char * +print_address(const in_addr *address, char *buf, size_t bufLen) +{ + unsigned int addr = ntohl(address->s_addr); + + snprintf(buf, bufLen, "%u.%u.%u.%u", (addr >> 24) & 0xff, + (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff); + + return buf; +} + + RawSocket::RawSocket(net_socket *socket) : DatagramSocket<>("ipv4 raw socket", socket) { @@ -496,6 +511,23 @@ MulticastGroup::Remove(IPv4Multicast::GroupState *groupState) } +void +MulticastGroup::DumpInternalState() const +{ + char addrBuf[64]; + + kprintf("group %s (%p)\n", print_address(&fMulticastAddress, addrBuf, + sizeof(addrBuf)), this); + + Links::ConstIterator it = fLinks.GetIterator(); + while (it.HasNext()) { + IPv4Multicast::GroupState *group = it.Next(); + + kprintf(" socket %p\n", group->Socket()); + } +} + + // #pragma mark - @@ -1561,6 +1593,18 @@ ipv4_error_reply(net_protocol *protocol, net_buffer *causedError, uint32 code, } +static int +dump_ipv4_multicast(int argc, char *argv[]) +{ + MulticastGroups::Iterator it = sMulticastGroups->GetIterator(); + + while (it.HasNext()) + it.Next()->DumpInternalState(); + + return 0; +} + + // #pragma mark - @@ -1613,6 +1657,9 @@ init_ipv4() if (status < B_OK) goto err6; + add_debugger_command("ipv4_multicast", dump_ipv4_multicast, + "list all current IPv4 multicast states"); + return B_OK; err6: @@ -1636,6 +1683,8 @@ uninit_ipv4() { benaphore_lock(&sReceivingProtocolLock); + remove_debugger_command("ipv4_multicast", dump_ipv4_multicast); + // put all the domain receiving protocols we gathered so far for (uint32 i = 0; i < 256; i++) { if (sReceivingProtocol[i] != NULL)