]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/sctp.c
rtpenc_mpegts: Set chain->rtp_ctx only after avformat_write_header succeeded
[ffmpeg] / libavformat / sctp.c
index 817b0049a990bfd81b21852863970b017237a889..9cfaeccd179d7040432f740c60a0b032477ae454 100644 (file)
@@ -39,8 +39,6 @@
 
 #include <netinet/in.h>
 #include <netinet/sctp.h>
-#include <sys/time.h>
-#include <unistd.h>
 
 #include "config.h"
 
 
 /*
  * The sctp_recvmsg and sctp_sendmsg functions are part of the user
- * library that offers support
- * for the SCTP kernel Implementation. The main purpose of this
- * code is to provide the SCTP Socket API mappings for user
- * application to interface with the SCTP in kernel.
+ * library that offers support for the SCTP kernel Implementation.
+ * To avoid build-time clashes the functions sport an ff_-prefix here.
+ * The main purpose of this code is to provide the SCTP Socket API
+ * mappings for user applications to interface with SCTP in the kernel.
  *
  * This implementation is based on the Socket API Extensions for SCTP
  * defined in <draft-ietf-tsvwg-sctpsocket-10.txt>
@@ -145,7 +143,7 @@ static int ff_sctp_send(int s, const void *msg, size_t len,
         memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo));
     }
 
-    return sendmsg(s, &outmsg, flags);
+    return sendmsg(s, &outmsg, flags | MSG_NOSIGNAL);
 }
 
 typedef struct SCTPContext {
@@ -172,8 +170,12 @@ static int sctp_open(URLContext *h, const char *uri, int flags)
 
     av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
                  &port, path, sizeof(path), uri);
-    if (strcmp(proto,"sctp") || port <= 0 || port >= 65536)
+    if (strcmp(proto, "sctp"))
         return AVERROR(EINVAL);
+    if (port <= 0 || port >= 65536) {
+        av_log(s, AV_LOG_ERROR, "Port missing in uri\n");
+        return AVERROR(EINVAL);
+    }
 
     s->max_streams = 0;
     p = strchr(uri, '?');
@@ -196,7 +198,7 @@ static int sctp_open(URLContext *h, const char *uri, int flags)
 
     cur_ai = ai;
 
-    fd = socket(cur_ai->ai_family, SOCK_STREAM, IPPROTO_SCTP);
+    fd = ff_socket(cur_ai->ai_family, SOCK_STREAM, IPPROTO_SCTP);
     if (fd < 0)
         goto fail;
 
@@ -295,10 +297,10 @@ static int sctp_write(URLContext *h, const uint8_t *buf, int size)
         struct sctp_sndrcvinfo info = { 0 };
         info.sinfo_stream           = AV_RB16(buf);
         if (info.sinfo_stream > s->max_streams)
-            abort();
+            return AVERROR_BUG;
         ret = ff_sctp_send(s->fd, buf + 2, size - 2, &info, MSG_EOR);
     } else
-        ret = send(s->fd, buf, size, 0);
+        ret = send(s->fd, buf, size, MSG_NOSIGNAL);
 
     return ret < 0 ? ff_neterrno() : ret;
 }