[FFmpeg-devel] [PATCH] Use getaddrinfo in resolve_host (ipv6 support)

Michael Niedermayer michaelni
Fri Aug 24 01:46:40 CEST 2007


Hi

On Mon, Aug 20, 2007 at 10:02:00PM -0400, Ronald S. Bultje wrote:
> Hi,
> 
> attached patch makes resolve_host() use getaddrinfo() in addition to
> gethostbyname(). This makes ffmpeg's tcp (udp already was) ipv6-compatible.
> 
> Features:
> - tcp.c is now ipv6-compatible
> 
> Bugs:
> - ffserver (which also uses resolve_host()) is not, because it uses all sort
> of ipv4-specific structures internally. I will fix this later.
> - udp.c was already ipv6-compatible, and I didn't do anything to integrate
> it. The new function declaration of resolve_host() is now similar to the
> ipv6-version inside udp.c, which should make it easy to integrate the two
> versions. However, the ipv4 and ipv6-versions in udp.c are not only
> completely different code paths, they are also completely non-resemblent, so
> I can't integrate them in any reasonable way without changing at least one
> of the two completely. Merging those two codepaths should, at the least, be
> in a separate patch, and whoever cracked up udp.c should fix it (after being
> shot), not me. I don't feel much like fixing what I didn't break to begin
> with.
> - the return code (what I'm really interested in, for things like "could not
> resolve host" error notices to users etc.) isn't useful/used yet, that'll
> come in a next version or separate patch (I expect people will want separate
> patches for this one).
> 
> The patch is not ready yet, this preliminary version is more for comments on
> the way in which I did it, I'll fix up ffserver for the final version in
> addition to stuff you guys want me to change.
> 
> Ronald

> Index: ffmpeg/libavformat/avformat.h
> ===================================================================
> --- ffmpeg.orig/libavformat/avformat.h	2007-08-14 09:38:26.000000000 -0400
> +++ ffmpeg/libavformat/avformat.h	2007-08-19 16:21:56.000000000 -0400
> @@ -27,6 +27,7 @@
>  
>  #define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
>  
> +#include <sys/socket.h> /* struct sockaddr */

ugly ...


>  #include <time.h>
>  #include <stdio.h>  /* FILE */
>  #include "avcodec.h"
> @@ -857,8 +858,35 @@
>  const char *small_strptime(const char *p, const char *fmt,
>                             struct tm *dt);
>  
> -struct in_addr;
> -int resolve_host(struct in_addr *sin_addr, const char *hostname);
> +typedef struct AVInetAddr AVInetAddr;
> +/**
> + * Structure containing internet hostname lookup data in a way that
> + * can be used to create sockets for use with connect().
> + */
> +struct AVInetAddr {
> +	int family, socket_type, protocol, addr_len;
> +	struct sockaddr *addr;
> +	AVInetAddr *next;

tabs


> +};
> +
> +/**
> + * Resolve a host, includes parsing of numeric hosts. Supports both
> + * IPv4 and IPv6 (if the OS supports it).
> + *
> + * @param in_addr pointer where the filled-in (and newly allocated)
> + *                list of addresses that the hostname resolved to will
> + *                be placed after a successful call to this function.
> + *                Should be free'ed with av_free() after use.
> + * @param socket_stream 1 if the returned address will be used for a
> + *                      TCP/IP stream-based connection, 0 for others.
> + * @param port the port number that will be connected to.
> + * @param passive 1 if the port will be used to bind() to, else 0.
> + * @param hostname the hostname (or numeric IPv4/6 string) to be parsed
> + *                 or looked up.
> + * return 0 on success, an error code otherwise.
> + */
> +int av_resolve_host(AVInetAddr **in_addr, int port, int passive,
> +                    int socket_stream, const char *hostname);

can we keep this stuff please private to av*/ffserver for the moment
instead of providing it in libavformats public API

making it public needs more thoughts, iam not saying iam against it ...


>  
>  void url_split(char *proto, int proto_size,
>                 char *authorization, int authorization_size,
> Index: ffmpeg/libavformat/os_support.c
> ===================================================================
> --- ffmpeg.orig/libavformat/os_support.c	2007-08-14 09:38:26.000000000 -0400
> +++ ffmpeg/libavformat/os_support.c	2007-08-19 16:28:20.000000000 -0400
> @@ -55,16 +55,73 @@
>  #endif /* !defined(HAVE_INET_ATON) */
>  
>  /* resolve host with also IP address parsing */
> -int resolve_host(struct in_addr *sin_addr, const char *hostname)
> +int av_resolve_host(AVInetAddr **in_addr, int port, int passive,
> +                    int socket_stream, const char *hostname)
>  {
> +    AVInetAddr *addr;
> +#ifdef CONFIG_IPV6
> +    struct addrinfo *resl, *res, hints;
> +    int err, num = 0, size = 0;
> +    char sport[16];
> +    AVInetAddr *addri;
> +    void *addr_ptr;
> +
> +    memset(&hints, 0, sizeof(hints));
> +    hints.ai_flags = AI_NUMERICHOST;
> +    if (passive) hints.ai_flags |= AI_PASSIVE;
> +    hints.ai_socktype = socket_stream ? SOCK_STREAM : SOCK_DGRAM;
> +    hints.ai_family = PF_UNSPEC;
> +    if (port > 0) snprintf(sport, sizeof(sport), "%d", port);
> +    if ((err = getaddrinfo(hostname, port > 0 ? sport : NULL, &hints, &resl))) {
> +        hints.ai_flags &= ~AI_NUMERICHOST;
> +        if ((err = getaddrinfo(hostname, port > 0 ? sport : NULL, &hints, &resl)))
> +            return err;
> +    }
> +
> +    for (res = resl; res != NULL; res = res->ai_next) {

superflous != NULL


> +        size += sizeof(AVInetAddr) + res->ai_addr_len;
> +        num++;
> +    }
> +    if (!(addr = av_mallocz(size))) return AVERROR(ENOMEM);
> +    ptr = &addr[num];
> +    for (n = 0, res = resl, addri = addr; res != NULL;
> +         addr = addr->next, res = res->ai_next) {

no please, dont put 6 statements in a for and then split the
line randomly 


[...]
> Index: ffmpeg/ffserver.c
> ===================================================================
> --- ffmpeg.orig/ffserver.c	2007-08-14 09:38:26.000000000 -0400
> +++ ffmpeg/ffserver.c	2007-08-19 16:47:57.000000000 -0400
> @@ -3792,6 +3792,9 @@
>      FFStream **last_feed, *feed;
>      AVCodecContext audio_enc, video_enc;
>      int audio_id, video_id;
> +    char http_host[1024] = {'\0'}, rtsp_host[1024] = {'\0'};

'\0' == 0 IIRC


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Democracy is the form of government in which you can choose your dictator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070824/75b38a75/attachment.pgp>



More information about the ffmpeg-devel mailing list