Can't get correct address in string form

Sergey fenix at
Tue May 3 08:39:35 PDT 2005

Hello freebsd-hackers

I have a question related to the simple code below:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <netinet/tcp_var.h>

#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
     struct addrinfo hints, *la, *localaddr;
     char buf[31];
     int gaierr=0;

     bzero (buf, sizeof(buf));

       //get local address - local address is
       if ((gaierr = getaddrinfo(argv[1], argv[2], &hints, &localaddr)) != 0)
           errx(1, "%s port %s: %s", argv[1], argv[2], gai_strerror(gaierr));

     for (la = localaddr; ail; la = la->ai_next)

      inet_ntop(la->ai_family, la->ai_addr->sa_data, buf, sizeof(struct sockaddr));
      fprintf(stderr, "Address: %s\n", buf);
  return 0;

result - something like:


but must be - ???

What i'm doing wrong !?

More information about the freebsd-hackers mailing list