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]
Other format: [Raw text]

RE: Using bind() with LWIP


Hi,
   The thread or the program  that you have created( in which the bind is
called) should be in the lwip memory area. other wise it will hang at this
system call(Not for bind for any system call that use the lwip stack memory
area  it will hang).Create thread in the lwip memory .From the lwip example
programs you will get information on how to create thread in the lwip stack
memory area.
regards,
S.Ramesh Chandra.
   




-----Original Message-----
From: Chris Garry [mailto:cgarry@sweeneydesign.co.uk]
Sent: Monday, May 12, 2003 10:09 PM
To: ecos-discuss@sources.redhat.com
Cc: jani@iv.ro
Subject: [ECOS] Using bind() with LWIP


When I call the bind() function with LWIP the function never returns.

It looks like the function that actually locks up is:
sys_mbox_fetch() in net\lwip_tcpip\current\src\sys.c.

Has anybody else come accross this problem?

Thanks,
Chris


--
Example code (Which works with BSD stack):

#define __LWIP

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

#ifdef __LWIP
#include <lwip/inet.h>
#include <lwip/sys.h>
#define LWIP_COMPAT_SOCKETS 1
#include <lwip/sockets.h>
#else
#include <network.h>
#endif

#define MYPORT 3490 // the port users will be connecting to
#define BACKLOG 10 // how many pending connections queue will hold
#define NUM_CONNECTIONS  5

/* this is the main program which runs in a thread */
int main(void)
{
    int sockfd, new_fd; // listen on sock_fd, new connection on new_fd
    struct sockaddr_in my_addr; // my address information
    struct sockaddr_in their_addr; // connector's address information
    int sin_size;

#ifdef __LWIP
    diag_printf("lwip_init()\n");
    lwip_init();
#else
    diag_printf("init_all_network_interfaces()\n");
    init_all_network_interfaces();
#endif

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        diag_printf("socket() failed\n");
    }

    my_addr.sin_family = AF_INET; // host byte order
    my_addr.sin_port = htons(MYPORT); // short, network byte order
    my_addr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP
    memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

    diag_printf("bind()\n");
    bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));

    diag_printf("listen()\n");
    listen(sockfd, BACKLOG);

    diag_printf("accept()\n");
    sin_size = sizeof(struct sockaddr_in);
    new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);

    diag_printf("Done accept new_fd: %d\n", new_fd);

    while(1)
    {
        cyg_thread_delay(1000);
    }
}


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

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


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