testbabelserver.c

00001 /* 
00002  * Gnome Chemisty Utils
00003  * tests/testbabelserver.c 
00004  *
00005  * Copyright (C) 2010 Jean Bréfort <jean.brefort@normalesup.org>
00006  *
00007  * This program is free software; you can redistribute it and/or 
00008  * modify it under the terms of the GNU General Public License as 
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00020  * USA
00021  */
00022 
00023 #include "config.h"
00024 #include <glib.h>
00025 #include <netinet/in.h>
00026 #include <stdio.h>
00027 #include <sys/stat.h>
00028 #include <sys/un.h>
00029 #include <unistd.h>
00030 
00031 int main ()
00032 {
00033         char *args[] = {"babelserver", NULL};
00034         GError *error = NULL;
00035         g_spawn_async (NULL, (char **) args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL,&error);
00036         if (error) {
00037                 g_error_free (error);
00038                 error = NULL;
00039         }
00040         struct stat statbuf;
00041         while (stat ("/tmp/babelsocket", &statbuf));
00042         int babelsocket = socket (AF_UNIX, SOCK_STREAM, 0);
00043         if (babelsocket == -1) {
00044                 perror("Could not create the socket");
00045                 return FALSE;
00046         }
00047         struct sockaddr_un adr_serv;
00048         adr_serv.sun_family = AF_UNIX;
00049         strcpy (adr_serv.sun_path, "/tmp/babelsocket");
00050         if (connect (babelsocket, (const struct sockaddr*) &adr_serv, sizeof (struct sockaddr_un)) == -1) {
00051                 perror ("Connexion failed");
00052                 return FALSE;
00053         }
00054         // TODO: write the code
00055         return 0;
00056 }

Generated on Wed Nov 24 13:27:22 2010 for The Gnome Chemistry Utils by  doxygen 1.5.9