Added check for number of arguments

master
Aadhavan Srinivasan 2 years ago
parent e483ffaf8f
commit 4c49370276

@ -3,6 +3,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "easysock.h" #include "easysock.h"
#define PROG_NAME "basicproxy"
void forward_data(int from_fd, int to_fd) { void forward_data(int from_fd, int to_fd) {
int n = 0; int n = 0;
@ -24,6 +25,10 @@ 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);
}
int main(int argc,char* argv[]) { int main(int argc,char* argv[]) {
/* argv[1] = local address /* argv[1] = local address
@ -31,6 +36,12 @@ int main(int argc,char* argv[]) {
argv[3] = remote address argv[3] = remote address
argv[4] = remote port */ argv[4] = remote port */
if (argc != 5) {
print_prog_info();
exit(-30);
}
char* local_addr = argv[1]; char* local_addr = argv[1];
int local_port = strtol(argv[2],NULL,10); int local_port = strtol(argv[2],NULL,10);
char* remote_addr = argv[3]; char* remote_addr = argv[3];

Loading…
Cancel
Save