4 * Copyright 1997 Owen Taylor <owt1@cornell.edu>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
20 /* handles mechanics of communicating with a client */
22 gxid_send_message(char *host, int port, GxidMessage *msg)
25 struct sockaddr_in sin;
30 if (!port) port = 6951;
32 if (!host || strcmp(host,"localhost") )
34 /* looking it up as localhost can be _SLOW_ on ppp systems */
35 /* FIXME: Could localhost be anything other than loopback? */
39 he = gethostbyname(host);
42 fprintf(stderr,"gxid_lib: error looking up %s\n",host);
43 return GXID_RETURN_ERROR;
46 sin.sin_family = he->h_addrtype;
47 sin.sin_port = htons(port);
48 memcpy(&sin.sin_addr,he->h_addr_list[0],he->h_length);
50 socket_fd = socket(AF_INET,SOCK_STREAM,0);
53 fprintf(stderr,"gxid_lib: can't get socket");
54 return GXID_RETURN_ERROR;
57 if (connect(socket_fd, (struct sockaddr *)&sin,
60 fprintf(stderr,"gxid_lib: can't connect to %s:%d\n",host,port);
62 return GXID_RETURN_ERROR;
65 count = write(socket_fd,(char *)msg,ntohl(msg->any.length));
66 if (count != ntohl(msg->any.length))
68 fprintf(stderr,"gxid_lib: error writing");
70 return GXID_RETURN_ERROR;
73 /* now read the return code */
74 count = read(socket_fd,(char *)&retval,sizeof(GxidI32));
75 if (count != sizeof(GxidI32))
77 fprintf(stderr,"gxid_lib: error reading return code");
79 return GXID_RETURN_ERROR;
86 /* claim a device. If exclusive, device is claimed exclusively */
88 gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window,
92 msg.type = htonl(GXID_CLAIM_DEVICE);
93 msg.length = htonl(sizeof(GxidClaimDevice));
94 msg.device = htonl(device);
95 msg.window = htonl(window);
96 msg.exclusive = htonl(exclusive);
98 return gxid_send_message(host,port,(GxidMessage *)&msg);
101 /* release a device/window pair */
103 gxid_release_device(char *host, int port, GxidU32 device, GxidU32 window)
105 GxidReleaseDevice msg;
106 msg.type = htonl(GXID_RELEASE_DEVICE);
107 msg.length = htonl(sizeof(GxidReleaseDevice));
108 msg.device = htonl(device);
109 msg.window = htonl(window);
111 return gxid_send_message(host,port,(GxidMessage *)&msg);
114 #else /* !XINPUT_GXI */
116 /* Some compilers don't like empty source files */
118 gxid_claim_device(char *host, int port, GxidU32 device, GxidU32 window,
124 #endif /* XINPUT_GXI */