From 561f2657319e68b7a952e6976df2c2e2cdd30f2e Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Mon, 30 May 2016 00:33:03 +0200 Subject: [PATCH] Fixed help message. Fixed error: not copying inet_ntoa buffer. --- check_upnp/check_upnp.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/check_upnp/check_upnp.cpp b/check_upnp/check_upnp.cpp index 9c82ac3..d3baa68 100755 --- a/check_upnp/check_upnp.cpp +++ b/check_upnp/check_upnp.cpp @@ -14,7 +14,7 @@ void printHelp(bool longVersion) if(longVersion) { printVersion(); - cout << "Check CS:GO DS instance." << endl << endl; + cout << "Check UPnP server" << endl << endl; printHelp(false); cout << "Options:" << endl; cout << " -h" << endl; @@ -22,12 +22,10 @@ void printHelp(bool longVersion) cout << " -V" << endl; cout << " Print version information" << endl; cout << " -H HOSTADDRESS" << endl; - cout << " Host where the Source DS is running" << endl; - cout << " -p" << endl; - cout << " Port where the Source DS is listening. Default is 27015." << endl << endl; + cout << " Host where the UPnP server is running" << endl; return; } - cout << "Usage: " << endl << "check_csgo [-hV] -H HOSTADDRESS [-p PORT]" << endl << endl; + cout << "Usage: " << endl << "check_upnp [-hV] -H HOSTADDRESS" << endl << endl; } int check_upnp(char *hostname, string *serverinfo) @@ -47,15 +45,23 @@ int check_upnp(char *hostname, string *serverinfo) return 3; } addr_list = (struct in_addr **) he->h_addr_list; - char *targetIP = inet_ntoa(*addr_list[0]); + char targetIP[16]; + strcpy(targetIP,inet_ntoa(*addr_list[0])); setupSocket(1900,(char*)"239.255.255.250",host,timeout,&si,&s); memset(buffer,0x00,MAX_UDP+1); char *discover = (char*) "M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 5\r\nST: urn:schemas-upnp-org:device:MediaServer:1\r\n\r\n"; sendMsg(s,discover,strlen(discover),&si); + int recvstatus; while(true) { - recvMsg(s, buffer, MAX_UDP, &si); + recvstatus = recvMsg(s, buffer, MAX_UDP, &si); + if(recvstatus == -1) + { + *serverinfo = "No response"; + return 2; + } + char *sourceIP = inet_ntoa(si.sin_addr); if(!strcmp(sourceIP,targetIP)) { -- libgit2 0.22.2