www.nico.schottelius.org/software/cinit/browse_source/cinit-0.2/client/connect_sock.c
Nico Schottelius 423ba10303 import cinit from unix.schottelius.org
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
2009-09-16 12:53:45 +02:00

37 lines
703 B
C

/*
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
* run_svc
* part of cinit
*/
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include "cinit.h"
/* open socket connection to cinit-serv and close original socket */
int connect_sock(int socke)
{
int nsock;
struct sockaddr_un addr;
close(socke);
nsock = socket(PF_UNIX,SOCK_STREAM,0);
if( nsock == -1 ) {
perror(MSG_SOCKET);
return -1;
}
socke = sizeof(addr);
memset(&addr,0,socke);
strcpy(addr.sun_path, CINIT_SOCK);
addr.sun_family = AF_UNIX;
if(connect(nsock,(struct sockaddr *)&addr,socke) == -1) {
return -1;
}
return nsock;
}