Altera_Forum
Honored Contributor
20 years agoSending a UDP-message
Hi all,
this is my code. I am trying to send messages through UDP. But all it is sending are ARP's. Could anyone tell me what's wrong? I am going crazy overhere.... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/unsure.gif Cheers, Danny ******************************************************************** /* * * 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/netif.h"# include "netif/lan91c111if.h" # include "httpd.h"# include "echo.h" # include "sys/alt_alarm.h" //#define get_milliseconds() alt_nticks() /* ---------- 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 0# define GWADDR1 0# define GWADDR2 0# define GWADDR3 0 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 char buffer[100]; // char *buffPtr; alt_avalon_lan91c111_if* dev_list_ptr = (alt_avalon_lan91c111_if*)alt_ethernet_device_list.next; printf("UDP-server using Light-weight IP (LWIP)\n\n"); // sprintf(buffer, "PWNED \n"); //MSG to send to vics0urce // buffPtr = mem_malloc(sizeof(buffer)); // memcpy(buffPtr, buffer, sizeof(buffer)); //copy's from buffer to buffer packetBuffer = pbuf_alloc(PBUF_TRANSPORT,666,PBUF_RAM); pbuf_free(packetBuffer); // packetBuffer -> payload = (void *)buffPtr; //packetBuffer -> next = NULL; // packetBuffer -> tot_len=1450; // packetBuffer -> len=1450; /* * 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\n\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); udpSocket = udp_new(); udp_bind(udpSocket, IP_ADDR_ANY, 1024); //Bind socket to port udp_connect(udpSocket, &udpDestIpAddr, 666); //Bind socket to any incoming IP-address printf("Ready to send....\n"); while(1) { //0.6.4 lan91c111if_service(netif); //udp_recv(udpSocket, &packetBuffer, (int *)sizeof(packetBuffer)); // pbuf2->payload = (void*)((UDP_CHECKSUM_BASE+4*11)|0x80000000); udp_send(udpSocket, packetBuffer); if(buffer != NULL) { printf("Pakket is verzonden\n"); // sprintf(udpSocket, "socket is \n"); } } lan91c111if_service(&netif); } ******************************************************************