From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4214 invoked by alias); 19 Jun 2005 17:38:52 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 4158 invoked by uid 22791); 19 Jun 2005 17:38:44 -0000 Received: from mail.esiee.fr (HELO mail.esiee.fr) (147.215.1.3) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sun, 19 Jun 2005 17:38:44 +0000 Received: from mail.esiee.fr (localhost.esiee.fr [127.0.0.1]) by mail.esiee.fr (Postfix) with SMTP id 04443365903 for ; Sun, 19 Jun 2005 19:38:42 +0200 (CEST) Received: from esiee.fr (localhost.esiee.fr [127.0.0.1]) by mail.esiee.fr (Postfix) with ESMTP id 5BDBB3658F4 for ; Sun, 19 Jun 2005 19:38:41 +0200 (CEST) Content-Type: text/plain; charset=iso-8859-1 User-Agent: IMHO/0.99 (Webmail for Roxen) Date: Sun, 19 Jun 2005 17:38:00 -0000 MIME-Version: 1.0 To: ecos-discuss@sources.redhat.com From: Thierry =?iso-8859-1?q?Br=E9mard?= Message-Id: <20050619173841.5BDBB3658F4@mail.esiee.fr> Content-Transfer-Encoding: quoted-printable Subject: [ECOS] re: TCP problem: Accept doesn't accept + No ARP reply of Arcom Viper running with eCos X-SW-Source: 2005-06/txt/msg00161.txt.bz2 Hello,=20 I am still on my TCP Server, I managed to specify a static IP address and now I am able to connect from my arcom viper card to my PC and send to my pc data via TCP sockets. However my final issue is to build a server on my viper card. My function OpenPort return with 1 (succesful) and when I attempt to connect (whith the correct ip and correct port) with a telnet , I can see SYN request from my PC without any ack from the viper. Furthermore, it doesn't reply to arp request (ie for the moment I have to set a arp -s ip mac to be able to send packets to the viper .. but the viper announce itself (once)just after the go command ) I built my project with the eCos configuration Tool, selected the 'net' package, checked and filled the 'address setups for eth0' and unchecked the DNS support (because only work whit ip addresses). Here is the output of redBoot, lauching my eCos program ---------------------------------------------------------------- RedBoot> RedBoot> go [cyg_net_init] Init: mbinit(0x00000000) [cyg_net_init] Init: cyg_net_init_devs(0x00000000) Init device 'lan91cxx_eth0' [cyg_net_init] Init: loopattach(0x00000000) [cyg_net_init] Init: ifinit(0x00000000) [cyg_net_init] Init: domaininit(0x00000000) [cyg_net_init] Init: cyg_net_add_domain(0x0043d774) New domain internet at 0x00000000 [cyg_net_init] Init: cyg_net_add_domain(0x0043d1fc) New domain route at 0x00000000 [cyg_net_init] Init: call_route_init(0x00000000) [cyg_net_init] Done BOOTP[eth0] op: REPLY htype: Ethernet hlen: 6 hops: 0 xid: 0x0 secs: 0 flags: 0x0 hw_addr: 00:80:66:10:14:ee client IP: 147.215.40.77 my IP: 147.215.40.77 server IP: 147.215.40.2 gateway IP: 147.215.40.1 options: subnet mask: 255.255.255.0 IP broadcast: 147.215.40.255 gateway: 147.215.40.1 [eth_drv_ioctl] Warning: Driver can't set multi-cast mode [eth_drv_ioctl] Warning: Driver can't set multi-cast mode [eth_drv_ioctl] Warning: Driver can't set multi-cast mode Server Redboot ! Opening port 105..ok ---------------------------------------------------------------- Here is the source code: ---------------------------------------------------------------- #include #include #include #include #define SOCKET_ERROR -1 #define DESIRED_BACKGROUND_LOAD 50 int OpenPort(unsigned short port) { struct sockaddr_in sin; int sock; if((sock =3D socket(AF_INET, SOCK_STREAM, 0))=3D=3D SOCKET_ERROR) { printf("error in OpenPort, socket()"); return 0; } sin.sin_port =3D htons(port); sin.sin_addr.s_addr =3D 0; // sin.sin_addr.s_addr =3D INADDR_ANY; sin.sin_family =3D AF_INET; sin.sin_len =3D sizeof(sin); =20=20=20=20=20=20=20=20 if(SOCKET_ERROR =3D=3D bind(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) )) { printf("error in OpenPort, bind()"); return 0; } if(SOCKET_ERROR =3D=3D listen(sock, SOMAXCONN)) { printf("error in OpenPort, listen()"); return 0; } =20 return sock; } int Connexion(unsigned short port) { struct sockaddr_in sin; int sock; if((sock =3D socket(AF_INET, SOCK_STREAM, 0))=3D=3D SOCKET_ERROR) { printf("error in OpenPort, socket()\n"); return 0; } sin.sin_port =3D htons(port); sin.sin_addr.s_addr =3D inet_addr("147.215.40.139"); sin.sin_family =3D AF_INET; =20=20 if(SOCKET_ERROR =3D=3D connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) )) { printf("error in Connexion, connect()\n"); return 0; } return sock; } // envoi les donn=E9es point=E9es par data taille =3D len // tout est envoy=E9 grace =E0 un appel =E0 recv dans le while // retourne le nombre d'octets envoy=E9s=20 int SendData(int sock, char *data, int len) { int total =3D 0; int ret; =20=20=20=20 while((ret =3D send(sock, data, len, 0))>0) // envoi les donn=E9es { total +=3D ret; // octets envoy=E9s au total data +=3D ret; // pointe plus loin sur les donn=E9es non envoy=E9es len -=3D ret; // la taille restante diminue } =20=20=20=20 return total; // nombre d'octets envoy=E9s } // envoie la chaine de caract=E8re ascii, termin=E9e par un 0. // retourne le nombre d'octets envoy=E9s (n'envoie pas le 0) int SendString(int sock, char *str) { return SendData(sock, str, strlen(str)); } // recoit des donn=E9es, les stocke dans buffer // la r=E9ception s'ach=E8ve oubien quand len octets ont =E9t=E9 recus // ou bien quand \n est recu. // les caract=E8res \r et \n sont enlev=E9s de la fin du buffer avant de retourner // le nombre de caract=E8res mis dans buffer est retourn=E9. int RecvLine(int sock, char *buffer, int len) { char c; int total =3D 0; int ret; =20=20=20=20 memset(buffer, 0 , len); =20=20=20=20 while( (total0) ) { memcpy(&buffer[total], &c, ret ); // buffer[total] =3D c; total +=3D ret; // total++; if(buffer[total-1] =3D=3D'\n') break ; // sortie de la boucle si retour chariot recu. =20=20=20=20 } =20=20=20=20 len =3D strlen(buffer); while((buffer[len-1] =3D=3D'\n') || (buffer[len-1] =3D=3D'\r')) { buffer[len-1] =3D 0; // =E9crase \n ou \r par caract=E8re de fin de chaine len--; if(!len) // si taille nulle break; // termine la boucle } =20=20=20=20 return len; =20=20=20=20 } //void cyg_user_start(void) int main(void) { //int i; int sock, client; char buffer[1024]; init_all_network_interfaces(); // calibrate_load(DESIRED_BACKGROUND_LOAD); printf("Server Redboot !\n"); =20=20=20=20 /* if(sock =3D Connexion(90)) { =20=20=20=20=20=20=20=20 printf("Connected ... "); SendString(sock, "Hello Server, I am the Viper !!\r\n"); SendString(sock, "quit\r\n"); close(sock); printf("Disconnected!\r\n"); =20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20 }*/ =20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20 printf("Opening port 105.."); if(!(sock =3D OpenPort(105))) { printf("error opening port !\n"); return 0; } printf("ok\n"); =20=20=20=20 =20=20=20=20 if(SOCKET_ERROR =3D=3D (client =3D accept(sock, NULL, 0))) { printf("error of accept!"); return 0; } printf("Client connected!"); strcpy(buffer, "Hello you are on the Viper Server!\r\n"); SendString(client, buffer); while(strncmp(buffer, "quit", 3)) { RecvLine(client, buffer, 1024); printf("client sent: %s", buffer); SendString(client, "220 ok for"); SendString(client, buffer); SendString(client, "\r\n"); }=20=20=20=20 =20=20=20=20 close(sock); close(client); puts("Server finished"); return 0; =20=20 } ---------------------------------------------------------------- Here is another source provided whith eCos which gives the same result: opens port but donot ack the syn: //=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D // Network server test code #include #include #include #ifndef CYGPKG_LIBC_STDIO #define perror(s) diag_printf(#s ": %s\n", strerror(errno)) #endif #define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000) static char stack[STACK_SIZE]; static cyg_thread thread_data; static cyg_handle_t thread_handle; extern void cyg_test_exit(void); void pexit(char *s) { perror(s); cyg_test_exit(); } static void server_test(struct bootp *bp) { int s, client, client_len; struct sockaddr_in client_addr, local; char buf[256]; int one =3D 1; fd_set in_fds; int num, len; struct timeval tv; s =3D socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { pexit("stream socket"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { pexit("setsockopt SO_REUSEADDR"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { pexit("setsockopt SO_REUSEPORT"); } memset(&local, 0, sizeof(local)); local.sin_family =3D AF_INET; local.sin_len =3D sizeof(local); local.sin_port =3D htons(7734); local.sin_addr.s_addr =3D INADDR_ANY; if(bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) { pexit("bind error"); } listen(s, SOMAXCONN); printf("server ok .. wainting for client on 7734\n"); while (true) { client_len =3D sizeof(client_addr); if ((client =3D accept(s, (struct sockaddr *)&client_addr, &client_len)) < 0) { pexit("accept"); } client_len =3D sizeof(client_addr); getpeername(client, (struct sockaddr *)&client_addr, &client_len); diag_printf("connection from %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); #ifdef CYGPKG_LIBC_STDIO=20=20=20=20=20=20=20=20 sprintf(buf, "Hello %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); #else=20=20=20=20=20=20=20=20 strcpy(buf, "Hello "); strcat(buf, inet_ntoa(client_addr.sin_addr)); strcat(buf,":"); strcat(buf, atoi(ntohs(client_addr.sin_port))); strcat(buf,"\n"); #endif =20=20=20=20=20=20=20=20 write(client, buf, strlen(buf)); tv.tv_sec =3D 5; tv.tv_usec =3D 0; FD_ZERO(&in_fds); FD_SET(client, &in_fds); num =3D select(client+1, &in_fds, 0, 0, &tv); if (num > 0) { len =3D read(client, buf, sizeof(buf)-1); buf[len] =3D '\0'; diag_printf("buf =3D '%s'\n", buf); } else if (num =3D=3D 0) { diag_printf("No reply - timed out\n"); } else { perror("select"); } close(client); } close(s); } void net_test(cyg_addrword_t param) { diag_printf("Start SERVER test\n"); init_all_network_interfaces(); #ifdef CYGHWR_NET_DRIVER_ETH0 if (eth0_up) { server_test(ð0_bootp_data); } #endif cyg_test_exit(); } void cyg_start(void) { // Create a main thread, so we can run the scheduler and have time 'pass' cyg_thread_create(10, // Priority - just a number net_test, // entry 0, // entry parameter "Network test", // Name &stack[0], // Stack STACK_SIZE, // Size &thread_handle, // Handle &thread_data // Thread data structure ); cyg_thread_resume(thread_handle); // Start it cyg_scheduler_start(); } Thank you I am wondering why it doesnt reply to arp request whereas it announces itself at the startup(whith a packet 'who has me me ?'). And the card is able to make arp queries to connect to my pc.... is there something special to check in the eCos configuration tool ? Thierry Br=E9mard -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss