Created
July 13, 2011 13:53
-
-
Save sbz/1080330 to your computer and use it in GitHub Desktop.
create a unix socket on X11 display in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
#include <sys/un.h> | |
#include <unistd.h> | |
#include <string.h> | |
#include <stdio.h> | |
#define _PATH_UNIX_X "/tmp/.X11-unix/X%d" | |
#define DISPLAY_PORT 0 | |
int | |
main(void) { | |
int rc,sock; | |
struct sockaddr_un addr; | |
sock = socket(AF_UNIX, SOCK_STREAM, 0); | |
if (sock<0) return -1; | |
memset(&addr, 0, sizeof(addr)); | |
addr.sun_family = AF_UNIX; | |
snprintf(addr.sun_path, sizeof(addr.sun_path), _PATH_UNIX_X, DISPLAY_PORT); | |
rc = connect(sock, (struct sockaddr *) &addr, sizeof(addr)); | |
sleep(10); | |
close(sock); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm doing the same im Assembly, you did a great job!