This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with socket


Hi,

I'm trying to make an simulation environment on the eCos synthetic target.
To do this, I need that two applications running on the same PC or between
two PC communicates using socket.
If I use the INADDR_ANY address, I have an errno 22 "invalid argument".
What is wrong?
If I use the IP address, I have an errno 365 "no route to host". The two
machines known each other, a ping works with no problem.
Must I initialize the route in my eCos application? If yes, how?

Hereafter, an extract of my source code.
Server src code:
    init_all_network_interfaces();
    s_source = socket(AF_INET, SOCK_STREAM, 0);
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_len = sizeof(local);
    local.sin_port = ntohs(SOURCE_PORT);
    local.sin_addr.s_addr = htonl(INADDR_ANY);
    if(bind(s_source, (struct sockaddr *) &local, sizeof(local)) < 0) {
        pexit("bind /source/ error");
    }
    if (setsockopt(s_source, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)))
{
        pexit("setsockopt /source/ SO_REUSEADDR");
    }
    if (setsockopt(s_source, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)))
{
        pexit("setsockopt /source/ SO_REUSEPORT");
    }
    listen(s_source, SOMAXCONN);

   e_source = 0;
    while (true) {
        FD_ZERO(&in_fds);
        FD_SET(s_source, &in_fds);
        if ((e_source = accept(s_source,(struct sockaddr *)&e_source_addr,
&len))<0) {
            pexit("accept /source/");
        }
        printf("TCP SERVER connection from %s: %d\n",

inet_ntoa(e_source_addr.sin_addr),ntohs(e_source_addr.sin_port));
        if (e_source != 0) {
            break;
        }
    }   /* while (true) */

Client src code:
    init_all_network_interfaces();
    s_source = socket(AF_INET, SOCK_STREAM, 0);
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_port = htons(SOURCE_PORT);
    local.sin_addr.s_addr = htonl(INADDR_ANY);

     result = connect(s_source, (struct sockaddr *)&local, sizeof(local));


Could anyone help me in this regard.

Thanks in advance.

Regards

Nadine.






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]