source: trunk/athena/bin/xversion/xversion.c @ 1945

Revision 1945, 1.6 KB checked in by probe, 35 years ago (diff)
If a -r argument is supplied, the minor revision number is also printed. The format for the major/minor revision format is: XnRn, (ie. X11R3).
Line 
1#include <X11/copyright.h>
2/* Copyright    Massachusetts Institute of Technology    1985   */
3
4/*
5 * This program determines which X server is likely to be running by
6 * attempting to connect to the X socket.
7 *
8 * $Header: /afs/dev.mit.edu/source/repository/athena/bin/xversion/xversion.c,v 1.2 1989-06-10 11:48:01 probe Exp $
9 */
10
11static char *rcsid = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/xversion/xversion.c,v 1.2 1989-06-10 11:48:01 probe Exp $";
12
13#include <X11/Xlib.h>
14#include <stdio.h>
15#include <sys/socket.h>
16#include <sys/un.h>
17 
18#define X_UNIX_PATH     "/tmp/X0"       /* X10 UNIX socket! */
19
20main(argc,argv)
21int argc;
22char *argv[];
23{
24    struct sockaddr_un addr;            /* UNIX socket address */
25    int full_version = 0;               /* Full protocol version number? */
26    int addrlen;
27    int fd;
28    int i;
29    Display *dpy;
30
31    if (--argc)
32        if (!strcmp(*++argv, "-r"))
33            full_version = 1;
34   
35    addr.sun_family = AF_UNIX;
36    strcpy(addr.sun_path, X_UNIX_PATH);
37    addrlen = strlen(addr.sun_path) + 2;
38
39    if ((fd = socket(addr.sun_family, SOCK_STREAM, 0)) < 0) {
40        /* Socket call failed! */
41        /* errno set by system call. */
42        perror( "couldn't open socket" );
43        exit( 1 );
44    }
45 
46    /* try connecting to X10 first */
47    if (connect(fd, &addr, addrlen) == 0) {
48        close(fd);
49        printf( "10\n" );
50        exit( 0 );
51    }
52
53    /* X11 requires connection information */
54    if ((dpy = XOpenDisplay( "unix:0" )) != NULL) {
55        printf((full_version ? "X%dR%d\n" : "%d\n" ),
56               ProtocolVersion(dpy),
57               VendorRelease(dpy));
58        XCloseDisplay( dpy );
59        exit( 0 );
60    }
61
62    printf( "?unknown\n" );
63    exit( 1 );
64}
Note: See TracBrowser for help on using the repository browser.