From: John Mudd <johnbmudd@gmail.com>
To: musl <musl@lists.openwall.com>
Cc: John Mudd <johnbmudd@gmail.com>
Subject: getaddrinfo, ip address sort order?
Date: Fri, 3 Jun 2016 11:21:42 -0400 [thread overview]
Message-ID: <CAGDMk9Ht0Jb4UkpxzKrvo5cNMJViY_4a20+G3oEXD9im03PH7w@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 322 bytes --]
I read that getaddrinfo() returns addresses sorted based on RFC 3484. I'm
using the attached program to test it and I'm not sure if they are sorted.
I looked at the musl getaddrinfo.c here:
https://github.com/idunham/musl/blob/master/src/network/getaddrinfo.c
I don't see an obvious sort in the code. Is it there?
John
[-- Attachment #1.2: Type: text/html, Size: 544 bytes --]
[-- Attachment #2: showip.c --]
[-- Type: text/x-csrc, Size: 1506 bytes --]
//
//
//
// Copied from http://www.logix.cz/michal/devel/various/getaddrinfo.c.xp
// Some changes.
//
//
/*
* getaddrinfo.c - Simple example of using getaddrinfo(3) function.
*
* Michal Ludvig <michal@logix.cz> (c) 2002, 2003
* http://www.logix.cz/michal/devel/
*
* License: public domain.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int
lookup_host (const char *host)
{
struct addrinfo hints, *res;
int errcode;
char addrstr[100];
void *ptr;
memset (&hints, 0, sizeof (hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags |= AI_CANONNAME;
errcode = getaddrinfo (host, NULL, &hints, &res);
if (errcode != 0)
{
perror ("getaddrinfo");
return -1;
}
//printf ("Host: %s\n", host);
while (res)
{
inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, 100);
switch (res->ai_family)
{
case AF_INET:
ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
break;
case AF_INET6:
ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
break;
}
inet_ntop (res->ai_family, ptr, addrstr, 100);
printf ("IPv%d %s\n", res->ai_family == PF_INET6 ? 6 : 4, addrstr);
res = res->ai_next;
}
return 0;
}
int
main (int argc, char *argv[])
{
if (argc < 2)
exit (1);
return lookup_host (argv[1]);
}
next reply other threads:[~2016-06-03 15:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-03 15:21 John Mudd [this message]
2016-06-03 15:25 ` John Mudd
2016-06-03 16:08 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGDMk9Ht0Jb4UkpxzKrvo5cNMJViY_4a20+G3oEXD9im03PH7w@mail.gmail.com \
--to=johnbmudd@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).