]> hackdaworld.org Git - my-code/ivac.git/commitdiff
implemented break through argv[1] prog
authorhackbard <hackbard>
Sat, 19 Oct 2002 01:33:01 +0000 (01:33 +0000)
committerhackbard <hackbard>
Sat, 19 Oct 2002 01:33:01 +0000 (01:33 +0000)
datagram.c

index 72179b719b1d4ef707b8f0c44ecd3d348bbb87d6..c2884829bdff40f2011558c70993670e24f3450f 100644 (file)
 #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]);
@@ -66,7 +67,7 @@ int main(int argc, char *argv[]) {
   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);
   }
@@ -75,8 +76,9 @@ int main(int argc, char *argv[]) {
   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);