Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 May 2005 18:39:10 +0300
From:      Sergey <fenix@intercollab.net>
To:        freebsd-hackers@freebsd.org
Subject:   Can't get correct address in string form
Message-ID:  <1908103559.20050503183910@intercollab.net>

next in thread | raw e-mail | index | archive | help
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 192.168.0.250
       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:

Address: 232.101.192.168

but must be - 192.168.0.250 ???

What i'm doing wrong !?
     



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1908103559.20050503183910>