]> hackdaworld.org Git - my-code/ivac.git/commitdiff
fixed dgramrcv.c
authorhackbard <hackbard>
Wed, 30 Oct 2002 23:50:38 +0000 (23:50 +0000)
committerhackbard <hackbard>
Wed, 30 Oct 2002 23:50:38 +0000 (23:50 +0000)
dgramrcv.c

index 060fd4a6a595c4946b14bcca0775fc13951a7452..d8ec19ee5bb0a6702294c3ae16a7140f8d4771d0 100644 (file)
 
 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 <target-ip> <port>\n",argv[0]);
+    printf("usage: %s <port>\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);