DNS is an internet service that maps domain names, like rosettacode.org, to IP addresses, like 66.220.0.231.

Use DNS to resolve www.kame.net to both IPv4 and IPv6 addresses. Print these addresses.




      name$ = "www.kame.net"
 
      AF_INET = 2
      AF_INET6 = 23
      WSASYS_STATUS_LEN = 128
      WSADESCRIPTION_LEN = 256
 
      SYS "LoadLibrary", "WS2_32.DLL" TO ws2%
      SYS "GetProcAddress", ws2%, "WSAStartup"  TO `WSAStartup`
      SYS "GetProcAddress", ws2%, "WSACleanup"  TO `WSACleanup`
      SYS "GetProcAddress", ws2%, "getaddrinfo" TO `getaddrinfo`
 
      DIM WSAdata{wVersion{l&,h&}, wHighVersion{l&,h&}, \
      \ szDescription&(WSADESCRIPTION_LEN), szSystemStatus&(WSASYS_STATUS_LEN), \
      \ iMaxSockets{l&,h&}, iMaxUdpDg{l&,h&}, lpVendorInfo%}
 
      DIM addrinfo{ai_flags%, ai_family%, ai_socktype%, ai_protocol%, \
      \      ai_addrlen%, lp_ai_canonname%, lp_ai_addr%, lp_ai_next%}
      DIM ipv4info{} = addrinfo{}, ipv6info{} = addrinfo{}
 
      DIM sockaddr_in{sin_family{l&,h&}, sin_port{l&,h&}, sin_addr&(3), sin_zero&(7)}
      DIM sockaddr_in6{sin6_family{l&,h&}, sin6_port{l&,h&}, sin6_flowinfo%, \
      \                sin6_addr&(15), sin6_scope_id%}
 
      SYS `WSAStartup`, &202, WSAdata{} TO res%
      IF res% ERROR 102, "WSAStartup failed"
 
      addrinfo.ai_family% = AF_INET
      SYS `getaddrinfo`, name$, 0, addrinfo{}, ^ipv4info{}+4 TO res%
      IF res% ERROR 103, "getaddrinfo failed"
 
      !(^sockaddr_in{}+4) = ipv4info.lp_ai_addr%
      PRINT "IPv4 address = " ;
      PRINT ;sockaddr_in.sin_addr&(0) "." sockaddr_in.sin_addr&(1) "." ;
      PRINT ;sockaddr_in.sin_addr&(2) "." sockaddr_in.sin_addr&(3)
 
      addrinfo.ai_family% = AF_INET6
      SYS `getaddrinfo`, name$, 0, addrinfo{}, ^ipv6info{}+4 TO res%
      IF res% ERROR 104, "getaddrinfo failed"
 
      !(^sockaddr_in6{}+4) = ipv6info.lp_ai_addr%
      PRINT "IPv6 address = " ;
      PRINT ;~sockaddr_in6.sin6_addr&(0) * 256 + sockaddr_in6.sin6_addr&(1) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(2) * 256 + sockaddr_in6.sin6_addr&(3) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(4) * 256 + sockaddr_in6.sin6_addr&(5) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(6) * 256 + sockaddr_in6.sin6_addr&(7) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(8) * 256 + sockaddr_in6.sin6_addr&(9) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(10) * 256 + sockaddr_in6.sin6_addr&(11) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(12) * 256 + sockaddr_in6.sin6_addr&(13) ":" ;
      PRINT ;~sockaddr_in6.sin6_addr&(14) * 256 + sockaddr_in6.sin6_addr&(15)
 
      SYS `WSACleanup`
 