Forum Discussion

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

sending packet like broadcast

Hello all,

is possible to send packets in uClinux like broadcast ?

I include code:

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

void udp_init_all(void)

{

// proved nastaveni ciloveho adresata soketoveho spojeni

host = gethostbyname("192.168.3.255"); // remote server

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 in main cycle:

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

// 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 code report me:

I am not able to send data to remote server.

How can i send packets via broadcast ?

Where is error ?

Thank you for answer.

Jan Naceradsky, Czech Republic

6 Replies

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

    Is sending IP packets as braoadcast not just using the broadcast address of the terwork you ar targeting (e.g. 192.168.2,255) ?

    As routers don't forward broadcasts, I suppose not giving a network address will not work.

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

    Yes, i use broadcast address (in my case 192.168.3.255).

    I found, that ping -c 5 192.168.3.255

    send data, but without answer - 5 packets transmitting, 0 received.

    May be i should use another function, not sendto(.....), in c source code.

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

    I don't think that ping is bound to support broadcast.

    A user protocol that does support broadcast is UDP. You need to write code for both ends.

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

    When i use:

    ping -c 5 192.168.3.255

    the command tries to send 5 packets, every packets i can see in wireshark, but the uclinux doesnot get answer.

    You mean, that i must to write program for pc (except program for uClinux) ?

    (yes, i use the udp protocol)

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

    Hi,

    --- Quote Start ---

    When i use:

    ping -c 5 192.168.3.255

    the command tries to send 5 packets, every packets i can see in wireshark, but the uclinux doesnot get answer.

    --- Quote End ---

    I think that you hit the command 'ping -c 5 192.168.3.255' from your Nios uClinux system. If so, please consider who will reply the answer. Can your network reply to the 'ping broadcast' ? MS Windows OS ignores such broadcasts and Linux can ignore those by setting 'echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts'.

    Kazu