1997-11-24 22:37:52 +00:00
|
|
|
/*
|
|
|
|
* gxid version 0.3
|
|
|
|
*
|
|
|
|
* Copyright 1997 Owen Taylor <owt1@cornell.edu>
|
|
|
|
*/
|
|
|
|
|
Removed DEFS "+=" mess that breaks recent automakes. INCLUDES is the
* gdk/Makefile.am, gtk/Makefile.am:
Removed DEFS "+=" mess that breaks recent automakes.
INCLUDES is the correct way to add to CFLAGS from Makefile.am.
* gdk/gdk.c, gdk/gdkglobals.c, gdk/gdkimage.c, gdk/gdkinput.c,
gdk/gdkpixmap.c, gdk/gdkthreads.c, gdk/gdkwindow.c,
gdk/gxid_lib.c, gtk/fnmatch.c, gtk/gtkclist.c, gtk/gtkmain.c,
gtk/testthreads.c:
Include "config.h" instead of "../config.h".
Now that DEFS works again, automake will automatically pass us
the location of config.h in -I.
1998-11-24 05:58:53 +00:00
|
|
|
#include "config.h"
|
1997-12-18 02:17:14 +00:00
|
|
|
#include "gxid_lib.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
/* handles mechanics of communicating with a client */
|
|
|
|
static int
|
|
|
|
gxid_send_message(char *host, int port, GxidMessage *msg)
|
|
|
|
{
|
|
|
|
int socket_fd;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
int count;
|
|
|
|
GxidI32 retval;
|
|
|
|
struct hostent *he;
|
|
|
|
|
|
|
|
if (!port) port = 6951;
|
|
|
|
|
|
|
|
if (!host || strcmp(host,"localhost") )
|
|
|
|
{
|
|
|
|
/* looking it up as localhost can be _SLOW_ on ppp systems */
|
|
|
|
/* FIXME: Could localhost be anything other than loopback? */
|
|
|
|
host = "127.0.0.1";
|
|
|
|
}
|
|
|
|
|
|
|
|
he = gethostbyname(host);
|
|
|
|
if (!he)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"gxid_lib: error looking up %s\n",host);
|
|
|
|
return GXID_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sin.sin_family = he->h_addrtype;
|
|
|
|
sin.sin_port = htons(port);
|
|
|
|
memcpy(&sin.sin_addr,he->h_addr_list[0],he->h_length);
|
|
|
|
|
|
|
|
socket_fd = socket(AF_INET,SOCK_STREAM,0);
|
|
|
|
if (socket_fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"gxid_lib: can't get socket");
|
|
|
|
return GXID_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connect(socket_fd, (struct sockaddr *)&sin,
|
|
|
|
sizeof sin) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"gxid_lib: can't connect to %s:%d\n",host,port);
|
|
|
|
close(socket_fd);
|
|
|
|
return GXID_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = write(socket_fd,(char *)msg,ntohl(msg->any.length));
|
|
|
|
if (count != ntohl(msg->any.length))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"gxid_lib: error writing");
|
|
|
|
close(socket_fd);
|
|
|
|
return GXID_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now read the return code */
|
|
|
|
count = read(socket_fd,(char *)&retval,sizeof(GxidI32));
|
|
|
|
if (count != sizeof(GxidI32))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"gxid_lib: error reading return code");
|
|
|
|
close(socket_fd);
|
|
|
|
return GXID_RETURN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
close (socket_fd);
|
|
|
|
return ntohl(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* claim a device. If exclusive, device is claimed exclusively */
|
|
|
|
int
|
2002-01-31 15:48:58 +00:00
|
|
|
_gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window,
|
1997-11-24 22:37:52 +00:00
|
|
|
int exclusive)
|
|
|
|
{
|
|
|
|
GxidClaimDevice msg;
|
|
|
|
msg.type = htonl(GXID_CLAIM_DEVICE);
|
|
|
|
msg.length = htonl(sizeof(GxidClaimDevice));
|
|
|
|
msg.device = htonl(device);
|
|
|
|
msg.window = htonl(window);
|
|
|
|
msg.exclusive = htonl(exclusive);
|
|
|
|
|
|
|
|
return gxid_send_message(host,port,(GxidMessage *)&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* release a device/window pair */
|
|
|
|
int
|
2002-01-31 15:48:58 +00:00
|
|
|
_gxid_release_device(char *host, int port, GxidU32 device, GxidU32 window)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
|
|
|
GxidReleaseDevice msg;
|
|
|
|
msg.type = htonl(GXID_RELEASE_DEVICE);
|
|
|
|
msg.length = htonl(sizeof(GxidReleaseDevice));
|
|
|
|
msg.device = htonl(device);
|
|
|
|
msg.window = htonl(window);
|
|
|
|
|
|
|
|
return gxid_send_message(host,port,(GxidMessage *)&msg);
|
|
|
|
}
|