]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zwgc/browser.c
rules *.docs: attempt to install documentation
[1ts-debian.git] / zwgc / browser.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It is one of the source files comprising zwgc, the Zephyr WindowGram
3  * client.
4  *
5  *      Created by:     Marc Horowitz <marc@athena.mit.edu>
6  *
7  *      $Id: browser.c,v 1.4 1999/01/22 23:20:10 ghudson Exp $
8  *
9  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
10  *      For copying and distribution information, see the file
11  *      "mit-copyright.h".
12  */
13
14 #if (!defined(lint) && !defined(SABER))
15 static char rcsid_browser_c[] = "$Id: browser.c,v 1.4 1999/01/22 23:20:10 ghudson Exp $";
16 #endif
17
18 #include <zephyr/mit-copyright.h>
19
20 #include <sysdep.h>
21 #include <sys/socket.h>
22 #include <sys/un.h>
23 #include "zwgc.h"
24
25 static int browser_fd;
26 struct sockaddr_un sun;
27
28 int BOpenSocket()
29 {
30    int fd,len;
31    char *temp;
32
33    if ((fd=socket(PF_UNIX,SOCK_STREAM,0)) == -1)
34       return(-1);
35
36    sun.sun_family=AF_UNIX;
37    if (temp=getenv("WGSOCK"))
38       strncpy(sun.sunpath,temp,sizeof(sun.sunpath));
39    else
40       sprintf(sun.sun_path,"/tmp/.zwgc.%d",getuid());
41    if (bind(fd,(struct sockaddr *) &sun,
42             (len=strlen(sun.sunpath)) > sizeof(sun.sunpath)?
43             sizeof(sun.sunpath):len) == -1) {
44       close(fd);
45       return(-1);
46    }
47
48    if (listen(fd,5) == -1) {
49       unlink(sun.sunpath);
50       close(fd);
51       return(-1);
52    }
53
54    return(fd);
55 }