/*
* UdpTable.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/08/22
#pragma once
#include <sol/net/MibTable.h>
#include <sol/Arg.h>
#include <sol/String.h>
namespace SOL {
class UdpTable :public MibTable {
/*
typedef struct _MIB_UDPTABLE {
DWORD dwNumEntries;
MIB_UDPROW table[ANY_SIZE];
}MIB_UDPTABLE, *PMIB_UDPTABLE;
*/
private:
PMIB_UDPTABLE table;
public:
UdpTable()
:table(NULL)
{
}
public:
~UdpTable()
{
clear();
}
public:
virtual bool getTable()
{
clear();
bool rc = false;
DWORD dwSize = 0;
if (GetUdpTable(NULL, &dwSize, FALSE)== ERROR_INSUFFICIENT_BUFFER) {
table = (PMIB_UDPTABLE)new char[dwSize];
DWORD r = NO_ERROR;
if ((r = GetUdpTable(table, &dwSize, FALSE)) == NO_ERROR) {
rc = true;
} else {
clear();
throw r;
}
}
return rc;
}
public:
void clear()
{
if (table) {
delete [] (char*)table;
table = NULL;
}
}
/*
typedef struct _MIB_UDPROW {
DWORD dwLocalAddr;
DWORD dwLocalPort;
}MIB_UDPROW, *PMIB_UDPROW;
*/
public:
virtual void display(MIB_UDPROW& table)
{
StringT<char> localIP;
getIPAddress(table.dwLocalAddr, localIP);
unsigned short localPort = getPort(table.dwLocalPort);
printf("UDP LocalIP=%s:%d\n",
(const char*)localIP,
localPort);
}
public:
virtual void display()
{
if (table == NULL) {
getTable();
}
if (table) {
for (int i = 0 ; i < (int)table->dwNumEntries; i++) {
display(table->table[i]);
printf("\n");
}
}
}
};
}
|