"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "minissdp.c" between
minidlna-1.2.0.tar.gz and minidlna-1.2.1.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

minissdp.c  (minidlna-1.2.0):minissdp.c  (minidlna-1.2.1)
skipping to change at line 116 skipping to change at line 116
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0) if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)) < 0)
DPRINTF(E_WARN, L_SSDP, "setsockopt(udp, SO_REUSEADDR): %s\n", st rerror(errno)); DPRINTF(E_WARN, L_SSDP, "setsockopt(udp, SO_REUSEADDR): %s\n", st rerror(errno));
#ifdef __linux__ #ifdef __linux__
if (setsockopt(s, IPPROTO_IP, IP_PKTINFO, &i, sizeof(i)) < 0) if (setsockopt(s, IPPROTO_IP, IP_PKTINFO, &i, sizeof(i)) < 0)
DPRINTF(E_WARN, L_SSDP, "setsockopt(udp, IP_PKTINFO): %s\n", stre rror(errno)); DPRINTF(E_WARN, L_SSDP, "setsockopt(udp, IP_PKTINFO): %s\n", stre rror(errno));
#endif #endif
memset(&sockname, 0, sizeof(struct sockaddr_in)); memset(&sockname, 0, sizeof(struct sockaddr_in));
sockname.sin_family = AF_INET; sockname.sin_family = AF_INET;
sockname.sin_port = htons(SSDP_PORT); sockname.sin_port = htons(SSDP_PORT);
#ifdef __linux__
/* NOTE: Binding a socket to a UDP multicast address means, that we just want /* NOTE: Binding a socket to a UDP multicast address means, that we just want
* to receive datagramms send to this multicast address. * to receive datagramms send to this multicast address.
* To specify the local nics we want to use we have to use setsockopt, * To specify the local nics we want to use we have to use setsockopt,
* see AddMulticastMembership(...). */ * see AddMulticastMembership(...). */
sockname.sin_addr.s_addr = inet_addr(SSDP_MCAST_ADDR); sockname.sin_addr.s_addr = inet_addr(SSDP_MCAST_ADDR);
#else
/* NOTE: Binding to SSDP_MCAST_ADDR on Darwin & *BSD causes NOTIFY replie
s are
* sent from SSDP_MCAST_ADDR what forces some clients to ignore subsequen
t
* unsolicited NOTIFY packets from the real interface address. */
sockname.sin_addr.s_addr = htonl(INADDR_ANY);
#endif
if (bind(s, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in)) < 0 ) if (bind(s, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in)) < 0 )
{ {
DPRINTF(E_ERROR, L_SSDP, "bind(udp): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "bind(udp): %s\n", strerror(errno));
close(s); close(s);
return -1; return -1;
} }
return s; return s;
} }
/* open the UDP socket used to send SSDP notifications to /* open the UDP socket used to send SSDP notifications to
* the multicast group reserved for them */ * the multicast group reserved for them */
int int
OpenAndConfSSDPNotifySocket(struct lan_addr_s *iface) OpenAndConfSSDPNotifySocket(struct lan_addr_s *iface)
{ {
int s; int s;
unsigned char loopchar = 0; unsigned char loopchar = 0;
int bcast = 1;
uint8_t ttl = 4; uint8_t ttl = 4;
struct in_addr mc_if; struct in_addr mc_if;
struct sockaddr_in sockname; struct sockaddr_in sockname;
s = socket(PF_INET, SOCK_DGRAM, 0); s = socket(PF_INET, SOCK_DGRAM, 0);
if (s < 0) if (s < 0)
{ {
DPRINTF(E_ERROR, L_SSDP, "socket(udp_notify): %s\n", strerror(err no)); DPRINTF(E_ERROR, L_SSDP, "socket(udp_notify): %s\n", strerror(err no));
return -1; return -1;
} }
skipping to change at line 169 skipping to change at line 175
if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, (char *)&mc_if, sizeof(mc_ if)) < 0) if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, (char *)&mc_if, sizeof(mc_ if)) < 0)
{ {
DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp_notify, IP_MULTICAST_IF) : %s\n", strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp_notify, IP_MULTICAST_IF) : %s\n", strerror(errno));
close(s); close(s);
return -1; return -1;
} }
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)); setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &bcast, sizeof(bcast)) < 0)
{
DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp_notify, SO_BROADCAST): %
s\n", strerror(errno));
close(s);
return -1;
}
memset(&sockname, 0, sizeof(struct sockaddr_in)); memset(&sockname, 0, sizeof(struct sockaddr_in));
sockname.sin_family = AF_INET; sockname.sin_family = AF_INET;
sockname.sin_addr.s_addr = iface->addr.s_addr; sockname.sin_addr.s_addr = iface->addr.s_addr;
if (bind(s, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in)) < 0 ) if (bind(s, (struct sockaddr *)&sockname, sizeof(struct sockaddr_in)) < 0 )
{ {
DPRINTF(E_ERROR, L_SSDP, "bind(udp_notify): %s\n", strerror(errno )); DPRINTF(E_ERROR, L_SSDP, "bind(udp_notify): %s\n", strerror(errno ));
close(s); close(s);
return -1; return -1;
} }
skipping to change at line 221 skipping to change at line 220
sleep_time.tv_sec = 0; sleep_time.tv_sec = 0;
sleep_time.tv_nsec = usecs * 1000; sleep_time.tv_nsec = usecs * 1000;
nanosleep(&sleep_time, NULL); nanosleep(&sleep_time, NULL);
} }
/* not really an SSDP "announce" as it is the response /* not really an SSDP "announce" as it is the response
* to a SSDP "M-SEARCH" */ * to a SSDP "M-SEARCH" */
static void static void
SendSSDPResponse(int s, struct sockaddr_in sockname, int st_no, SendSSDPResponse(int s, struct sockaddr_in sockname, int st_no,
const char *host, unsigned short port) const char *host, unsigned short port, socklen_t len_r)
{ {
int l, n; int l, n;
char buf[512]; char buf[512];
char tmstr[30]; char tmstr[30];
time_t tm = time(NULL); time_t tm = time(NULL);
/* /*
* follow guideline from document "UPnP Device Architecture 1.0" * follow guideline from document "UPnP Device Architecture 1.0"
* uppercase is recommended. * uppercase is recommended.
* DATE: is recommended * DATE: is recommended
skipping to change at line 259 skipping to change at line 258
(st_no > 1 ? "1" : ""), (st_no > 1 ? "1" : ""),
uuidvalue, uuidvalue,
(st_no > 0 ? "::" : ""), (st_no > 0 ? "::" : ""),
(st_no > 0 ? known_service_types[st_no] : ""), (st_no > 0 ? known_service_types[st_no] : ""),
(st_no > 1 ? "1" : ""), (st_no > 1 ? "1" : ""),
host, (unsigned int)port); host, (unsigned int)port);
DPRINTF(E_DEBUG, L_SSDP, "Sending M-SEARCH response to %s:%d ST: %s\n", DPRINTF(E_DEBUG, L_SSDP, "Sending M-SEARCH response to %s:%d ST: %s\n",
inet_ntoa(sockname.sin_addr), ntohs(sockname.sin_port), inet_ntoa(sockname.sin_addr), ntohs(sockname.sin_port),
known_service_types[st_no]); known_service_types[st_no]);
n = sendto(s, buf, l, 0, n = sendto(s, buf, l, 0,
(struct sockaddr *)&sockname, sizeof(struct sockaddr_in) ); (struct sockaddr *)&sockname, len_r);
if (n < 0) if (n < 0)
DPRINTF(E_ERROR, L_SSDP, "sendto(udp): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "sendto(udp): %s\n", strerror(errno));
} }
void void
SendSSDPNotifies(int s, const char *host, unsigned short port, SendSSDPNotifies(int s, const char *host, unsigned short port,
unsigned int interval) unsigned int interval)
{ {
struct sockaddr_in sockname; struct sockaddr_in sockname;
int l, n, dup, i=0; int l, n, dup, i=0;
skipping to change at line 493 skipping to change at line 492
* process SSDP M-SEARCH requests and responds to them */ * process SSDP M-SEARCH requests and responds to them */
void void
ProcessSSDPRequest(int s, unsigned short port) ProcessSSDPRequest(int s, unsigned short port)
{ {
int n; int n;
char bufr[1500]; char bufr[1500];
struct sockaddr_in sendername; struct sockaddr_in sendername;
int i; int i;
char *st = NULL, *mx = NULL, *man = NULL, *mx_end = NULL; char *st = NULL, *mx = NULL, *man = NULL, *mx_end = NULL;
int man_len = 0; int man_len = 0;
socklen_t len_r = sizeof(struct sockaddr_in);
#ifdef __linux__ #ifdef __linux__
char cmbuf[CMSG_SPACE(sizeof(struct in_pktinfo))]; char cmbuf[CMSG_SPACE(sizeof(struct in_pktinfo))];
struct iovec iovec = { struct iovec iovec = {
.iov_base = bufr, .iov_base = bufr,
.iov_len = sizeof(bufr)-1 .iov_len = sizeof(bufr)-1
}; };
struct msghdr mh = { struct msghdr mh = {
.msg_name = &sendername, .msg_name = &sendername,
.msg_namelen = sizeof(struct sockaddr_in), .msg_namelen = sizeof(struct sockaddr_in),
.msg_iov = &iovec, .msg_iov = &iovec,
.msg_iovlen = 1, .msg_iovlen = 1,
.msg_control = cmbuf, .msg_control = cmbuf,
.msg_controllen = sizeof(cmbuf) .msg_controllen = sizeof(cmbuf)
}; };
n = recvmsg(s, &mh, 0); n = recvmsg(s, &mh, 0);
#else #else
socklen_t len_r = sizeof(struct sockaddr_in);
n = recvfrom(s, bufr, sizeof(bufr)-1, 0, n = recvfrom(s, bufr, sizeof(bufr)-1, 0,
(struct sockaddr *)&sendername, &len_r); (struct sockaddr *)&sendername, &len_r);
len_r = MIN(len_r, sizeof(struct sockaddr_in));
#endif #endif
if (n < 0) if (n < 0)
{ {
DPRINTF(E_ERROR, L_SSDP, "recvfrom(udp): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "recvfrom(udp): %s\n", strerror(errno));
return; return;
} }
bufr[n] = '\0'; bufr[n] = '\0';
n -= 2; n -= 2;
if (memcmp(bufr, "NOTIFY", 6) == 0) if (memcmp(bufr, "NOTIFY", 6) == 0)
skipping to change at line 727 skipping to change at line 727
DPRINTF(E_MAXDEBUG, L_SSDP, DPRINTF(E_MAXDEBUG, L_SSDP,
"Ignoring SSDP M-SEARCH w ith bad extra data '%c' [%s]\n", "Ignoring SSDP M-SEARCH w ith bad extra data '%c' [%s]\n",
st[l], inet_ntoa(senderna me.sin_addr)); st[l], inet_ntoa(senderna me.sin_addr));
break; break;
} }
if (l != st_len) if (l != st_len)
break; break;
} }
_usleep(random()>>20); _usleep(random()>>20);
SendSSDPResponse(s, sendername, i, SendSSDPResponse(s, sendername, i,
host, port); host, port, len_r);
return; return;
} }
/* Responds to request with ST: ssdp:all */ /* Responds to request with ST: ssdp:all */
/* strlen("ssdp:all") == 8 */ /* strlen("ssdp:all") == 8 */
if ((st_len == 8) && (memcmp(st, "ssdp:all", 8) == 0)) if ((st_len == 8) && (memcmp(st, "ssdp:all", 8) == 0))
{ {
for (i=0; known_service_types[i]; i++) for (i=0; known_service_types[i]; i++)
{ {
l = strlen(known_service_types[i]); l = strlen(known_service_types[i]);
SendSSDPResponse(s, sendername, i, SendSSDPResponse(s, sendername, i,
host, port); host, port, len_r);
} }
} }
} }
else else
{ {
DPRINTF(E_INFO, L_SSDP, "Invalid SSDP M-SEARCH from %s:%d \n", DPRINTF(E_INFO, L_SSDP, "Invalid SSDP M-SEARCH from %s:%d \n",
inet_ntoa(sendername.sin_addr), ntohs(sendername. sin_port)); inet_ntoa(sendername.sin_addr), ntohs(sendername. sin_port));
} }
} }
else if (memcmp(bufr, "YOUKU-NOTIFY", 12) == 0) else if (memcmp(bufr, "YOUKU-NOTIFY", 12) == 0)
 End of changes. 11 change blocks. 
14 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)