/** * main entry point */ int main(int argc ,char **argv) { bool result=true; if(argc < 5) { printf("Usage: %s 61.135.250.1 80 61.135.250.2 80\n", argv[0]); exit(1); } initLogInfo(); logInfo(LOG_NOTICE,"%s %s %s %s %s",argv[0],argv[1], argv[2],argv[3],argv[4]); logInfo(LOG_NOTICE,"tcpcopy version:%s",VERSION); #if (TCPCOPY_MYSQL_SKIP) logInfo(LOG_NOTICE,"TCPCOPY_MYSQL_SKIP mode"); #endif #if (TCPCOPY_MYSQL_NO_SKIP) logInfo(LOG_NOTICE,"TCPCOPY_MYSQL_NO_SKIP mode"); #endif result=retrieveVirtualIPAddress(argv[1]); if(!result) { printf("it does not support local ip addr or domain name"); logInfo(LOG_ERR,"it does not support local ip addr or domain name"); } local_port = htons(atoi(argv[2])); remote_ip = inet_addr(argv[3]); remote_port = htons(atoi(argv[4])); if(argc>5) { if(!readArgs(argc,argv,&options)) { #if (TCPCOPY_MYSQL_ADVANCED) logInfo(LOG_ERR,"user password pair is missing:%d",argc); #endif } }else { #if (TCPCOPY_MYSQL_ADVANCED) logInfo(LOG_ERR,"user password pair is missing"); printf("Usage: %s 1.1.1.1 80 1.1.1.2 80 -p user1@psw1:user2@psw2:...\n", argv[0]); exit(1); #endif } if(port_shift_factor||replica_num>1) { struct timeval tp; gettimeofday(&tp,NULL); unsigned int seed=tp.tv_usec; rand_shift_port=(int)((rand_r(&seed)/(RAND_MAX+1.0))*512); if(port_shift_factor) { logInfo(LOG_NOTICE,"port shift factor:%u",port_shift_factor); }else { logInfo(LOG_NOTICE,"replica num:%d",replica_num); } logInfo(LOG_NOTICE,"random shift port:%u",rand_shift_port); } set_signal_handler(); if(SUCCESS==init_tcp_copy()) { select_server_run(); return 0; }else { return 1; } }
/* Main procedure for interception */ void interception_run() { select_server_run(); }