Originally committed as revision 21150 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -92,6 +92,14 @@ struct addrinfo {
|
| 92 | 92 |
#define EAI_FAIL 4 |
| 93 | 93 |
#endif |
| 94 | 94 |
|
| 95 |
+#ifndef EAI_FAMILY |
|
| 96 |
+#define EAI_FAMILY 5 |
|
| 97 |
+#endif |
|
| 98 |
+ |
|
| 99 |
+#ifndef EAI_NONAME |
|
| 100 |
+#define EAI_NONAME 8 |
|
| 101 |
+#endif |
|
| 102 |
+ |
|
| 95 | 103 |
#ifndef AI_PASSIVE |
| 96 | 104 |
#define AI_PASSIVE 1 |
| 97 | 105 |
#endif |
| ... | ... |
@@ -104,12 +112,36 @@ struct addrinfo {
|
| 104 | 104 |
#define AI_NUMERICHOST 4 |
| 105 | 105 |
#endif |
| 106 | 106 |
|
| 107 |
+#ifndef NI_NOFQDN |
|
| 108 |
+#define NI_NOFQDN 1 |
|
| 109 |
+#endif |
|
| 110 |
+ |
|
| 111 |
+#ifndef NI_NUMERICHOST |
|
| 112 |
+#define NI_NUMERICHOST 2 |
|
| 113 |
+#endif |
|
| 114 |
+ |
|
| 115 |
+#ifndef NI_NAMERQD |
|
| 116 |
+#define NI_NAMERQD 4 |
|
| 117 |
+#endif |
|
| 118 |
+ |
|
| 119 |
+#ifndef NI_NUMERICSERV |
|
| 120 |
+#define NI_NUMERICSERV 8 |
|
| 121 |
+#endif |
|
| 122 |
+ |
|
| 123 |
+#ifndef NI_DGRAM |
|
| 124 |
+#define NI_DGRAM 16 |
|
| 125 |
+#endif |
|
| 126 |
+ |
|
| 107 | 127 |
#if !HAVE_GETADDRINFO |
| 108 | 128 |
int ff_getaddrinfo(const char *node, const char *service, |
| 109 | 129 |
const struct addrinfo *hints, struct addrinfo **res); |
| 110 | 130 |
void ff_freeaddrinfo(struct addrinfo *res); |
| 131 |
+int ff_getnameinfo(const struct sockaddr *sa, int salen, |
|
| 132 |
+ char *host, int hostlen, |
|
| 133 |
+ char *serv, int servlen, int flags); |
|
| 111 | 134 |
#define getaddrinfo ff_getaddrinfo |
| 112 | 135 |
#define freeaddrinfo ff_freeaddrinfo |
| 136 |
+#define getnameinfo ff_getnameinfo |
|
| 113 | 137 |
#endif |
| 114 | 138 |
|
| 115 | 139 |
#endif /* AVFORMAT_NETWORK_H */ |
| ... | ... |
@@ -128,6 +128,50 @@ void ff_freeaddrinfo(struct addrinfo *res) |
| 128 | 128 |
av_free(res->ai_addr); |
| 129 | 129 |
av_free(res); |
| 130 | 130 |
} |
| 131 |
+ |
|
| 132 |
+int ff_getnameinfo(const struct sockaddr *sa, int salen, |
|
| 133 |
+ char *host, int hostlen, |
|
| 134 |
+ char *serv, int servlen, int flags) |
|
| 135 |
+{
|
|
| 136 |
+ const struct sockaddr_in *sin = (const struct sockaddr_in *)sa; |
|
| 137 |
+ |
|
| 138 |
+ if (sa->sa_family != AF_INET) |
|
| 139 |
+ return EAI_FAMILY; |
|
| 140 |
+ if (!host && !serv) |
|
| 141 |
+ return EAI_NONAME; |
|
| 142 |
+ |
|
| 143 |
+ if (host && hostlen > 0) {
|
|
| 144 |
+ struct hostent *ent = NULL; |
|
| 145 |
+ uint32_t a; |
|
| 146 |
+ if (!(flags & NI_NUMERICHOST)) |
|
| 147 |
+ ent = gethostbyaddr((const char *)&sin->sin_addr, |
|
| 148 |
+ sizeof(sin->sin_addr), AF_INET); |
|
| 149 |
+ |
|
| 150 |
+ if (ent) {
|
|
| 151 |
+ snprintf(host, hostlen, "%s", ent->h_name); |
|
| 152 |
+ } else if (flags & NI_NAMERQD) {
|
|
| 153 |
+ return EAI_NONAME; |
|
| 154 |
+ } else {
|
|
| 155 |
+ a = ntohl(sin->sin_addr.s_addr); |
|
| 156 |
+ snprintf(host, hostlen, "%d.%d.%d.%d", |
|
| 157 |
+ ((a >> 24) & 0xff), ((a >> 16) & 0xff), |
|
| 158 |
+ ((a >> 8) & 0xff), ( a & 0xff)); |
|
| 159 |
+ } |
|
| 160 |
+ } |
|
| 161 |
+ |
|
| 162 |
+ if (serv && servlen > 0) {
|
|
| 163 |
+ struct servent *ent = NULL; |
|
| 164 |
+ if (!(flags & NI_NUMERICSERV)) |
|
| 165 |
+ ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp"); |
|
| 166 |
+ |
|
| 167 |
+ if (ent) {
|
|
| 168 |
+ snprintf(serv, servlen, "%s", ent->s_name); |
|
| 169 |
+ } else |
|
| 170 |
+ snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); |
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ return 0; |
|
| 174 |
+} |
|
| 131 | 175 |
#endif |
| 132 | 176 |
|
| 133 | 177 |
/* resolve host with also IP address parsing */ |