#include #include #include #include #include #include #include #include #include int main (int argc, char **argv) { struct sockaddr_un address; int socket_fd; socklen_t address_length; unsigned char buffer[512]; struct timeval now, msg; int cnt = 0; long *diffs; int num_diffs; if (argc != 2) { printf("Usage:\n"); printf(" unixdomain_server \n"); return 0; } num_diffs = atoi(argv[1]); if (num_diffs <= 0) { printf("Number of samples to collect must be >0\n"); return 1; } fprintf(stderr, "Number of samples to collect: %d\n", num_diffs); diffs = malloc(sizeof(*diffs)*num_diffs); socket_fd = socket (PF_UNIX, SOCK_DGRAM, 0); if (socket_fd < 0) { printf ("socket() failed\n"); return 1; } /* start with a clean address structure */ memset (&address, 0, sizeof (struct sockaddr_un)); address.sun_family = AF_UNIX; snprintf (address.sun_path, FILENAME_MAX, "./demo_socket"); unlink (address.sun_path); if (bind (socket_fd, (struct sockaddr *) &address, sizeof (struct sockaddr_un)) != 0) { perror ("bind() failed"); return 1; } while (read (socket_fd, &msg, sizeof (msg)) >= sizeof (msg)) { long long t1, t2; t1 = msg.tv_sec * 1000000; t1 += msg.tv_usec; gettimeofday (&now, NULL); t2 = now.tv_sec * 1000000; t2 += now.tv_usec; diffs[cnt] = t2 - t1; cnt++; if (cnt > num_diffs) { cnt = 0; for (int j = 0; j