changeset 12610:7992cd49a698

calling bind with multicast addresses doesn't work on windows, patch by Martin Decky <deckm1am at ss1000.ms.mff.cuni.cz>
author faust3
date Fri, 18 Jun 2004 14:31:10 +0000
parents 4be019266884
children e7c4f5d539e9
files libmpdemux/network.c
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/network.c	Fri Jun 18 13:51:45 2004 +0000
+++ b/libmpdemux/network.c	Fri Jun 18 14:31:10 2004 +0000
@@ -1080,6 +1080,7 @@
 	struct sockaddr_in server_address;
 	struct ip_mreq mcast;
         struct timeval tv;
+	struct hostent *hp;
 
 	mp_msg(MSGT_NETWORK,MSGL_V,"Listening for traffic on %s:%d ...\n", url->hostname, url->port );
 
@@ -1091,12 +1092,16 @@
 	}
 
 	if( isalpha(url->hostname[0]) ) {
-		struct hostent *hp =(struct hostent*)gethostbyname( url->hostname );
+#ifndef HAVE_WINSOCK2
+		hp =(struct hostent*)gethostbyname( url->hostname );
 		if( hp==NULL ) {
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
 			return -1;
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
+#else
+		server_address.sin_addr.s_addr = htonl(INADDR_ANY);
+#endif
 	} else {
 #ifndef HAVE_WINSOCK2
 #ifdef USE_ATON
@@ -1105,8 +1110,7 @@
 		inet_pton(AF_INET, url->hostname, &server_address.sin_addr);
 #endif
 #else
-		unsigned int addr = inet_addr(url->hostname);
-		memcpy( (void*)&server_address.sin_addr, (void*)&addr, sizeof(addr) );
+		server_address.sin_addr.s_addr = htonl(INADDR_ANY);
 #endif
 	}
 	server_address.sin_family=AF_INET;
@@ -1123,6 +1127,20 @@
 			return -1;
 		}
 	}
+	
+#ifdef HAVE_WINSOCK2
+	if (isalpha(url->hostname[0])) {
+		hp =(struct hostent*)gethostbyname( url->hostname );
+		if( hp==NULL ) {
+			mp_msg(MSGT_NETWORK,MSGL_ERR,"Counldn't resolve name: %s\n", url->hostname);
+			return -1;
+		}
+		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
+	} else {
+		unsigned int addr = inet_addr(url->hostname);
+		memcpy( (void*)&server_address.sin_addr, (void*)&addr, sizeof(addr) );
+	}
+#endif
 
 	// Increase the socket rx buffer size to maximum -- this is UDP
 	rxsockbufsz = 240 * 1024;