* Use MiniSSDPd if it is available. (Thanks Thomas Bernard)

This commit is contained in:
Justin Maggard
2011-07-22 23:03:38 +00:00
parent a818f5db33
commit 0b3295b701
8 changed files with 87 additions and 4 deletions

View File

@ -32,6 +32,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
@ -44,6 +45,7 @@
#include "upnpreplyparse.h"
#include "getifaddr.h"
#include "minissdp.h"
#include "codelength.h"
#include "utils.h"
#include "log.h"
@ -52,7 +54,7 @@
#define SSDP_MCAST_ADDR ("239.255.255.250")
static int
AddMulticastMembership(int s, in_addr_t ifaddr/*const char * ifaddr*/)
AddMulticastMembership(int s, in_addr_t ifaddr)
{
struct ip_mreq imr; /* Ip multicast membership */
@ -70,6 +72,8 @@ AddMulticastMembership(int s, in_addr_t ifaddr/*const char * ifaddr*/)
return 0;
}
/* Open and configure the socket listening for
* SSDP udp packets sent on 239.255.255.250 port 1900 */
int
OpenAndConfSSDPReceiveSocket()
{
@ -242,9 +246,9 @@ SendSSDPAnnounce2(int s, struct sockaddr_in sockname, int st_no,
{
int l, n;
char buf[512];
/* TODO :
/*
* follow guideline from document "UPnP Device Architecture 1.0"
* put in uppercase.
* uppercase is recommended.
* DATE: is recommended
* SERVER: OS/ver UPnP/1.0 minidlna/1.0
* - check what to put in the 'Cache-Control' header
@ -742,3 +746,62 @@ SendSSDPGoodbye(int * sockets, int n_sockets)
}
return 0;
}
/* SubmitServicesToMiniSSDPD() :
* register services offered by MiniUPnPd to a running instance of
* MiniSSDPd */
int
SubmitServicesToMiniSSDPD(const char * host, unsigned short port) {
struct sockaddr_un addr;
int s;
unsigned char buffer[2048];
char strbuf[256];
unsigned char * p;
int i, l;
s = socket(AF_UNIX, SOCK_STREAM, 0);
if(s < 0) {
DPRINTF(E_ERROR, L_SSDP, "socket(unix): %s", strerror(errno));
return -1;
}
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, minissdpdsocketpath, sizeof(addr.sun_path));
if(connect(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
DPRINTF(E_ERROR, L_SSDP, "connect(\"%s\"): %s",
minissdpdsocketpath, strerror(errno));
return -1;
}
for(i = 0; known_service_types[i]; i++) {
buffer[0] = 4;
p = buffer + 1;
l = (int)strlen(known_service_types[i]);
if(i > 0)
l++;
CODELENGTH(l, p);
memcpy(p, known_service_types[i], l);
if(i > 0)
p[l-1] = '1';
p += l;
l = snprintf(strbuf, sizeof(strbuf), "%s::%s%s",
uuidvalue, known_service_types[i], (i==0)?"":"1");
CODELENGTH(l, p);
memcpy(p, strbuf, l);
p += l;
l = (int)strlen(MINIDLNA_SERVER_STRING);
CODELENGTH(l, p);
memcpy(p, MINIDLNA_SERVER_STRING, l);
p += l;
l = snprintf(strbuf, sizeof(strbuf), "http://%s:%u" ROOTDESC_PATH,
host, (unsigned int)port);
CODELENGTH(l, p);
memcpy(p, strbuf, l);
p += l;
if(write(s, buffer, p - buffer) < 0) {
DPRINTF(E_ERROR, L_SSDP, "write(): %s", strerror(errno));
return -1;
}
}
close(s);
return 0;
}