PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/libretroshare/src/upnp/upnputil.c

https://gitlab.com/g10h4ck/RetroShare
C | 589 lines | 451 code | 33 blank | 105 comment | 65 complexity | bc023cd5b519c5592cf400b17685bb2b MD5 | raw file
Possible License(s): 0BSD, GPL-2.0, AGPL-1.0
  1. //this file uses miniupnp
  2. //From https://github.com/miniupnp/miniupnp/blob/master/miniupnpc/upnpc.c
  3. #include "upnp/upnputil.h"
  4. #if MINIUPNPC_API_VERSION >= -4//1.0 2008/02/18
  5. #include <time.h>
  6. #endif
  7. /* protofix() checks if protocol is "UDP" or "TCP"
  8. * returns NULL if not */
  9. const char * protofix(const char * proto)
  10. {
  11. static const char proto_tcp[4] = { 'T', 'C', 'P', 0};
  12. static const char proto_udp[4] = { 'U', 'D', 'P', 0};
  13. int i, b;
  14. for(i=0, b=1; i<4; i++)
  15. b = b && ( (proto[i] == proto_tcp[i])
  16. || (proto[i] == (proto_tcp[i] | 32)) );
  17. if(b)
  18. return proto_tcp;
  19. for(i=0, b=1; i<4; i++)
  20. b = b && ( (proto[i] == proto_udp[i])
  21. || (proto[i] == (proto_udp[i] | 32)) );
  22. if(b)
  23. return proto_udp;
  24. return 0;
  25. }
  26. void DisplayInfos(struct UPNPUrls * urls,
  27. struct IGDdatas * data)
  28. {
  29. char externalIPAddress[40];
  30. char connectionType[64];
  31. char status[64];
  32. char lastconnerr[64];
  33. unsigned int uptime;
  34. unsigned int brUp, brDown;
  35. time_t timenow, timestarted;
  36. int r;
  37. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  38. const char * servicetype = data->first.servicetype;
  39. const char * servicetype_CIF = data->CIF.servicetype;
  40. #else
  41. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  42. const char * servicetype = data->servicetype;
  43. const char * servicetype_CIF = data->servicetype_CIF;
  44. #else
  45. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  46. #endif//>=-7
  47. #endif//>=-2
  48. #if MINIUPNPC_API_VERSION >= -3//1.0 2009/04/17
  49. if(UPNP_GetConnectionTypeInfo(urls->controlURL,
  50. servicetype,
  51. connectionType) != UPNPCOMMAND_SUCCESS)
  52. #else
  53. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  54. UPNP_GetConnectionTypeInfo(urls->controlURL, servicetype,
  55. connectionType);
  56. if(connectionType[0])
  57. #endif//>=-7
  58. #endif//>=-3
  59. printf("GetConnectionTypeInfo failed.\n");
  60. else
  61. printf("Connection Type : %s\n", connectionType);
  62. #if MINIUPNPC_API_VERSION >= -4//1.0 2008/02/18
  63. if(UPNP_GetStatusInfo(urls->controlURL, servicetype,
  64. status, &uptime, lastconnerr) != UPNPCOMMAND_SUCCESS)
  65. printf("GetStatusInfo failed.\n");
  66. else
  67. printf("Status : %s, uptime=%us, LastConnectionError : %s\n",
  68. status, uptime, lastconnerr);
  69. timenow = time(NULL);
  70. timestarted = timenow - uptime;
  71. printf(" Time started : %s", ctime(&timestarted));
  72. #else
  73. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  74. UPNP_GetStatusInfo(urls->controlURL, servicetype,
  75. status, &uptime, lastconnerr);
  76. printf("Status : %s, uptime=%u, LastConnectionError : %s\n",
  77. status, uptime, lastconnerr);
  78. #endif//>=-7
  79. #endif//>=-4
  80. #if MINIUPNPC_API_VERSION >= -4//1.0 2008/02/18
  81. if(UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF, servicetype_CIF,
  82. &brDown, &brUp) != UPNPCOMMAND_SUCCESS) {
  83. printf("GetLinkLayerMaxBitRates failed.\n");
  84. } else {
  85. printf("MaxBitRateDown : %u bps", brDown);
  86. if(brDown >= 1000000) {
  87. printf(" (%u.%u Mbps)", brDown / 1000000, (brDown / 100000) % 10);
  88. } else if(brDown >= 1000) {
  89. printf(" (%u Kbps)", brDown / 1000);
  90. }
  91. printf(" MaxBitRateUp %u bps", brUp);
  92. if(brUp >= 1000000) {
  93. printf(" (%u.%u Mbps)", brUp / 1000000, (brUp / 100000) % 10);
  94. } else if(brUp >= 1000) {
  95. printf(" (%u Kbps)", brUp / 1000);
  96. }
  97. printf("\n");
  98. }
  99. #else
  100. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  101. UPNP_GetLinkLayerMaxBitRates(urls->controlURL_CIF,
  102. servicetype_CIF,
  103. &brDown, &brUp);
  104. printf("MaxBitRateDown : %u bps MaxBitRateUp %u bps\n", brDown, brUp);
  105. #endif//>=-7
  106. #endif//>=-4
  107. #if MINIUPNPC_API_VERSION >= -5//1.0 2007/12/19
  108. r = UPNP_GetExternalIPAddress(urls->controlURL,
  109. servicetype,
  110. externalIPAddress);
  111. if(r != UPNPCOMMAND_SUCCESS) {
  112. printf("GetExternalIPAddress failed. (errorcode=%d)\n", r);
  113. } else {
  114. printf("ExternalIPAddress = %s\n", externalIPAddress);
  115. }
  116. #else
  117. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  118. UPNP_GetExternalIPAddress(urls->controlURL,
  119. servicetype,
  120. externalIPAddress);
  121. if(externalIPAddress[0])
  122. printf("ExternalIPAddress = %s\n", externalIPAddress);
  123. else
  124. printf("GetExternalIPAddress failed.\n");
  125. #endif//>=-7
  126. #endif//>=-4
  127. }
  128. void GetConnectionStatus(struct UPNPUrls * urls,
  129. struct IGDdatas * data)
  130. {
  131. unsigned int bytessent, bytesreceived, packetsreceived, packetssent;
  132. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  133. const char * servicetype_CIF = data->CIF.servicetype;
  134. #else
  135. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  136. const char * servicetype_CIF = data->servicetype_CIF;
  137. #else
  138. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  139. #endif//>=-7
  140. #endif//>=-2
  141. DisplayInfos(urls, data);
  142. bytessent = UPNP_GetTotalBytesSent(urls->controlURL_CIF, servicetype_CIF);
  143. bytesreceived = UPNP_GetTotalBytesReceived(urls->controlURL_CIF, servicetype_CIF);
  144. packetssent = UPNP_GetTotalPacketsSent(urls->controlURL_CIF, servicetype_CIF);
  145. packetsreceived = UPNP_GetTotalPacketsReceived(urls->controlURL_CIF, servicetype_CIF);
  146. printf("Bytes: Sent: %8u\tRecv: %8u\n", bytessent, bytesreceived);
  147. printf("Packets: Sent: %8u\tRecv: %8u\n", packetssent, packetsreceived);
  148. }
  149. void ListRedirections(struct UPNPUrls * urls,
  150. struct IGDdatas * data)
  151. {
  152. int r;
  153. int i = 0;
  154. char index[6];
  155. char intClient[40];
  156. char intPort[6];
  157. char extPort[6];
  158. char protocol[4];
  159. char desc[80];
  160. char enabled[6];
  161. char rHost[64];
  162. char duration[16];
  163. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  164. const char * servicetype = data->first.servicetype;
  165. #else
  166. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  167. const char * servicetype = data->servicetype;
  168. #else
  169. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  170. #endif//>=-7
  171. #endif//>=-2
  172. /*unsigned int num=0;
  173. UPNP_GetPortMappingNumberOfEntries(urls->controlURL, data->servicetype, &num);
  174. printf("PortMappingNumberOfEntries : %u\n", num);*/
  175. do {
  176. snprintf(index, 6, "%d", i);
  177. rHost[0] = '\0'; enabled[0] = '\0';
  178. duration[0] = '\0'; desc[0] = '\0';
  179. extPort[0] = '\0'; intPort[0] = '\0'; intClient[0] = '\0';
  180. r = UPNP_GetGenericPortMappingEntry(urls->controlURL,
  181. servicetype,
  182. index,
  183. extPort, intClient, intPort,
  184. protocol, desc, enabled,
  185. rHost, duration);
  186. if(r==0)
  187. printf("%02d - %s %5s->%s:%-5s"
  188. "\tenabled=%s leaseDuration=%s\n"
  189. " desc='%s' rHost='%s'\n",
  190. i, protocol, extPort, intClient, intPort,
  191. enabled, duration,
  192. desc, rHost);
  193. else
  194. printf("GetGenericPortMappingEntry() returned %d (%s)\n",
  195. r, strupnperror(r));
  196. i++;
  197. } while(r==0);
  198. }
  199. /* Test function
  200. * 1 - get connection type
  201. * 2 - get extenal ip address
  202. * 3 - Add port mapping
  203. * 4 - get this port mapping from the IGD */
  204. int SetRedirectAndTest(struct UPNPUrls * urls,
  205. struct IGDdatas * data,
  206. const char * iaddr,
  207. const char * iport,
  208. const char * eport,
  209. const char * proto,
  210. const char * leaseDuration,
  211. const char * description,
  212. int addAny)
  213. {
  214. char externalIPAddress[40];
  215. char intClient[40];
  216. char intPort[6];
  217. char reservedPort[6];
  218. char duration[16];
  219. int r;
  220. int ok = 1;
  221. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  222. const char * servicetype = data->first.servicetype;
  223. #else
  224. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  225. const char * servicetype = data->servicetype;
  226. #else
  227. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  228. #endif
  229. #endif
  230. if(!iaddr || !iport || !eport || !proto)
  231. {
  232. fprintf(stderr, "Wrong arguments\n");
  233. return 0;
  234. }
  235. proto = protofix(proto);
  236. if(!proto)
  237. {
  238. fprintf(stderr, "invalid protocol\n");
  239. return 0;
  240. }
  241. #if MINIUPNPC_API_VERSION >= -5//1.0 2007/12/19
  242. r = UPNP_GetExternalIPAddress(urls->controlURL,
  243. servicetype,
  244. externalIPAddress);
  245. if(r != UPNPCOMMAND_SUCCESS)
  246. printf("GetExternalIPAddress failed. (errorcode=%d)\n", r);
  247. else
  248. printf("ExternalIPAddress = %s\n", externalIPAddress);
  249. #else
  250. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  251. UPNP_GetExternalIPAddress(urls->controlURL,
  252. servicetype,
  253. externalIPAddress);
  254. if(externalIPAddress[0])
  255. printf("ExternalIPAddress = %s\n", externalIPAddress);
  256. else
  257. printf("GetExternalIPAddress failed.\n");
  258. #endif//>=-7
  259. #endif//>=-4
  260. #if MINIUPNPC_API_VERSION >= 11
  261. if (addAny) {
  262. r = UPNP_AddAnyPortMapping(urls->controlURL, data->first.servicetype,
  263. eport, iport, iaddr, description,
  264. proto, 0, leaseDuration, reservedPort);
  265. if(r==UPNPCOMMAND_SUCCESS)
  266. eport = reservedPort;
  267. else
  268. printf("AddAnyPortMapping(%s, %s, %s) failed with code %d (%s)\n",
  269. eport, iport, iaddr, r, strupnperror(r));
  270. } else
  271. #endif
  272. {
  273. #if MINIUPNPC_API_VERSION >= -1
  274. /* $Id: upnpcommands.h,v 1.30 2015/07/15 12:21:28 nanard Exp $ */
  275. /* $Id: upnpcommands.h,v 1.20 2011/02/15 11:13:22 nanard Exp $ */
  276. //UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
  277. // const char * extPort,
  278. // const char * inPort,
  279. // const char * inClient,
  280. // const char * desc,
  281. // const char * proto,
  282. // const char * remoteHost,
  283. // const char * leaseDuration);
  284. r = UPNP_AddPortMapping(urls->controlURL, servicetype,
  285. eport, iport, iaddr, NULL, proto, NULL, NULL);
  286. #else
  287. #if MINIUPNPC_API_VERSION >= -3 //1.0 2009/04/17
  288. /* $Id: upnpcommands.h,v 1.18 2010/06/09 10:59:09 nanard Exp $ */
  289. /* $Id: upnpcommands.h,v 1.17 2009/04/17 21:21:19 nanard Exp $ */
  290. //UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
  291. // const char * extPort,
  292. // const char * inPort,
  293. // const char * inClient,
  294. // const char * desc,
  295. // const char * proto,
  296. // const char * remoteHost);
  297. r = UPNP_AddPortMapping(urls->controlURL, servicetype,
  298. eport, iport, iaddr, NULL, proto, NULL);
  299. #else
  300. #if MINIUPNPC_API_VERSION >= -7//Before 1.0
  301. /* $Id: upnpcommands.h,v 1.14 2008/09/25 18:02:50 nanard Exp $ */
  302. /* $Id: upnpcommands.h,v 1.7 2006/07/09 12:00:54 nanard Exp $ */
  303. //UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
  304. // const char * extPort,
  305. // const char * inPort,
  306. // const char * inClient,
  307. // const char * desc,
  308. // const char * proto);
  309. r = UPNP_AddPortMapping(urls->controlURL, servicetype,
  310. eport, iport, iaddr, NULL, proto);
  311. #else
  312. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  313. #endif//>=-7
  314. #endif//>=-3
  315. #endif//>=-1
  316. #if MINIUPNPC_API_VERSION >= -5//2007/12/19
  317. if(r!=UPNPCOMMAND_SUCCESS){
  318. #else
  319. #if MINIUPNPC_API_VERSION >= -7//Before 1.0
  320. if(r==0){
  321. #else
  322. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  323. #endif//>=-7
  324. #endif//>=-5
  325. printf("AddPortMapping(%s, %s, %s) failed and returns %d\n", eport, iport, iaddr, r);
  326. //this seems to trigger for unknown reasons sometimes.
  327. //rely on Checking it afterwards...
  328. //should check IP address then!
  329. ok = 0;
  330. }
  331. }
  332. #if MINIUPNPC_API_VERSION >= 10//1.0 2006/09/04
  333. /* $Id: upnpcommands.h,v 1.30 2015/07/15 12:21:28 nanard Exp $ */
  334. /* $Id: upnpcommands.h,v 1.26 2014/01/31 13:18:26 nanard Exp $ */
  335. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  336. // const char * servicetype,
  337. // const char * extPort,
  338. // const char * proto,
  339. // const char * remoteHost,
  340. // char * intClient,
  341. // char * intPort,
  342. // char * desc,
  343. // char * enabled,
  344. // char * leaseDuration);
  345. r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  346. data->first.servicetype,
  347. eport, proto, NULL/*remoteHost*/,
  348. intClient, intPort, NULL/*desc*/,
  349. NULL/*enabled*/, duration);
  350. #else
  351. #if MINIUPNPC_API_VERSION >= 6//1.0 2006/09/04
  352. /* $Id: upnpcommands.h,v 1.24 2012/03/05 19:42:47 nanard Exp $ */
  353. /* $Id: upnpcommands.h,v 1.22 2011/03/14 13:36:01 nanard Exp $ */
  354. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  355. // const char * servicetype,
  356. // const char * extPort,
  357. // const char * proto,
  358. // char * intClient,
  359. // char * intPort,
  360. // char * desc,
  361. // char * enabled,
  362. // char * leaseDuration);
  363. r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  364. data->first.servicetype,
  365. eport, proto,
  366. intClient, intPort, NULL/*desc*/,
  367. NULL/*enabled*/, duration);
  368. #else
  369. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  370. /* $Id: upnpcommands.h,v 1.20 2011/02/15 11:13:22 nanard Exp $ */
  371. /* $Id: upnpcommands.h,v 1.7 2006/07/09 12:00:54 nanard Exp $ */
  372. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  373. // const char * servicetype,
  374. // const char * extPort,
  375. // const char * proto,
  376. // char * intClient,
  377. // char * intPort);
  378. UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  379. servicetype,
  380. eport,
  381. proto,
  382. intClient,
  383. intPort);
  384. if(intClient[0]) r = UPNPCOMMAND_SUCCESS;
  385. #endif//>=-7
  386. #endif//>=6
  387. #endif//>=10
  388. if(r!=UPNPCOMMAND_SUCCESS) {
  389. printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n",
  390. r, strupnperror(r));
  391. ok = 0;
  392. } else if(intClient[0]) {
  393. printf("InternalIP:Port = %s:%s\n", intClient, intPort);
  394. printf("external %s:%s %s is redirected to internal %s:%s (duration=%s)\n",
  395. externalIPAddress, eport, proto, intClient, intPort, duration);
  396. }
  397. if ((strcmp(iaddr, intClient) != 0) || (strcmp(iport, intPort) != 0))
  398. {
  399. printf("PortMappingEntry to wrong location! FAILED\n");
  400. printf("IP1:\"%s\"\n", iaddr);
  401. printf("IP2:\"%s\"\n", intClient);
  402. printf("PORT1:\"%s\"\n", iport);
  403. printf("PORT2:\"%s\"\n", intPort);
  404. ok = 0;
  405. }
  406. if (ok)
  407. {
  408. printf("uPnP Forward/Mapping Succeeded\n");
  409. }
  410. else
  411. {
  412. printf("uPnP Forward/Mapping Failed\n");
  413. }
  414. return ok;
  415. }
  416. int TestRedirect(struct UPNPUrls * urls,
  417. struct IGDdatas * data,
  418. const char * iaddr,
  419. const char * iport,
  420. const char * eport,
  421. const char * proto)
  422. {
  423. char externalIPAddress[40];
  424. char intClient[40];
  425. char intPort[6];
  426. char duration[16];
  427. int r = 0;
  428. int ok = 1;
  429. if(!iaddr || !iport || !eport || !proto)
  430. {
  431. fprintf(stderr, "Wrong arguments\n");
  432. return 0;
  433. }
  434. proto = protofix(proto);
  435. if(!proto)
  436. {
  437. fprintf(stderr, "invalid protocol\n");
  438. return 0;
  439. }
  440. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  441. const char * servicetype = data->first.servicetype;
  442. #else
  443. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  444. const char * servicetype = data->servicetype;
  445. #else
  446. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  447. #endif
  448. #endif
  449. #if MINIUPNPC_API_VERSION >= 10//1.0 2006/09/04
  450. /* $Id: upnpcommands.h,v 1.30 2015/07/15 12:21:28 nanard Exp $ */
  451. /* $Id: upnpcommands.h,v 1.26 2014/01/31 13:18:26 nanard Exp $ */
  452. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  453. // const char * servicetype,
  454. // const char * extPort,
  455. // const char * proto,
  456. // const char * remoteHost,
  457. // char * intClient,
  458. // char * intPort,
  459. // char * desc,
  460. // char * enabled,
  461. // char * leaseDuration);
  462. r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  463. servicetype,
  464. eport, proto, NULL/*remoteHost*/,
  465. intClient, intPort, NULL/*desc*/,
  466. NULL/*enabled*/, duration);
  467. #else
  468. #if MINIUPNPC_API_VERSION >= 6//1.0 2006/09/04
  469. /* $Id: upnpcommands.h,v 1.24 2012/03/05 19:42:47 nanard Exp $ */
  470. /* $Id: upnpcommands.h,v 1.22 2011/03/14 13:36:01 nanard Exp $ */
  471. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  472. // const char * servicetype,
  473. // const char * extPort,
  474. // const char * proto,
  475. // char * intClient,
  476. // char * intPort,
  477. // char * desc,
  478. // char * enabled,
  479. // char * leaseDuration);
  480. r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  481. servicetype,
  482. eport, proto,
  483. intClient, intPort, NULL/*desc*/,
  484. NULL/*enabled*/, duration);
  485. #else
  486. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  487. /* $Id: upnpcommands.h,v 1.20 2011/02/15 11:13:22 nanard Exp $ */
  488. /* $Id: upnpcommands.h,v 1.7 2006/07/09 12:00:54 nanard Exp $ */
  489. //UPNP_GetSpecificPortMappingEntry(const char * controlURL,
  490. // const char * servicetype,
  491. // const char * extPort,
  492. // const char * proto,
  493. // char * intClient,
  494. // char * intPort);
  495. UPNP_GetSpecificPortMappingEntry(urls->controlURL,
  496. servicetype,
  497. eport,
  498. proto,
  499. intClient,
  500. intPort);
  501. if(intClient[0]) r = UPNPCOMMAND_SUCCESS;
  502. #endif//>=-7
  503. #endif//>=6
  504. #endif//>=10
  505. if(r!=UPNPCOMMAND_SUCCESS) {
  506. printf("GetSpecificPortMappingEntry() failed with code %d (%s)\n",
  507. r, strupnperror(r));
  508. ok = 0;
  509. } else if(intClient[0]) {
  510. printf("uPnP Check: InternalIP:Port = %s:%s\n", intClient, intPort);
  511. printf("external %s:%s %s is redirected to internal %s:%s (duration=%s)\n",
  512. externalIPAddress, eport, proto, intClient, intPort, duration);
  513. }
  514. if (ok)
  515. {
  516. printf("uPnP Check: uPnP Forward/Mapping still Active\n");
  517. }
  518. else
  519. {
  520. printf("uPnP Check: Forward/Mapping has been Dropped\n");
  521. }
  522. return ok;
  523. }
  524. int
  525. RemoveRedirect(struct UPNPUrls * urls,
  526. struct IGDdatas * data,
  527. const char * eport,
  528. const char * proto)
  529. {
  530. if(!proto || !eport)
  531. {
  532. fprintf(stderr, "invalid arguments\n");
  533. return 0;
  534. }
  535. proto = protofix(proto);
  536. if(!proto)
  537. {
  538. fprintf(stderr, "protocol invalid\n");
  539. return 0;
  540. }
  541. #if MINIUPNPC_API_VERSION >= -2//1.4 2010/12/09
  542. UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, NULL);
  543. #else
  544. #if MINIUPNPC_API_VERSION >= -3//1.3 2009/04/17
  545. UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto, NULL);
  546. #else
  547. #if MINIUPNPC_API_VERSION >= -7//1.0 2006/09/04
  548. UPNP_DeletePortMapping(urls->controlURL, data->servicetype, eport, proto);
  549. #else
  550. #error MINIUPNPC_API_VERSION is not defined. You may define one follow miniupnpc library version
  551. #endif//>= -7
  552. #endif//>= -3
  553. #endif//>= -2
  554. return 1;
  555. }
  556. /* EOF */