hi experts,
i am trying to send an array of data and print it after recieving from
recvfrom call. the program says tat it has successfully recieved some
data but it is not printing anythin please help me..
thanking u in advance..
XOINKI..
code:
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip_icmp.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
int main()
{
int val=1,bytes;
struct sockaddr_in addr;
struct protoent *proto;
struct hostent *hname;
int sd;
char pckt[20];
char buf[40];
hname=gethostbyname("192.168.15.2");
proto=getprotobyname("OSPFIGP");
strcpy(pckt,"hello");
printf("the %s\n",pckt);
bzero(&addr, sizeof(addr));
addr.sin_family = hname->h_addrtype;
addr.sin_port = 0;
addr.sin_addr.s_addr = *(long*)hname->h_addr;
sd = socket(PF_INET, SOCK_RAW, proto->p_proto);
if ( sd < 0 )
{
perror("socket");
return 0;
}
if ( setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val)) != 0)
perror("Set TTL option");
if ( sendto(sd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&addr,
sizeof(addr)) <= 0 )
perror("sendto");
for(;;)
{
int len=sizeof(addr);
sleep(2);
bytes = recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr*)&addr,
&len);
if(bytes>0)
{
buf[bytes]=(char)NULL;
goto ther;
//printf("it worked %s\n",buf);
}
else
printf("didn work\n");
}
ther:
printf("it worked.. %s",buf);
return 0;
}