1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <fail.h>
|
1997-05-13 08:46:49 -07:00
|
|
|
#include <signals.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#include "unixsupport.h"
|
1995-05-08 08:18:32 -07:00
|
|
|
|
|
|
|
#ifdef HAS_SOCKETS
|
|
|
|
|
|
|
|
#include "socketaddr.h"
|
1996-09-04 07:15:31 -07:00
|
|
|
#ifndef _WIN32
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <netdb.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#endif
|
1995-05-08 08:18:32 -07:00
|
|
|
|
|
|
|
static int entry_h_length;
|
|
|
|
|
|
|
|
extern int socket_domain_table[];
|
|
|
|
|
|
|
|
static value alloc_one_addr(a)
|
|
|
|
char * a;
|
|
|
|
{
|
|
|
|
bcopy(a, &sock_addr.s_inet.sin_addr, entry_h_length);
|
|
|
|
return alloc_inet_addr(sock_addr.s_inet.sin_addr.s_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static value alloc_host_entry(entry)
|
|
|
|
struct hostent * entry;
|
|
|
|
{
|
|
|
|
value res;
|
1997-05-26 10:16:31 -07:00
|
|
|
value name = Val_unit, aliases = Val_unit;
|
|
|
|
value addr_list = Val_unit, addr = Val_unit;
|
1995-05-08 08:18:32 -07:00
|
|
|
|
1997-05-26 10:16:31 -07:00
|
|
|
Begin_roots4 (name, aliases, addr_list, addr);
|
|
|
|
name = copy_string(entry->h_name);
|
|
|
|
aliases = copy_string_array(entry->h_aliases);
|
|
|
|
entry_h_length = entry->h_length;
|
1995-05-08 08:18:32 -07:00
|
|
|
#ifdef h_addr
|
1997-05-26 10:16:31 -07:00
|
|
|
addr_list = alloc_array(alloc_one_addr, entry->h_addr_list);
|
1995-05-08 08:18:32 -07:00
|
|
|
#else
|
1997-05-26 10:16:31 -07:00
|
|
|
addr = alloc_one_addr(entry->h_addr);
|
|
|
|
addr_list = alloc_tuple(1);
|
|
|
|
Field(addr_list, 0) = addr;
|
1995-05-08 08:18:32 -07:00
|
|
|
#endif
|
1997-05-26 10:16:31 -07:00
|
|
|
res = alloc_tuple(4);
|
|
|
|
Field(res, 0) = name;
|
|
|
|
Field(res, 1) = aliases;
|
|
|
|
Field(res, 2) = entry->h_addrtype == PF_UNIX ? Val_int(0) : Val_int(1);
|
|
|
|
Field(res, 3) = addr_list;
|
|
|
|
End_roots();
|
1995-05-08 08:18:32 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
value unix_gethostbyaddr(a) /* ML */
|
|
|
|
value a;
|
|
|
|
{
|
1996-04-01 07:26:38 -08:00
|
|
|
uint32 addr;
|
1995-05-08 08:18:32 -07:00
|
|
|
struct hostent * entry;
|
1996-04-01 07:26:38 -08:00
|
|
|
addr = GET_INET_ADDR(a);
|
|
|
|
enter_blocking_section();
|
|
|
|
entry = gethostbyaddr((char *) &addr, 4, AF_INET);
|
|
|
|
leave_blocking_section();
|
1995-06-18 07:59:32 -07:00
|
|
|
if (entry == (struct hostent *) NULL) raise_not_found();
|
1995-05-08 08:18:32 -07:00
|
|
|
return alloc_host_entry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
value unix_gethostbyname(name) /* ML */
|
|
|
|
value name;
|
|
|
|
{
|
1996-04-01 07:26:38 -08:00
|
|
|
char hostname[256];
|
1995-05-08 08:18:32 -07:00
|
|
|
struct hostent * entry;
|
1996-04-01 07:26:38 -08:00
|
|
|
strncpy(hostname, String_val(name), sizeof(hostname) - 1);
|
|
|
|
hostname[sizeof(hostname) - 1] = 0;
|
|
|
|
enter_blocking_section();
|
|
|
|
entry = gethostbyname(hostname);
|
|
|
|
leave_blocking_section();
|
1995-06-18 07:59:32 -07:00
|
|
|
if (entry == (struct hostent *) NULL) raise_not_found();
|
1995-05-08 08:18:32 -07:00
|
|
|
return alloc_host_entry(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
value unix_gethostbyaddr()
|
|
|
|
{ invalid_argument("gethostbyaddr not implemented"); }
|
|
|
|
|
|
|
|
value unix_gethostbyname()
|
|
|
|
{ invalid_argument("gethostbyname not implemented"); }
|
|
|
|
|
|
|
|
#endif
|