Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

LWIP broadcast

Hello,

I have set up NIOS w/LWIP as UDP client. Addresses are fixed, not using DHCP. I can send and receive okay to fixed IP addresses, but LWIP will not receive a packet when the server sets the last dot quad to .255 instead of the particular value (.003 in my case). The subnet mask both server (a PC running Labview) and the client (NIOS) are 255.255.255.0. Packet sniffer shows proper packets.

I can trace (by breakpoints) the UDP packet with x.x.x.255 address to the function udp_input (in file udp.c), but the function does not recognize the packet as being of interest and doesn't process it completely, so the function recvfrom() never returns. I can't tell exactly what is going on within the function, but I'm pretty sure this is where the hangup is.

Has anyone had any luck receiving broadcast UDP packets? Suggestions?

Thanks for your help,

Tim

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have developed my own patch that appears to solve the problem. In file udp.c, line 216, replace

    ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {

    with

    ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) ||

    ip_addr_isbroadcast(&iphdr->dest, inp) ) {

    effectively adding a check for broadcast to one of the many checks of the packet control block. I am not sure this is rigorously correct, but appears to work. Comments invited.

    Regards,

    Tim
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Tim,

    I've question regarding your patch.

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    ...p_addr_isbroadcast(&iphdr->dest, inp)..[/b]

    --- Quote End ---

    What kind of type is the variable inp? Because i cannot find a variable in the code that is suitable for that.

    Regards,

    Peter

    EDIT: OK found it by myself :-)
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have simular issue. I have setup the NIOS udp client but when a broadcast message is sent out on the network my receive led flashes but my break point in the udp.c file does not get hit. If I send a regular udp message it does? Whats that all about..

    mask = 0xFFFFFF00

    IP = 192.168.31.44

    PC is broadcasting SO_BROADCAST out

    mask 0xFFFFFF00

    IP = 192.168.31.45

    Used 192.168.31.45 to send out broadcast..

    Used 239.0.0.31 to send out broadcast.. above NIOS gets neithe but will receive

    a regular udp message to it.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Dear friend,

    I am trying to communicate through UDP from nios-ii to my PC ...please send me a sample code. as the one i had write generate lot's of error related to header files.

    kaushal
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I have developed my own patch that appears to solve the problem. In file udp.c, line 216, replace

    ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest)))) {

    with

    ip_addr_cmp(&(pcb->local_ip), &(iphdr->dest))) ||

    ip_addr_isbroadcast(&iphdr->dest, inp) ) {

    effectively adding a check for broadcast to one of the many checks of the packet control block. I am not sure this is rigorously correct, but appears to work. Comments invited.

    Regards,

    Tim

    --- Quote End ---

    Tim, please join the lwip-users mailing list and submit the problem and your proposed solution. Development on lwIP is active as a new major upgrade is in the works. You didn't mention lwIP version and you'll need to do this there. Here would have been nice too. :)

    https://savannah.nongnu.org/mail/?group=lwip

    Bill
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hello all,

    I read discussion about broadcast listening, but i need to send broadcast from nios to network, could you advise me:

    I include code:

    ----------------------------

    void udp_init_all(void)

    {

    // proved nastaveni ciloveho adresata soketoveho spojeni

    host = gethostbyname("192.168.3.255");

    if(host==NULL)

    { printf("Address error.");

    return;

    }

    // nastav struktury a cilovy port adresata

    remoteServAddr.sin_family = host->h_addrtype;

    memcpy((char *) &remoteServAddr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);

    // remoteServAddr.sin_port = htons(serverPort);

    // navaz sitove spojeni

    if ((socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0)) < 0)

    { printf("Not able to create socket connection. \n");

    return;

    // exit(1);

    }

    serverAddress.sin_family = AF_INET;

    serverAddress.sin_addr.s_addr = inet_addr(SRC_IP_ADR); //"192.168.3.238");

    }

    --------------------------

    and sending code:

    --------------------------

    // nastav adresu portu a posli udp paket

    remoteServAddr.sin_port = htons(serverPort);

    if (sendto(socketDescriptor, out_buf, len, 0,

    (struct sockaddr *) &remoteServAddr, sizeof(remoteServAddr)) < 0)

    { printf("I am not able to send data to remote server.\n");

    // close(socketDescriptor);

    return;

    // exit(1);

    }

    -----------------------------

    and sending code report me:

    I am not able to send data to remote server.

    What should I change ? Where is error ?

    Jan Naceradsky, Altera