From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18431 invoked by alias); 17 Jun 2005 16:00:13 -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 18355 invoked by uid 22791); 17 Jun 2005 16:00:02 -0000 Received: from mail.esiee.fr (HELO mail.esiee.fr) (147.215.1.3) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Fri, 17 Jun 2005 16:00:02 +0000 Received: from mail.esiee.fr (localhost.esiee.fr [127.0.0.1]) by mail.esiee.fr (Postfix) with SMTP id 10DE236591B; Fri, 17 Jun 2005 18:00:00 +0200 (CEST) Received: from esiee.fr (localhost.esiee.fr [127.0.0.1]) by mail.esiee.fr (Postfix) with ESMTP id 8140C365917; Fri, 17 Jun 2005 17:59:59 +0200 (CEST) Content-Type: text/plain; charset=iso-8859-1 User-Agent: IMHO/0.99 (Webmail for Roxen) Date: Fri, 17 Jun 2005 16:00:00 -0000 In-Reply-To: <20050617151119.46649.qmail@web33512.mail.mud.yahoo.com> MIME-Version: 1.0 Cc: ecos-discuss@sources.redhat.com To: Matt Jerdonek From: Thierry =?iso-8859-1?q?Br=E9mard?= Message-Id: <20050617155959.8140C365917@mail.esiee.fr> Content-Transfer-Encoding: quoted-printable Subject: Re: [ECOS] TCP socket problem : connect and bind X-SW-Source: 2005-06/txt/msg00144.txt.bz2 ok, I Added the function 'init_all_network_interfaces()' now I have the folowing output (note the correct ip at the redboot start up and the 0x000 in cyg_init): =3D> IP: 147.215.40.77/255.255.255.0, Gateway: 147.215.40.1 Default server: 147.215.1.4 =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=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=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20 RedBoot(tm) bootstrap and debug environment [ROM] Non-certified release, version W468 V3I4 - built 09:58:14, Aug 3 2004 =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=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=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20 Platform: VIPER (XScale PXA255) Copyright (C) 2000, 2001, 2002, Red Hat, Inc. =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=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=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20 RAM: 0x00000000-0x04000000, [0x00400000-0x03fd1000] available FLASH: base 0x60000000, size 0x02000000, 256 blocks of 0x00020000 bytes each. RedBoot> load -v -m ymodem CEntry point: 0x00400040, address range: 0x00400000-0x00443678 xyzModem - CRC mode, 25580(SOH)/0(STX)/0(CAN) packets, 5 retries RedBoot> 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(0x00442fe0) New domain internet at 0x00000000 [cyg_net_init] Init: cyg_net_add_domain(0x00442a28) New domain route at 0x00000000 [cyg_net_init] Init: call_route_init(0x00000000) [cyg_net_init] Done [eth_drv_ioctl] Warning: Driver can't set multi-cast mode [eth_drv_ioctl] Warning: Driver can't set multi-cast mode BOOTP/DHCP failed on eth0 Server Redboot ! error in Connexion, connect() opening port 50.. error in OpenPort, bind()error =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=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=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20 <=3D I don't have a dhcp server since at the beginning of the start up the ip is correct. before loading the code on the arcom viper card, I can ping my card (my card can't ping my host) after the execution of my code (finished by bind error) the card do not reply anymore to my host pings (and the light of the eth0 is shutdown) The source code is follwing: =3D> ///gnutools/arm-elf/bin/arm-elf- //#include #include //#include #include /*#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; =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()"); 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()"); 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"); if(sock =3D Connexion(90)) printf("connected!"); =20=20=20=20=20=20=20=20 printf("opening port 50.."); if(!(sock =3D OpenPort(50))) { printf("error opening port !"); 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 I am 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 } <=3D Thank you for your help ------------------- >=20 > --- Thierry Br=E9mard wrote: >=20 > > =3D> is there some functions to call before using the > > network ? >=20 > Add the function 'init_all_network_interfaces()' to > your main routine before making any TCP function > calls. >=20 > -- Matt >=20 >=20 >=20 >=20=09=09 > __________________________________=20 > Yahoo! Mail=20 > Stay connected, organized, and protected. Take the tour:=20 > http://tour.mail.yahoo.com/mailtour.html=20 >=20 >=20 > --=20 > Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos > and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss >=20 >=20 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss