Altera_Forum
Honored Contributor
20 years agoUDP Header isn't sent
hi all,
I'm having problems with sending out my udp-header. When I use ethereal it claims that no header was sent out. I am using the LWIP stand alone webserver example to send out my udp messages CODE ******************************************************************** /* * * This file is for testing stand-alone (NO_SYS) LWIP * using a RAM-based simple file system * */ # include "system.h" # include "arch/init.h"# include "lwip/ip_addr.h"# include "lwip/tcpip.h"# include "lwip/udp.h"# include "lwip/netif.h"# include "netif/lan91c111if.h"# include "stdio.h"# include "stdlib.h" # include "sys/alt_alarm.h" /* ---------- IP oriented addresses for ethernet adapter ---------- */# define IPADDR0 169# define IPADDR1 254# define IPADDR2 0# define IPADDR3 2 # define NETMASK0 255# define NETMASK1 255# define NETMASK2 0# define NETMASK3 0 # define GWADDR0 10# define GWADDR1 1# define GWADDR2 1# define GWADDR3 11 int main(void) { //0.6.4 struct netif *netif; struct netif netif; struct ip_addr ipaddr, netmask, gw; struct ip_addr udpDestIpAddr; //IP-address to send UDP packet to struct pbuf* packetBuffer; //Pointer to a packet buffer struct udp_pcb* udpSocket; //Create UDP-socket struct udp_hdr* udpHeader; //Create UDP-header u16_t localPort, destPort; 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"); packetBuffer = pbuf_alloc(PBUF_TRANSPORT,100,PBUF_RAM); /* * 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); IP4_ADDR(&udpDestIpAddr, 169, 254, 0, 1); udpHeader->src = localPort; udpHeader->dest = destPort; udpSocket = udp_new(); udp_bind(udpSocket, IP_ADDR_ANY, localPort); //Bind socket to port udp_connect(udpSocket, &udpDestIpAddr, destPort); printf("Ready to send....\n"); while(1) { //0.6.4 lan91c111if_service(netif); lan91c111if_service(&netif); udp_send(udpSocket, packetBuffer); printf("Send a package\n"); // printf("Local port is %d\n", udpHeader->dest); } } ******************************************************************** But for some reason, the UDP header isn't sent. Does anyone know what I'm doing wrong?! Cheers, Danny