PreviousUpNext

15.4.1205  src/lib/std/src/socket/net-protocol-db.pkg

## net-protocol-db.pkg

# Compiled by:
#     src/lib/std/src/standard-core.sublib

stipulate
    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
    #
    fun cfun  fun_name
        =
        ci::find_c_function'' { lib_name => "socket", fun_name };
herein

    package   net_protocol_db
    : (weak)  Net_Protocol_Db                                           # Net_Protocol_Db                       is from   src/lib/std/src/socket/net-protocol-db.api
    {
        Entry = ENTRY { name:       String,
                        aliases:    List( String ),
                        protocol:   Int
                      };

        Protoent = (String, List(String), Int);

        stipulate
            fun conc field' (ENTRY a)
                =
                field' a;
        herein

            name     = conc .name;
            aliases  = conc .aliases;
            protocol = conc .protocol;

        end;

        (cfun "get_protocol_by_name")
            ->
            (      get_prot_by_name__syscall:      String -> Null_Or( Protoent ),                               # "get_protocol_by_name"                def in   src/c/lib/socket/get-protocol-by-name.c
                   get_prot_by_name__ref,
              set__get_prot_by_name__ref
            );

        (cfun "get_protocol_by_number")
            ->
            (      get_prot_by_number__syscall:    Int   -> Null_Or( Protoent ),                                # "get_protocol_by_number"              def in   src/c/lib/socket/get-protocol-by-number.c
                   get_prot_by_number__ref,
              set__get_prot_by_number__ref
            );

        # Protocol DB query functions 
        #
        stipulate
            #
            fun get (THE (name, aliases, protocol))
                    =>
                    THE (ENTRY { name, aliases, protocol } );

                get NULL =>   NULL;
            end;

        herein
            fun get_by_name    name   =   get (*get_prot_by_name__ref    name  );
            fun get_by_number  number =   get (*get_prot_by_number__ref  number);
        end;

    };
end;


## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext