Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,47 @@
#include <Rcpp.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace Rcpp ;
// [[Rcpp::export]]
CharacterVector getNameInfo(std::string fqdn) {
struct addrinfo hints, *res, *res0;
int error;
char host[NI_MAXHOST];
memset(&hints, 0, sizeof hints);
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(fqdn.c_str(), NULL, &hints, &res0);
if (error) { return(NA_STRING); }
int i = 0 ;
for (res = res0; res; res = res->ai_next) {
error = getnameinfo(res->ai_addr, res->ai_addrlen,
host, sizeof host, NULL, 0, NI_NUMERICHOST);
if (!error) { i++ ; }
}
CharacterVector results(i) ;
i = 0;
for (res = res0; res; res = res->ai_next) {
error = getnameinfo(res->ai_addr, res->ai_addrlen,
host, sizeof host, NULL, 0, NI_NUMERICHOST);
if (!error) { results[i++] = host ; }
}
freeaddrinfo(res0);
return(results) ;
}

View file

@ -0,0 +1,5 @@
library(Rcpp)
sourceCpp("dns.cpp")
getNameInfo("www.kame.net")
## [1] "203.178.141.194"
## [2] "2001:200:dff:fff1:216:3eff:feb1:44d7"

View file

@ -1,16 +1,16 @@
/*REXX pgm displays IPv4 and IPv6 addresses for a supplied domain name. */
/*REXX pgm displays IPv4 and IPv6 addresses for a supplied domain name.*/
trace off /*don't show the PING return code*/
parse arg dn . /*get the optional domain name. */
if dn=='' then dn='www.kame.net' /*Not specified? Then use default*/
tmp='\TEMP\TEMP.PING' /*define temp file to store IPv4.*/
if dn=='' then dn = 'www.kame.net' /*Not specified? Then use default*/
tmp = '\TEMP\TEMP.PING' /*define temp file to store IPv4.*/
do j=4 to 6 by 2 /*handle IPv4 and IPv6 addresses.*/
'PING' (-j) '-l 0 -n 1' dn ">" tmp /*restrict PING's output to min. */
q=charin(tmp,1,999) /*read output file from PING cmd.*/
parse var q '[' IPA ']' /*parse IP a ddress from output.*/
say 'IPv'j 'for domain name ' dn " is " IPA /*IPv4 | IPv6 addr.*/
call lineout tmp /*needed by most REXXes to force */
end /*j*/ /* [↑] file integrity. */
call lineout tmp /*needed by most REXXes to ··· */
end /*j*/ /* [↑] ··· force file integrity.*/
'ERASE' tmp /*clean up the temporary file. */
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,9 @@
import java.net.{InetAddress,Inet4Address,Inet6Address}
object DnsQuery extends App {
val ipAddresses = InetAddress.getAllByName("www.kame.net");
ipAddresses.foreach { ipAddr =>
if (ipAddr.isInstanceOf[Inet4Address]) println("IPv4 : " + ipAddr.getHostAddress())
else if (ipAddr.isInstanceOf[Inet6Address]) println("IPv6 : " + ipAddr.getHostAddress())
}
}