From 33fd01882816576d0aac9e5aebc2581018cd08ae Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 8 Jan 2018 18:04:57 -0800 Subject: [PATCH] minissdp: Delay before answering ssdp:all requests With some device combinations, our responses may be lost if we don't delay for some time. --- minissdp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/minissdp.c b/minissdp.c index 9147977..74eef3c 100644 --- a/minissdp.c +++ b/minissdp.c @@ -204,9 +204,10 @@ static const char * const known_service_types[] = }; static void -_usleep(long usecs) +_usleep(long min, long max) { struct timespec sleep_time; + long usecs = min + rand() / (RAND_MAX / (max - min + 1) + 1); sleep_time.tv_sec = 0; sleep_time.tv_nsec = usecs * 1000; @@ -278,7 +279,7 @@ SendSSDPNotifies(int s, const char *host, unsigned short port, for (dup = 0; dup < 2; dup++) { if (dup) - _usleep(200000); + _usleep(150000, 250000); i = 0; while (known_service_types[i]) { @@ -722,7 +723,7 @@ ProcessSSDPRequest(int s, unsigned short port) if (l != st_len) break; } - _usleep(random()>>20); + _usleep(13000, 20000); SendSSDPResponse(s, sendername, i, host, port, len_r); return; @@ -731,6 +732,7 @@ ProcessSSDPRequest(int s, unsigned short port) /* strlen("ssdp:all") == 8 */ if ((st_len == 8) && (memcmp(st, "ssdp:all", 8) == 0)) { + _usleep(13000, 30000); for (i=0; known_service_types[i]; i++) { l = strlen(known_service_types[i]);