mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Provide a fallback for getnameinfo() also. Patch by Martin Storsjö
<$firstname()$firstname,st>. Originally committed as revision 21150 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
34a65f1fdd
commit
5d629b72cb
@ -92,6 +92,14 @@ struct addrinfo {
|
||||
#define EAI_FAIL 4
|
||||
#endif
|
||||
|
||||
#ifndef EAI_FAMILY
|
||||
#define EAI_FAMILY 5
|
||||
#endif
|
||||
|
||||
#ifndef EAI_NONAME
|
||||
#define EAI_NONAME 8
|
||||
#endif
|
||||
|
||||
#ifndef AI_PASSIVE
|
||||
#define AI_PASSIVE 1
|
||||
#endif
|
||||
@ -104,12 +112,36 @@ struct addrinfo {
|
||||
#define AI_NUMERICHOST 4
|
||||
#endif
|
||||
|
||||
#ifndef NI_NOFQDN
|
||||
#define NI_NOFQDN 1
|
||||
#endif
|
||||
|
||||
#ifndef NI_NUMERICHOST
|
||||
#define NI_NUMERICHOST 2
|
||||
#endif
|
||||
|
||||
#ifndef NI_NAMERQD
|
||||
#define NI_NAMERQD 4
|
||||
#endif
|
||||
|
||||
#ifndef NI_NUMERICSERV
|
||||
#define NI_NUMERICSERV 8
|
||||
#endif
|
||||
|
||||
#ifndef NI_DGRAM
|
||||
#define NI_DGRAM 16
|
||||
#endif
|
||||
|
||||
#if !HAVE_GETADDRINFO
|
||||
int ff_getaddrinfo(const char *node, const char *service,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
void ff_freeaddrinfo(struct addrinfo *res);
|
||||
int ff_getnameinfo(const struct sockaddr *sa, int salen,
|
||||
char *host, int hostlen,
|
||||
char *serv, int servlen, int flags);
|
||||
#define getaddrinfo ff_getaddrinfo
|
||||
#define freeaddrinfo ff_freeaddrinfo
|
||||
#define getnameinfo ff_getnameinfo
|
||||
#endif
|
||||
|
||||
#endif /* AVFORMAT_NETWORK_H */
|
||||
|
@ -128,6 +128,50 @@ void ff_freeaddrinfo(struct addrinfo *res)
|
||||
av_free(res->ai_addr);
|
||||
av_free(res);
|
||||
}
|
||||
|
||||
int ff_getnameinfo(const struct sockaddr *sa, int salen,
|
||||
char *host, int hostlen,
|
||||
char *serv, int servlen, int flags)
|
||||
{
|
||||
const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
|
||||
|
||||
if (sa->sa_family != AF_INET)
|
||||
return EAI_FAMILY;
|
||||
if (!host && !serv)
|
||||
return EAI_NONAME;
|
||||
|
||||
if (host && hostlen > 0) {
|
||||
struct hostent *ent = NULL;
|
||||
uint32_t a;
|
||||
if (!(flags & NI_NUMERICHOST))
|
||||
ent = gethostbyaddr((const char *)&sin->sin_addr,
|
||||
sizeof(sin->sin_addr), AF_INET);
|
||||
|
||||
if (ent) {
|
||||
snprintf(host, hostlen, "%s", ent->h_name);
|
||||
} else if (flags & NI_NAMERQD) {
|
||||
return EAI_NONAME;
|
||||
} else {
|
||||
a = ntohl(sin->sin_addr.s_addr);
|
||||
snprintf(host, hostlen, "%d.%d.%d.%d",
|
||||
((a >> 24) & 0xff), ((a >> 16) & 0xff),
|
||||
((a >> 8) & 0xff), ( a & 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
if (serv && servlen > 0) {
|
||||
struct servent *ent = NULL;
|
||||
if (!(flags & NI_NUMERICSERV))
|
||||
ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp");
|
||||
|
||||
if (ent) {
|
||||
snprintf(serv, servlen, "%s", ent->s_name);
|
||||
} else
|
||||
snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* resolve host with also IP address parsing */
|
||||
|
Loading…
Reference in New Issue
Block a user