FreeCalypso > hg > sipout-test-utils
comparison librtpalloc/rtpmgr_resp.c @ 0:35c0d9f03c0a
beginning with sipout-test-voice,
a copy of sip-manual-out from themwi-system-sw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Mar 2024 23:20:19 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:35c0d9f03c0a |
---|---|
1 /* | |
2 * Here we implement the collect_rtpmgr_resp() function, | |
3 * which is a wrapper around the mess of recvmsg | |
4 * with file descriptor passing. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <sys/socket.h> | |
9 #include <stdint.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include "../include/rtp_alloc.h" | |
13 #include "rtpmgr_resp.h" | |
14 | |
15 collect_rtpmgr_resp(ctrl_fd, recv_flags, out) | |
16 struct rtp_alloc_resp_wrap *out; | |
17 { | |
18 int rc; | |
19 struct iovec iov; | |
20 struct msghdr msg; | |
21 union { | |
22 char buf[CMSG_SPACE(sizeof(int) * 4)]; | |
23 struct cmsghdr align; | |
24 } cmsgu; | |
25 struct cmsghdr *cmsg; | |
26 | |
27 iov.iov_base = &out->resp; | |
28 iov.iov_len = sizeof(struct rtp_alloc_resp); | |
29 bzero(&msg, sizeof msg); | |
30 msg.msg_iov = &iov; | |
31 msg.msg_iovlen = 1; | |
32 msg.msg_control = cmsgu.buf; | |
33 msg.msg_controllen = CMSG_SPACE(sizeof(int) * 4); | |
34 rc = recvmsg(ctrl_fd, &msg, recv_flags); | |
35 if (rc < 0) | |
36 return rc; | |
37 out->resp_len = rc; | |
38 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { | |
39 if (cmsg->cmsg_level == SOL_SOCKET && | |
40 cmsg->cmsg_type == SCM_RIGHTS) | |
41 break; | |
42 } | |
43 if (cmsg) { | |
44 switch (cmsg->cmsg_len) { | |
45 case CMSG_LEN(sizeof(int)): | |
46 out->num_fd = 1; | |
47 break; | |
48 case CMSG_LEN(sizeof(int) * 2): | |
49 out->num_fd = 2; | |
50 break; | |
51 case CMSG_LEN(sizeof(int) * 3): | |
52 out->num_fd = 3; | |
53 break; | |
54 case CMSG_LEN(sizeof(int) * 4): | |
55 out->num_fd = 4; | |
56 break; | |
57 default: | |
58 out->num_fd = 0; | |
59 } | |
60 if (out->num_fd) | |
61 bcopy(CMSG_DATA(cmsg), out->fd_buf, | |
62 sizeof(int) * out->num_fd); | |
63 } else | |
64 out->num_fd = 0; | |
65 return 0; | |
66 } |