Libav
|
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 "config.h" 00025 00026 #if HAVE_WINSOCK2_H 00027 #include <winsock2.h> 00028 #include <ws2tcpip.h> 00029 00030 #define ff_neterrno() (-WSAGetLastError()) 00031 #define FF_NETERROR(err) (-WSA##err) 00032 #define WSAEAGAIN WSAEWOULDBLOCK 00033 #else 00034 #include <sys/types.h> 00035 #include <sys/socket.h> 00036 #include <netinet/in.h> 00037 #include <netdb.h> 00038 00039 #define ff_neterrno() AVERROR(errno) 00040 #define FF_NETERROR(err) AVERROR(err) 00041 #endif 00042 00043 #if HAVE_ARPA_INET_H 00044 #include <arpa/inet.h> 00045 #endif 00046 00047 int ff_socket_nonblock(int socket, int enable); 00048 00049 static inline int ff_network_init(void) 00050 { 00051 #if HAVE_WINSOCK2_H 00052 WSADATA wsaData; 00053 if (WSAStartup(MAKEWORD(1,1), &wsaData)) 00054 return 0; 00055 #endif 00056 return 1; 00057 } 00058 00059 static inline void ff_network_close(void) 00060 { 00061 #if HAVE_WINSOCK2_H 00062 WSACleanup(); 00063 #endif 00064 } 00065 00066 int ff_inet_aton (const char * str, struct in_addr * add); 00067 00068 #if !HAVE_STRUCT_SOCKADDR_STORAGE 00069 struct sockaddr_storage { 00070 #if HAVE_STRUCT_SOCKADDR_SA_LEN 00071 uint8_t ss_len; 00072 uint8_t ss_family; 00073 #else 00074 uint16_t ss_family; 00075 #endif 00076 char ss_pad1[6]; 00077 int64_t ss_align; 00078 char ss_pad2[112]; 00079 }; 00080 #endif 00081 00082 #if !HAVE_STRUCT_ADDRINFO 00083 struct addrinfo { 00084 int ai_flags; 00085 int ai_family; 00086 int ai_socktype; 00087 int ai_protocol; 00088 int ai_addrlen; 00089 struct sockaddr *ai_addr; 00090 char *ai_canonname; 00091 struct addrinfo *ai_next; 00092 }; 00093 #endif 00094 00095 /* getaddrinfo constants */ 00096 #ifndef EAI_FAIL 00097 #define EAI_FAIL 4 00098 #endif 00099 00100 #ifndef EAI_FAMILY 00101 #define EAI_FAMILY 5 00102 #endif 00103 00104 #ifndef EAI_NONAME 00105 #define EAI_NONAME 8 00106 #endif 00107 00108 #ifndef AI_PASSIVE 00109 #define AI_PASSIVE 1 00110 #endif 00111 00112 #ifndef AI_CANONNAME 00113 #define AI_CANONNAME 2 00114 #endif 00115 00116 #ifndef AI_NUMERICHOST 00117 #define AI_NUMERICHOST 4 00118 #endif 00119 00120 #ifndef NI_NOFQDN 00121 #define NI_NOFQDN 1 00122 #endif 00123 00124 #ifndef NI_NUMERICHOST 00125 #define NI_NUMERICHOST 2 00126 #endif 00127 00128 #ifndef NI_NAMERQD 00129 #define NI_NAMERQD 4 00130 #endif 00131 00132 #ifndef NI_NUMERICSERV 00133 #define NI_NUMERICSERV 8 00134 #endif 00135 00136 #ifndef NI_DGRAM 00137 #define NI_DGRAM 16 00138 #endif 00139 00140 #if !HAVE_GETADDRINFO 00141 int ff_getaddrinfo(const char *node, const char *service, 00142 const struct addrinfo *hints, struct addrinfo **res); 00143 void ff_freeaddrinfo(struct addrinfo *res); 00144 int ff_getnameinfo(const struct sockaddr *sa, int salen, 00145 char *host, int hostlen, 00146 char *serv, int servlen, int flags); 00147 const char *ff_gai_strerror(int ecode); 00148 #define getaddrinfo ff_getaddrinfo 00149 #define freeaddrinfo ff_freeaddrinfo 00150 #define getnameinfo ff_getnameinfo 00151 #define gai_strerror ff_gai_strerror 00152 #endif 00153 00154 #endif /* AVFORMAT_NETWORK_H */