IPv6 on windows?

Ok, I'm looking into socket programming on windows, and I feel that what I'm resorting to is very unorthodox. I was trying to compile functions from the socket library with mingw32 but from what I understood mingw32 still doesnt support the latest functionalty of that library, So I was forced to switch to the microsoft compiler cl. Now I wrote a small program that is supposed to find the IP address of a domain name, basically activates the DNS lookup. However in windows it fails to retrieve the IPv6 addresses, It only gives me IPv4. I Want to write my application on IPv6. Why my programm works on linux with IPv6 but on windows it doesnt??

here is code, enjoy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* code taken from beej tutorial
http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html
*/
#include <Ws2tcpip.h>
#include <Winsock2.h>


#include <iostream>
#include <string.h>
#include <stdlib.h>


int main(int argc, char* argv[]){

        //initialize windows socket library or something like that
	WSADATA wsaData;
	std::cout << WSAStartup( MAKEWORD(1,1), &wsaData) << std::endl;
	
	struct addrinfo hints;     
	struct addrinfo* result;   //this is a linked list of all the IP addresses
                                               //returned by getaddrinfo

	struct addrinfo* runner; //this is used to loop on the list
	char ipstr[INET6_ADDRSTRLEN]; //will hold the address in printable
	int status;
	
        //recieve the domane name from command line
	if( argc != 2 ){
		std::cerr << "usage: showip hostname" << std::endl;
		exit(-1);
	}
	
        //set hints to both IPv4 and IPv6, requesting TCP connection
	memset(&hints, 0, sizeof( hints ));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	
        //returns the list of IP associated with the domain at argv[1]
	status = getaddrinfo(argv[1], NULL, &hints, &result);
	if( status != 0 ){
		std::cerr << "getaddrinfo: " << gai_strerror( status ) << std::endl;
		exit(2);
	}
	
	std::cout << "IP addressses for " << argv[1] << std::endl;
	
        //run on list and print all IP
	for(runner=result; runner!=NULL; runner=runner->ai_next){
		void * addr;
		char * ipver;
		
		if( runner->ai_family == AF_INET ){//IPv4
			struct sockaddr_in* ipv4 = (struct sockaddr_in*)runner->ai_addr;
			addr = &(ipv4->sin_addr);
			ipver = "IPv4";
		}else{//IPv6
			struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)runner->ai_addr;
			addr = &(ipv6->sin6_addr);
			ipver = "IPv6";
		}
		
		inet_ntop(runner->ai_family, addr, ipstr, INET6_ADDRSTRLEN);
		
		std::cout << "Version " << ipver << " IP " << ipstr << std::endl;
		
	}
	
	freeaddrinfo( result );
	
	WSACleanup();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.