getpeername always returns ipv6

Hi,
I have a problem with the function getpeername. It always returns me a structure of type IPV6. Why is that?

I used the code found on http://www.beej.us/guide/bgnet/output/html/multipage/getpeernameman.html and when it gets to checking if it'a an ipv4 or ipv6 it always returns an ipv6.

Any clue?

Thanks.

Lace28
Part of the problem was in the following code:
(from http://www.beej.us/guide/bgnet/output/html/multipage/syscalls.html#getaddrinfo)

1
2
3
4
5
6
7
8
int status;
struct addrinfo hints;
struct addrinfo *servinfo;  // will point to the results

memset(&hints, 0, sizeof hints); // make sure the struct is empty
hints.ai_family = AF_UNSPEC;     // don't care IPv4 or IPv6
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
hints.ai_flags = AI_PASSIVE;     // fill in my IP for me 


The code is not wrong but it may return a structure filled with IPV6 information depending on the computer it's being run on.

To avoid this instead of using AF_UNSPEC I used AF_INET.
Topic archived. No new replies allowed.