/* ugsend.c */ /* Send a datagram without using a connected socket */ #define begin { #define end } #include #include #include #include #include char buf[] = "This is some data"; struct hostent *hp; struct hostent *gethostbyname(); struct sockaddr name; main(argc, argv) int argc; char *argv[]; begin int i; unsigned char c; int sock; int status; sock = socket(AF_UNIX, SOCK_DGRAM, 0); if (sock < 0) begin printf("Socket create failed \n"); exit(1); end name.sa_family = AF_UNIX; memcpy(name.sa_data, "zzzzz", 5); status = bind(sock, (struct sockaddr *)&name, sizeof(name)); printf("Bind status = %d \n", status); if (status < 0) exit(1); name.sa_family = AF_UNIX; memcpy(name.sa_data, "/tmp/abcde", 10); status = sendto(sock, buf, sizeof(buf), 0, (struct sockaddr *)&name, sizeof(name)); printf("status = %d \n", status); unlink("zzzzz"); end