diff --git a/include/unistd.h b/include/unistd.h index 4f6953c4..d3bb781a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -165,6 +165,7 @@ int getpagesize(void); int getdtablesize(void); int sethostname(const char *, size_t); int getdomainname(char *, size_t); +int setdomainname(const char *, size_t); int setgroups(size_t, const gid_t []); char *getpass(const char *); int daemon(int, int); diff --git a/src/misc/getdomainname.c b/src/misc/getdomainname.c index 7eb113d7..59df566d 100644 --- a/src/misc/getdomainname.c +++ b/src/misc/getdomainname.c @@ -1,9 +1,17 @@ +#define _GNU_SOURCE #include #include #include +#include int getdomainname(char *name, size_t len) { - *name = 0; + struct utsname temp; + uname(&temp); + if (!len || strlen(temp.domainname) >= len) { + errno = EINVAL; + return -1; + } + strcpy(name, temp.domainname); return 0; } diff --git a/src/misc/setdomainname.c b/src/misc/setdomainname.c new file mode 100644 index 00000000..22d3f746 --- /dev/null +++ b/src/misc/setdomainname.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int setdomainname(const char *name, size_t len) +{ + return syscall(SYS_setdomainname, name, len); +}