"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "minissdp.c" between
minidlna-1.1.4.tar.gz and minidlna-1.1.5.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.1.4):minissdp.c  (minidlna-1.1.5)
skipping to change at line 76 skipping to change at line 76
memset(&imr, '\0', sizeof(imr)); memset(&imr, '\0', sizeof(imr));
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR); imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
imr.imr_ifindex = iface->ifindex; imr.imr_ifindex = iface->ifindex;
#else #else
struct ip_mreq imr; /* Ip multicast membership */ struct ip_mreq imr; /* Ip multicast membership */
/* setting up imr structure */ /* setting up imr structure */
memset(&imr, '\0', sizeof(imr)); memset(&imr, '\0', sizeof(imr));
imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR); imr.imr_multiaddr.s_addr = inet_addr(SSDP_MCAST_ADDR);
imr.imr_interface.s_addr = iface->addr.s_addr; imr.imr_interface.s_addr = iface->addr.s_addr;
#endif #endif
/* Setting the socket options will guarantee, tha we will only receive
* multicast traffic on a specific Interface.
* In addition the kernel is instructed to send an igmp message (choose
* mcast group) on the specific interface/subnet. */
ret = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(i mr)); ret = setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&imr, sizeof(i mr));
if (ret < 0 && errno != EADDRINUSE) if (ret < 0 && errno != EADDRINUSE)
{ {
DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\ n", DPRINTF(E_ERROR, L_SSDP, "setsockopt(udp, IP_ADD_MEMBERSHIP): %s\ n",
strerror(errno)); strerror(errno));
return -1; return -1;
} }
return 0; return 0;
} }
skipping to change at line 105 skipping to change at line 109
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): %s\n", strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "socket(udp): %s\n", strerror(errno));
return -1; return -1;
} }
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__
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));
#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);
/* NOTE : it seems it doesnt work when binding on the specific address */ /* NOTE: Binding a socket to a UDP multicast address means, that we just
sockname.sin_addr.s_addr = htonl(INADDR_ANY); want
* to receive datagramms send to this multicast address.
* To specify the local nics we want to use we have to use setsockopt,
* see AddMulticastMembership(...). */
sockname.sin_addr.s_addr = inet_addr(SSDP_MCAST_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): %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;
} }
skipping to change at line 310 skipping to change at line 320
DPRINTF(E_MAXDEBUG, L_SSDP, "Sending ssdp:alive [%d]\n", s); DPRINTF(E_MAXDEBUG, L_SSDP, "Sending ssdp:alive [%d]\n", s);
n = sendto(s, bufr, l, 0, n = sendto(s, bufr, l, 0,
(struct sockaddr *)&sockname, sizeof(struct socka ddr_in)); (struct sockaddr *)&sockname, sizeof(struct socka ddr_in));
if (n < 0) if (n < 0)
DPRINTF(E_ERROR, L_SSDP, "sendto(udp_notify=%d, % s): %s\n", s, host, strerror(errno)); DPRINTF(E_ERROR, L_SSDP, "sendto(udp_notify=%d, % s): %s\n", s, host, strerror(errno));
i++; i++;
} }
} }
} }
void static void
ParseUPnPClient(char *location) ParseUPnPClient(char *location)
{ {
char buf[8192]; char buf[8192];
struct sockaddr_in dest; struct sockaddr_in dest;
int s, n, do_headers = 0, nread = 0; int s, n, do_headers = 0, nread = 0;
struct timeval tv; struct timeval tv;
char *addr, *path, *port_str; char *addr, *path, *port_str;
long port = 80; long port = 80;
char *off = NULL, *p; char *off = NULL, *p;
int content_len = sizeof(buf); int content_len = sizeof(buf);
skipping to change at line 479 skipping to change at line 489
} }
} }
/* ProcessSSDPRequest() /* ProcessSSDPRequest()
* 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];
socklen_t len_r;
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;
len_r = sizeof(struct sockaddr_in); #ifdef __linux__
char cmbuf[CMSG_SPACE(sizeof(struct in_pktinfo))];
struct iovec iovec = {
.iov_base = bufr,
.iov_len = sizeof(bufr)-1
};
struct msghdr mh = {
.msg_name = &sendername,
.msg_namelen = sizeof(struct sockaddr_in),
.msg_iov = &iovec,
.msg_iovlen = 1,
.msg_control = cmbuf,
.msg_controllen = sizeof(cmbuf)
};
n = recvmsg(s, &mh, 0);
#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);
#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 627 skipping to change at line 654
inet_ntoa(sendername.sin_addr), "MAN", man_len, m an); inet_ntoa(sendername.sin_addr), "MAN", man_len, m an);
} }
else if (!mx || mx == mx_end || mx_val < 0) else if (!mx || mx == mx_end || mx_val < 0)
{ {
DPRINTF(E_INFO, L_SSDP, "WARNING: Ignoring invalid SSDP M -SEARCH from %s [bad %s header '%.*s']\n", DPRINTF(E_INFO, L_SSDP, "WARNING: Ignoring invalid SSDP M -SEARCH from %s [bad %s header '%.*s']\n",
inet_ntoa(sendername.sin_addr), "MX", mx_len, mx) ; inet_ntoa(sendername.sin_addr), "MX", mx_len, mx) ;
} }
else if (st && (st_len > 0)) else if (st && (st_len > 0))
{ {
int l; int l;
#ifdef __linux__
char host[40] = "127.0.0.1";
struct cmsghdr *cmsg;
/* find the interface we received the msg from */
for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(
&mh, cmsg))
{
struct in_addr addr;
struct in_pktinfo *pi;
/* ignore the control headers that don't match wh
at we want */
if (cmsg->cmsg_level != IPPROTO_IP ||
cmsg->cmsg_type != IP_PKTINFO)
continue;
pi = (struct in_pktinfo *)CMSG_DATA(cmsg);
addr = pi->ipi_spec_dst;
inet_ntop(AF_INET, &addr, host, sizeof(host));
}
#else
const char *host;
int iface = 0; int iface = 0;
/* find in which sub network the client is */ /* find in which sub network the client is */
for (i = 0; i < n_lan_addr; i++) for (i = 0; i < n_lan_addr; i++)
{ {
if((sendername.sin_addr.s_addr & lan_addr[i].mask .s_addr) == if((sendername.sin_addr.s_addr & lan_addr[i].mask .s_addr) ==
(lan_addr[i].addr.s_addr & lan_addr[i].mask.s_ addr)) (lan_addr[i].addr.s_addr & lan_addr[i].mask.s_ addr))
{ {
iface = i; iface = i;
break; break;
} }
} }
if (n_lan_addr == i) if (n_lan_addr == i)
{ {
DPRINTF(E_DEBUG, L_SSDP, "Ignoring SSDP M-SEARCH on other interface [%s]\n", DPRINTF(E_DEBUG, L_SSDP, "Ignoring SSDP M-SEARCH on other interface [%s]\n",
inet_ntoa(sendername.sin_addr)); inet_ntoa(sendername.sin_addr));
return; return;
} }
host = lan_addr[iface].str;
#endif
DPRINTF(E_DEBUG, L_SSDP, "SSDP M-SEARCH from %s:%d ST: %. *s, MX: %.*s, MAN: %.*s\n", DPRINTF(E_DEBUG, L_SSDP, "SSDP M-SEARCH from %s:%d ST: %. *s, MX: %.*s, MAN: %.*s\n",
inet_ntoa(sendername.sin_addr), inet_ntoa(sendername.sin_addr),
ntohs(sendername.sin_port), ntohs(sendername.sin_port),
st_len, st, mx_len, mx, man_len, man); st_len, st, mx_len, mx, man_len, man);
/* Responds to request with a device as ST header */ /* Responds to request with a device as ST header */
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]);
if ((l > st_len) || (memcmp(st, known_service_typ es[i], l) != 0)) if ((l > st_len) || (memcmp(st, known_service_typ es[i], l) != 0))
continue; continue;
skipping to change at line 678 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,
lan_addr[iface].str, port); host, port);
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,
lan_addr[iface].str, port ); host, port);
} }
} }
} }
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. 
8 lines changed or deleted 61 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS