- added support for Mac OSX (10.3 Panther and 10.4 Tiger). For tuntap support
[vde.git] / vde-2 / sockutils.c
blob063c618b08f972800887af98fd7ba404baff553f
1 /* Copyright 2005 Renzo Davoli - VDE-2
2 * Mattia Belletti (C) 2004.
3 * Licensed under the GPLv2
4 */
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <errno.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <stdint.h>
13 #include <libgen.h>
14 #include <syslog.h>
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
17 #include <sys/socket.h>
18 #include <sys/un.h>
19 #include <switch.h>
20 #include <consmgmt.h>
22 /* check to see if given unix socket is still in use; if it isn't, remove the
23 * * socket from the file system */
24 int still_used(struct sockaddr_un *sun)
26 int test_fd, ret = 1;
28 if((test_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0){
29 printlog(LOG_ERR,"socket %s",strerror(errno));
30 return(1);
32 if(connect(test_fd, (struct sockaddr *) sun, sizeof(*sun)) < 0){
33 if(errno == ECONNREFUSED){
34 if(unlink(sun->sun_path) < 0){
35 printlog(LOG_ERR,"Failed to removed unused socket '%s': %s",
36 sun->sun_path,strerror(errno));
38 ret = 0;
40 else printlog(LOG_ERR,"connect %s",strerror(errno));
42 close(test_fd);
43 return(ret);