Commit 561f2657319e68b7a952e6976df2c2e2cdd30f2e

Authored by Imanol-Mikel Barba Sabariego
1 parent a0960c84

Fixed help message.

Fixed error: not copying inet_ntoa buffer.
Showing 1 changed file with 13 additions and 7 deletions
check_upnp/check_upnp.cpp
... ... @@ -14,7 +14,7 @@ void printHelp(bool longVersion)
14 14 if(longVersion)
15 15 {
16 16 printVersion();
17   - cout << "Check CS:GO DS instance." << endl << endl;
  17 + cout << "Check UPnP server" << endl << endl;
18 18 printHelp(false);
19 19 cout << "Options:" << endl;
20 20 cout << " -h" << endl;
... ... @@ -22,12 +22,10 @@ void printHelp(bool longVersion)
22 22 cout << " -V" << endl;
23 23 cout << " Print version information" << endl;
24 24 cout << " -H HOSTADDRESS" << endl;
25   - cout << " Host where the Source DS is running" << endl;
26   - cout << " -p" << endl;
27   - cout << " Port where the Source DS is listening. Default is 27015." << endl << endl;
  25 + cout << " Host where the UPnP server is running" << endl;
28 26 return;
29 27 }
30   - cout << "Usage: " << endl << "check_csgo [-hV] -H HOSTADDRESS [-p PORT]" << endl << endl;
  28 + cout << "Usage: " << endl << "check_upnp [-hV] -H HOSTADDRESS" << endl << endl;
31 29 }
32 30  
33 31 int check_upnp(char *hostname, string *serverinfo)
... ... @@ -47,15 +45,23 @@ int check_upnp(char *hostname, string *serverinfo)
47 45 return 3;
48 46 }
49 47 addr_list = (struct in_addr **) he->h_addr_list;
50   - char *targetIP = inet_ntoa(*addr_list[0]);
  48 + char targetIP[16];
  49 + strcpy(targetIP,inet_ntoa(*addr_list[0]));
51 50  
52 51 setupSocket(1900,(char*)"239.255.255.250",host,timeout,&si,&s);
53 52 memset(buffer,0x00,MAX_UDP+1);
54 53 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";
55 54 sendMsg(s,discover,strlen(discover),&si);
  55 + int recvstatus;
56 56 while(true)
57 57 {
58   - recvMsg(s, buffer, MAX_UDP, &si);
  58 + recvstatus = recvMsg(s, buffer, MAX_UDP, &si);
  59 + if(recvstatus == -1)
  60 + {
  61 + *serverinfo = "No response";
  62 + return 2;
  63 + }
  64 +
59 65 char *sourceIP = inet_ntoa(si.sin_addr);
60 66 if(!strcmp(sourceIP,targetIP))
61 67 {
... ...