mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 04:43:53 +00:00
extras/curs/curs.m:
extras/curs/curs.panel.m:
Make panel a separate submodule of curs, not a nested submodule.
extras/base64/base64.m:
extras/curses/mcurses.basics.m:
extras/curses/mcurses.m:
extras/curses/mcurses.misc.m:
extras/curses/mcurses.user.m:
extras/gator/evolve.m:
extras/gator/genotype.m:
extras/gator/phenotype.m:
extras/gator/tausworthe3.m:
extras/monte/dots.m:
extras/monte/geom.m:
extras/monte/hg.m:
extras/monte/monte.m:
extras/monte/rnd.m:
extras/moose/grammar.m:
extras/moose/moose.m:
extras/mopenssl/mopenssl.m:
extras/net/echo.m:
extras/net/errno.m:
extras/net/getaddrinfo.m:
extras/net/net.m:
extras/net/netdb.m:
extras/net/sockets.m:
extras/net/streams.m:
extras/net/tcp.m:
extras/net/test_lookups.m:
extras/net/types.m:
extras/odbc/odbc.m:
extras/odbc/odbc_test.m:
extras/references/README:
extras/references/reference.m:
extras/references/scoped_update.m:
extras/solver_types/library/any.m:
extras/solver_types/library/any_array.m:
extras/solver_types/library/any_assoc_list.m:
extras/solver_types/library/any_list.m:
extras/solver_types/library/any_map.m:
extras/solver_types/library/any_tree234.m:
extras/solver_types/library/any_util.m:
extras/trail/trail.m:
extras/trailed_update/samples/interpreter.m:
extras/trailed_update/samples/vqueens.m:
extras/trailed_update/tests/var_test.m:
extras/trailed_update/tr_array.m:
extras/trailed_update/tr_store.m:
extras/trailed_update/trailed_update.m:
extras/trailed_update/unsafe.m:
extras/trailed_update/var.m:
Bring programming style up to date.
77 lines
2.5 KiB
Mathematica
77 lines
2.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module test_lookups.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module maybe.
|
|
:- import_module string.
|
|
|
|
:- import_module net.
|
|
:- import_module net.netdb.
|
|
:- import_module net.types.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
TCPS = "tcp",
|
|
getprotobyname(TCPS, TCP, !IO),
|
|
io.format("get_proto_by_name(""%s"", %s, !IO).\n",
|
|
[s(TCPS), s(string(TCP))], !IO),
|
|
|
|
io.format("in_addr_any: %s\n", [s(to_string(in_addr_any))], !IO),
|
|
io.format("in_addr_loopback: %s\n", [s(to_string(in_addr_loopback))], !IO),
|
|
io.format("in_addr_broadcast: %s\n", [s(to_string(in_addr_broadcast))],
|
|
!IO),
|
|
io.format("in6_addr_any: %s\n", [s(to_string(in6_addr_any))], !IO),
|
|
io.format("in6_addr_loopback: %s\n", [s(to_string(in6_addr_loopback))],
|
|
!IO),
|
|
|
|
lookup_host_and_service("www.google.com", string_service("http"),
|
|
no, no, GAIResultHostService),
|
|
(
|
|
GAIResultHostService = ok(HostServiceResults),
|
|
io.write_string("www.google.com:\n", !IO),
|
|
foldl(write_lookup_result, HostServiceResults, !IO)
|
|
;
|
|
GAIResultHostService = error(ErrorA),
|
|
io.format("Lookup error for www.google.com: %s", [s(ErrorA)], !IO)
|
|
),
|
|
lookup_local_socket(string_service("http"), yes(fam_inet),
|
|
yes(sock_stream), ResultLocalSocket),
|
|
(
|
|
ResultLocalSocket = ok(LocalSockets),
|
|
io.write_string("local sockets:\n", !IO),
|
|
foldl(write_lookup_result, LocalSockets, !IO)
|
|
;
|
|
ResultLocalSocket = error(ErrorB),
|
|
io.format("Lookup error for local sockets: %s", [s(ErrorB)], !IO)
|
|
).
|
|
|
|
:- pred write_lookup_result(lookup_result::in,
|
|
io::di, io::uo) is det.
|
|
|
|
write_lookup_result(lookup_result(Family, Socktype, ProtoNum, SockAddr),
|
|
!IO) :-
|
|
io.format("Family: %s, Socktype: %s, Protocol: %s, Addr: %s\n",
|
|
[s(string(Family)), s(string(Socktype)), s(ProtoName),
|
|
s(SockStr)],
|
|
!IO),
|
|
ProtoName = string(ProtoNum),
|
|
( if sockaddr_get_addr_port(SockAddr, Addr, Port) then
|
|
SockStr = format("%s:%d", [s(to_string(Addr)), i(Port)])
|
|
else
|
|
SockStr = "unknown"
|
|
).
|