[FFmpeg-cvslog] r25405 - trunk/libavformat/udp.c
mstorsjo
subversion
Fri Oct 8 10:42:30 CEST 2010
Author: mstorsjo
Date: Fri Oct 8 10:42:30 2010
New Revision: 25405
Log:
udp: Add an option for connecting the udp socket
This allows us to find out the local sending address via getsockname,
otherwise we just get INADDR_ANY (or similar for v6).
This also makes writes return ECONNREFUSED if nobody is listening on the
receiving port.
Modified:
trunk/libavformat/udp.c
Modified: trunk/libavformat/udp.c
==============================================================================
--- trunk/libavformat/udp.c Fri Oct 8 10:40:08 2010 (r25404)
+++ trunk/libavformat/udp.c Fri Oct 8 10:42:30 2010 (r25405)
@@ -50,6 +50,7 @@ typedef struct {
int reuse_socket;
struct sockaddr_storage dest_addr;
int dest_addr_len;
+ int is_connected;
} UDPContext;
#define UDP_TX_BUF_SIZE 32768
@@ -325,6 +326,9 @@ static int udp_open(URLContext *h, const
if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
s->buffer_size = strtol(buf, NULL, 10);
}
+ if (find_info_tag(buf, sizeof(buf), "connect", p)) {
+ s->is_connected = strtol(buf, NULL, 10);
+ }
}
/* fill the dest addr */
@@ -393,6 +397,12 @@ static int udp_open(URLContext *h, const
/* make the socket non-blocking */
ff_socket_nonblock(udp_fd, 1);
}
+ if (s->is_connected) {
+ if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) {
+ av_log(NULL, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
+ goto fail;
+ }
+ }
s->udp_fd = udp_fd;
return 0;
@@ -444,9 +454,12 @@ static int udp_write(URLContext *h, cons
int ret;
for(;;) {
+ if (!s->is_connected) {
ret = sendto (s->udp_fd, buf, size, 0,
(struct sockaddr *) &s->dest_addr,
s->dest_addr_len);
+ } else
+ ret = send(s->udp_fd, buf, size, 0);
if (ret < 0) {
if (ff_neterrno() != FF_NETERROR(EINTR) &&
ff_neterrno() != FF_NETERROR(EAGAIN))
More information about the ffmpeg-cvslog
mailing list