#include <fcntl.h>
int main(int argc, char *argv[]) {
- int send_fd,cmd_fd;
+ int send_fd;
struct sockaddr_in local_addr, remote_addr;
socklen_t remote_addr_len,optlen;
int send_bytes, read_bytes;
+ FILE *cmd_fd;
if(argc!=4) {
printf("usage: %s \"cmd command\" <target-ip/broadcast-addr> <port>\n",argv[0]);
remote_addr.sin_port=htons(atoi(argv[3]));
remote_addr.sin_addr.s_addr=inet_addr(argv[2]);
- if((cmd_fd=open(argv[1],O_RDONLY))<0) {
+ if((cmd_fd=popen(argv[1],"w"))<0) {
printf("unable to open file descriptor for %s.\n",argv[1]);
exit(1);
}
read_bytes=1;
while(read_bytes>0) {
unsigned char buf[1000];
- read_bytes=read(cmd_fd,buf,sizeof(buf));
+ read_bytes=read(0,buf,sizeof(buf));
send_bytes=sendto(send_fd,buf,read_bytes,0,(struct sockaddr *)&remote_addr,remote_addr_len);
+ fwrite(buf,read_bytes,1,cmd_fd);
}
close(send_fd);