libavformat/network.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 The FFmpeg Project
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #ifndef AVFORMAT_NETWORK_H
00022 #define AVFORMAT_NETWORK_H
00023 
00024 #include <errno.h>
00025 
00026 #include "config.h"
00027 #include "libavutil/error.h"
00028 #include "os_support.h"
00029 
00030 #if HAVE_WINSOCK2_H
00031 #include <winsock2.h>
00032 #include <ws2tcpip.h>
00033 
00034 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
00035 #define ETIMEDOUT       WSAETIMEDOUT
00036 #define ECONNREFUSED    WSAECONNREFUSED
00037 #define EINPROGRESS     WSAEINPROGRESS
00038 
00039 int ff_neterrno(void);
00040 #else
00041 #include <sys/types.h>
00042 #include <sys/socket.h>
00043 #include <netinet/in.h>
00044 #include <netdb.h>
00045 
00046 #define ff_neterrno() AVERROR(errno)
00047 #endif
00048 
00049 #if HAVE_ARPA_INET_H
00050 #include <arpa/inet.h>
00051 #endif
00052 
00053 #if HAVE_POLL_H
00054 #include <poll.h>
00055 #endif
00056 
00057 int ff_socket_nonblock(int socket, int enable);
00058 
00059 extern int ff_network_inited_globally;
00060 int ff_network_init(void);
00061 void ff_network_close(void);
00062 
00063 void ff_tls_init(void);
00064 void ff_tls_deinit(void);
00065 
00066 int ff_network_wait_fd(int fd, int write);
00067 
00068 int ff_inet_aton (const char * str, struct in_addr * add);
00069 
00070 #if !HAVE_STRUCT_SOCKADDR_STORAGE
00071 struct sockaddr_storage {
00072 #if HAVE_STRUCT_SOCKADDR_SA_LEN
00073     uint8_t ss_len;
00074     uint8_t ss_family;
00075 #else
00076     uint16_t ss_family;
00077 #endif
00078     char ss_pad1[6];
00079     int64_t ss_align;
00080     char ss_pad2[112];
00081 };
00082 #endif
00083 
00084 #if !HAVE_STRUCT_ADDRINFO
00085 struct addrinfo {
00086     int ai_flags;
00087     int ai_family;
00088     int ai_socktype;
00089     int ai_protocol;
00090     int ai_addrlen;
00091     struct sockaddr *ai_addr;
00092     char *ai_canonname;
00093     struct addrinfo *ai_next;
00094 };
00095 #endif
00096 
00097 /* getaddrinfo constants */
00098 #ifndef EAI_FAIL
00099 #define EAI_FAIL 4
00100 #endif
00101 
00102 #ifndef EAI_FAMILY
00103 #define EAI_FAMILY 5
00104 #endif
00105 
00106 #ifndef EAI_NONAME
00107 #define EAI_NONAME 8
00108 #endif
00109 
00110 #ifndef AI_PASSIVE
00111 #define AI_PASSIVE 1
00112 #endif
00113 
00114 #ifndef AI_CANONNAME
00115 #define AI_CANONNAME 2
00116 #endif
00117 
00118 #ifndef AI_NUMERICHOST
00119 #define AI_NUMERICHOST 4
00120 #endif
00121 
00122 #ifndef NI_NOFQDN
00123 #define NI_NOFQDN 1
00124 #endif
00125 
00126 #ifndef NI_NUMERICHOST
00127 #define NI_NUMERICHOST 2
00128 #endif
00129 
00130 #ifndef NI_NAMERQD
00131 #define NI_NAMERQD 4
00132 #endif
00133 
00134 #ifndef NI_NUMERICSERV
00135 #define NI_NUMERICSERV 8
00136 #endif
00137 
00138 #ifndef NI_DGRAM
00139 #define NI_DGRAM 16
00140 #endif
00141 
00142 #if !HAVE_GETADDRINFO
00143 int ff_getaddrinfo(const char *node, const char *service,
00144                    const struct addrinfo *hints, struct addrinfo **res);
00145 void ff_freeaddrinfo(struct addrinfo *res);
00146 int ff_getnameinfo(const struct sockaddr *sa, int salen,
00147                    char *host, int hostlen,
00148                    char *serv, int servlen, int flags);
00149 const char *ff_gai_strerror(int ecode);
00150 #define getaddrinfo ff_getaddrinfo
00151 #define freeaddrinfo ff_freeaddrinfo
00152 #define getnameinfo ff_getnameinfo
00153 #define gai_strerror ff_gai_strerror
00154 #endif
00155 
00156 #ifndef INET6_ADDRSTRLEN
00157 #define INET6_ADDRSTRLEN INET_ADDRSTRLEN
00158 #endif
00159 
00160 #ifndef IN_MULTICAST
00161 #define IN_MULTICAST(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
00162 #endif
00163 #ifndef IN6_IS_ADDR_MULTICAST
00164 #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff)
00165 #endif
00166 
00167 int ff_is_multicast_address(struct sockaddr *addr);
00168 
00169 #endif /* AVFORMAT_NETWORK_H */