--- xmove-2.0beta2.orig/man/man1/xmove.1 +++ xmove-2.0beta2/man/man1/xmove.1 @@ -6,11 +6,15 @@ .B xmove [ .B -server -.I server_name:port +.I [server_name]:port ] [ .B -port .I listen_port ] +] [ +.B -interface +.I listen_interface +] .SH DESCRIPTION .I xmove @@ -25,7 +29,7 @@ .PP .I xmove will assume logical default values for both the -default listening port and the default server. Take as an +default listening port, default interface and the default server. Take as an example a typical machine named \fIchestnut\fP, with a standard X11 server named \fIchestnut:0\fP. .PP @@ -41,6 +45,11 @@ \fIchestnut:0\fP if you wish them to be run through .I xmove. .PP +The default is to listen on all interfaces of the machine, +so local clients can use both localhost:1 and chestnut:1. +.I xmove +can be restricted to only listen on one specific interface. +.PP .SH TYPICAL USAGE Assuming that the environment variable \fBDISPLAY\fP contains the name of your default server, no options need to be set. @@ -95,6 +104,18 @@ .I xmove was executed, and n is the specified port. The port must be a number from 1 to 9. +.TP +.I -interface +Clients can only connect to +.I xmove +through the specified interface. +Users must specify a \fBDISPLAY\fP of \fIname:n\fP, +where \fIname\fP is a name of that perticular interface on the machine on which +.I xmove +was executed. +Without this option, +.I xmove +will accept connections to all interfaces on the machine. .SH "MULTI-HEADED DISPLAYS" .I xmove @@ -148,9 +169,7 @@ programs. Although xmove does support moving clients between displays with different characteristics, there are limitations. Most notably, a client started on a 1-bit black-and-white display -can only be moved to other 1-bit displays. Additionally, xmove -does not support 24-bit displays, although some users have -reported sporadic success. +can only be moved to other 1-bit displays .PP .I xmove requires font compatibility between displays. Thus, if your --- xmove-2.0beta2.orig/xmove/main.c +++ xmove-2.0beta2/xmove/main.c @@ -26,6 +26,7 @@ #include /* needed by sys/socket.h and netinet/in.h */ #include /* for struct iovec, used by socket.h */ +#include #include /* for AF_INET, SOCK_STREAM, ... */ #include /* for FIONCLEX, FIONBIO, ... */ #if defined(SYSV) || defined(SVR4) @@ -70,6 +71,7 @@ /*static char *OfficialName P((char *name ));*/ static void ResizeBuffer P((Buffer *buffer, long len)); static char *SetDefaultServer P((char *server_name)); +#define SVR4 #ifdef SVR4 static void SignalURG P((int signum )); static void SignalPIPE P((int signum )); @@ -129,10 +131,11 @@ static int ServerPort = 0; Global int ServerScreen = 0; static int ListenForClientsPort = 1; +static char *ListenForClientsInterface = NULL; static char ServerHostName[255]; static char DefaultHost[256]; -Global void +Global int main(argc, argv) int argc; char **argv; @@ -312,6 +315,15 @@ ListenForClientsPort = 0; debug(1,(stderr, "ListenForClientsPort=%d\n",ListenForClientsPort)); } + else if (Streq(argv[i], "-interface")) + { + if (++i < argc) + ListenForClientsInterface = argv[i]; + else + Usage(); + debug(1,(stderr, "ListenForClientsInterface=%s\n", + ListenForClientsInterface)); + } else if (Streq(argv[i], "-debug")) { /* @@ -354,8 +366,13 @@ Usage(); } - LocalHostName = (char *)malloc(255); - (void) gethostname(LocalHostName, 255); + if (ListenForClientsInterface) + LocalHostName = ListenForClientsInterface; + else + { + LocalHostName = (char *)malloc(255); + (void) gethostname(LocalHostName, 255); + } if (string == NULL) string = getenv("DISPLAY"); @@ -426,7 +443,13 @@ host machine. The host machine may have several different network addresses. INADDR_ANY should work with all of them at once. */ - sin.sin_addr.s_addr = INADDR_ANY; + /* But the user can have specified a single one of them with the + -interface option. */ + + if (ListenForClientsInterface) + sin.sin_addr.s_addr = HostIPAddr; + else + sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons (iport); @@ -651,6 +674,7 @@ fprintf(stderr, "Usage: xmove\n"); fprintf(stderr, " [-server ]\n"); fprintf(stderr, " [-port ]\n"); + fprintf(stderr, " [-interface ]\n"); fprintf(stderr, " [-verbose ]\n"); exit(1); } @@ -1137,31 +1161,53 @@ ConnectToServer(char *hostName, short portNum, unsigned long *ip_addr) { int ON = 1; - int ServerFD; + int ServerFD = -1; + struct sockaddr *sap; + socklen_t saz; + struct sockaddr_un sun; struct sockaddr_in sin; struct hostent *hp; enterprocedure("ConnectToServer"); - hp = gethostbyname(hostName); - if (hp == NULL) + /* try local unix socket first if server is local */ + if (Streq(hostName, "")) { - perror("gethostbyname failed"); - return -1; + bzero((char *)&sun, sizeof(sun)); + sun.sun_family = AF_UNIX; + sprintf(sun.sun_path, "/tmp/.X11-unix/X%d", portNum); + sap = (struct sockaddr *)&sun; + saz = SUN_LEN(&sun); + ServerFD = socket(AF_UNIX, SOCK_STREAM, 0); } + if (ServerFD < 0) + { + hp = gethostbyname(hostName); + if (hp == NULL) + { + perror("gethostbyname failed"); + return -1; + } - if (ip_addr) - *ip_addr = *(unsigned long *)(hp->h_addr); + if (ip_addr) + *ip_addr = *(unsigned long *)(hp->h_addr); - if (*(unsigned long *)(hp->h_addr) == HostIPAddr && - portNum == ListenForClientsPort) - { - return -1; - } + if (*(unsigned long *)(hp->h_addr) == HostIPAddr && + portNum == ListenForClientsPort) + { + return -1; + } - /* establish a socket to the name server for this host */ - bzero((char *)&sin, sizeof(sin)); - ServerFD = socket(AF_INET, SOCK_STREAM, 0); + /* establish a socket to the name server for this host */ + bzero((char *)&sin, sizeof(sin)); + sin.sin_family = AF_INET; + bcopy((char *)hp->h_addr, (char *)&sin.sin_addr, hp->h_length); + sin.sin_port = htons (portNum + XBasePort); + sap = (struct sockaddr *)&sin; + saz = sizeof(sin); + ServerFD = socket(AF_INET, SOCK_STREAM, 0); + } + if (ServerFD < 0) { perror("socket() to Server failed"); @@ -1179,14 +1225,10 @@ debug(4,(stderr, "try to connect on %s\n", hostName)); - sin.sin_family = AF_INET; - bcopy((char *)hp->h_addr, (char *)&sin.sin_addr, hp->h_length); - sin.sin_port = htons (portNum + XBasePort); - /* ******************************************************** */ /* try to connect to Server */ - if (connect(ServerFD, (struct sockaddr *)&sin, sizeof(sin)) < 0) + if (connect(ServerFD, sap, saz) < 0) { debug(4,(stderr, "connect returns errno of %d\n", errno)); close (ServerFD); @@ -1514,7 +1556,7 @@ index = strchr(new_defaulthost, ':'); if (index == new_defaulthost) - strcpy(new_serverhostname, LocalHostName); + strcpy(new_serverhostname, ""); /* UNIX domain socket */ else if (index == NULL) strcpy(new_serverhostname, new_defaulthost); else { --- xmove-2.0beta2.orig/xmovectrl/xmovectrl.c +++ xmove-2.0beta2/xmovectrl/xmovectrl.c @@ -117,7 +117,10 @@ (void) setsockopt(ServerFD, SOL_SOCKET, SO_USELOOPBACK,(char *) NULL, 0); #endif - hp = gethostbyname(XmoveDisplay); + if (strlen (XmoveDisplay) == 0) + hp = gethostbyname("localhost"); + else + hp = gethostbyname(XmoveDisplay); if (hp == 0) { perror("gethostbyname failed");