-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathupnpigddump.c
110 lines (89 loc) · 3.47 KB
/
upnpigddump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/************************************************************
*
* mUPnP for C
*
* Copyright (C) Satoshi Konno 2008
*
* File: upnpigddump.c
*
* Revision:
* 08/05/24
* - first release.
*
************************************************************/
#include <mupnp/upnp.h>
#define UPNPAVDUMP_IGD_DEVICETYPE "urn:schemas-upnp-org:device:InternetGatewayDevice:1"
#define UPNPAVDUMP_IGD_WANIPCON_SERVICETYPE "urn:schemas-upnp-org:service:WANIPConnection:1"
#define UPNPAVDUMP_IGD_WANCOMIFCFG_SERVICETYPE "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
/////////////////////////////////////////////////////////////////////////////////
// PrintIGDInfo
/////////////////////////////////////////////////////////////////////////////////
void PrintIGDInfo(mUpnpDevice* dev, int igdNum)
{
mUpnpService* ipConService;
mUpnpAction* extIpAddrAction;
mUpnpService* wanComIfCfgService;
mUpnpAction* totalBytesSentAction;
mUpnpAction* totalBytesRecvAction;
if (!mupnp_device_isdevicetype(dev, UPNPAVDUMP_IGD_DEVICETYPE))
return;
printf("[%d] : %s\n", igdNum, mupnp_device_getfriendlyname(dev));
ipConService = mupnp_device_getservicebytype(dev, UPNPAVDUMP_IGD_WANIPCON_SERVICETYPE);
if (ipConService) {
extIpAddrAction = mupnp_service_getactionbyname(ipConService, "GetExternalIPAddress");
if (extIpAddrAction) {
if (mupnp_action_post(extIpAddrAction))
printf(" GetExternalIPAddress = %s\n", mupnp_action_getargumentvaluebyname(extIpAddrAction, "NewExternalIPAddress"));
}
}
wanComIfCfgService = mupnp_device_getservicebytype(dev, UPNPAVDUMP_IGD_WANCOMIFCFG_SERVICETYPE);
if (wanComIfCfgService) {
totalBytesSentAction = mupnp_service_getactionbyname(ipConService, "GetTotalBytesSent");
if (totalBytesSentAction) {
if (mupnp_action_post(totalBytesSentAction))
printf(" GetTotalBytesSent = %s\n", mupnp_action_getargumentvaluebyname(totalBytesSentAction, "NewTotalBytesSent"));
}
totalBytesRecvAction = mupnp_service_getactionbyname(ipConService, "GetTotalBytesReceived");
if (totalBytesRecvAction) {
if (mupnp_action_post(totalBytesRecvAction))
printf(" GetTotalBytesSent = %s\n", mupnp_action_getargumentvaluebyname(totalBytesRecvAction, "NewTotalBytesReceived"));
}
}
}
/////////////////////////////////////////////////////////////////////////////////
// PrintIGDInfos
/////////////////////////////////////////////////////////////////////////////////
void PrintIGDInfos(mUpnpControlPoint* ctrlPoint)
{
mUpnpDevice* dev;
int igdNum;
igdNum = 0;
for (dev = mupnp_controlpoint_getdevices(ctrlPoint); dev != NULL; dev = mupnp_device_next(dev)) {
if (mupnp_device_isdevicetype(dev, UPNPAVDUMP_IGD_DEVICETYPE))
PrintIGDInfo(dev, ++igdNum);
}
if (igdNum <= 0)
printf("IGD is not found !!\n");
}
/////////////////////////////////////////////////////////////////////////////////
// main
/////////////////////////////////////////////////////////////////////////////////
#if defined(TENGINE)
MBEG
#else
int main(int argc, char* argv[])
#endif
{
mUpnpControlPoint* ctrlPoint;
ctrlPoint = mupnp_controlpoint_new();
if (!mupnp_controlpoint_start(ctrlPoint)) {
printf("Couldn't start this control point !!");
exit(1);
}
mupnp_controlpoint_search(ctrlPoint, MUPNP_ST_ROOT_DEVICE);
mupnp_sleep(mupnp_controlpoint_getssdpsearchmx(ctrlPoint) * 1000);
PrintIGDInfos(ctrlPoint);
mupnp_controlpoint_stop(ctrlPoint);
mupnp_controlpoint_delete(ctrlPoint);
return (0);
}