GETHOSTNAME(3P)

πŸ’– PROLOG πŸ’–

okay so first things first bestie β€” this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the actual Linux behavior), or the interface may not be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

gethostname β€” get name of current host πŸ–₯️


🌸 SYNOPSIS 🌸

#include <unistd.h>

int gethostname(char *name, size_t namelen);

πŸ’… DESCRIPTION πŸ’…

so the gethostname() function shall return the standard host name for the current machine. like… who am I? what's my name? main character energy fr fr. πŸŽ€

the namelen argument shall specify the size of the array pointed to by the name argument. size matters, ok.

the returned name shall be null-terminated β€” EXCEPT (and here's the plot twist 😭) if namelen is an insufficient length to hold the host name, then the returned name shall be truncated, and it is unspecified whether the returned name is null-terminated. unspecified means nobody is promising you anything, it's giving pure chaos, no cap.

host names are limited to {HOST_NAME_MAX} bytes. that's the ceiling, bestie.


πŸ”₯ RETURN VALUE πŸ”₯

upon successful completion, 0 shall be returned. otherwise, -1 shall be returned. that's the whole vibe check, nothing more. πŸ’€


πŸ’€ ERRORS πŸ’€

no errors are defined. literally none. flawless, honestly.

the following sections are informative.


πŸŽ€ EXAMPLES πŸŽ€

none.


πŸ¦‹ APPLICATION USAGE πŸ¦‹

none.


⭐ RATIONALE ⭐

none.


🌈 FUTURE DIRECTIONS 🌈

none.


πŸ‘‘ SEE ALSO πŸ‘‘

  • gethostid(), uname()
  • The Base Definitions volume of POSIX.1‐2017, <unistd.h>

portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document β€” yes, it's the final boss, it wins, periodt. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's a wrap 🫢 this one came to you from IEEE/The Open Group, dated 2017, and it's the one and only GETHOSTNAME(3P) ✨ bye bestie, go get that host name πŸ’–

πŸ“¦ where this page comes from