September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
163
Task/DNS-query/ARM-Assembly/dns-query.arm
Normal file
163
Task/DNS-query/ARM-Assembly/dns-query.arm
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program dnsquery.s */
|
||||
|
||||
/************************************/
|
||||
/* Constantes */
|
||||
/************************************/
|
||||
.equ STDIN, 0 @ Linux input console
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
|
||||
.equ EXIT, 1 @ Linux syscall END PROGRAM
|
||||
.equ FORK, 2 @ Linux syscall
|
||||
.equ READ, 3 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
.equ OPEN, 5 @ Linux syscall
|
||||
.equ CLOSE, 6 @ Linux syscall
|
||||
.equ EXECVE, 0xB @ Linux syscall
|
||||
.equ PIPE, 0x2A @ Linux syscall
|
||||
.equ DUP2, 0x3F @ Linux syscall
|
||||
.equ WAIT4, 0x72 @ Linux syscall
|
||||
|
||||
.equ WUNTRACED, 2 @ Wait, return status of stopped child
|
||||
.equ TAILLEBUFFER, 500
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szCarriageReturn: .asciz "\n"
|
||||
szMessFinOK: .asciz "Fin normale du programme. \n"
|
||||
szMessError: .asciz "Error occured !!!"
|
||||
szCommand: .asciz "/usr/bin/host" @ command host
|
||||
szNameHost: .asciz "www.kame.net" @ string query name
|
||||
.align 4
|
||||
stArg1: .int szCommand @ address command
|
||||
.int szNameHost @ address argument
|
||||
.int 0,0 @ zeroes
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
.align 4
|
||||
iStatusThread: .skip 4
|
||||
pipefd: .skip 8
|
||||
sBuffer: .skip TAILLEBUFFER
|
||||
stRusage: .skip TAILLEBUFFER
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
/* création pipe */
|
||||
ldr r0,iAdrpipefd @ FDs address
|
||||
mov r7, #PIPE @ create pipe
|
||||
svc 0 @ call system Linux
|
||||
cmp r0,#0 @ error ?
|
||||
blt 99f
|
||||
|
||||
/* create child thread */
|
||||
mov r0,#0
|
||||
mov r7, #FORK @ call system
|
||||
svc #0
|
||||
cmp r0,#0 @ error ?
|
||||
blt 99f
|
||||
bne parent @ if <> zero r0 contains father pid
|
||||
@ else is the child
|
||||
/****************************************/
|
||||
/* Child thread */
|
||||
/****************************************/
|
||||
/* redirection sysout -> pipe */
|
||||
ldr r0,iAdrpipefd
|
||||
ldr r0,[r0,#4]
|
||||
mov r7, #DUP2 @ call system linux
|
||||
mov r1, #STDOUT @
|
||||
svc #0
|
||||
cmp r0,#0 @ error ?
|
||||
blt 99f
|
||||
|
||||
/* run command host */
|
||||
ldr r0, iAdrszCommand @ r0 = address de "/usr/bin/host"
|
||||
ldr r1,iAdrstArg1 @ address argument 1
|
||||
mov r2,#0
|
||||
mov r7, #EXECVE @ call system linux (execve)
|
||||
svc #0 @ if ok -> no return !!!
|
||||
b 100f @ never exec this label
|
||||
/****************************************/
|
||||
/* Father thread */
|
||||
/****************************************/
|
||||
parent:
|
||||
mov r4,r0 @ save child pid
|
||||
1: @ loop child signal
|
||||
mov r0,r4
|
||||
ldr r1,iAdriStatusThread @ return status thread
|
||||
mov r2,#WUNTRACED @ flags
|
||||
ldr r3,iAdrstRusage @ return structure thread
|
||||
mov r7, #WAIT4 @ Call System
|
||||
svc #0
|
||||
cmp r0,#0 @ error ?
|
||||
blt 99f
|
||||
@ recup status
|
||||
ldr r0,iAdriStatusThread @ analyse status
|
||||
ldrb r0,[r0] @ firest byte
|
||||
cmp r0,#0 @ normal end thread ?
|
||||
bne 1b @ loop
|
||||
|
||||
/* close entry pipe */
|
||||
ldr r0,iAdrpipefd
|
||||
mov r7,#CLOSE @ call system
|
||||
svc #0
|
||||
|
||||
/* read datas pipe */
|
||||
ldr r0,iAdrpipefd
|
||||
ldr r0,[r0]
|
||||
ldr r1,iAdrsBuffer @ buffer address
|
||||
mov r2,#TAILLEBUFFER @ buffer size
|
||||
mov r7, #READ @ call system
|
||||
svc #0
|
||||
ldr r0,iAdrsBuffer @ display buffer
|
||||
bl affichageMess
|
||||
|
||||
ldr r0,iAdrszMessFinOK @ display message Ok
|
||||
bl affichageMess
|
||||
mov r0, #0 @ return code
|
||||
b 100f
|
||||
99:
|
||||
ldr r0,iAdrszMessError @ erreur
|
||||
bl affichageMess
|
||||
mov r0, #1 @ return code
|
||||
b 100f
|
||||
100: @ standard end of the program
|
||||
mov r7, #EXIT @ request to exit program
|
||||
svc #0 @ perform the system call
|
||||
|
||||
iAdrszCarriageReturn: .int szCarriageReturn
|
||||
iAdrszMessFinOK: .int szMessFinOK
|
||||
iAdrszMessError: .int szMessError
|
||||
iAdrsBuffer: .int sBuffer
|
||||
iAdrpipefd: .int pipefd
|
||||
iAdrszCommand: .int szCommand
|
||||
iAdrstArg1: .int stArg1
|
||||
iAdriStatusThread: .int iStatusThread
|
||||
iAdrstRusage: .int stRusage
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {r0,r1,r2,r7,lr} @ save registres
|
||||
mov r2,#0 @ counter length
|
||||
1: @ loop length calculation
|
||||
ldrb r1,[r0,r2] @ read octet start position + index
|
||||
cmp r1,#0 @ if 0 its over
|
||||
addne r2,r2,#1 @ else add 1 in the length
|
||||
bne 1b @ and loop
|
||||
@ so here r2 contains the length of the message
|
||||
mov r1,r0 @ address message in r1
|
||||
mov r0,#STDOUT @ code to write to the standard output Linux
|
||||
mov r7, #WRITE @ code call system "write"
|
||||
svc #0 @ call systeme
|
||||
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
|
||||
bx lr @ return
|
||||
3
Task/DNS-query/Common-Lisp/dns-query-7.lisp
Normal file
3
Task/DNS-query/Common-Lisp/dns-query-7.lisp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(require "comm")
|
||||
(comm:ip-address-string (comm:get-host-entry "www.rosettacode.org" :fields '(:address)))
|
||||
"104.28.10.103"
|
||||
4
Task/DNS-query/Factor/dns-query.factor
Normal file
4
Task/DNS-query/Factor/dns-query.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
USING: dns io kernel sequences ;
|
||||
|
||||
"www.kame.net" [ dns-A-query ] [ dns-AAAA-query ] bi
|
||||
[ message>names second print ] bi@
|
||||
8
Task/DNS-query/J/dns-query-3.j
Normal file
8
Task/DNS-query/J/dns-query-3.j
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
const dns = require("dns");
|
||||
|
||||
dns.lookup("www.kame.net", {
|
||||
all: true
|
||||
}, (err, addresses) => {
|
||||
if(err) return console.error(err);
|
||||
console.log(addresses);
|
||||
})
|
||||
7
Task/DNS-query/Julia/dns-query.julia
Normal file
7
Task/DNS-query/Julia/dns-query.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
julia> using Sockets
|
||||
|
||||
julia> getaddrinfo("www.kame.net")
|
||||
ip"203.178.141.194"
|
||||
|
||||
julia> getaddrinfo("www.kame.net", IPv6)
|
||||
ip"2001:200:dff:fff1:216:3eff:feb1:44d7"
|
||||
6
Task/DNS-query/Lua/dns-query.lua
Normal file
6
Task/DNS-query/Lua/dns-query.lua
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
local socket = require('socket')
|
||||
local ip_tbl = socket.dns.getaddrinfo('www.kame.net')
|
||||
|
||||
for _, v in ipairs(ip_tbl) do
|
||||
io.write(string.format('%s: %s\n', v.family, v.addr))
|
||||
end
|
||||
9
Task/DNS-query/Neko/dns-query-1.neko
Normal file
9
Task/DNS-query/Neko/dns-query-1.neko
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* dns in neko */
|
||||
var host_resolve = $loader.loadprim("std@host_resolve", 1);
|
||||
var host_to_string = $loader.loadprim("std@host_to_string", 1);
|
||||
var host_reverse = $loader.loadprim("std@host_reverse", 1);
|
||||
|
||||
var ip = host_resolve("www.kame.net");
|
||||
|
||||
$print("www.kame.net: ", ip, ", ", host_to_string(ip), "\n");
|
||||
$print(host_to_string(ip), ": ", host_reverse(ip), "\n");
|
||||
13
Task/DNS-query/Neko/dns-query-2.neko
Normal file
13
Task/DNS-query/Neko/dns-query-2.neko
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
ir = InetAddress
|
||||
addresses = InetAddress[] InetAddress.getAllByName('www.kame.net')
|
||||
loop ir over addresses
|
||||
if ir <= Inet4Address then do
|
||||
say 'IPv4 :' ir.getHostAddress
|
||||
end
|
||||
if ir <= Inet6Address then do
|
||||
say 'IPv6 :' ir.getHostAddress
|
||||
end
|
||||
end ir
|
||||
11
Task/DNS-query/Neko/dns-query-3.neko
Normal file
11
Task/DNS-query/Neko/dns-query-3.neko
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(define (dnsLookup site , ipv)
|
||||
;; captures current IPv mode
|
||||
(set 'ipv (net-ipv))
|
||||
;; IPv mode agnostic lookup
|
||||
(println "IPv4: " (begin (net-ipv 4) (net-lookup site)))
|
||||
(println "IPv6: " (begin (net-ipv 6) (net-lookup site)))
|
||||
;; returns newLISP to previous IPv mode
|
||||
(net-ipv ipv)
|
||||
)
|
||||
|
||||
(dnsLookup "www.kame.net")
|
||||
16
Task/DNS-query/Nim/dns-query.nim
Normal file
16
Task/DNS-query/Nim/dns-query.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import nativesockets
|
||||
|
||||
iterator items(ai: ptr AddrInfo): ptr AddrInfo =
|
||||
var current = ai
|
||||
while current != nil:
|
||||
yield current
|
||||
current = current.aiNext
|
||||
|
||||
proc main() =
|
||||
let addrInfos = getAddrInfo("www.kame.net", Port 80, AfUnspec)
|
||||
defer: freeAddrInfo addrInfos
|
||||
|
||||
for i in addrInfos:
|
||||
echo getAddrString i.aiAddr
|
||||
|
||||
when isMainModule: main()
|
||||
142
Task/DNS-query/Phix/dns-query.phix
Normal file
142
Task/DNS-query/Phix/dns-query.phix
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
include builtins\cffi.e
|
||||
|
||||
constant AF_UNSPEC = 0,
|
||||
-- AF_INET = 2,
|
||||
-- AF_INET6 = 23,
|
||||
-- SOCK_STREAM = 1,
|
||||
SOCK_DGRAM = 2,
|
||||
-- IPPROTO_TCP = 6,
|
||||
NI_MAXHOST = 1025,
|
||||
NI_NUMERICHOST = iff(platform()=LINUX?1:2)
|
||||
|
||||
constant tWAD = """
|
||||
typedef struct WSAData {
|
||||
WORD wVersion;
|
||||
WORD wHighVersion;
|
||||
char szDescription[257];
|
||||
char szSystemStatus[129];
|
||||
unsigned short iMaxSockets;
|
||||
unsigned short iMaxUdpDg;
|
||||
char *lpVendorInfo;
|
||||
} WSADATA, *LPWSADATA;
|
||||
""",
|
||||
tWAS = """
|
||||
int WSAStartup(
|
||||
_In_ WORD wVersionRequested,
|
||||
_Out_ LPWSADATA lpWSAData
|
||||
);
|
||||
""",
|
||||
tWAC = """
|
||||
int WSACleanup(void);
|
||||
""",
|
||||
tAI_W="""
|
||||
typedef struct addrinfo {
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
size_t ai_addrlen;
|
||||
char *ai_canonname;
|
||||
struct sockaddr *ai_addr;
|
||||
struct addrinfo *ai_next;
|
||||
} ADDRINFOA, *PADDRINFOA;
|
||||
""",
|
||||
tAI_L="""
|
||||
typedef struct addrinfo {
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
int ai_addrlen;
|
||||
struct sockaddr *ai_addr;
|
||||
char *ai_canonname;
|
||||
struct addrinfo *ai_next;
|
||||
};
|
||||
""",
|
||||
tGAI = """
|
||||
int getaddrinfo(
|
||||
_In_opt_ PCSTR pNodeName,
|
||||
_In_opt_ PCSTR pServiceName,
|
||||
_In_opt_ const ADDRINFOA *pHints,
|
||||
_Out_ PADDRINFOA *ppResult
|
||||
);
|
||||
""",
|
||||
--int getaddrinfo(const char *node, const char *service,
|
||||
-- const struct addrinfo *hints,
|
||||
-- struct addrinfo **res);
|
||||
tGNI = """
|
||||
int getnameinfo(
|
||||
_In_ sockaddr *sa,
|
||||
_In_ int salen,
|
||||
_Out_ char *host,
|
||||
_In_ DWORD hostlen,
|
||||
_Out_ char *serv,
|
||||
_In_ DWORD servlen,
|
||||
_In_ int flags
|
||||
);
|
||||
""",
|
||||
--int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
|
||||
-- char *host, socklen_t hostlen,
|
||||
-- char *serv, socklen_t servlen, int flags);
|
||||
tFAI = """
|
||||
void freeaddrinfo(
|
||||
_In_ struct addrinfo *ai
|
||||
);
|
||||
"""
|
||||
--void freeaddrinfo(struct addrinfo *res);
|
||||
|
||||
integer xgetaddrinfo = NULL, xgetnameinfo, xfreeaddrinfo, idAI,
|
||||
xwsastartup, xwsacleanup, error
|
||||
|
||||
function get_name_info(string fqdn)
|
||||
if xgetaddrinfo=NULL then
|
||||
atom lib
|
||||
if platform()=WINDOWS then
|
||||
integer idWAD = define_struct(tWAD)
|
||||
atom pWAD = allocate_struct(idWAD,cleanup:=true)
|
||||
lib = open_dll("Ws2_32.dll")
|
||||
xwsastartup = define_cffi_func(lib,tWAS)
|
||||
xwsacleanup = define_cffi_func(lib,tWAC)
|
||||
error = c_func(xwsastartup,{#00020002,pWAD})
|
||||
if error then ?9/0 end if
|
||||
idAI = define_struct(tAI_W)
|
||||
elsif platform()=LINUX then
|
||||
lib = open_dll("libc.so.6")
|
||||
idAI = define_struct(tAI_L)
|
||||
end if
|
||||
xgetaddrinfo = define_cffi_func(lib,tGAI)
|
||||
xgetnameinfo = define_cffi_func(lib,tGNI)
|
||||
xfreeaddrinfo = define_cffi_proc(lib,tFAI)
|
||||
end if
|
||||
atom hints = allocate_struct(idAI,cleanup:=true),
|
||||
res = allocate(machine_word(),cleanup:=true),
|
||||
host = allocate(NI_MAXHOST,cleanup:=true)
|
||||
set_struct_field(idAI,hints,"ai_family",AF_UNSPEC)
|
||||
-- set_struct_field(idAI,hints,"ai_socktype",SOCK_STREAM)
|
||||
set_struct_field(idAI,hints,"ai_socktype",SOCK_DGRAM)
|
||||
error = c_func(xgetaddrinfo,{fqdn,NULL,hints,res})
|
||||
if error then ?9/0 end if
|
||||
res = peekNS(res,machine_word(),false)
|
||||
atom ptr = res
|
||||
sequence results = {}
|
||||
while ptr!=NULL do
|
||||
atom addr = get_struct_field(idAI,ptr,"ai_addr")
|
||||
integer len = get_struct_field(idAI,ptr,"ai_addrlen")
|
||||
error = c_func(xgetnameinfo,{addr, len, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST})
|
||||
if error then ?9/0 end if
|
||||
results = append(results,peek_string(host))
|
||||
ptr = get_struct_field(idAI,ptr,"ai_next")
|
||||
end while
|
||||
c_proc(xfreeaddrinfo,{res})
|
||||
return results
|
||||
end function
|
||||
|
||||
procedure WSACleanup()
|
||||
if platform()=WINDOWS then
|
||||
error = c_func(xwsacleanup,{})
|
||||
if error then crash("WSACleanup failed: %d\n",{error}) end if
|
||||
end if
|
||||
end procedure
|
||||
|
||||
?get_name_info("www.kame.net")
|
||||
WSACleanup()
|
||||
|
|
@ -1,8 +1,3 @@
|
|||
import java.net.{Inet4Address, Inet6Address, InetAddress}
|
||||
import java.net._
|
||||
|
||||
object DnsQuery extends App {
|
||||
InetAddress.getAllByName("google.com").foreach {
|
||||
case x: Inet4Address => println(s"IPv4 : ${x.getHostAddress}")
|
||||
case x: Inet6Address => println(s"IPv6 : ${x.getHostAddress}")
|
||||
}
|
||||
}
|
||||
InetAddress.getAllByName("www.kame.net").foreach(x => println(x.getHostAddress))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue