Hi all,

I'm working on a hardware control system on a BF548 via ethernet using UDP
using the lwIP stack. I tried to use ioctlsocket() to make the recv()
unblocking. However, when I use ioctlsocket(), i can't receive anything.
recv() keeps returning (-1) even if i try to send in a DOS attack ;).  when
i'm operating in blocking mode, everything works fine. i'm in dire need of
help.. find my code below... 
(note that for easy debugging I have made the code simple silly)

 socket_fd = socket(AF_INET, SOCK_DGRAM, 0); // create socket

        if ( socket_fd < 0 ) {
            printf("socket call failed\n");
            return;
        }

        memset(&sa, 0, sizeof(struct sockaddr_in));
        ra.sin_family = AF_INET;
        ra.sin_addr.s_addr = htonl(INADDR_ANY);
        ra.sin_port = htons(RECEIVER_PORT_NUM);

          
        
        if (bind(socket_fd, (struct sockaddr *)&ra, sizeof(struct
sockaddr_in)) == -1)  //  Bind the UDP socket to the port RECEIVER_PORT_NUM 
            {
            printf("bind to port number %d ,IP address INADDR_ANY
failed\n",RECEIVER_PORT_NUM);
            close(socket_fd);
                return;
        }
        
       
         
       mode = 1;
         ret = ioctlsocket(socket_fd, FIONBIO, &mode );
         if(ret<0) printf("ioctlsocket() failed\n"); 
         
        while(1)  
        {recv_data = recv(socket_fd,data_buffer1,sizeof(data_buffer1),0); //
This is silly i know. but still                            // returns -1
          if(recv_data>0) break;}
          printf("I got a packet\n");  
           
     
 
    printf("closing socket....\n");      
    close(socket_fd); 
    
}        
-- 
View this message in context: 
http://old.nabble.com/lwIP-ioctlsocket%28%29-problems-tp34376679p34376679.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to