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)

๐Ÿ’ซ 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 ๐Ÿ˜ญ: -1 is returned, and errno is set to tell you what went wrong.

๐Ÿ’€ ERRORS ๐Ÿ’€

setdomainname() can fail with these:

  • EFAULT โ€” name pointed outside of user address space. rude of it tbh.
  • EINVAL โ€” size was negative or too large. not the size being negative ๐Ÿ’€
  • EPERM โ€” the caller did not have the CAP_SYS_ADMIN capability in the user namespace associated with its UTS namespace (peep namespaces(7)). no cap, no permission, no slay.

getdomainname() can fail with this one:

  • EINVAL โ€” For getdomainname() under libc: name is NULL or name is equal or longer than size bytes.

๐Ÿฆ‹ 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms