<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>gethostname</TITLE
|
>gethostname</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="TCP/IP Library Reference"
|
TITLE="TCP/IP Library Reference"
|
HREF="tcpip-library-reference.html"><LINK
|
HREF="tcpip-library-reference.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="byteorder"
|
TITLE="byteorder"
|
HREF="net-common-tcpip-manpages-byteorder.html"></HEAD
|
HREF="net-common-tcpip-manpages-byteorder.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 38. TCP/IP Library Reference</TD
|
>Chapter 38. TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-byteorder.html"
|
HREF="net-common-tcpip-manpages-byteorder.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="NET-COMMON-TCPIP-MANPAGES-GETHOSTNAME">gethostname</H1
|
NAME="NET-COMMON-TCPIP-MANPAGES-GETHOSTNAME">gethostname</H1
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>GETHOSTNAME(3) System Library Functions Manual GETHOSTNAME(3)
|
>GETHOSTNAME(3) System Library Functions Manual GETHOSTNAME(3)
|
|
|
NAME
|
NAME
|
gethostname, sethostname - get/set name of current host
|
gethostname, sethostname - get/set name of current host
|
|
|
SYNOPSIS
|
SYNOPSIS
|
#include <unistd.h>
|
#include <unistd.h>
|
|
|
int
|
int
|
gethostname(char *name, size_t namelen);
|
gethostname(char *name, size_t namelen);
|
|
|
int
|
int
|
sethostname(const char *name, size_t namelen);
|
sethostname(const char *name, size_t namelen);
|
|
|
DESCRIPTION
|
DESCRIPTION
|
The gethostname() function returns the standard host name for the current
|
The gethostname() function returns the standard host name for the current
|
processor, as previously set by sethostname(). The parameter namelen
|
processor, as previously set by sethostname(). The parameter namelen
|
specifies the size of the name array. If insufficient space is provided,
|
specifies the size of the name array. If insufficient space is provided,
|
the returned name is truncated. The returned name is always null termi-
|
the returned name is truncated. The returned name is always null termi-
|
nated.
|
nated.
|
|
|
sethostname() sets the name of the host machine to be name, which has
|
sethostname() sets the name of the host machine to be name, which has
|
length namelen. This call is restricted to the superuser and is normally
|
length namelen. This call is restricted to the superuser and is normally
|
used only when the system is bootstrapped.
|
used only when the system is bootstrapped.
|
|
|
RETURN VALUES
|
RETURN VALUES
|
If the call succeeds a value of 0 is returned. If the call fails, a
|
If the call succeeds a value of 0 is returned. If the call fails, a
|
value of -1 is returned and an error code is placed in the global vari-
|
value of -1 is returned and an error code is placed in the global vari-
|
able errno.
|
able errno.
|
|
|
ERRORS
|
ERRORS
|
The following errors may be returned by these calls:
|
The following errors may be returned by these calls:
|
|
|
[EFAULT] The name or namelen parameter gave an invalid address.
|
[EFAULT] The name or namelen parameter gave an invalid address.
|
|
|
[EPERM] The caller tried to set the hostname and was not the
|
[EPERM] The caller tried to set the hostname and was not the
|
superuser.
|
superuser.
|
|
|
SEE ALSO
|
SEE ALSO
|
hostname(1), getdomainname(3), gethostid(3), sysctl(3), sysctl(8), yp(8)
|
hostname(1), getdomainname(3), gethostid(3), sysctl(3), sysctl(8), yp(8)
|
|
|
STANDARDS
|
STANDARDS
|
The gethostname() function call conforms to X/Open Portability Guide
|
The gethostname() function call conforms to X/Open Portability Guide
|
Issue 4.2 (``XPG4.2'').
|
Issue 4.2 (``XPG4.2'').
|
|
|
HISTORY
|
HISTORY
|
The gethostname() function call appeared in 4.2BSD.
|
The gethostname() function call appeared in 4.2BSD.
|
|
|
BUGS
|
BUGS
|
Host names are limited to MAXHOSTNAMELEN (from <sys/param.h>) characters,
|
Host names are limited to MAXHOSTNAMELEN (from <sys/param.h>) characters,
|
currently 256. This includes the terminating NUL character.
|
currently 256. This includes the terminating NUL character.
|
|
|
If the buffer passed to gethostname() is smaller than MAXHOSTNAMELEN,
|
If the buffer passed to gethostname() is smaller than MAXHOSTNAMELEN,
|
other operating systems may not guarantee termination with NUL.
|
other operating systems may not guarantee termination with NUL.
|
|
|
BSD June 4, 1993 BSD
|
BSD June 4, 1993 BSD
|
</PRE
|
</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="net-common-tcpip-manpages-byteorder.html"
|
HREF="net-common-tcpip-manpages-byteorder.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>TCP/IP Library Reference</TD
|
>TCP/IP Library Reference</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="tcpip-library-reference.html"
|
HREF="tcpip-library-reference.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>byteorder</TD
|
>byteorder</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|