any one help me that in this matter. my program can not run. code to bind the socket which i write is:
char sendbuf[5]={"\0"};
unsigned int iMsgCode=1;
unsigned int iServiceID=3;
short int iAliveStatus=1;
memcpy(sendbuf,&iMsgCode,2);
memcpy(sendbuf+2,&iServiceID,2);
memcpy(sendbuf+4,&iAliveStatus,1);
char broadcast = '1';
int numbytes = 0;
int sock;
struct sockaddr_in their_addr;
sock = socket(AF_INET,SOCK_DGRAM,0);
if(setsockopt(sock,SOL_SOCKET,SO_BROADCAST,&broadcast,sizeof(broadcast)) < 0)
{
printf("Error in setting Broadcast option");
return 0;
}//End if
their_addr.sin_family = AF_INET;
//Target Port Number
their_addr.sin_port = htons(iKeepAlivePort);
//Target IP
their_addr.sin_addr.s_addr = inet_addr (strKIP);
int sentbytes =0;
while(1)
{
//sendto Fuction for sending data (Non-Standard)
sentbytes = sendto(sock,sendbuf,5,0,(sockaddr*)&their_addr,sizeof(their_addr));
if( sentbytes < 0)
{
printf("error in SENDTO() function");
close(sock);
break;
}//End if
else
printf("\n-------------------------------------");
printf("\n KEEP ALIVE SEND AT PORT:%d AND IP:%s\n",iKeepAlivePort,strKIP);
sleep(1);
}//End else
close(sock);
fflush(stdout);