OpenWrt Forum Archive

Topic: WGT634U - multiple recv's fail ...

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I am working on a little client application that uses sockets to connect to the kismet server running on this router. On my Laptop, the following code works. But compiled for OpenWRT it doesnt sad

[...]
int create_socket;
char * buffer = (char*) malloc (BUF);
struct sockaddr_in      address;
int                     size;

if ((create_socket = socket (AF_INET, SOCK_STREAM, 0)) > 0)
     printf ("PacketReader: Socket wurde angelegt\n");
else
     return 0;

address.sin_family      = AF_INET;
address.sin_port        = htons (2501);
inet_aton ("127.0.0.1", &address.sin_addr);

if (connect ( create_socket, (struct sockaddr *) &address, sizeof (address)) == 0) {
       printf("PacketReader: Verbindung mit dem Server (%s) hergestellt\n", inet_ntoa (address.sin_addr));
} else {
        printf("PacketReader: Could not connect to Server 127.0.0.1 on port 2501!\n");
        return 0;
}

while(1) {
        printf("At beginning of while loop ...\n");
        size = recv(create_socket, buffer, BUF-1, 0);
        printf("Got after recv ...\n");
        if( size > 0) buffer[size] = '\0';
        printf("Got Message: %s\n", buffer);
}
        close (create_socket);
        return 0;
[...]

It appears as if the first recv worked fine but the second crashes the application ...
(This Code runs as a pthread.) Output is the following:

root@OpenWrt:/# /usr/local/bin/wispy                                                                                                                                        
PacketReader: Socket wurde angelegt                                                                                                                                         
Accepted interface connection from 127.0.0.1                                                                                                                                
PacketReader: Verbindung mit dem Server (127.0.0.1) hergestellt                                                                                                             
At beginning of while loop ...                                                                                                                                              
Got after recv ...                                                                                                                                                          
Got Message: *KISMET: 0.0.0 946685577 .Kismet. 20050815211952 1 2006.04.R1                                                                                                  
*PROTOCOLS: KISMET,ERROR,ACK,PROTOCOLS,CAPABILITY,TERMINATE,TIME,ALERT,NETWORK,CLIENT,GPS,INFO,REMOVE,STATUS,PACKET,STRING,WEPKEY,CARD                                      
                                                                                                                                                                            
At beginning of while loop ...                                                                                                                                              
root@OpenWrt:/#

Any hints / tips?

Thank you ...

Robert

Could it be that the syscall recv is not fully implemented in uclibc (for mips)? Kismet does not use recv and works ... (it binds the socket to a local file-descriptor and makes a fgets to read from the socket ...)

Ok, got a bit further:

I blocked all signals during the recv command and it works ... what kind of signal did I get? Why?

pthreads sometimes gives me signals on OpenWRT (but also on OpenSlug, which is not uClibc based). More specifically, I get a signal (I think its sig 32, some sort of real-time signal) on thread creation, and sometimes at a connect command. I only notice these signals in gdb, they do not show up when running the code outside gdb. As long as your program doesn't terminate on received signals, you should be fine. Have you tried running it in gdb on OpenWRT?

The discussion might have continued from here.