From: "Thierry Brémard" <bremardt@esiee.fr>
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] TCP socket problem : connect and bind
Date: Fri, 17 Jun 2005 14:11:00 -0000 [thread overview]
Message-ID: <20050617141042.E9E37365910@mail.esiee.fr> (raw)
In-Reply-To: <1119016906.32044.ezmlm@ecos.sourceware.org>
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
next parent reply other threads:[~2005-06-17 14:11 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 [this message]
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
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=20050617141042.E9E37365910@mail.esiee.fr \
--to=bremardt@esiee.fr \
--cc=ecos-discuss@sources.redhat.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).