Esempio n. 1
0
Val   _lib7_netdb_get_host_by_name   (Task* task,  Val arg)   {
    //============================
    //
    // Mythryl type:   String -> Null_Or(   (String, List(String), Raw_Address_Family, List( Internet_Address ))   )
    //
    // This fn gets bound as   get_host_by_name'   in:
    //
    //     src/lib/std/src/socket/dns-host-lookup.pkg

													ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_netdb_get_host_by_name");

    char* heap_name = HEAP_STRING_AS_C_STRING( arg );							// Last use of 'arg'.

    struct hostent* result;

    // We cannot reference anything on the Mythryl
    // heap between RELEASE_MYTHRYL_HEAP and RECOVER_MYTHRYL_HEAP
    // because garbage collection might be moving
    // it around, so copy heap_path into C storage: 
    //
    Mythryl_Heap_Value_Buffer  name_buf;
    //
    {	char* c_name
	    = 
	    buffer_mythryl_heap_value( &name_buf, (void*) heap_name, strlen( heap_name ) +1 );		// '+1' for terminal NUL on string.


	RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_netdb_get_host_by_name", NULL );
	    //
	    result = gethostbyname( c_name );
	    //
	RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_netdb_get_host_by_name" );

	unbuffer_mythryl_heap_value( &name_buf );
    }

    return  _util_NetDB_mkhostent (task, result);							// _util_NetDB_mkhostent	def in    src/c/lib/socket/util-mkhostent.c
}
Esempio n. 2
0
Val   _lib7_netdb_get_host_by_address   (Task* task,  Val arg)   {
    //===============================
    //
    // Mythryl type:   Internet_Address -> Null_Or(  (String, List(String), Raw_Address_Family, List(Internet_Address))  )
    //
    // This fn gets bound as   get_host_by_addr'   in:
    //
    //     src/lib/std/src/socket/dns-host-lookup.pkg

															ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_netdb_get_host_by_address");

    ASSERT (sizeof(struct in_addr) == GET_VECTOR_LENGTH( arg ));

    struct in_addr*  heap_arg =  (struct in_addr*) HEAP_STRING_AS_C_STRING( arg );					// Last use of 'arg'.
    struct in_addr      c_arg = *heap_arg;

    RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_netdb_get_host_by_address", NULL );
	//
	struct hostent* result = gethostbyaddr (&c_arg, sizeof(struct in_addr), AF_INET);
	//
    RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_netdb_get_host_by_address" );

    return  _util_NetDB_mkhostent ( task, result );									// _util_NetDB_mkhostent	def in    src/c/lib/socket/util-mkhostent.c
}
Esempio n. 3
0
/* _ml_NetDB_gethostbyname
 *     : string -> (string * string list * addr_family * addr list) option
 */
ml_val_t _ml_NetDB_gethostbyname (ml_state_t *msp, ml_val_t arg)
{
    return _util_NetDB_mkhostent (msp, gethostbyname (STR_MLtoC(arg)));

} /* end of _ml_NetDB_gethostbyname */