From: hackbard Date: Wed, 30 Oct 2002 23:50:38 +0000 (+0000) Subject: fixed dgramrcv.c X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=788a2a936bb7e9a1f8224a7a6cfd2658db52df10;p=my-code%2Fivac.git fixed dgramrcv.c --- diff --git a/dgramrcv.c b/dgramrcv.c index 060fd4a..d8ec19e 100644 --- a/dgramrcv.c +++ b/dgramrcv.c @@ -28,12 +28,13 @@ int main(int argc, char *argv[]) { int receive_fd; - struct sockaddr_in target_addr; + int opt; + struct sockaddr_in local_addr,target_addr; int receive_bytes, write_bytes; - socklen_t target_addr_len,optlen; + socklen_t target_addr_len; if(argc!=3) { - printf("usage: %s \n",argv[0]); + printf("usage: %s \n",argv[0]); exit(1); } @@ -42,12 +43,17 @@ int main(int argc, char *argv[]) { exit(1); } - optlen=1; - setsockopt(receive_fd,SOL_SOCKET,SO_BROADCAST,NULL,optlen); + opt=1; + setsockopt(receive_fd,SOL_SOCKET,SO_BROADCAST,&opt,sizeof(opt)); + + local_addr.sin_family=AF_INET; + local_addr.sin_port=htons(atoi(argv[1])); + local_addr.sin_addr.s_addr=htonl(INADDR_ANY); + bind(receive_fd,(const struct sockaddr *)&local_addr,sizeof(local_addr)); memset(&target_addr,0,sizeof(target_addr)); target_addr.sin_family=AF_INET; - target_addr.sin_port=htons(atoi(argv[2])); + target_addr.sin_port=htons(atoi(argv[1])); target_addr.sin_addr.s_addr=inet_addr(argv[1]); target_addr_len=sizeof(target_addr);