public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] TCP socket problem : connect and bind
       [not found] <1119016906.32044.ezmlm@ecos.sourceware.org>
@ 2005-06-17 14:11 ` Thierry Brémard
  2005-06-17 15:23   ` Matt Jerdonek
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Brémard @ 2005-06-17 14:11 UTC (permalink / raw)
  To: ecos-discuss

Hello, I have the code folowing , it works fine under a cygwin
environement, it compiles fine with the ecos tools and I load it fine
on my viper card.

after a 'load -v -m ymodem'
I run: 'go'
and I have an error of connect() and of bind().

Furthermore I can ping the viper card thanks to my computer, but the
command 'ping -n 3 -h 1.1.1.2' doesn't succeed on the redboot
environement (where 1.1.1.2 is the ip of my computer), my computer is
linked with a ethernet cable to the card directly.

=> is there some functions to call before using the network ?
in my repository I have an ecos environnement build arround the 'net'
package.


**
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define SOCKET_ERROR -1

int OpenPort(int port)
{
struct sockaddr_in sin;
int sock;
unsigned char val=1;

    if((sock=socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) return 0;
    sin.sin_port=htons((short)port);
    sin.sin_addr.s_addr=0;
    sin.sin_family=AF_INET;
    //Allow the socket to be bound to an address which is already in
use
//   
if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val))==SOCKET_E
RROR) return 0;
// (By default, a socket cannot be bound  to a local address which is
already in use.)

    if(bind(sock,(struct sockaddr *)&sin,sizeof(sin))==SOCKET_ERROR)
return 0;

    if(listen(sock,SOMAXCONN)==SOCKET_ERROR) return 0;

    return sock;
}

int connecta(short port)
{
struct sockaddr_in sin;
int sock;

    if((sock=socket(AF_INET,SOCK_STREAM,0)) == SOCKET_ERROR) return 0;
    sin.sin_port=htons((short)port);
    sin.sin_addr.s_addr = inet_addr("147.215.40.139");
    sin.sin_family=AF_INET;
    //Allow the socket to be bound to an address which is already in
use
//   
if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&val,sizeof(val))==SOCKET_E
RROR) return 0;
// (By default, a socket cannot be bound  to a local address which is
already in use.)

   // if(bind(sock,(struct sockaddr *)&sin,sizeof(sin))==SOCKET_ERROR)
return 0;

    connect(sock, (struct sockaddr *)&sin, sizeof(sin));
    //if(listen(sock,SOMAXCONN)==SOCKET_ERROR) return 0;

    return sock;
}

int main()
{
    int sock;
    int sock_client;
    
    connecta(90);
    
    sock = OpenPort(90);
    sock_client = accept(sock, NULL, 0);
    printf("client connected");
    return 0;
    
    
    
}
**eof

Thank you 

Thierry

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] TCP socket problem : connect and bind
  2005-06-17 14:11 ` [ECOS] TCP socket problem : connect and bind Thierry Brémard
@ 2005-06-17 15:23   ` Matt Jerdonek
  2005-06-17 16:00     ` Thierry Brémard
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Jerdonek @ 2005-06-17 15:23 UTC (permalink / raw)
  To: Thierry Brémard, ecos-discuss


--- Thierry Brémard <bremardt@esiee.fr> wrote:

> => is there some functions to call before using the
> network ?

Add the function 'init_all_network_interfaces()' to
your main routine before making any TCP function
calls.

-- Matt



		
__________________________________ 
Yahoo! Mail 
Stay connected, organized, and protected. Take the tour: 
http://tour.mail.yahoo.com/mailtour.html 


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] TCP socket problem : connect and bind
  2005-06-17 15:23   ` Matt Jerdonek
@ 2005-06-17 16:00     ` Thierry Brémard
  2005-06-17 17:24       ` Matt Jerdonek
  0 siblings, 1 reply; 6+ messages in thread
From: Thierry Brémard @ 2005-06-17 16:00 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: ecos-discuss

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):

=>
IP: 147.215.40.77/255.255.255.0, Gateway: 147.215.40.1
Default server: 147.215.1.4
                                                                      
         
RedBoot(tm) bootstrap and debug environment [ROM]
Non-certified release, version W468 V3I4 - built 09:58:14, Aug  3 2004
                                                                      
         
Platform: VIPER (XScale PXA255)
Copyright (C) 2000, 2001, 2002, Red Hat, Inc.
                                                                      
         
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
                                                                      
         
<=

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:
=>
///gnutools/arm-elf/bin/arm-elf-

//#include <cyg/kernel/kapi.h>

#include <stdio.h>
//#include <math.h>
#include <stdlib.h>
/*#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
*/
#include <network.h>

#define SOCKET_ERROR -1
#define DESIRED_BACKGROUND_LOAD 50

int OpenPort(unsigned short port)
{
    struct sockaddr_in sin;
    int sock;

    if((sock = socket(AF_INET, SOCK_STREAM, 0))== SOCKET_ERROR)
    {
        printf("error in OpenPort, socket()");
        return 0;
    }

    sin.sin_port = htons(port);
//    sin.sin_addr.s_addr = 0;
    sin.sin_addr.s_addr = INADDR_ANY;
    sin.sin_family = AF_INET;
        
    if(SOCKET_ERROR == bind(sock, (struct sockaddr *)&sin,
sizeof(struct sockaddr_in) ))
    {
        printf("error in OpenPort, bind()");
        return 0;
    }

    if(SOCKET_ERROR == listen(sock, SOMAXCONN))
    {
        printf("error in OpenPort, listen()");
        return 0;
    }
 
    return sock;

}




int Connexion(unsigned short port)
{
    struct sockaddr_in sin;
    int sock;

    if((sock = socket(AF_INET, SOCK_STREAM, 0))== SOCKET_ERROR)
    {
        printf("error in OpenPort, socket()");
        return 0;
    }

    sin.sin_port = htons(port);
    sin.sin_addr.s_addr = inet_addr("147.215.40.139");
    sin.sin_family = AF_INET;
  
    if(SOCKET_ERROR == connect(sock, (struct sockaddr *)&sin,
sizeof(struct sockaddr_in) ))
    {
        printf("error in Connexion, connect()");
        return 0;
    }
    return sock;

}



// envoi les données pointées par data taille = len
// tout est envoyé grace à un appel à recv dans le while
// retourne le nombre d'octets envoyés 
int SendData(int sock, char *data, int len)
{
    int total = 0;
    int ret;
    
    while((ret = send(sock, data, len, 0))>0) // envoi les données
    {
        total += ret;  // octets envoyés au total
        data  += ret;  // pointe plus loin sur les données non
envoyées
        len   -= ret;  // la taille restante diminue
    }
    
    return total;  // nombre d'octets envoyés
}

// envoie la chaine de caractère ascii, terminée par un 0.
// retourne le nombre d'octets envoyés (n'envoie pas le 0)
int SendString(int sock, char *str)
{
   return SendData(sock, str, strlen(str));
}

// recoit des données, les stocke dans buffer
// la réception s'achève oubien quand len octets ont été recus
// ou bien quand \n est recu.
// les caractères \r et \n sont enlevés de la fin du buffer avant de
retourner
// le nombre de caractères mis dans buffer est retourné.
int RecvLine(int sock, char *buffer, int len)
{
    char c;
    int total = 0;
    int ret;
    
    memset(buffer, 0 , len);
    
    while( (total<len) && ((ret = recv(sock, &c, 1, 0))>0) )
    {
        memcpy(&buffer[total], &c, ret ); // buffer[total] = c;
        total += ret; // total++;
        if(buffer[total-1] =='\n')
            break ; // sortie de la boucle si retour chariot recu.
    
    }
    
    len = strlen(buffer);
    while((buffer[len-1] =='\n') || (buffer[len-1] =='\r'))
    {
        buffer[len-1] = 0; // écrase \n ou \r par caractère de fin de
chaine
        len--;
        if(!len)   // si taille nulle
            break; // termine la boucle
    }
    
    return len;
    
}

//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 = Connexion(90))
        printf("connected!");
        
    printf("opening port 50..");
    if(!(sock = OpenPort(50)))
    {
        printf("error opening port !");
        return 0;
    }
    printf("ok\n");
    
    
    if(SOCKET_ERROR == (client = 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");
    }    
    
    close(sock);
    close(client);

    puts("Server finished");
    return 0;
  
}
<=


Thank you for your help

-------------------
> 
> --- Thierry Brémard <bremardt@esiee.fr> wrote:
> 
> > => is there some functions to call before using the
> > network ?
> 
> Add the function 'init_all_network_interfaces()' to
> your main routine before making any TCP function
> calls.
> 
> -- Matt
> 
> 
> 
> 		
> __________________________________ 
> Yahoo! Mail 
> Stay connected, organized, and protected. Take the tour: 
> http://tour.mail.yahoo.com/mailtour.html 
> 
> 
> -- 
> Before posting, please read the FAQ:
http://ecos.sourceware.org/fom/ecos
> and search the list archive:
http://ecos.sourceware.org/ml/ecos-discuss
> 
> 

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] TCP socket problem : connect and bind
  2005-06-17 16:00     ` Thierry Brémard
@ 2005-06-17 17:24       ` Matt Jerdonek
  2005-06-17 19:26         ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Jerdonek @ 2005-06-17 17:24 UTC (permalink / raw)
  To: Thierry Brémard; +Cc: ecos-discuss


> BOOTP/DHCP failed on eth0
> Server Redboot !
> error in Connexion, connect()
> opening port 50..
> error in OpenPort, bind()error
>                                                     
>                  
>          
> <=
> 
> I don't have a dhcp server since at the beginning of
> the start up the
> ip is correct.

Since you don't have a DHCP server, I suggest you
disable DHCP and manually assign the IP address. 
Check your ecc file and look for 
CYGHWR_NET_DRIVER_ETH0_MANUAL (set to 1)
CYGHWR_NET_DRIVER_ETH0_BOOTP (set to 0)
Of course then you'll have to setup the IP address,
mask and gateway in the CDL as well.

-- Matt


		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] TCP socket problem : connect and bind
  2005-06-17 17:24       ` Matt Jerdonek
@ 2005-06-17 19:26         ` Andrew Lunn
  2005-06-17 21:05           ` [ECOS] " Grant Edwards
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Lunn @ 2005-06-17 19:26 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: Thierry =?unknown-8bit?Q?Br=E9mard?=, ecos-discuss

On Fri, Jun 17, 2005 at 10:24:06AM -0700, Matt Jerdonek wrote:
> 
> > BOOTP/DHCP failed on eth0
> > Server Redboot !
> > error in Connexion, connect()
> > opening port 50..
> > error in OpenPort, bind()error
> >                                                     
> >                  
> >          
> > <=
> > 
> > I don't have a dhcp server since at the beginning of
> > the start up the
> > ip is correct.
> 
> Since you don't have a DHCP server, I suggest you
> disable DHCP and manually assign the IP address. 
> Check your ecc file and look for 
> CYGHWR_NET_DRIVER_ETH0_MANUAL (set to 1)
> CYGHWR_NET_DRIVER_ETH0_BOOTP (set to 0)
> Of course then you'll have to setup the IP address,
> mask and gateway in the CDL as well.

Also remember that RedBoot and the application need different IP
addresses.

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ECOS] Re: TCP socket problem : connect and bind
  2005-06-17 19:26         ` Andrew Lunn
@ 2005-06-17 21:05           ` Grant Edwards
  0 siblings, 0 replies; 6+ messages in thread
From: Grant Edwards @ 2005-06-17 21:05 UTC (permalink / raw)
  To: ecos-discuss

In gmane.os.ecos.general, you wrote:

>> Since you don't have a DHCP server, I suggest you
>> disable DHCP and manually assign the IP address. 
>> Check your ecc file and look for 
>> CYGHWR_NET_DRIVER_ETH0_MANUAL (set to 1)
>> CYGHWR_NET_DRIVER_ETH0_BOOTP (set to 0)
>> Of course then you'll have to setup the IP address,
>> mask and gateway in the CDL as well.
>
> Also remember that RedBoot and the application need different
> IP addresses.

If you want to do GDB via TCP.  The product line I work on is
set up so that RedBoot and the eCos app used the same IP
configuration (both either got the same address from DHCP or
they both used the same static IP address).  It works fine if
that's what you really want to do.  Shipping something that
required two IP addresses was deemed to be untenable.

-- 
Grant Edwards                   grante             Yow!  .. Should I get
                                  at               locked in the PRINCIPAL'S
                               visi.com            OFFICE today -- or have
                                                   a VASECTOMY??

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-06-17 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1119016906.32044.ezmlm@ecos.sourceware.org>
2005-06-17 14:11 ` [ECOS] TCP socket problem : connect and bind Thierry Brémard
2005-06-17 15:23   ` Matt Jerdonek
2005-06-17 16:00     ` Thierry Brémard
2005-06-17 17:24       ` Matt Jerdonek
2005-06-17 19:26         ` Andrew Lunn
2005-06-17 21:05           ` [ECOS] " Grant Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).