This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Using bind() with LWIP
- From: "Chris Garry" <cgarry at sweeneydesign dot co dot uk>
- To: <ecos-discuss at sources dot redhat dot com>
- Cc: <jani at iv dot ro>
- Date: Mon, 12 May 2003 17:39:16 +0100
- Subject: [ECOS] Using bind() with LWIP
- Organization: Sweeney Design
- Reply-to: "Chris Garry" <cgarry at sweeneydesign dot co dot uk>
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