GETDOMAINNAME(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… GETDOMAINNAME(3) β€” bestie's guide to the host's NIS domain name ✨

Okay so this one's from the Standard C Library (libc, -lc) and it's literally about getting and setting the NIS domain name of the current host. Two functions, one mission. Let's get into it πŸŽ€


✨ SYNOPSIS ✨

#include <unistd.h>

int
getdomainname(char *name, int namelen);

int
setdomainname(const char *name, int namelen);

πŸ¦‹ DESCRIPTION πŸ¦‹

So getdomainname() is the one that reads β€” it hands you back the standard NIS domain name for the current host, exactly as it was previously set by setdomainname(). You pass in namelen to tell it how big your name array is, okay? And the returned name is null-terminated unless you didn't give it enough room. No cap πŸ‘‘

Then there's setdomainname(), the one that writes β€” it sets the NIS domain name of the host machine to be name, which has length namelen.

⚠️ Real talk: this call is restricted to the super-user, and it's normally used only when the system is bootstrapped. So like, not your everyday vibe. πŸ”₯

πŸ’– RETURN VALUES πŸ’–

Slay on success β†’ the value 0 comes back.

Otherwise you get -1, and the global variable errno gets set to tell you what went wrong. 😭


🩷 ERRORS 🩷

These are the errors these calls might throw at you, bestie:

  • [EFAULT] β€” the name or namelen argument gave an invalid address. Rude of them ngl πŸ™ˆ
  • [EPERM] β€” the caller tried to set the hostname and was not the super-user. Permission denied, main character behavior only πŸ’…

⭐ SEE ALSO ⭐

Go read those too, iykyk πŸ“š


🌸 HISTORY 🌸

The getdomainname() function appeared in 4.2BSD. Vintage icon behavior πŸ•°οΈπŸ’œ


πŸ’€ BUGS πŸ’€

Domain names are limited to MAXHOSTNAMELEN (from <sys/param.h>) characters, and currently that's 256. So don't be out here writing a novel as your domain name, okay? πŸ“


sign-off 🫢 β€” this page came from Debian, dated May 6, 1994, and honestly it's been serving ever since. Stay iconic, and go set a domain name (only if you're root) 🌈✨

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms