Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Reply-To: From: "Patrick Lidstone" To: Subject: Re: Re Re: Re: UNIX Sockets - Broadcast address Date: Wed, 18 Dec 2002 12:29:30 -0000 Message-ID: <002601c2a691$1eb062a0$5300a8c0@emea.tibco.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 >On Mon, Dec 17, 2001 at 03:37:13AM +0000, Kay M wrote: >> So what the bottom line, no broadcasting ?. >> >> Question: Has any one ever written a program on cygwin that uses A broadcast >> address ?. A client program to be more specific. > >What about actually debugging the problem? Or did you try using >WinSock functions directly instead of the Cygwin wrapper functions >just for debugging purposes? Anything which tracks down the cause? > >Corinna I have a similar issue with the use of broadcast sockets. I have code which binds correctly to a broadcast socket under Linux, but which won't bind to anything other than INADDR_ANY under Win/32. Code which performs a similar function under Winsock 2 API and MSVC 6 works just fine. The symptoms are indentical to that described by the previous poster: the socket is created ok and broadcast options are set ok, and the bind fails with a return of 1. Although not listed in the man pages as a valid error number, this looks like it could be related to permissions going by error.h -- but I'm not aware of any permissioning mechanisms under Win/32 for this kind of thing? Here is the test code in full: gcc -o bs badsock.c for Linux gcc -o bs badsock.c -D WIN32 for Windows #include #include #include #include #include #include #include #include #include #include #include #include #ifndef WIN32 #include #endif #include #include #include #include int main() { int i_optval, i_optlen; int i; struct sockaddr_in server_address; int server_sockfd; server_sockfd=socket(AF_INET, SOCK_DGRAM, 0); i_optval=1; i_optlen=sizeof(int); if (setsockopt(server_sockfd, SOL_SOCKET, SO_BROADCAST, (char*)&i_optval, i_optlen)) { printf("Cannot set options on broadcast socket\n"); } i_optval=1; i_optlen=sizeof(int); if (setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&i_optval, i_optlen)) { printf("Cannot set reuseaddr options on broadcast socket\n"); } server_address.sin_family = AF_INET; // server_address.sin_addr.s_addr=inet_addr("127.255.255.255"); //<-- fails under windows // server_address.sin_addr.s_addr=inet_addr("0.0.0.0"); //<-- works under windows server_address.sin_addr.s_addr=inet_addr("192.168.0.255"); //<-- fails under windows // server_address.sin_addr.s_addr=htonl(INADDR_ANY); //<-- same as 0.0.0.0 server_address.sin_port=htons(3639); if (i=bind(server_sockfd, (struct sockaddr*)&server_address, sizeof(server_address))!=0) { switch (i) { case EPERM: printf("Not a superuser\n"); break; case EBADF: printf("Bad sock desc\n"); break; case EINVAL: printf("Sock in use\n"); break; case EACCES: printf("User not entitled\n"); break; case ENOTSOCK: printf("Not a socket!\n"); break; case EROFS: printf("Read only FS\n"); break; } // switch printf("Broadcast socket error, bind returned %d\n",i); } else printf("All hunky-dory\n"); return 0; } Any assistance most appreciated. Patrick -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/