OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [java/] [net/] [natVMInetAddressWin32.cc] - Blame information for rev 766

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 758 jeremybenn
/* Copyright (C) 2003, 2006 Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
#include <config.h>
10
#include <platform.h>
11
 
12
#undef STRICT
13
 
14
#include <java/net/VMInetAddress.h>
15
#include <java/net/UnknownHostException.h>
16
 
17
jstring
18
java::net::VMInetAddress::getLocalHostname ()
19
{
20
  char buffer[400];
21
  if (gethostname (buffer, sizeof(buffer)))
22
    return NULL;
23
  // It is admittedly non-optimal to convert the hostname to Unicode
24
  // only to convert it back in getByName, but simplicity wins.
25
  return JvNewStringUTF (buffer);
26
}
27
 
28
jbyteArray
29
java::net::VMInetAddress::lookupInaddrAny ()
30
{
31
  unsigned long laddr = INADDR_ANY;
32
  char *bytes = (char *) &laddr;
33
  int blen = sizeof (laddr);
34
  jbyteArray result = JvNewByteArray (blen);
35
  memcpy (elements (result), bytes, blen);
36
  return result;
37
}
38
 
39
jstring
40
java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
41
{
42
  struct hostent *hptr = NULL;
43
  char *bytes = (char*) elements (addr);
44
  int len = addr->length;
45
  int type;
46
  char *val;
47
  if (len == 4)
48
    {
49
      val = bytes;
50
      type = AF_INET;
51
    }
52
#ifdef HAVE_INET6
53
  else if (len == 16)
54
    {
55
      val = (char *) &bytes;
56
      type = AF_INET6;
57
    }
58
#endif /* HAVE_INET6 */
59
  else
60
    JvFail ("unrecognized size");
61
 
62
  // FIXME: this is insufficient if some other piece of code calls
63
  // this gethostbyaddr.
64
  JvSynchronize sync (&java::net::VMInetAddress::class$);
65
  hptr = gethostbyaddr (val, len, type);
66
 
67
  if (hptr == NULL)
68
    throw new java::net::UnknownHostException ();
69
 
70
  return JvNewStringUTF (hptr->h_name);
71
}
72
 
73
JArray<jbyteArray> *
74
java::net::VMInetAddress::getHostByName (jstring host)
75
{
76
  struct hostent *hptr = NULL;
77
  JV_TEMP_UTF_STRING (hostname, host);
78
 
79
  // FIXME: this is insufficient if some other piece of code calls
80
  // this gethostbyname.
81
  JvSynchronize sync (&java::net::VMInetAddress::class$);
82
  hptr = gethostbyname (hostname);
83
 
84
  if (hptr == NULL)
85
    throw new java::net::UnknownHostException (host);
86
 
87
  int count = 0;
88
  char ** ptr = hptr->h_addr_list;
89
  while (*ptr++)  count++;
90
 
91
  JArray<jbyteArray> *result =
92
    (JArray<jbyteArray> *) _Jv_NewObjectArray (
93
      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
94
  jbyteArray* addrs = elements (result);
95
 
96
  for (int i = 0; i < count; i++)
97
    {
98
      addrs[i] = JvNewByteArray (hptr->h_length);
99
      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
100
    }
101
  return result;
102
}
103
 
104
jbyteArray
105
java::net::VMInetAddress::aton (jstring host)
106
{
107
  JV_TEMP_UTF_STRING (hostname, host);
108
  char* bytes = NULL;
109
  int blen = 0;
110
  unsigned long laddr = inet_addr (hostname);
111
  if (laddr != INADDR_NONE)
112
    {
113
      bytes = (char *) &laddr;
114
      blen = 4;
115
    }
116
  if (blen == 0)
117
    return NULL;
118
  jbyteArray result = JvNewByteArray (blen);
119
  memcpy (elements (result), bytes, blen);
120
  return result;
121
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.