40 #include <netinet/in.h>
41 #include <netinet/sctp.h>
74 socklen_t *fromlen,
struct sctp_sndrcvinfo *sinfo,
79 char incmsg[CMSG_SPACE(
sizeof(
struct sctp_sndrcvinfo))];
80 struct msghdr inmsg = { 0 };
81 struct cmsghdr *cmsg = NULL;
86 inmsg.msg_name =
from;
87 inmsg.msg_namelen = fromlen ? *fromlen : 0;
90 inmsg.msg_control = incmsg;
91 inmsg.msg_controllen =
sizeof(incmsg);
93 if ((recvb = recvmsg(s, &inmsg, msg_flags ? *msg_flags : 0)) < 0)
97 *fromlen = inmsg.msg_namelen;
99 *msg_flags = inmsg.msg_flags;
101 for (cmsg = CMSG_FIRSTHDR(&inmsg); cmsg != NULL;
102 cmsg = CMSG_NXTHDR(&inmsg, cmsg)) {
103 if ((IPPROTO_SCTP == cmsg->cmsg_level) &&
104 (SCTP_SNDRCV == cmsg->cmsg_type))
110 memcpy(sinfo, CMSG_DATA(cmsg),
sizeof(
struct sctp_sndrcvinfo));
116 const struct sctp_sndrcvinfo *sinfo,
int flags)
118 struct msghdr outmsg;
121 outmsg.msg_name = NULL;
122 outmsg.msg_namelen = 0;
123 outmsg.msg_iov = &iov;
124 iov.iov_base = (
void*)msg;
126 outmsg.msg_iovlen = 1;
127 outmsg.msg_controllen = 0;
130 char outcmsg[CMSG_SPACE(
sizeof(
struct sctp_sndrcvinfo))];
131 struct cmsghdr *cmsg;
133 outmsg.msg_control = outcmsg;
134 outmsg.msg_controllen =
sizeof(outcmsg);
135 outmsg.msg_flags = 0;
137 cmsg = CMSG_FIRSTHDR(&outmsg);
138 cmsg->cmsg_level = IPPROTO_SCTP;
139 cmsg->cmsg_type = SCTP_SNDRCV;
140 cmsg->cmsg_len = CMSG_LEN(
sizeof(
struct sctp_sndrcvinfo));
142 outmsg.msg_controllen = cmsg->cmsg_len;
143 memcpy(CMSG_DATA(cmsg), sinfo,
sizeof(
struct sctp_sndrcvinfo));
146 return sendmsg(s, &outmsg, flags);
160 struct sctp_event_subscribe event = { 0 };
161 struct sctp_initmsg initparams = { 0 };
167 int ret, listen_socket = 0;
168 char hostname[1024], proto[1024], path[1024];
171 av_url_split(proto,
sizeof(proto), NULL, 0, hostname,
sizeof(hostname),
172 &port, path,
sizeof(path), uri);
173 if (strcmp(proto,
"sctp"))
175 if (port <= 0 || port >= 65536) {
181 p = strchr(uri,
'?');
191 snprintf(portstr,
sizeof(portstr),
"%d", port);
201 fd = socket(cur_ai->
ai_family, SOCK_STREAM, IPPROTO_SCTP);
211 fd1 = accept(fd, NULL, NULL);
219 event.sctp_data_io_event = 1;
222 if (setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event,
223 sizeof(event)) != 0) {
225 "SCTP ERROR: Unable to subscribe to events\n");
232 if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, &initparams,
233 sizeof(initparams)) < 0)
235 "SCTP ERROR: Unable to initialize socket max streams %d\n",
253 int ev = write ? POLLOUT : POLLIN;
254 struct pollfd p = { .fd = fd, .events = ev, .revents = 0 };
257 ret = poll(&p, 1, 100);
274 struct sctp_sndrcvinfo info = { 0 };
276 AV_WB16(buf, info.sinfo_stream);
277 ret = ret < 0 ? ret : ret + 2;
279 ret = recv(s->
fd, buf, size, 0);
297 struct sctp_sndrcvinfo info = { 0 };
298 info.sinfo_stream =
AV_RB16(buf);
305 ret = send(s->
fd, buf, size, 0);