getdomainname(2)
๐ getdomainname(2) โ the Linux Programmer's Manual, bestie edition ๐
okay so this is a page from the Linux programmer's manual, section 2 (that's the system calls girlies ๐ ). Sit down, grab a strawberry matcha, we're learning about NIS domain names.
โจ NAME โจ
getdomainname, setdomainname โ the get/set duo for your NIS domain name ๐
๐ LIBRARY ๐
Standard C library (that's libc, link with -lc) ๐ซถ
๐ธ SYNOPSIS ๐ธ
#include <unistd.h>
int getdomainname(size_t size;
char name[size], size_t size);
int setdomainname(size_t size;
const char name[size], size_t size);
๐ง Feature Test Macro Requirements for glibc (peep feature_test_macros(7) for the deets)
getdomainname(),setdomainname():- Since glibc 2.21:
_DEFAULT_SOURCE
- In glibc 2.19 and 2.20:
_DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
- Up to and including glibc 2.19:
_BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
- Since glibc 2.21:
๐ซ DESCRIPTION ๐ซ
So these two functions let you access or change the NIS domain name of the host system. And like, more precisely (because precision is the vibe โจ), they work on the NIS domain name that's tied to the calling process's UTS namespace. iykyk.
setdomainname() sets the domain name to whatever value you put in the character array name. The size argument is how many bytes are in name. And listen โ because of that, name does not need a terminating null byte. it's giving raw bytes and honestly? iconic.
getdomainname() returns the null-terminated domain name in the character array name, which is size bytes big. Now here's the plot twist ๐ญ: if the null-terminated domain name needs more than len bytes, getdomainname() returns the first len bytes (that's glibc for you) or gives an error (that's libc). Bestie, why the discrepancy? nobody knows, that's just how it is.
๐ RETURN VALUE ๐
- On success ๐: zero is returned.
- On error ๐ญ:
-1is returned, anderrnois set to tell you what went wrong.
๐ ERRORS ๐
setdomainname() can fail with these:
EFAULTโnamepointed outside of user address space. rude of it tbh.EINVALโsizewas negative or too large. not the size being negative ๐EPERMโ the caller did not have theCAP_SYS_ADMINcapability in the user namespace associated with its UTS namespace (peepnamespaces(7)). no cap, no permission, no slay.
getdomainname() can fail with this one:
EINVALโ Forgetdomainname()under libc:nameis NULL ornameis equal or longer thansizebytes.
๐ฆ VERSIONS ๐ฆ
Okay so this is the fun part ๐. On most Linux architectures (x86 included, bestie), there is no getdomainname() system call at all. Instead, glibc implements getdomainname() as a library function that just hands you back a copy of the domainname field it got from a call to uname(2). Sneaky! not me finding out it's not even a syscall ๐ญ
โญ STANDARDS โญ
None. that's it. no standard. free spirit energy, periodt. ๐
๐ HISTORY ๐
Since Linux 1.0, the limit on the size of a domain name โ and yes, that includes the terminating null byte โ is 64 bytes. In older kernels though? it was only 8 bytes. glow-up fr fr. ๐ธ
๐ซถ SEE ALSO ๐ซถ
and that's the whole page bestie!! this one's from Linux man-pages 6.20, dated 2026-02-08, which is genuinely so recent of it. go forth and name your domains, just don't forget CAP_SYS_ADMIN ๐โจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Rickard E. Faith <faith@cs.unc.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms