UDP BROADCAST problem with NetOS6.3 using C

hi all,
i am using ns9360 board and NetOS6.3 version for writing an application in C for data exchange between ns9360 board and a PC with VB application
Here i am able to create a socket and bind it and i am getting the status for sendto command as 4 bytes i.e i am sending “5555”…but the problem is on VB side i could n’t get the data.Nothing happening in VB side.I am getting correct return type for sendto command but still why i am not getting the data on VB side at the same time whenever i tried to send the data fron VB to NetOS board also data not receiving in Board side.
I am giving the source code at the bottom i have written for the reference…
what could be the problem pls any one can suggest me on this …or mail me at kotireddy@bhelrnd.co.in


UDP code on NetOS6.3 in C is:
int sFd,idd,bytes;
struct sockaddr_in serverAddr; /* server’s socket address /
struct sockaddr_in clientAddr; /
client’s socket address /
int sockAddrSize; /
size of socket address structure */
char ack[1024]=“5555”;

if (sFd<0)
socket creation failed
socket creation success
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons (6000);
serverAddr.sin_addr.s_addr = htonl (INADDR_ANY);

if (idd==0)
	printf(" udp bind success 

else if (idd==-1)
udp bind failure
clientAddr.sin_family = AF_INET;
clientAddr.sin_port = htons (6000);
clientAddr.sin_addr.s_addr = htonl(“”);
bytes = sendto (sFd, ack, strlen (ack), 0, &clientAddr, sizeof(clientAddr));
if (bytes==-1)
ERROR in Send :%s",ack);
%s %d",ack,bytes);

my VB side code on a PC with XP-sp2 is:

WINSOCK1 object settings on VB form are:protocol is UDPPROTOCOL

Private Sub Form_Load()
With Winsock1
.RemotePort = 6000 ’ Port to connect to.
.Bind 6000 ’ Bind to the local port.
End With
end sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim NewLine As String
Winsock1.GetData str
end sub

i guess you should edit like below:-

//struct sockaddr_in serverAddr; /* server’s socket address /
//struct sockaddr_in clientAddr; /
client’s socket address */

struct sockaddr_storage serverAddr;
struct sockaddr_storage clientAddr;


->serverAddr.sin_addr.s_addr = htonl (INADDR_ANY);
use inet_pton() and only “serverAddr.sin_addr” is enough.

use memset(&clientAddr, 0, sizeof(clientAddr)); also…

in bind
replace like below
idd=bind(sFd,(struct sockaddr *) &serverAddr,sizeof(serverAddr)) ;

sendto and recvfrom also should contain

->>sendto (sFd, ack, strlen (ack), 0, (struct sockaddr*)&clientAddr, sizeof(clientAddr));

I do not have 6.3, i have 7.5… so not sure whether inet_pton works or not.
Try this out…

and VB…he he sorry… No idea :slight_smile:

Thank u bob for the reply,

I tried even this but no result.
It is not at all taking (struct sockaddr*) in send to command.It is giving error that incompatable argument number 5 in sendto function.
sendto (sFd, ack, strlen (ack), 0, (struct sockaddr*)&clientAddr, sizeof(clientAddr)); /*giving error/
sendto (sFd, ack, strlen (ack), 0, (struct sockaddr_in
)&clientAddr, sizeof(clientAddr)); /**is working and acknowledge ment also giving correct/

But today i observed the main problem as: i set client address as and my NetOS board address (server)as in my NetOS board side code and given sendto command.I am getting acknowledge correctly for sendto command as 6 for the data “ffffff”.
But when i observed the packets on the network through WIRESHARK from my client PC i observed ARP protocol with target address as (though i set and underlying protocol is UDP).how come this came as my target address and is keeps changing.