Commits

Ivan Vučica  committed bf5731d

Added the ability to specify input and output files on command line.

  • Participants
  • Parent commits 345b593

Comments (0)

Files changed (2)

File tapper-macosx.c

 {
 	close(primary_fd); /* close the tap network device */
 }
-int main()
+int main(int argc, char ** argv)
 {
 	int fd; /* file descriptor of the tap device; shorthand for primary_fd */
 	char devname[25]={0}; /* initialize device name (where we'll pick up the generated dev name) 
 				to zeros so it doesn't look like we're sending a device name in*/
 	char buf[255]; /* buffer for receiving stuff */
+
+	if(argc == 3)
+	{
+		/* we can receive two arguments:
+		   - file we'll use for reading in place of stdin
+		   - file we'll use for writing in place of stdout */
+		close(0);
+		close(1);
+		fopen(argv[1], "r");
+		fopen(argv[2], "w");
+	}
+
 	primary_fd=createTap(devname); /* let's create a tap device */
 
 	srand(time(NULL)+devname[3]); /* we want our ip address to depend on time, and on last
 {
 	close(primary_fd); /* close the tap network device */
 }
-int main()
+int main(int argc, char ** argv)
 {
 	int fd; /* file descriptor of the tap device; shorthand for primary_fd */
 	char devname[25]={0}; /* initialize device name (where we'll pick up the generated dev name) 
 				to zeros so it doesn't look like we're sending a device name in*/
 	char buf[255]; /* buffer for receiving stuff */
+
+	if(argc == 3)
+	{
+		/* we can receive two arguments:
+		   - file we'll use for reading in place of stdin
+		   - file we'll use for writing in place of stdout */
+		close(0);
+		close(1);
+		fopen(argv[1], "r");
+		fopen(argv[2], "w");
+	}
+
 	primary_fd=createTap(devname); /* let's create a tap device */
 
 	srand(time(NULL)+devname[3]); /* we want our ip address to depend on time, and on last