Subject: Re: bind: Address already in use
To: None <netbsd-help@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: netbsd-help
Date: 04/03/2002 03:10:47
In article <3CAA5C44.546CD07C@riverstonenet.com>,
Ravi Josyula <rjosyula@riverstonenet.com> wrote:

[stuff deleted]
the following works:

christos

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#define SOCK_PATH "/tmp/sock"

void main()
{
    int fd;
    struct sockaddr_un local;

    fd = socket(AF_UNIX, SOCK_STREAM, 0);
    if (fd == -1) {
        perror("listen");
        exit(1);
    }
    local.sun_family = AF_UNIX;
    local.sun_length = sizeof(local);
    strcpy(local.sun_path, SOCK_PATH);
    unlink(local.sun_path);

    if (bind(fd, (struct sockaddr *)&local, sizeof(local)) == -1) {
        perror("bind");
        exit(1);
    }
    close(fd);
}
>
>=================
>