Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

sending packet like broadcast

Altera_Forum
Honored Contributor II
1,456 Views

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
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
730 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

Yes, 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
730 Views

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
0 Kudos
Reply