URL: <http://savannah.gnu.org/support/?106914>
Summary: what's wrong with my lwip-raw api udp_send design? Project: Savannah Administration Submitted by: the_gadfly Submitted on: Thu Jun 25 12:47:25 2009 Category: None Priority: 5 - Normal Severity: 3 - Normal Status: None Assigned to: None Originator Email: the_gad...@163.com Operating System: None Open/Closed: Open Discussion Lock: Any _______________________________________________________ Details: Hi : I am a new guy to lwip ,and when i use udp to my design .i hit a big broblem.After seaching a long time,it is still here . I cant receive any udp message at all ,i hope you could help me here is my code ,can you see some incorrect things? thank you the_gadfly --------------------------- #include "system.h" #include "lwip/debug.h" #include "lwip/stats.h" #include "arch/init.h" #include "lwip/ip_addr.h" #include "lwip/tcpip.h" #include "lwip/netif.h" #include "netif/lan91c111if.h" #include "lwip/udp.h" #include #include "httpd.h" #include "sys/alt_alarm.h" #define get_milliseconds() alt_nticks() int n; /* ---------- IP oriented addresses for ethernet adapter ---------- */ #define IPADDR0 10 #define IPADDR1 1 #define IPADDR2 1 #define IPADDR3 51 #define NETMASK0 255 #define NETMASK1 255 #define NETMASK2 255 #define NETMASK3 0 #define GWADDR0 10 #define GWADDR1 1 #define GWADDR2 1 #define GWADDR3 2 void httpd_init(void) { char Test[]="hello world !"; struct udp_pcb *pcb; struct ip_addr ipaddr; struct pbuf *p; err_t err; IP4_ADDR(&ipaddr,10,1,1,52); p = pbuf_alloc(PBUF_RAW,15,PBUF_RAM); p->payload=(void *)Test; p->len=p->tot_len=15; pcb = udp_new(); err=udp_bind(pcb, IP_ADDR_ANY, 30); printf("err= %s",err); err=udp_connect(pcb,&ipaddr,30); printf("err= %s",err); err=udp_send(pcb,p); printf("err= %s",err); pbuf_free(p); udp_remove( pcb ); } int main(void) { //0.6.4 struct netif *netif; struct netif netif; struct ip_addr ipaddr, netmask, gw; unsigned int now, lasttime; int i; #if IP_REASSEMBLY int j; #endif alt_avalon_lan91c111_if* dev_list_ptr = (alt_avalon_lan91c111_if*)alt_ethernet_device_list.next; printf("Example web server using Light-weight IP (LWIP)\n"); printf("and simple RAM-based file system.\n\n"); /* * Initialize lwip */ lwip_init(); printf ("Setting IP address to: %d.%d.%d.%d\n", IPADDR0, IPADDR1, IPADDR2, IPADDR3); printf ("Setting netmask to: %d.%d.%d.%d\n", NETMASK0, NETMASK1, NETMASK2, NETMASK3); printf ("Setting gateway address to: %d.%d.%d.%d\n", GWADDR0, GWADDR1, GWADDR2, GWADDR3); IP4_ADDR(&ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3); IP4_ADDR(&netmask, NETMASK0, NETMASK1, NETMASK2, NETMASK3); IP4_ADDR(&gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3); //0.6.4 netif = netif_add(&ipaddr, &netmask, &gw, netif_add(&netif, &ipaddr, &netmask, &gw, (void*)dev_list_ptr, lan91c111if_init, ip_input); //0.6.4 netif_set_default(&netif); netif_set_default(&netif); /* * Initialize application(s) */ httpd_init(); //udp_echo_init(); /* main loop to service the Ethernet device and expire TCP timers */ lasttime = get_milliseconds(); i=0; #if IP_REASSEMBLY j=0; #endif while(1) { //0.6.4 lan91c111if_service(netif); lan91c111if_service(&netif); now = get_milliseconds(); if (now - lasttime > TCP_TMR_INTERVAL) { lasttime = now; tcp_tmr(); if (++i==50) { //etharp_tmr(); i=0; } } #if IP_REASSEMBLY if (++j==1000) { ip_reass_timer(); j=0; } #endif } } ------------------------------------ _______________________________________________________ Reply to this item at: <http://savannah.gnu.org/support/?106914> _______________________________________________ Message sent via/by Savannah http://savannah.gnu.org/