added 'udp_endpoints' debugger command.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20908 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -109,6 +109,12 @@ public:
|
|||||||
return AddressString(fModule, fAddress, printPort);
|
return AddressString(fModule, fAddress, printPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *AsString(char *buffer, size_t bufferSize,
|
||||||
|
bool printPort = false) const {
|
||||||
|
fModule->print_address_buffer(fAddress, buffer, bufferSize, printPort);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
const sockaddr *operator *() const { return fAddress; }
|
const sockaddr *operator *() const { return fAddress; }
|
||||||
sockaddr *operator *() { return fAddress; }
|
sockaddr *operator *() { return fAddress; }
|
||||||
|
|
||||||
@@ -188,6 +194,12 @@ public:
|
|||||||
return AddressString(fModule, fAddress, printPort);
|
return AddressString(fModule, fAddress, printPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *AsString(char *buffer, size_t bufferSize,
|
||||||
|
bool printPort = false) const {
|
||||||
|
fModule->print_address_buffer(fAddress, buffer, bufferSize, printPort);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
const sockaddr *operator *() const { return fAddress; }
|
const sockaddr *operator *() const { return fAddress; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ struct net_address_module_info {
|
|||||||
|
|
||||||
status_t (*print_address)(const sockaddr *address, char **buffer,
|
status_t (*print_address)(const sockaddr *address, char **buffer,
|
||||||
bool printPort);
|
bool printPort);
|
||||||
|
status_t (*print_address_buffer)(const sockaddr *address, char *buffer,
|
||||||
|
size_t bufferSize, bool printPort);
|
||||||
|
|
||||||
uint16 (*get_port)(const sockaddr *address);
|
uint16 (*get_port)(const sockaddr *address);
|
||||||
status_t (*set_port)(sockaddr *address, uint16 port);
|
status_t (*set_port)(sockaddr *address, uint16 port);
|
||||||
|
|||||||
@@ -251,35 +251,45 @@ ipv4_check_mask(const sockaddr *_mask)
|
|||||||
\return B_NO_MEMORY if the buffer could not be allocated
|
\return B_NO_MEMORY if the buffer could not be allocated
|
||||||
*/
|
*/
|
||||||
static status_t
|
static status_t
|
||||||
ipv4_print_address(const sockaddr *_address, char **_buffer, bool printPort)
|
ipv4_print_address_buffer(const sockaddr *_address, char *buffer,
|
||||||
|
size_t bufferSize, bool printPort)
|
||||||
{
|
{
|
||||||
const sockaddr_in *address = (const sockaddr_in *)_address;
|
const sockaddr_in *address = (const sockaddr_in *)_address;
|
||||||
|
|
||||||
if (_buffer == NULL)
|
if (buffer == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
char tmp[64];
|
|
||||||
|
|
||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
strcpy(tmp, "<none>");
|
strlcpy(buffer, "<none>", bufferSize);
|
||||||
else {
|
else {
|
||||||
unsigned int addr = ntohl(address->sin_addr.s_addr);
|
unsigned int addr = ntohl(address->sin_addr.s_addr);
|
||||||
|
|
||||||
if (printPort)
|
if (printPort)
|
||||||
sprintf(tmp, "%u.%u.%u.%u:%u", (addr >> 24) & 0xff,
|
snprintf(buffer, bufferSize, "%u.%u.%u.%u:%u",
|
||||||
(addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff,
|
(addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
|
||||||
ntohs(address->sin_port));
|
addr & 0xff, ntohs(address->sin_port));
|
||||||
else
|
else
|
||||||
sprintf(tmp, "%u.%u.%u.%u", (addr >> 24) & 0xff,
|
snprintf(buffer, bufferSize, "%u.%u.%u.%u", (addr >> 24) & 0xff,
|
||||||
(addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
|
(addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static status_t
|
||||||
|
ipv4_print_address(const sockaddr *_address, char **_buffer, bool printPort)
|
||||||
|
{
|
||||||
|
if (_buffer == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
char tmp[64];
|
||||||
|
ipv4_print_address_buffer(_address, tmp, sizeof(tmp), printPort);
|
||||||
|
|
||||||
*_buffer = strdup(tmp);
|
*_buffer = strdup(tmp);
|
||||||
if (*_buffer == NULL)
|
if (*_buffer == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,6 +436,7 @@ net_address_module_info gIPv4AddressModule = {
|
|||||||
ipv4_first_mask_bit,
|
ipv4_first_mask_bit,
|
||||||
ipv4_check_mask,
|
ipv4_check_mask,
|
||||||
ipv4_print_address,
|
ipv4_print_address,
|
||||||
|
ipv4_print_address_buffer,
|
||||||
ipv4_get_port,
|
ipv4_get_port,
|
||||||
ipv4_set_port,
|
ipv4_set_port,
|
||||||
ipv4_set_to,
|
ipv4_set_to,
|
||||||
|
|||||||
@@ -168,8 +168,7 @@ public:
|
|||||||
status_t ConnectEndpoint(UdpEndpoint *endpoint, const sockaddr *address);
|
status_t ConnectEndpoint(UdpEndpoint *endpoint, const sockaddr *address);
|
||||||
status_t UnbindEndpoint(UdpEndpoint *endpoint);
|
status_t UnbindEndpoint(UdpEndpoint *endpoint);
|
||||||
|
|
||||||
status_t ActivateEndpoint(UdpEndpoint *endpoint);
|
void DumpEndpoints() const;
|
||||||
status_t DeactivateEndpoint(UdpEndpoint *endpoint);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address);
|
status_t _BindEndpoint(UdpEndpoint *endpoint, const sockaddr *address);
|
||||||
@@ -220,6 +219,8 @@ public:
|
|||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|
||||||
|
static int DumpEndpoints(int argc, char *argv[]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UdpDomainSupport *_GetDomain(net_domain *domain, bool create);
|
UdpDomainSupport *_GetDomain(net_domain *domain, bool create);
|
||||||
|
|
||||||
@@ -337,6 +338,27 @@ UdpDomainSupport::UnbindEndpoint(UdpEndpoint *endpoint)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
UdpDomainSupport::DumpEndpoints() const
|
||||||
|
{
|
||||||
|
kprintf("-------- UDP Domain %p ---------\n", this);
|
||||||
|
kprintf("%10s %20s %20s %8s\n", "address", "local", "peer", "recv-q");
|
||||||
|
|
||||||
|
EndpointTable::Iterator it = fActiveEndpoints.GetIterator();
|
||||||
|
|
||||||
|
while (it.HasNext()) {
|
||||||
|
UdpEndpoint *endpoint = it.Next();
|
||||||
|
|
||||||
|
char localBuf[64], peerBuf[64];
|
||||||
|
endpoint->LocalAddress().AsString(localBuf, sizeof(localBuf), true);
|
||||||
|
endpoint->PeerAddress().AsString(peerBuf, sizeof(peerBuf), true);
|
||||||
|
|
||||||
|
kprintf("%p %20s %20s %8lu\n", endpoint, localBuf, peerBuf,
|
||||||
|
endpoint->AvailableData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
UdpDomainSupport::_BindEndpoint(UdpEndpoint *endpoint,
|
UdpDomainSupport::_BindEndpoint(UdpEndpoint *endpoint,
|
||||||
const sockaddr *address)
|
const sockaddr *address)
|
||||||
@@ -580,6 +602,18 @@ UdpEndpointManager::InitCheck() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
UdpEndpointManager::DumpEndpoints(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
UdpDomainList::Iterator it = sUdpEndpointManager->fDomains.GetIterator();
|
||||||
|
|
||||||
|
while (it.HasNext())
|
||||||
|
it.Next()->DumpEndpoints();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - inbound
|
// #pragma mark - inbound
|
||||||
|
|
||||||
|
|
||||||
@@ -1127,6 +1161,9 @@ init_udp()
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
goto err1;
|
goto err1;
|
||||||
|
|
||||||
|
add_debugger_command("udp_endpoints", UdpEndpointManager::DumpEndpoints,
|
||||||
|
"lists all open UDP endpoints");
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
err1:
|
err1:
|
||||||
@@ -1141,6 +1178,8 @@ static status_t
|
|||||||
uninit_udp()
|
uninit_udp()
|
||||||
{
|
{
|
||||||
TRACE_EPM("uninit_udp()");
|
TRACE_EPM("uninit_udp()");
|
||||||
|
remove_debugger_command("udp_endpoints",
|
||||||
|
UdpEndpointManager::DumpEndpoints);
|
||||||
delete sUdpEndpointManager;
|
delete sUdpEndpointManager;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user