You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

623 lines
19KB

  1. /*
  2. * UDP prototype streaming system
  3. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * UDP protocol
  24. */
  25. #define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */
  26. #include "avformat.h"
  27. #include "avio_internal.h"
  28. #include "libavutil/parseutils.h"
  29. #include "libavutil/fifo.h"
  30. #include "libavutil/intreadwrite.h"
  31. #include "libavutil/avstring.h"
  32. #include <unistd.h>
  33. #include "internal.h"
  34. #include "network.h"
  35. #include "os_support.h"
  36. #include "url.h"
  37. #if HAVE_PTHREADS
  38. #include <pthread.h>
  39. #endif
  40. #include <sys/time.h>
  41. #ifndef IPV6_ADD_MEMBERSHIP
  42. #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
  43. #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
  44. #endif
  45. #define UDP_TX_BUF_SIZE 32768
  46. #define UDP_MAX_PKT_SIZE 65536
  47. typedef struct {
  48. int udp_fd;
  49. int ttl;
  50. int buffer_size;
  51. int is_multicast;
  52. int local_port;
  53. int reuse_socket;
  54. struct sockaddr_storage dest_addr;
  55. int dest_addr_len;
  56. int is_connected;
  57. /* Circular Buffer variables for use in UDP receive code */
  58. int circular_buffer_size;
  59. AVFifoBuffer *fifo;
  60. int circular_buffer_error;
  61. #if HAVE_PTHREADS
  62. pthread_t circular_buffer_thread;
  63. #endif
  64. uint8_t tmp[UDP_MAX_PKT_SIZE+4];
  65. int remaining_in_dg;
  66. } UDPContext;
  67. static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
  68. struct sockaddr *addr)
  69. {
  70. #ifdef IP_MULTICAST_TTL
  71. if (addr->sa_family == AF_INET) {
  72. if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
  73. av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL): %s\n", strerror(errno));
  74. return -1;
  75. }
  76. }
  77. #endif
  78. #if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS)
  79. if (addr->sa_family == AF_INET6) {
  80. if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) {
  81. av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno));
  82. return -1;
  83. }
  84. }
  85. #endif
  86. return 0;
  87. }
  88. static int udp_join_multicast_group(int sockfd, struct sockaddr *addr)
  89. {
  90. #ifdef IP_ADD_MEMBERSHIP
  91. if (addr->sa_family == AF_INET) {
  92. struct ip_mreq mreq;
  93. mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
  94. mreq.imr_interface.s_addr= INADDR_ANY;
  95. if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
  96. av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP): %s\n", strerror(errno));
  97. return -1;
  98. }
  99. }
  100. #endif
  101. #if HAVE_STRUCT_IPV6_MREQ && defined(IPPROTO_IPV6)
  102. if (addr->sa_family == AF_INET6) {
  103. struct ipv6_mreq mreq6;
  104. memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
  105. mreq6.ipv6mr_interface= 0;
  106. if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
  107. av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP): %s\n", strerror(errno));
  108. return -1;
  109. }
  110. }
  111. #endif
  112. return 0;
  113. }
  114. static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr)
  115. {
  116. #ifdef IP_DROP_MEMBERSHIP
  117. if (addr->sa_family == AF_INET) {
  118. struct ip_mreq mreq;
  119. mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
  120. mreq.imr_interface.s_addr= INADDR_ANY;
  121. if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
  122. av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP): %s\n", strerror(errno));
  123. return -1;
  124. }
  125. }
  126. #endif
  127. #if HAVE_STRUCT_IPV6_MREQ && defined(IPPROTO_IPV6)
  128. if (addr->sa_family == AF_INET6) {
  129. struct ipv6_mreq mreq6;
  130. memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr));
  131. mreq6.ipv6mr_interface= 0;
  132. if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
  133. av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP): %s\n", strerror(errno));
  134. return -1;
  135. }
  136. }
  137. #endif
  138. return 0;
  139. }
  140. static struct addrinfo* udp_resolve_host(const char *hostname, int port,
  141. int type, int family, int flags)
  142. {
  143. struct addrinfo hints, *res = 0;
  144. int error;
  145. char sport[16];
  146. const char *node = 0, *service = "0";
  147. if (port > 0) {
  148. snprintf(sport, sizeof(sport), "%d", port);
  149. service = sport;
  150. }
  151. if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) {
  152. node = hostname;
  153. }
  154. memset(&hints, 0, sizeof(hints));
  155. hints.ai_socktype = type;
  156. hints.ai_family = family;
  157. hints.ai_flags = flags;
  158. if ((error = getaddrinfo(node, service, &hints, &res))) {
  159. res = NULL;
  160. av_log(NULL, AV_LOG_ERROR, "udp_resolve_host: %s\n", gai_strerror(error));
  161. }
  162. return res;
  163. }
  164. static int udp_set_url(struct sockaddr_storage *addr,
  165. const char *hostname, int port)
  166. {
  167. struct addrinfo *res0;
  168. int addr_len;
  169. res0 = udp_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0);
  170. if (res0 == 0) return AVERROR(EIO);
  171. memcpy(addr, res0->ai_addr, res0->ai_addrlen);
  172. addr_len = res0->ai_addrlen;
  173. freeaddrinfo(res0);
  174. return addr_len;
  175. }
  176. static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr,
  177. int *addr_len, const char *localaddr)
  178. {
  179. int udp_fd = -1;
  180. struct addrinfo *res0 = NULL, *res = NULL;
  181. int family = AF_UNSPEC;
  182. if (((struct sockaddr *) &s->dest_addr)->sa_family)
  183. family = ((struct sockaddr *) &s->dest_addr)->sa_family;
  184. res0 = udp_resolve_host(localaddr[0] ? localaddr : NULL, s->local_port,
  185. SOCK_DGRAM, family, AI_PASSIVE);
  186. if (res0 == 0)
  187. goto fail;
  188. for (res = res0; res; res=res->ai_next) {
  189. udp_fd = socket(res->ai_family, SOCK_DGRAM, 0);
  190. if (udp_fd > 0) break;
  191. av_log(NULL, AV_LOG_ERROR, "socket: %s\n", strerror(errno));
  192. }
  193. if (udp_fd < 0)
  194. goto fail;
  195. memcpy(addr, res->ai_addr, res->ai_addrlen);
  196. *addr_len = res->ai_addrlen;
  197. freeaddrinfo(res0);
  198. return udp_fd;
  199. fail:
  200. if (udp_fd >= 0)
  201. closesocket(udp_fd);
  202. if(res0)
  203. freeaddrinfo(res0);
  204. return -1;
  205. }
  206. static int udp_port(struct sockaddr_storage *addr, int addr_len)
  207. {
  208. char sbuf[sizeof(int)*3+1];
  209. if (getnameinfo((struct sockaddr *)addr, addr_len, NULL, 0, sbuf, sizeof(sbuf), NI_NUMERICSERV) != 0) {
  210. av_log(NULL, AV_LOG_ERROR, "getnameinfo: %s\n", strerror(errno));
  211. return -1;
  212. }
  213. return strtol(sbuf, NULL, 10);
  214. }
  215. /**
  216. * If no filename is given to av_open_input_file because you want to
  217. * get the local port first, then you must call this function to set
  218. * the remote server address.
  219. *
  220. * url syntax: udp://host:port[?option=val...]
  221. * option: 'ttl=n' : set the ttl value (for multicast only)
  222. * 'localport=n' : set the local port
  223. * 'pkt_size=n' : set max packet size
  224. * 'reuse=1' : enable reusing the socket
  225. *
  226. * @param h media file context
  227. * @param uri of the remote server
  228. * @return zero if no error.
  229. */
  230. int ff_udp_set_remote_url(URLContext *h, const char *uri)
  231. {
  232. UDPContext *s = h->priv_data;
  233. char hostname[256], buf[10];
  234. int port;
  235. const char *p;
  236. av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
  237. /* set the destination address */
  238. s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port);
  239. if (s->dest_addr_len < 0) {
  240. return AVERROR(EIO);
  241. }
  242. s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr);
  243. p = strchr(uri, '?');
  244. if (p) {
  245. if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
  246. int was_connected = s->is_connected;
  247. s->is_connected = strtol(buf, NULL, 10);
  248. if (s->is_connected && !was_connected) {
  249. if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr,
  250. s->dest_addr_len)) {
  251. s->is_connected = 0;
  252. av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
  253. return AVERROR(EIO);
  254. }
  255. }
  256. }
  257. }
  258. return 0;
  259. }
  260. /**
  261. * Return the local port used by the UDP connection
  262. * @param h media file context
  263. * @return the local port number
  264. */
  265. int ff_udp_get_local_port(URLContext *h)
  266. {
  267. UDPContext *s = h->priv_data;
  268. return s->local_port;
  269. }
  270. /**
  271. * Return the udp file handle for select() usage to wait for several RTP
  272. * streams at the same time.
  273. * @param h media file context
  274. */
  275. static int udp_get_file_handle(URLContext *h)
  276. {
  277. UDPContext *s = h->priv_data;
  278. return s->udp_fd;
  279. }
  280. static void *circular_buffer_task( void *_URLContext)
  281. {
  282. URLContext *h = _URLContext;
  283. UDPContext *s = h->priv_data;
  284. fd_set rfds;
  285. struct timeval tv;
  286. for(;;) {
  287. int left;
  288. int ret;
  289. int len;
  290. if (ff_check_interrupt(&h->interrupt_callback)) {
  291. s->circular_buffer_error = EINTR;
  292. return NULL;
  293. }
  294. FD_ZERO(&rfds);
  295. FD_SET(s->udp_fd, &rfds);
  296. tv.tv_sec = 1;
  297. tv.tv_usec = 0;
  298. ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
  299. if (ret < 0) {
  300. if (ff_neterrno() == AVERROR(EINTR))
  301. continue;
  302. s->circular_buffer_error = EIO;
  303. return NULL;
  304. }
  305. if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds)))
  306. continue;
  307. /* How much do we have left to the end of the buffer */
  308. /* Whats the minimum we can read so that we dont comletely fill the buffer */
  309. left = av_fifo_space(s->fifo);
  310. /* No Space left, error, what do we do now */
  311. if(left < UDP_MAX_PKT_SIZE + 4) {
  312. av_log(h, AV_LOG_ERROR, "circular_buffer: OVERRUN\n");
  313. s->circular_buffer_error = EIO;
  314. return NULL;
  315. }
  316. left = FFMIN(left, s->fifo->end - s->fifo->wptr);
  317. len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0);
  318. if (len < 0) {
  319. if (ff_neterrno() != AVERROR(EAGAIN) && ff_neterrno() != AVERROR(EINTR)) {
  320. s->circular_buffer_error = EIO;
  321. return NULL;
  322. }
  323. continue;
  324. }
  325. AV_WL32(s->tmp, len);
  326. av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
  327. }
  328. return NULL;
  329. }
  330. /* put it in UDP context */
  331. /* return non zero if error */
  332. static int udp_open(URLContext *h, const char *uri, int flags)
  333. {
  334. char hostname[1024], localaddr[1024] = "";
  335. int port, udp_fd = -1, tmp, bind_ret = -1;
  336. UDPContext *s = h->priv_data;
  337. int is_output;
  338. const char *p;
  339. char buf[256];
  340. struct sockaddr_storage my_addr;
  341. int len;
  342. int reuse_specified = 0;
  343. h->is_streamed = 1;
  344. h->max_packet_size = 1472;
  345. is_output = !(flags & AVIO_FLAG_READ);
  346. s->ttl = 16;
  347. s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
  348. s->circular_buffer_size = 7*188*4096;
  349. p = strchr(uri, '?');
  350. if (p) {
  351. if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) {
  352. char *endptr = NULL;
  353. s->reuse_socket = strtol(buf, &endptr, 10);
  354. /* assume if no digits were found it is a request to enable it */
  355. if (buf == endptr)
  356. s->reuse_socket = 1;
  357. reuse_specified = 1;
  358. }
  359. if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
  360. s->ttl = strtol(buf, NULL, 10);
  361. }
  362. if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
  363. s->local_port = strtol(buf, NULL, 10);
  364. }
  365. if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
  366. h->max_packet_size = strtol(buf, NULL, 10);
  367. }
  368. if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) {
  369. s->buffer_size = strtol(buf, NULL, 10);
  370. }
  371. if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
  372. s->is_connected = strtol(buf, NULL, 10);
  373. }
  374. if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) {
  375. s->circular_buffer_size = strtol(buf, NULL, 10)*188;
  376. }
  377. if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
  378. av_strlcpy(localaddr, buf, sizeof(localaddr));
  379. }
  380. }
  381. /* fill the dest addr */
  382. av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
  383. /* XXX: fix av_url_split */
  384. if (hostname[0] == '\0' || hostname[0] == '?') {
  385. /* only accepts null hostname if input */
  386. if (!(flags & AVIO_FLAG_READ))
  387. goto fail;
  388. } else {
  389. if (ff_udp_set_remote_url(h, uri) < 0)
  390. goto fail;
  391. }
  392. if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ))
  393. s->local_port = port;
  394. udp_fd = udp_socket_create(s, &my_addr, &len, localaddr);
  395. if (udp_fd < 0)
  396. goto fail;
  397. /* Follow the requested reuse option, unless it's multicast in which
  398. * case enable reuse unless explicitely disabled.
  399. */
  400. if (s->reuse_socket || (s->is_multicast && !reuse_specified)) {
  401. s->reuse_socket = 1;
  402. if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0)
  403. goto fail;
  404. }
  405. /* the bind is needed to give a port to the socket now */
  406. /* if multicast, try the multicast address bind first */
  407. if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) {
  408. bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len);
  409. }
  410. /* bind to the local address if not multicast or if the multicast
  411. * bind failed */
  412. if (bind_ret < 0 && bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0)
  413. goto fail;
  414. len = sizeof(my_addr);
  415. getsockname(udp_fd, (struct sockaddr *)&my_addr, &len);
  416. s->local_port = udp_port(&my_addr, len);
  417. if (s->is_multicast) {
  418. if (!(h->flags & AVIO_FLAG_READ)) {
  419. /* output */
  420. if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0)
  421. goto fail;
  422. } else {
  423. /* input */
  424. if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0)
  425. goto fail;
  426. }
  427. }
  428. if (is_output) {
  429. /* limit the tx buf size to limit latency */
  430. tmp = s->buffer_size;
  431. if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
  432. av_log(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno));
  433. goto fail;
  434. }
  435. } else {
  436. /* set udp recv buffer size to the largest possible udp packet size to
  437. * avoid losing data on OSes that set this too low by default. */
  438. tmp = s->buffer_size;
  439. if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) {
  440. av_log(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno));
  441. }
  442. /* make the socket non-blocking */
  443. ff_socket_nonblock(udp_fd, 1);
  444. }
  445. if (s->is_connected) {
  446. if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) {
  447. av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno));
  448. goto fail;
  449. }
  450. }
  451. s->udp_fd = udp_fd;
  452. #if HAVE_PTHREADS
  453. if (!is_output && s->circular_buffer_size) {
  454. /* start the task going */
  455. s->fifo = av_fifo_alloc(s->circular_buffer_size);
  456. if (pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h)) {
  457. av_log(h, AV_LOG_ERROR, "pthread_create failed\n");
  458. goto fail;
  459. }
  460. }
  461. #endif
  462. return 0;
  463. fail:
  464. if (udp_fd >= 0)
  465. closesocket(udp_fd);
  466. av_fifo_free(s->fifo);
  467. return AVERROR(EIO);
  468. }
  469. static int udp_read(URLContext *h, uint8_t *buf, int size)
  470. {
  471. UDPContext *s = h->priv_data;
  472. int ret;
  473. int avail;
  474. fd_set rfds;
  475. struct timeval tv;
  476. if (s->fifo) {
  477. do {
  478. avail = av_fifo_size(s->fifo);
  479. if (avail) { // >=size) {
  480. uint8_t tmp[4];
  481. av_fifo_generic_read(s->fifo, tmp, 4, NULL);
  482. avail= AV_RL32(tmp);
  483. if(avail > size){
  484. av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n");
  485. avail= size;
  486. }
  487. av_fifo_generic_read(s->fifo, buf, avail, NULL);
  488. av_fifo_drain(s->fifo, AV_RL32(tmp) - avail);
  489. return avail;
  490. }
  491. else {
  492. FD_ZERO(&rfds);
  493. FD_SET(s->udp_fd, &rfds);
  494. tv.tv_sec = 1;
  495. tv.tv_usec = 0;
  496. ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv);
  497. if (ret<0)
  498. return ret;
  499. }
  500. } while( 1);
  501. }
  502. if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
  503. ret = ff_network_wait_fd(s->udp_fd, 0);
  504. if (ret < 0)
  505. return ret;
  506. }
  507. ret = recv(s->udp_fd, buf, size, 0);
  508. return ret < 0 ? ff_neterrno() : ret;
  509. }
  510. static int udp_write(URLContext *h, const uint8_t *buf, int size)
  511. {
  512. UDPContext *s = h->priv_data;
  513. int ret;
  514. if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
  515. ret = ff_network_wait_fd(s->udp_fd, 1);
  516. if (ret < 0)
  517. return ret;
  518. }
  519. if (!s->is_connected) {
  520. ret = sendto (s->udp_fd, buf, size, 0,
  521. (struct sockaddr *) &s->dest_addr,
  522. s->dest_addr_len);
  523. } else
  524. ret = send(s->udp_fd, buf, size, 0);
  525. return ret < 0 ? ff_neterrno() : ret;
  526. }
  527. static int udp_close(URLContext *h)
  528. {
  529. UDPContext *s = h->priv_data;
  530. if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
  531. udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
  532. closesocket(s->udp_fd);
  533. av_fifo_free(s->fifo);
  534. return 0;
  535. }
  536. URLProtocol ff_udp_protocol = {
  537. .name = "udp",
  538. .url_open = udp_open,
  539. .url_read = udp_read,
  540. .url_write = udp_write,
  541. .url_close = udp_close,
  542. .url_get_file_handle = udp_get_file_handle,
  543. .priv_data_size = sizeof(UDPContext),
  544. };