Added 'PROG_VER' constant, added '--version' and '--help' flags

master
Aadhavan Srinivasan 2 years ago
parent dc44f4979c
commit 35398d8387

@ -4,7 +4,7 @@
#include <stdlib.h>
#include "easysock.h"
#define PROG_NAME "basicproxy"
#define PROG_VER "0.01"
void forward_data(int from_fd, int to_fd) {
int n = 0;
char* buffer = malloc(3000*sizeof(char));
@ -26,9 +26,23 @@ int check_ip_ver(char* address) {
void print_prog_info() {
printf("%s - [Local IP address] [local port] [remote IP address] [remote port]\n",PROG_NAME);
printf("%s [Local IP address] [local port] [remote IP address] [remote port]\n",PROG_NAME);
}
void print_version_info() {
printf("%s %s\n",PROG_NAME,PROG_VER);
}
void print_help_info() {
printf("\n%s - A simple TCP proxy written in C.\n\n",PROG_NAME);
printf("Syntax - ");
print_prog_info();
printf("[Local IP address] - The local address to bind to\n"
"[local port] - The local port to listen on\n"
"[remote IP address] - The remote IP to connect to\n"
"[remote port] - The remote port to connect to\n");
printf("\nExample: %s 127.0.0.1 3000 1.2.3.4 5000 - Listen on '127.0.0.1:3000', and forward all data from there to '1.2.3.4:5000'\n\n",PROG_NAME);
}
int main(int argc,char* argv[]) {
/* argv[1] = local address
@ -36,6 +50,16 @@ int main(int argc,char* argv[]) {
argv[3] = remote address
argv[4] = remote port */
if (argc == 2) {
if (strcmp(argv[1],"-v") == 0 || strcmp(argv[1],"--version") == 0) {
print_version_info();
exit(0);
} else if (strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0) {
print_help_info();
exit(0);
}
}
if (argc != 5) {
print_prog_info();
exit(30);

Loading…
Cancel
Save