public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Thierry Brémard" <bremardt@esiee.fr>
To: Matt Jerdonek <maj1224@yahoo.com>
Cc: ecos-discuss@sources.redhat.com
Subject: Re: [ECOS] TCP socket problem : connect and bind
Date: Fri, 17 Jun 2005 16:00:00 -0000	[thread overview]
Message-ID: <20050617155959.8140C365917@mail.esiee.fr> (raw)
In-Reply-To: <20050617151119.46649.qmail@web33512.mail.mud.yahoo.com>

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

  reply	other threads:[~2005-06-17 16:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1119016906.32044.ezmlm@ecos.sourceware.org>
2005-06-17 14:11 ` Thierry Brémard
2005-06-17 15:23   ` Matt Jerdonek
2005-06-17 16:00     ` Thierry Brémard [this message]
2005-06-17 17:24       ` Matt Jerdonek
2005-06-17 19:26         ` Andrew Lunn
2005-06-17 21:05           ` [ECOS] " Grant Edwards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050617155959.8140C365917@mail.esiee.fr \
    --to=bremardt@esiee.fr \
    --cc=ecos-discuss@sources.redhat.com \
    --cc=maj1224@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).