I am new to LWIP and im trying to build a echo server application using Sockets API, i dont know what i am doing wrong, im guessing i am not initialising few modules or something. pls help.
main.c ********************************************** int main(){ printf("Main "); socketserver_init(); return 0; } **************************************************** server.c #include <unistd.h> #include <getopt.h> #include "lwip/init.h" #include "lwip/debug.h" #include "lwip/mem.h" #include "lwip/memp.h" #include "lwip/sys.h" #include "lwip/stats.h" #include "lwip/ip.h" #include "lwip/ip_frag.h" #include "lwip/udp.h" #include "lwip/snmp_msg.h" #include "lwip/tcp.h" #include "lwip/tcpip.h" #include "lwip/sockets.h" #include "mintapif.h" #include "netif/etharp.h" #include "timer.h" //#include "sys/socket.h" //#include <arpa/inet.h> #include <signal.h> #include "server.h" #include "private_mib.h" #define MY_PORT 9999 #define MAXBUF 1024 /* nonstatic debug cmd option, exported in lwipopts.h */ unsigned char debug_flags; void socketserver_thread(); void socketserver_init(void) { debug_flags = LWIP_DBG_ON; sys_thread_new("socketserver_thread", socketserver_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); } // Sequential APIs have to be a part of separate thread void socketserver_thread(){ int sockfd; struct sockaddr_in self; char *buffer; lwip_socket_init(); printf("//Creating stream socket"); if((sockfd = lwip_socket(PF_INET, SOCK_STREAM,0)) < 0) { printf("Socket error"); return -1; } // Initialise address/port structure bzero(&self, sizeof(self)); self.sin_family = AF_INET; self.sin_port = htons(MY_PORT); self.sin_addr.s_addr = INADDR_ANY; // Bind the socket to port if ( lwip_bind(sockfd, (struct sockaddr*)&self, sizeof(self)) != 0 ) { printf("socket--bind error"); return -1; } // Make it a listening socket if( lwip_listen(sockfd, 20) != 0) { printf("socket--listen error"); return -1; } /*---Forever... ---*/ while (1) { printf("WAiting for connection"); int clientfd; struct sockaddr_in client_addr; int addrlen=sizeof(client_addr); /*---accept a connection (creating a data pipe)---*/ clientfd = lwip_accept(sockfd, (struct sockaddr*)&client_addr, &addrlen); printf("%s:%d connected\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); /*---Echo back anything sent---*/ lwip_send(clientfd, buffer, recv(clientfd, buffer, MAXBUF, 0), 0); /*---Close data connection---*/ lwip_close(clientfd); } /*---Clean up (should never get here!)---*/ close(sockfd); return 0; } ***********************************************************************
_______________________________________________ lwip-users mailing list lwip-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/lwip-users