AnsweredAssumed Answered

How to create chain of pbuf's to be sent? Send data using UDP.

Question asked by Prof Programmer on Feb 11, 2016
Latest reply on Feb 17, 2016 by isaacavila

How to creat and initsializtion this struct for send data using UDP

struct pbuf *p;

 

I using this code.   

 

struct netif fsl_netif0;  struct udp_pcb * pcb;  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;     #define PORT_M 9000    void eth_lwip_init () {        lwip_init();       IP4_ADDR(&fsl_netif0_ipaddr, 192,168,70,110);    IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);    IP4_ADDR(&fsl_netif0_gw, 192,168,70,1);    netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);       netif_set_default(&fsl_netif0);       {     uint32_t dt = 0;     ENET->MSCR = 0x26<<1;     PHY_DRV_Read (0,0,0x1f, &dt);     dt |= (1<<7);     PHY_DRV_Write (0, 0, 0x1f, dt );     OSA_TimeDelay(1000);    }           // get new pcb      pcb = udp_new();      if (pcb == NULL) {          LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));          return;      }          //bind to any IP address on port  //IP_ADDR_ANY      if (udp_bind(pcb, &fsl_netif0_ipaddr, PORT_M) != ERR_OK) {          LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));          return;      }         netif_set_up(&fsl_netif0);      // set udp_echo_recv() as callback function      // for received packets      udp_recv(pcb, udp_echo_recv, NULL);           ///  test message      {   uint8_t i;      err_t err_if;         struct pbuf *p;         struct udp_hdr* u_hdr;        // extern struct udp_pcb *pcb;         uint8_t data[8] = {0x55, 0x44, 0x33, 0x22, 0x11, 0x0, 0x0, 0x0 };            p = pbuf_alloc(PBUF_TRANSPORT, 8, PBUF_RAM);            u_hdr = (struct udp_hdr *)p->payload;         u_hdr->src = (uint16_t) fsl_netif0_ipaddr;         u_hdr->dest = PORT_M;         u_hdr->len = sizeof(struct udp_hdr) + sizeof(data);            for (i=0; i<sizeof(data); i++) {      ((char*)u_hdr)[sizeof(struct udp_hdr) + i] = (char)data[i];         }            u_hdr->chksum = inet_chksum( &u_hdr, 8UL);         err_if = udp_send ( pcb, p );      if (err_if != ERR_OK) {      printf ("Error udp_sendto = %d\n", err_if);      }        pbuf_free (p);      }  }

 

How to send data fo udp packets?

Outcomes