-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhandle_rtp.c
53 lines (45 loc) · 1.14 KB
/
handle_rtp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SOCKET_NAME "/tmp/rtpstream.sock"
#define BUFFER_SIZE 4096
int main(int argc, char *argv[]) {
int fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (-1 == fd) {
perror("socket");
return EXIT_FAILURE;
}
struct sockaddr_un addr = {AF_UNIX, {0}};
strncpy(addr.sun_path, SOCKET_NAME, sizeof(addr.sun_path) - 1);
if (connect(fd, (struct sockaddr *)&addr, sizeof addr) == -1) {
perror("connect");
return EXIT_FAILURE;
}
char *buffer = malloc(BUFFER_SIZE);
assert(buffer);
while (true) {
const ssize_t ret = read(fd, buffer, BUFFER_SIZE);
switch (ret) {
case -1: // Error
perror("read");
goto shutdown;
break;
case 0: // EOF
puts("Done!");
goto shutdown;
break;
default:
printf("%zd bytes received.\n", ret);
break;
}
}
shutdown:
close(fd);
free(buffer);
}