[X2serv-cvs] CVS: x2/source main.c,1.51,1.52 sock.c,1.7,1.8 sock.h,1.3,1.4
Brought to you by:
sirvulcan
From: Richard P. <lys...@us...> - 2001-05-29 09:06:24
|
Update of /cvsroot/x2serv/x2/source In directory usw-pr-cvs1:/tmp/cvs-serv5033 Modified Files: main.c sock.c sock.h Log Message: Added a conf option: BIND <resolvable server or ip> for x2.conf. X2 will use this ip to bind for connect and listen. It seems to work here, but I can't test it because I only have one IP. Please test it! This option was requested by Chaz. Index: main.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/main.c,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -r1.51 -r1.52 *** main.c 2001/04/25 06:05:40 1.51 --- main.c 2001/05/29 09:06:22 1.52 *************** *** 83,86 **** --- 83,87 ---- UpLinkList *UpLinks = NULL; extern int REMOTE_AUTHENTICATED; + char BindIP[80] = ""; /* Start of the code section */ *************** *** 274,277 **** --- 275,284 ---- SUB7SCAN = atoi(StrBuffr); printf("Sub7Scan: %s\n", GetWinGateMet(SUB7SCAN)); + } + else if(!strcmp(StrBuffr, "BIND")) + { + fscanf(ConfFile, "%s", StrBuffr); + strcpy(BindIP, StrBuffr); + printf("I will bind my IP to %s.\n", BindIP); } else Index: sock.c =================================================================== RCS file: /cvsroot/x2serv/x2/source/sock.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** sock.c 2000/08/22 02:19:25 1.7 --- sock.c 2001/05/29 09:06:22 1.8 *************** *** 20,23 **** --- 20,24 ---- #include "config.h" #include "misc.h" + #include "sock.h" int my_init_client(char *DefServHost, u_short Port) *************** *** 26,29 **** --- 27,31 ---- int Sckt; register struct hostent *hostptr; + struct sockaddr_in BindAddr; hostptr = gethostbyname(DefServHost); *************** *** 31,34 **** --- 33,37 ---- return (-1); bzero((char *) &ServAddr, sizeof(ServAddr)); + bzero((char *) &BindAddr, sizeof(BindAddr)); memcpy(&(ServAddr.sin_addr.s_addr), hostptr->h_addr_list[0], (size_t) hostptr->h_length); ServAddr.sin_family = AF_INET; *************** *** 36,40 **** --- 39,58 ---- Sckt = socket(AF_INET, SOCK_STREAM, 0); + if (Sckt >= 0) + if (BindIP[0]) + { + hostptr = gethostbyname(BindIP); + if (!hostptr) { + Debug(DBGWARNING, "Can't resolve %s", BindIP); + } + else { + memcpy(&(BindAddr.sin_addr.s_addr), hostptr->h_addr_list[0], (size_t) hostptr->h_length); + BindAddr.sin_family = AF_INET; + bind(Sckt, (struct sockaddr *) &BindAddr, sizeof(BindAddr)); + Debug(DBGWARNING, "Binding to %s", BindIP); + } + } + if (connect(Sckt, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) >= 0) { *************** *** 52,55 **** --- 70,74 ---- unsigned int CliLen; int reuse_addr = 1; + struct hostent *bind_hostent; Debug(DBGINFO, "Beginning init_server() %d", SERVERPORT); *************** *** 60,65 **** bzero((char *) &ServAddr, sizeof(ServAddr)); ServAddr.sin_family = AF_INET; - ServAddr.sin_addr.s_addr = htonl(INADDR_ANY); ServAddr.sin_port = htons(SERVERPORT); bind(Sckt, (struct sockaddr *) &ServAddr, sizeof(ServAddr)); if(listen(Sckt, 5) == -1) --- 79,94 ---- bzero((char *) &ServAddr, sizeof(ServAddr)); ServAddr.sin_family = AF_INET; ServAddr.sin_port = htons(SERVERPORT); + if (BindIP[0] == 0) + { + ServAddr.sin_addr.s_addr = htonl(INADDR_ANY); + Debug(DBGINFO, "Binding to INADDR_ANY"); + } + else + { + Debug(DBGINFO, "Binding to IP: %s", BindIP); + bind_hostent = gethostbyname(BindIP); + ServAddr.sin_addr.s_addr = ((struct in_addr *)(bind_hostent->h_addr))->s_addr; + } bind(Sckt, (struct sockaddr *) &ServAddr, sizeof(ServAddr)); if(listen(Sckt, 5) == -1) Index: sock.h =================================================================== RCS file: /cvsroot/x2serv/x2/source/sock.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** sock.h 2001/01/02 10:11:33 1.3 --- sock.h 2001/05/29 09:06:22 1.4 *************** *** 8,9 **** --- 8,11 ---- void SelectSockets(); int TryToConnect(); + + extern char BindIP[80]; |