X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=datagram.c;h=bcee9431bcd84e2c38fbd09488057d5c99a7287b;hb=b69fb509a515d69f1da0655866dff2c37a3a34cb;hp=c2884829bdff40f2011558c70993670e24f3450f;hpb=f4d20dbc1126c4ddf56d89182c1bd430dc141570;p=my-code%2Fivac.git diff --git a/datagram.c b/datagram.c index c288482..bcee943 100644 --- a/datagram.c +++ b/datagram.c @@ -31,7 +31,7 @@ #include int main(int argc, char *argv[]) { - int send_fd; + int send_fd,broadcast_on; struct sockaddr_in local_addr, remote_addr; socklen_t remote_addr_len,optlen; int send_bytes, read_bytes; @@ -47,8 +47,11 @@ int main(int argc, char *argv[]) { exit(1); } - optlen=1; - setsockopt(send_fd,SOL_SOCKET,SO_BROADCAST,NULL,optlen); + broadcast_on=1; + optlen=sizeof(broadcast_on); + if((setsockopt(send_fd,SOL_SOCKET,SO_BROADCAST,&broadcast_on,optlen))==-1) + perror("setsockopt"); + memset(&local_addr,0,sizeof(local_addr)); local_addr.sin_family=AF_INET; @@ -78,6 +81,10 @@ int main(int argc, char *argv[]) { unsigned char buf[1000]; read_bytes=read(0,buf,sizeof(buf)); send_bytes=sendto(send_fd,buf,read_bytes,0,(struct sockaddr *)&remote_addr,remote_addr_len); +#ifdef DEBUG + perror("sendto"); +#endif + fwrite(buf,read_bytes,1,cmd_fd); }