Annotation of embedaddon/coova-chilli/src/cmdsock.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:  * chilli - A Wireless LAN Access Point Controller.
                      3:  * Copyright (c) 2007 David Bird <david@coova.com>
                      4:  *
                      5:  * The contents of this file may be used under the terms of the GNU
                      6:  * General Public License Version 2, provided that the above copyright
                      7:  * notice and this permission notice is included in all copies or
                      8:  * substantial portions of the software.
                      9:  * 
                     10:  */
                     11: 
                     12: #include "system.h"
                     13: #include "redir.h"
                     14: #include "syserr.h"
                     15: #include "radius.h"
                     16: #include "dhcp.h"
                     17: #include "chilli.h"
                     18: #include "cmdline.h"
                     19: #include "options.h"
                     20: #include "cmdsock.h"
                     21: 
                     22: int
                     23: cmdsock_init() {
                     24:   struct sockaddr_un local;
                     25:   int cmdsock;
                     26:   
                     27:   if ((cmdsock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
                     28:     log_err(errno, "could not allocate UNIX Socket!");
                     29:   } else {
                     30:     local.sun_family = AF_UNIX;
                     31: 
                     32:     strcpy(local.sun_path, options.cmdsocket);
                     33:     unlink(local.sun_path);
                     34: 
                     35:     if (bind(cmdsock, (struct sockaddr *)&local, 
                     36:             sizeof(struct sockaddr_un)) == -1) {
                     37:       log_err(errno, "could bind UNIX Socket!");
                     38:       close(cmdsock);
                     39:       cmdsock = -1;
                     40:     } else {
                     41:       if (listen(cmdsock, 5) == -1) {
                     42:        log_err(errno, "could listen to UNIX Socket!");
                     43:        close(cmdsock);
                     44:        cmdsock = -1;
                     45:       }
                     46:     }
                     47:   }
                     48: 
                     49:   return cmdsock;
                     50: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>