Hostname: Difference between revisions

Content added Content deleted
(added haskell, not tested)
Line 27: Line 27:
{{works with|gcc|4.0.1}}
{{works with|gcc|4.0.1}}
{{works with|POSIX|.1}}
{{works with|POSIX|.1}}
#include <limits.h>
<c>#include <limits.h>
#include <unistd.h>
#include <unistd.h>

int main()
int main()
{
{
char name[_POSIX_HOST_NAME_MAX+1];
char name[_POSIX_HOST_NAME_MAX+1];
gethostname(name, _POSIX_HOST_NAME_MAX+1);
gethostname(name, _POSIX_HOST_NAME_MAX+1);
return 0;
}
}</c>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
System.Net.Dns.GetHostName();
<csharp>System.Net.Dns.GetHostName();</csharp>


=={{header|Factor}}==
=={{header|Factor}}==
host-name
host-name

=={{header|Haskell}}==
{{libheader|network}}
import Network.BSD
main = do hostName <- getHostName
putStrLn hostName


=={{header|IDL}}==
=={{header|IDL}}==
Line 47: Line 54:
=={{header|Java}}==
=={{header|Java}}==


String hostname = java.net.InetAddress.getLocalHost().getHostName();
<java>String hostname = java.net.InetAddress.getLocalHost().getHostName();</java>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 55: Line 62:
{{works with|Perl|5.8.6}}
{{works with|Perl|5.8.6}}
{{libheader|Sys::Hostname}}
{{libheader|Sys::Hostname}}
use Sys::Hostname;
<perl>use Sys::Hostname;

$name = hostname;
$name = hostname;</perl>


=={{header|PHP}}==
=={{header|PHP}}==
echo $_SERVER['HTTP_HOST'];
<php>echo $_SERVER['HTTP_HOST'];</php>


=={{header|Pop11}}==
=={{header|Pop11}}==
Line 67: Line 74:
=={{header|Python}}==
=={{header|Python}}==
{{works with|Python|2.5}}
{{works with|Python|2.5}}
import socket
<python>import socket
host = socket.gethostname()
host = socket.gethostname()</python>


=={{header|Tcl}}==
=={{header|Tcl}}==