annotate librtpalloc/rtpmgr_resp.c @ 240:c7a3ba56c636

themwi-short-dial: fix bug in printf arguments
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:37:59 -0800
parents f8c40090a0a8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
184
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement the collect_rtpmgr_resp() function,
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * which is a wrapper around the mess of recvmsg
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * with file descriptor passing.
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/socket.h>
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../include/rtp_alloc.h"
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "rtpmgr_resp.h"
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 collect_rtpmgr_resp(ctrl_fd, recv_flags, out)
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 struct rtp_alloc_resp_wrap *out;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int rc;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct iovec iov;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct msghdr msg;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 union {
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char buf[CMSG_SPACE(sizeof(int) * 4)];
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 struct cmsghdr align;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 } cmsgu;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct cmsghdr *cmsg;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 iov.iov_base = &out->resp;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 iov.iov_len = sizeof(struct rtp_alloc_resp);
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 bzero(&msg, sizeof msg);
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 msg.msg_iov = &iov;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 msg.msg_iovlen = 1;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 msg.msg_control = cmsgu.buf;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 msg.msg_controllen = CMSG_SPACE(sizeof(int) * 4);
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 rc = recvmsg(ctrl_fd, &msg, recv_flags);
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (rc < 0)
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return rc;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 out->resp_len = rc;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (cmsg->cmsg_level == SOL_SOCKET &&
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cmsg->cmsg_type == SCM_RIGHTS)
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (cmsg) {
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 switch (cmsg->cmsg_len) {
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case CMSG_LEN(sizeof(int)):
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 out->num_fd = 1;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case CMSG_LEN(sizeof(int) * 2):
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 out->num_fd = 2;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 break;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case CMSG_LEN(sizeof(int) * 3):
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 out->num_fd = 3;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case CMSG_LEN(sizeof(int) * 4):
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 out->num_fd = 4;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 break;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 default:
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 out->num_fd = 0;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (out->num_fd)
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 bcopy(CMSG_DATA(cmsg), out->fd_buf,
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 sizeof(int) * out->num_fd);
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 } else
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 out->num_fd = 0;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return 0;
f8c40090a0a8 librtpalloc: new library for talking to themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }