summaryrefslogtreecommitdiff
path: root/libavformat/os_support.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-01-11 17:45:17 +0000
committerRonald S. Bultje <rsbultje@gmail.com>2010-01-11 17:45:17 +0000
commit5d629b72cba60e1af4339b5646a9c1d511d892fb (patch)
tree81ee2d790b9df84f9be9750f69362084fa4dffa8 /libavformat/os_support.c
parent34a65f1fdd24c192dedc6638e909ceb7c58a2d18 (diff)
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
Diffstat (limited to 'libavformat/os_support.c')
-rw-r--r--libavformat/os_support.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 62fd183afd..120f23469f 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -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 */