garpd.c
int create_unix_socket(const char *sockname,
                       unsigned int namelen,
                       int *unix_sck)
{
    int connection;
    socklen_t remote_size;
    struct sockaddr_un sockdata;
    struct sockaddr_un remotedata;

    /*************************************************************************/
    /* For now, the Unix socket is a stream socket that sends the data       */
    /* newline-terminated. In future we may want to make this a datagram     */
    /* socket instead.                                                       */
    /*************************************************************************/
    if ((*unix_sck = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
        perror("cannot create unix socket");
        exit(1);
    }

    /*************************************************************************/
    /* Set up the Unix socket to the chosen path. If one is already there,   */
    /* remove it.                                                            */
    /*************************************************************************/
    sockdata.sun_family = AF_UNIX;
    strncpy(sockdata.sun_path, sockname, namelen);
    sockdata.sun_path[namelen] = '\0';

    unlink(sockdata.sun_path);

    /*************************************************************************/
    /* Bind and listen.                                                      */
    /*************************************************************************/
    if ((bind(*unix_sck, (struct sockaddr *)&sockdata, sizeof(sockdata))) < 0) {
        perror("cannot bind unix socket");
        exit(1);
    }

    if ((listen(*unix_sck, 1)) < 0) {
        perror("cannot listen on unix socket");
        exit(1);
    }

    /*************************************************************************/
    /* In this early iteration, only ever accept one connection.             */
    /* TODO: Fix this up.                                                    */
    /*************************************************************************/
    remote_size = sizeof(struct sockaddr_un);
    connection = accept(*unix_sck, (struct sockaddr *)&remotedata, &remote_size);

    if (connection < 0) {
        perror("error accepting unix socket connection");
        exit(1);
    }

    return connection;
}
/*****************************************************************************/
/* Creates a Unix domain socket and listens for a connection on it. In this  */
/* early prototype, only listens for one connection: multiple not allowed.   */
/*****************************************************************************/
Creates a Unix domain socket and listens for a connection on it. In this
early prototype, only listens for one connection: multiple not allowed.
Creates a Unix domain socket and listens for a connection on it . In this early prototype only listens for one connection : multiple not allowed .
int create_unix_socket(const char *sockname,
                       unsigned int namelen,
                       int *unix_sck)
{
    int connection;
    socklen_t remote_size;
    struct sockaddr_un sockdata;
    struct sockaddr_un remotedata;
    if ((*unix_sck = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
        perror("cannot create unix socket");
        exit(1);
    }
    sockdata.sun_family = AF_UNIX;
    strncpy(sockdata.sun_path, sockname, namelen);
    sockdata.sun_path[namelen] = '\0';
    unlink(sockdata.sun_path);
    if ((bind(*unix_sck, (struct sockaddr *)&sockdata, sizeof(sockdata))) < 0) {
        perror("cannot bind unix socket");
        exit(1);
    }
    if ((listen(*unix_sck, 1)) < 0) {
        perror("cannot listen on unix socket");
        exit(1);
    }
    remote_size = sizeof(struct sockaddr_un);
    connection = accept(*unix_sck, (struct sockaddr *)&remotedata, &remote_size);
    if (connection < 0) {
        perror("error accepting unix socket connection");
        exit(1);
    }
    return connection;
}
int create_unix_socket ( const char * sockname , unsigned int namelen , int * unix_sck ) { int connection ; socklen_t remote_size ; struct sockaddr_un sockdata ; struct sockaddr_un remotedata ; if ( ( * unix_sck = socket ( AF_UNIX , SOCK_STREAM , 0 ) ) < 0 ) { perror ( " " ) ; exit ( 1 ) ; } sockdata . sun_family = AF_UNIX ; strncpy ( sockdata . sun_path , sockname , namelen ) ; sockdata . sun_path [ namelen ] = ' \0 ' ; unlink ( sockdata . sun_path ) ; if ( ( bind ( * unix_sck , ( struct sockaddr * ) & sockdata , sizeof ( sockdata ) ) ) < 0 ) { perror ( " " ) ; exit ( 1 ) ; } if ( ( listen ( * unix_sck , 1 ) ) < 0 ) { perror ( " " ) ; exit ( 1 ) ; } remote_size = sizeof ( struct sockaddr_un ) ; connection = accept ( * unix_sck , ( struct sockaddr * ) & remotedata , & remote_size ) ; if ( connection < 0 ) { perror ( " " ) ; exit ( 1 ) ; } return connection ; }
Creates a Unix domain socket and listens for a connection on it.
Creates a Unix domain socket and listens for a connection on it .
/*************************************************************************/ /* For now, the Unix socket is a stream socket that sends the data       */ /* newline-terminated. In future we may want to make this a datagram     */ /* socket instead.                                                       */ /*************************************************************************/ /*************************************************************************/ /* Set up the Unix socket to the chosen path. If one is already there,   */ /* remove it.                                                            */ /*************************************************************************/ /*************************************************************************/ /* Bind and listen.                                                      */ /*************************************************************************/ /*************************************************************************/ /* In this early iteration, only ever accept one connection.             */ /* TODO: Fix this up.                                                    */ /*************************************************************************/