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);
}
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);