multicasting w/ lwip+RTOS on LPC1768

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

multicasting w/ lwip+RTOS on LPC1768

877 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jnewell88 on Fri Feb 15 15:10:41 MST 2013
Hello, I'm just wondering if anyone has any luck with getting FreeRTOS + lwip to join a multicast(udp) group?
I created a thread that is able to create a socket and bind the socket, but once setsockopt is run, it exits with error -1.
Any help would be appreciated, I've been banging my head against the wall for quite some time. Code is below.

Thanks, Josh

 

static void
rtp_recv_thread(void *arg)
{        LCD_PrintString2Terminal ("Start rcv thread\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
#define STREAM_PORT             2421
#define STREAM_ADDRESS          "237.0.0.0"
   
  int sock;
  struct sockaddr_in in_addr;   /* Structure used for bind() */
  struct sockaddr_in src_addr;    /* Used to receive (addr,port) of sender */
  int src_addr_len;   /* Length of src_addr */
  struct ip_mreq mreq;
  unsigned char buffer[32];
  LWIP_UNUSED_ARG(arg);

  /* create new socket */
    if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
    LCD_PrintString2Terminal ("unable to create socket\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
          vTaskDelete(NULL);
    }
LCD_PrintString2Terminal ("socket created\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);

    memset(&in_addr, 0, sizeof(in_addr));   /* Zero out structure */
      /* prepare local address */
      in_addr.sin_family=AF_INET;
      in_addr.sin_addr.s_addr= htonl(INADDR_ANY);
      in_addr.sin_port=htons(STREAM_PORT);

      /* bind to local address */
      if (bind(sock, (struct sockaddr *)&in_addr, sizeof(in_addr))){
    LCD_PrintString2Terminal ("unable to bind\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
      vTaskDelete(NULL);
      }
LCD_PrintString2Terminal ("bind success\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
        // prepare multicast "ip_mreq" struct
        mreq.imr_multiaddr.s_addr = inet_addr(STREAM_ADDRESS);
        mreq.imr_interface.s_addr = htonl(INADDR_ANY);

         //join multicast group

        if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,(char *) &mreq, sizeof(mreq))== -1)
          { LCD_PrintString2Terminal ("cant join mcast\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
                     //EXITS HERE~
          vTaskDelete(NULL);
          }
        LCD_PrintString2Terminal ("mcast join success\n", LCD_TERMINAL_NoNL,COLOR_RED, COLOR_YELLOW);
          /* receive RTP packets */
          while(1) { //Endless loop
          }
}
}
Labels (1)
0 Kudos
1 Reply

477 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jnewell88 on Tue Feb 19 11:58:44 MST 2013
Well, I did get some information about IGMP, stating that there is a bug in lwIP's setsockopt function and that netconn_join_leave_group should be used instead.
http://savannah.nongnu.org/bugs/?38165

Tried to use the netconn API and it still isn't joining the group( it passes with ERR_VAL (-6) on the netconn_join_leave_group call).


Has anyone successfully implemented the Netconn API with multicast?

~Josh
0 Kudos