connect xserver socket
刘杰
seu.liujie at 163.com
Thu Jul 21 02:43:49 PDT 2011
Hello, every one.
This days I am studying the oldest version of x-window realization, with the purpose of getting a insight of the internal machanism. From the website of x.org.I picked up X.V10R3 to get start of my work.
My pc is now working with i386 arch and Fedora15 linux desktop system, which of that X.V10R3 not supported. So first i must rebuild Xlib.To test with a x-client program, the XOpenDisplay fucntion gave a "connect to x server error.". Things like this:
I derectly test with the x-server on Fedora15.So i needn't wrote a xserver program first.
Using the DISPLAY :0.0
struct sockaddr_in inaddr; /* INET socket address. */
struct sockaddr *addr; /* address to connect to */
char displaybuf[256];
int addrlen; /* length of address */
int indian; /* to determine which indian. */
int fd;
struct hostent *host_ptr;
register XReq *req; /* XReq request packet pointer. */
XRep rep; /* XRep reply packet. */
gethostname(displaybuf, sizeof (displaybuf)); /* get local host name “localehost.localdomain” */
/* Get the statistics on the specified host. */
if ((host_ptr = gethostbyname(displaybuf)) == NULL)
{
/* No such host! */
errno = EINVAL;
return(NULL);
}
/* Check the address type to see if it is an internet host. */
if (host_ptr->h_addrtype != AF_INET) {
/* Not an Internet host! */
errno = EPROTOTYPE;
return(NULL);
}
/* Set up the socket data. */
inaddr.sin_family = AF_INET;
inaddr.sin_port = 0;
indian = 1;
if (*(char *) &indian)
{
inaddr.sin_port += 5800;
}
else
{
inaddr.sin_port += 5900;
}
inaddr.sin_port = htons(inaddr.sin_port);
inaddr.sin_addr = *((struct in_addr *)host_ptr->h_addr);
addr = (struct sockaddr *) &inaddr;
addrlen = sizeof (struct sockaddr_in);
}
if((fd = socket(addr->sa_family, SOCK_STREAM, 0)) < 0)
{
/* Socket call failed! */
/* errno set by system call. */
fprintf(stderr, "socket create error! \n");
return(NULL);
}
/* Open the connection to the specified X server. */
if(connect(fd, addr, addrlen) == -1)
{
/* Connection call failed! */
/* errno set by system call. */
fprintf(stderr, "socket connect error.\n");
return(NULL);
}
}
By myself, I have two reason for this:
1.x-server needs a authentication that my test program didn't add.
2. In the program of mine, the port which i tried to connect is not a correct one.
If someone known these things real, please give me a instructing.
Thanks very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20110721/06709cdb/attachment.html>
More information about the xorg-devel
mailing list