From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25922 invoked by alias); 18 Jan 2008 09:01:23 -0000 Received: (qmail 25909 invoked by uid 22791); 18 Jan 2008 09:01:22 -0000 X-Spam-Check-By: sourceware.org Received: from fk-out-0910.google.com (HELO fk-out-0910.google.com) (209.85.128.189) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 18 Jan 2008 09:00:59 +0000 Received: by fk-out-0910.google.com with SMTP id k31so835130fkk.14 for ; Fri, 18 Jan 2008 01:00:56 -0800 (PST) Received: by 10.78.170.17 with SMTP id s17mr4194493hue.35.1200646856068; Fri, 18 Jan 2008 01:00:56 -0800 (PST) Received: by 10.78.151.7 with HTTP; Fri, 18 Jan 2008 01:00:56 -0800 (PST) Message-ID: <3fae21000801180100s5a448e01v5da7c97978499b11@mail.gmail.com> Date: Fri, 18 Jan 2008 09:01:00 -0000 From: "Emmanuel Coullien" To: ecos-discuss@ecos.sourceware.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: [ECOS] Problem reading broadcast IP X-SW-Source: 2008-01/txt/msg00097.txt.bz2 Hi, I' am trying to get broadcast frame from Ethernet with the following code : void Test_system_UDP2(void) { int n_read; struct timeval tv; int srecept; struct sockaddr_in srv_recept; int FrameErrCountSocket1=0; int DataErrCountSocket1=0; int RecvError=0; int ErrSendSocket=0; int CountSocket1=0; int i; unsigned char j; int StartCycle =1; /* for select on socket */ int ret; fd_set file_set; int FlgON = 1; // Utiliser pour activer des Options dans SetSockOpt /*** Init de la socket de reception ***/ bzero(&srv_recept, sizeof(srv_recept)); srv_recept.sin_family = AF_INET; srv_recept.sin_port = htons(PORT_TO_SEND); // srv_recept.sin_addr.s_addr=INADDR_ANY; srv_recept.sin_addr.s_addr=inet_addr("192.168.1.3"); if ((srecept = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket"); return; } // positionner le socket en mode BROADCAST if (setsockopt(srecept, SOL_SOCKET, SO_BROADCAST, &FlgON, sizeof(FlgON))) { perror(" : setsockopt"); return; } if (bind(srecept, (struct sockaddr *)&srv_recept, sizeof(srv_recept)) < 0) { printf("Erreur :bind"); } tv.tv_sec = TIMEOUT_RECV; tv.tv_usec = 0; while (1) { FD_ZERO (&file_set); FD_SET (srecept, &file_set); ret = select (srecept+1, &file_set, NULL, NULL, &tv); if (ret >0) { /* we have data in the socket */ n_read = recvfrom(srecept, Bufrecept, MAXBUF, 0,NULL, NULL); if (n_read < 0) printf("Erreur lecture socket : n_read +%d\n",n_read); else { Bufrecept[n_read]='\0'; printf(" Reception OK (%s)\n",Bufrecept); } } else { printf("Erreur Timeout : ret +%d\n",ret); } } } If I use "srv_recept.sin_addr.s_addr=INADDR_ANY;", then it works fine, I receive my broadcast frame. But if I use "srv_recept.sin_addr.s_addr=inet_addr("192.168.1.3");" even with "setsockopt(srecept, SOL_SOCKET, SO_BROADCAST, &FlgON, sizeof(FlgON)" , then on eCos I can't receive any broadcast. I need to use inet_addr("192.168.1.3") to select this interface because I have 3 Ethernet interface and I don't want to receive from the other interface. I tried on a PC and I haven't any problem with srv_recept.sin_addr.s_addr=inet_addr("192.168.1.3");. I received the broadcast frame. Does someone know why I didn't received the broadcast frame in that case on eCos ? Is there something I missed or an other socket option to set ? -- Emmanuel Coullien -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss