[FFmpeg-devel] [PATCH] adding _GNU_SOURCE for udp.c compilation
Rich Felker
dalias
Mon Feb 11 03:17:52 CET 2008
On Sun, Feb 10, 2008 at 09:14:42PM -0500, Rich Felker wrote:
> On Sun, Feb 10, 2008 at 07:20:31PM +0100, Nicolas George wrote:
> > Hi.
> >
> > Le duodi 22 pluvi?se, an CCXVI, Reimar D?ffinger a ?crit?:
> > > Well in my header file (gentoo and debian) they are claimed to be part of
> > > POSIX1.g, so they are not under a GNU ifdef.
> > > Though I admit I could not find it in the POSIX specs I had lying
> > > around.
> >
> > Neither NI_MAXSERV nor NI_MAXHOST appear in the Single Unix Specification
> > version 3, which is a superset of POSIX.
> >
> > http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/resolv/netdb.h?annotate=1.47.2.1&cvsroot=glibc
> >
> > shows that the check for _GNU_SOURCE has been added three weeks ago, with
> > the log message "Cleanup namespace.".
> >
> > getnameinfo seems to return EAI_OVERFLOW if the buffers are not big enough.
> > EAI_OVERFLOW is standard, and described in the SUSv3 about netdb.h, but not
> > referenced in the page about getnameinfo.
> >
> > I fear that the only absolutely reliable way of doing this is to increase
> > dynamically the buffer each time EAI_OVERFLOW is returned. Yet, using
> > NI_MAX* when they are defined as the initial size for the buffer should be
> > helpful nonetheless.
>
> For the service number (port), sizeof(int)*3 is a perfectly acceptable
> bound. This function does not even make use of the hbuf result so it
> should be passing a null pointer for that rather than wasting
> complexity and stack space.
And here is the patch.
Rich
-------------- next part --------------
Index: libavformat/udp.c
===================================================================
--- libavformat/udp.c (revision 11901)
+++ libavformat/udp.c (working copy)
@@ -196,10 +196,9 @@
static int udp_port(struct sockaddr_storage *addr, int addr_len)
{
- char sbuf[NI_MAXSERV];
- char hbuf[NI_MAXHOST];
+ char sbuf[sizeof(int)*3+1];
- if (getnameinfo((struct sockaddr *)addr, addr_len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ if (getnameinfo((struct sockaddr *)addr, addr_len, NULL, 0, sbuf, sizeof(sbuf), NI_NUMERICSERV) != 0) {
av_log(NULL, AV_LOG_ERROR, "getnameinfo: %s\n", strerror(errno));
return -1;
}
More information about the ffmpeg-devel
mailing list