aboutsummaryrefslogtreecommitdiff
path: root/socket-sucker.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2012-08-21 14:59:28 -0500
committerTed Gould <ted@gould.cx>2012-08-21 14:59:28 -0500
commitc9798cf0441cc431d44a3e6db5999021ec2b2864 (patch)
tree47526ff1d1fd52f4a0c790674f2cc3c9dd84af70 /socket-sucker.c
parent45844af8292c400b63dcfaa2e53cb6aabc69251b (diff)
parent60c71fb063ea39a6324097b30f1e58dd3e8e734c (diff)
downloadlightdm-remote-session-freerdp2-c9798cf0441cc431d44a3e6db5999021ec2b2864.tar.gz
lightdm-remote-session-freerdp2-c9798cf0441cc431d44a3e6db5999021ec2b2864.tar.bz2
lightdm-remote-session-freerdp2-c9798cf0441cc431d44a3e6db5999021ec2b2864.zip
Adding a socket sucker C program
Diffstat (limited to 'socket-sucker.c')
-rw-r--r--socket-sucker.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/socket-sucker.c b/socket-sucker.c
new file mode 100644
index 0000000..7a1e82f
--- /dev/null
+++ b/socket-sucker.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Ted Gould <ted@canonical.com>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#define BUFFER_SIZE 256
+
+int
+main (int argc, char * argv[])
+{
+ int socket_fd = 0;
+ int servlen = 0;
+ struct sockaddr_un serv_addr;
+
+ bzero((char *)&serv_addr, sizeof(serv_addr));
+
+ const char * home = getenv("HOME");
+ if (home == NULL) {
+ return -1;
+ }
+
+ serv_addr.sun_family = AF_UNIX;
+ snprintf(serv_addr.sun_path, sizeof(serv_addr.sun_path), "%s/%s", home, ".freerdp-socket");
+ servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
+
+ if ((socket_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ return -1;
+ }
+
+ if (connect(socket_fd, (struct sockaddr *)&serv_addr, servlen) < 0) {
+ return -1;
+ }
+
+ char buffer[BUFFER_SIZE + 2];
+ int in = 0;
+ int out = 0;
+
+ in = read(socket_fd, buffer, BUFFER_SIZE);
+ out = write(1, buffer, in);
+
+ close(socket_fd);
+
+ if (in == 0) {
+ return 0;
+ } else {
+ return -1;
+ }
+}
+