4 * Copyright 1997 Owen Taylor <owt1@cornell.edu>
14 #include <sys/types.h>
15 #include <sys/socket.h>
16 #include <netinet/in.h>
21 /* handles mechanics of communicating with a client */
23 gxid_send_message(char *host, int port, GxidMessage *msg)
26 struct sockaddr_in sin;
31 if (!port) port = 6951;
33 if (!host || strcmp(host,"localhost") )
35 /* looking it up as localhost can be _SLOW_ on ppp systems */
36 /* FIXME: Could localhost be anything other than loopback? */
40 he = gethostbyname(host);
43 fprintf(stderr,"gxid_lib: error looking up %s\n",host);
44 return GXID_RETURN_ERROR;
47 sin.sin_family = he->h_addrtype;
48 sin.sin_port = htons(port);
49 memcpy(&sin.sin_addr,he->h_addr_list[0],he->h_length);
51 socket_fd = socket(AF_INET,SOCK_STREAM,0);
54 fprintf(stderr,"gxid_lib: can't get socket");
55 return GXID_RETURN_ERROR;
58 if (connect(socket_fd, (struct sockaddr *)&sin,
61 fprintf(stderr,"gxid_lib: can't connect to %s:%d\n",host,port);
63 return GXID_RETURN_ERROR;
66 count = write(socket_fd,(char *)msg,ntohl(msg->any.length));
67 if (count != ntohl(msg->any.length))
69 fprintf(stderr,"gxid_lib: error writing");
71 return GXID_RETURN_ERROR;
74 /* now read the return code */
75 count = read(socket_fd,(char *)&retval,sizeof(GxidI32));
76 if (count != sizeof(GxidI32))
78 fprintf(stderr,"gxid_lib: error reading return code");
80 return GXID_RETURN_ERROR;
87 /* claim a device. If exclusive, device is claimed exclusively */
89 gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window,
93 msg.type = htonl(GXID_CLAIM_DEVICE);
94 msg.length = htonl(sizeof(GxidClaimDevice));
95 msg.device = htonl(device);
96 msg.window = htonl(window);
97 msg.exclusive = htonl(exclusive);
99 return gxid_send_message(host,port,(GxidMessage *)&msg);
102 /* release a device/window pair */
104 gxid_release_device(char *host, int port, GxidU32 device, GxidU32 window)
106 GxidReleaseDevice msg;
107 msg.type = htonl(GXID_RELEASE_DEVICE);
108 msg.length = htonl(sizeof(GxidReleaseDevice));
109 msg.device = htonl(device);
110 msg.window = htonl(window);
112 return gxid_send_message(host,port,(GxidMessage *)&msg);
115 #endif /* XINPUT_GXI */