miniupnpd 1.9 (20160113)
[tomato.git] / release / src / router / miniupnpd / testssdppktgen.c
blob7f62daba40967a9bd88104ad215411f38a3e9a71
1 /* $Id: testssdppktgen.c,v 1.1 2015/10/26 16:54:31 nanard Exp $ */
2 #include <stdio.h>
3 #include <syslog.h>
4 #include <time.h>
6 #include "config.h"
7 #include "miniupnpdpath.h"
8 #include "upnphttp.h"
9 #include "macros.h"
11 #define SSDP_PORT 1900
13 char uuidvalue_igd[] = "uuid:12345678-0000-0000-0000-000000abcd01";
14 unsigned upnp_bootid;
15 unsigned upnp_configid;
17 static int
18 MakeSSDPPacket(const char * dest_str,
19 const char * host, unsigned short http_port,
20 #ifdef ENABLE_HTTPS
21 unsigned short https_port,
22 #endif
23 const char * nt, const char * suffix,
24 const char * usn1, const char * usn2, const char * usn3,
25 unsigned int lifetime)
27 char bufr[SSDP_PACKET_MAX_LEN];
28 int l;
30 l = snprintf(bufr, sizeof(bufr),
31 "NOTIFY * HTTP/1.1\r\n"
32 "HOST: %s:%d\r\n"
33 "CACHE-CONTROL: max-age=%u\r\n"
34 "LOCATION: http://%s:%u" ROOTDESC_PATH "\r\n"
35 #ifdef ENABLE_HTTPS
36 "SECURELOCATION.UPNP.ORG: https://%s:%u" ROOTDESC_PATH "\r\n"
37 #endif
38 "SERVER: " MINIUPNPD_SERVER_STRING "\r\n"
39 "NT: %s%s\r\n"
40 "USN: %s%s%s%s\r\n"
41 "NTS: ssdp:alive\r\n"
42 "OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n" /* UDA v1.1 */
43 "01-NLS: %u\r\n" /* same as BOOTID field. UDA v1.1 */
44 "BOOTID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
45 "CONFIGID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
46 "\r\n",
47 dest_str, SSDP_PORT, /* HOST: */
48 lifetime, /* CACHE-CONTROL: */
49 host, (unsigned int)http_port, /* LOCATION: */
50 #ifdef ENABLE_HTTPS
51 host, (unsigned int)https_port, /* SECURE-LOCATION: */
52 #endif
53 nt, suffix, /* NT: */
54 usn1, usn2, usn3, suffix, /* USN: */
55 upnp_bootid, /* 01-NLS: */
56 upnp_bootid, /* BOOTID.UPNP.ORG: */
57 upnp_configid ); /* CONFIGID.UPNP.ORG: */
58 if(l<0) {
59 syslog(LOG_ERR, "%s: snprintf error", "MakeSSDPPacket()");
60 return -1;
61 } else if((unsigned int)l >= sizeof(bufr)) {
62 syslog(LOG_WARNING, "%s: truncated output (%u>=%u)",
63 "MakeSSDPPacket()", (unsigned)l, (unsigned)sizeof(bufr));
64 l = sizeof(bufr) - 1;
65 return -1;
67 return 0;
71 int main(int argc, char * * argv)
73 int r;
74 UNUSED(argc); UNUSED(argv);
76 openlog("testssdppktgen", LOG_CONS|LOG_PERROR, LOG_USER);
77 upnp_bootid = (unsigned)time(NULL);
78 upnp_configid = 1234567890;
79 r = MakeSSDPPacket("123.456.789.123", "222.222.222.222", 12345,
80 #ifdef ENABLE_HTTPS
81 54321,
82 #endif /* ENABLE_HTTPS */
83 "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:", "1",
84 uuidvalue_igd, "", "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:",
85 1234567890);
86 if(r < 0) return 1;
87 #ifdef ENABLE_IPV6
88 r = MakeSSDPPacket("[1234:5678:abcd:ef00:1234:5678:abcd:ef00]",
89 "[1000:2000:3000:4000:5000:6000:7000:8000]", 12345,
90 #ifdef ENABLE_HTTPS
91 54321,
92 #endif /* ENABLE_HTTPS */
93 "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:", "1",
94 uuidvalue_igd, "", "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:",
95 1234567890);
96 if(r < 0) return 1;
97 #endif /* ENABLE_IPV6 */
98 return 0;