getaddrinfo parameters

I got something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void func(addrinfo * ip_list)
{
    addrinfo hints;
    ZeroMemory(&hints, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    const char * domain_addr = "someaddr.something.com";

    getaddrinfo(domain_addr, "43", &hints, &ip_list);
}

int main()
{
  addrinfo * ip_list = NULL;
  func(ip_list);
}


inside func(), after the call to getaddrinfo I check if "ip_list" == NULL... The result is that it's not NULL, but inside main it becomes NULL if I check after calling func(), and I can't figure out why. I want to use ip_list after the call to func() but it's null then :S
Last edited on
You would need to pass a reference to your pointer (C++), or a pointer to your pointer (C).

Or do
ip_list = func();
Thanks salem :)
Don't forget to call freeaddrinfo() to free the memory allocated by getaddrinfo().
Registered users can post here. Sign in or register to post.