## dns-host-lookup.pkg
# Compiled by:
#
src/lib/std/src/standard-core.sublibstipulate
package ci = mythryl_callable_c_library_interface; # mythryl_callable_c_library_interface is from
src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkg package hug = host_unt_guts; # host_unt_guts is from
src/lib/std/src/bind-sysword-32.pkg package ns = number_string; # number_string is from
src/lib/std/src/number-string.pkg package ps = proto_socket__premicrothread; # proto_socket__premicrothread is from
src/lib/std/src/socket/proto-socket--premicrothread.pkg package u1b = one_byte_unt_guts; # one_byte_unt_guts is from
src/lib/std/src/one-byte-unt-guts.pkg package vu1 = vector_of_one_byte_unts; # vector_of_one_byte_unts is from
src/lib/std/src/vector-of-one-byte-unts.pkg #
fun cfun fun_name
=
ci::find_c_function'' { lib_name => "socket", fun_name };
herein
package dns_host_lookupinternal
:
api {
# export extra element for internal use by Basis implementation
include api Dns_Host_Lookup; # Dns_Host_Lookup is from
src/lib/std/src/socket/dns-host-lookup.api internet_address: ps::Internet_Address -> Internet_Address;
un_internet_address: Internet_Address -> ps::Internet_Address;
}
where Address_Family == ps::af::Address_Family
=
package {
Internet_Address = IPV4_ADDRESS ps::Internet_Address;
Address_Family = ps::af::Address_Family;
internet_address = IPV4_ADDRESS;
fun un_internet_address (IPV4_ADDRESS a)
=
a;
Entry = HOSTENT {
name: String,
aliases: List( String ),
address_type: Address_Family,
addresses: List( Internet_Address )
};
stipulate
fun conc field' (HOSTENT a)
=
field' a;
herein
name = conc .name;
aliases = conc .aliases;
address_type = conc .address_type;
addresses = conc .addresses;
address = list::head o addresses;
end;
Hostent = (String, List(String), ps::Raw_Address_Family, List(ps::Internet_Address));
(cfun "get_host_by_name") # "get_host_by_name" def in src/c/lib/socket/get-host-by-name.c
->
( get_host_by_name__syscall: String -> Null_Or( Hostent ),
get_host_by_name__ref,
set__get_host_by_name__ref
);
(cfun "get_host_by_address") # "get_host_by_address" def in src/c/lib/socket/get-host-by-address.c
->
( get_host_by_addr__syscall: ps::Internet_Address -> Null_Or( Hostent ),
get_host_by_addr__ref,
set__get_host_by_addr__ref
);
# Host DB query functions
#
stipulate
#
fun get_host_typechecked_package (THE (name, aliases, address_type, addresses))
=>
THE (
HOSTENT
{ name,
aliases,
address_type => ps::af::ADDRESS_FAMILY address_type,
addresses => list::map IPV4_ADDRESS addresses
}
);
get_host_typechecked_package NULL
=>
NULL;
end;
herein
fun get_by_name name
=
get_host_typechecked_package (*get_host_by_name__ref name);
fun get_by_address (IPV4_ADDRESS address)
=
get_host_typechecked_package (*get_host_by_addr__ref address);
end;
fun scan getc stream
=
{ fun w2b w
=
u1b::from_large_unt (hug::to_large_unt w);
fun get_b (w, shft)
=
hug::bitwise_and (hug::(>>) (w, shft), 0uxFF);
fun mk_addr (a, b, c, d)
=
IPV4_ADDRESS (vu1::from_list
[
w2b a, w2b b, w2b c, w2b d
]
);
case (ps::to_unts getc stream)
#
THE ([a, b, c, d], stream)
=>
THE (mk_addr (a, b, c, d), stream);
THE ([a, b, c], stream)
=>
THE (mk_addr (a, b, get_b (c, 0u8), get_b (c, 0u0)), stream);
THE ([a, b], stream)
=>
THE (mk_addr (a, get_b (b, 0u16), get_b (b, 0u8), get_b (b, 0u0)), stream);
THE ([a], stream)
=>
THE (mk_addr (get_b (a, 0u24), get_b (a, 0u16), get_b (a, 0u8), get_b (a, 0u0)), stream);
_ => NULL;
esac;
};
from_string = ns::scan_string scan;
fun to_string (IPV4_ADDRESS address)
=
ps::from_bytes ( get 0,
get 1,
get 2,
get 3
)
where
fun get i
=
vu1::get (address, i);
end;
(cfun "get_host_name") # "get_host_name" def in src/c/lib/socket/get-host-name.c
->
( get_host_name__syscall: Void -> String,
get_host_name__ref,
set__get_host_name__ref
);
fun get_host_name ()
=
*get_host_name__ref ();
};
# Restrict to Dns_Host_Lookup:
#
package dns_host_lookup: (weak) Dns_Host_Lookup # Dns_Host_Lookup is from
src/lib/std/src/socket/dns-host-lookup.api = dns_host_lookupinternal; # dns_host_lookupinternal is from
src/lib/std/src/socket/dns-host-lookup.pkgend;