Tue Apr 29 16:53:56 CEST 2003 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / Mono.Posix / Mono.Posix / Syscall.cs
1 //
2 // Mono.Posix.Syscall.cs: System calls to Posix subsystem features
3 //
4
5 using System;
6 using System.Text;
7 using System.Runtime.InteropServices;
8
9 namespace Mono.Posix {
10
11         public class Syscall {
12                 [DllImport ("libc", EntryPoint="gethostname")]
13                 static extern int syscall_gethostname (byte[] p, int len);
14
15                 public static string GetHostName ()
16                 {
17                         byte [] buf = new byte [256];
18                         int res = syscall_gethostname (buf, buf.Length);
19                         if (res == -1)
20                                 return "localhost";
21                         for (res = 0; res < buf.Length; ++res) {
22                                 if (buf [res] == 0)
23                                         break;
24                         }
25                                 
26                         return Encoding.UTF8.GetString (buf, 0, res);
27                 }
28         }
29 }