#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

enum {
    listen_queue_len = 16,
    datagram_len = 508
};

typedef void (*signalhandler_t)(int);

static void terminate(const char *msg)
{
    perror(msg);
    exit(1);
}

int main()
{
    int fd, len, bytes;
    struct sockaddr_un addr;
    char buf[datagram_len];

    fd = socket(AF_UNIX, SOCK_DGRAM, 0);
    if (fd == -1)
        terminate("socket");

    addr.sun_family = AF_UNIX;
    strcpy(addr.sun_path, "socket08.t");

    strcpy(buf, "hello\n");
    len = strlen(buf);
    if (len > datagram_len) {
        fprintf(stderr, "Too much data trying to send in 1 packet\n");
        exit(1);
    }

    bytes = sendto(fd, buf, len, 0, (struct sockaddr *) &addr, sizeof(addr));
    if (bytes == -1)
        terminate("sendto");

    close(fd);

    return 0;
}
