Date: Sun, 4 Sep 2016 18:18:09 -0300 From: =?UTF-8?B?T3RhY8OtbGlv?= <otacilio.neto@bsd.com.br> To: "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>, "freebsd-wireless@freebsd.org" <freebsd-wireless@freebsd.org> Subject: Small example program shut down urtwn Message-ID: <fea1f0b8-d17c-5fc1-9593-6d8a6e2032db@bsd.com.br>
next in thread | raw e-mail | index | archive | help
Dears I wrote these two small programs to help debug a problem that I think I have found when using urtwn driver in a baglebone black. The problem is 100% reproducible. In a server machine I run: serverUDP 2508 In beaglebone black I run: ./clientUDP servername 2508 9216 0 All the times, after some packages be sent the urtwn interface do not respond from ping and stops send others packages. Some times this error message appears: % urtwn0: device timeout I have tested with RTL8192CU and RTL8188CUS The problem do no occurs in my notebook. Following the server and client #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <netinet/in.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #define BUFFER_LEN 1024*1024 void diep(char *s) { perror(s); exit(1); } int main(int argc, char **argv) { int lidos; struct sockaddr_in si_me, si_other; int s, i, slen=sizeof(si_other); char buf[BUFFER_LEN]; int aux; if(argc != 2){ fprintf(stderr, "Voce deve usar %s <porta>\n", argv[0]); exit(1); } if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) diep("socket"); memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(strtol(argv[1], (char **)NULL, 10)); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, (struct sockaddr *)&si_me, sizeof(si_me))==-1) diep("bind"); i = 1; do { if ((lidos = recvfrom(s, buf, BUFFER_LEN, 0, (struct sockaddr *)&si_other, (socklen_t *)&slen))==-1) diep("recvfrom()"); aux = ntohl(*(int*)&buf[0]); printf("Perdidos %d pacotes (%0.2f%%)\n", aux - i, 100*((float)(aux - i))/((float)aux)); printf("Sequencia %0000d Recebidos %d bytes\n", aux, lidos); i++; }while(lidos>0); close(s); return 0; } #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <netinet/in.h> #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/select.h> #define SOCKET_ERROR -1 #define INVALID_SOCKET -1 #define SRV_IP "127.0.0.1" void diep(char *s) { perror(s); exit(1); } int main(int argc, char **argv) { struct sockaddr_in si_other; int s, i, slen=sizeof(si_other); char *buf; int tamanho; int npack; struct addrinfo *result = NULL, *ptr = NULL, hints; int iResult, aux; fd_set fdset; if(argc != 5){ fprintf(stderr,"Voce deve usar %s <host> <porta> <tamanho> <numero de pacotes>\n", argv[0]); exit(1); } tamanho = (int)strtol(argv[3], (char **)NULL, 10); npack = (int)strtol(argv[4], (char **)NULL, 10); buf = malloc(tamanho); bzero(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; iResult = getaddrinfo(argv[1], argv[2], &hints, &result); if ( iResult != 0 ) { printf("getaddrinfo failed with error: %d\n", iResult); return 1; } // Attempt to connect to an address until one succeeds for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) { // Create a SOCKET for connecting to server s = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); if (s < 0){ perror("socket"); return 1; } // Connect to server. iResult = connect(s, ptr->ai_addr, (int)ptr->ai_addrlen); if (iResult == SOCKET_ERROR) { close(s); s = INVALID_SOCKET; continue; } break; } freeaddrinfo(result); FD_ZERO(&fdset); FD_SET(s, &fdset); for (i=1; i<=npack || npack==0; i++) { aux = htonl(i); memcpy(&buf[0], &aux, sizeof(aux)); aux = htonl(npack); memcpy(&buf[0+sizeof(i)], &aux, sizeof(aux)); do{ if(select(s+1, NULL, &fdset, NULL, NULL )<0) diep("select()"); }while(!FD_ISSET(s, &fdset)); if (send(s, buf, tamanho, 0)==-1) diep("sendto()"); } printf("Enviados %d pacotes de %d bytes\n", npack, tamanho); close(s); return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fea1f0b8-d17c-5fc1-9593-6d8a6e2032db>