mirror of
https://github.com/sheumann/hush.git
synced 2025-01-02 09:31:26 +00:00
provide safe_gethostname() for non-linux systems
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
3d0e7794eb
commit
1d448cff65
@ -59,12 +59,16 @@ char* FAST_FUNC safe_gethostname(void)
|
|||||||
*/
|
*/
|
||||||
char* FAST_FUNC safe_getdomainname(void)
|
char* FAST_FUNC safe_getdomainname(void)
|
||||||
{
|
{
|
||||||
/* The field domainname of struct utsname is Linux specific. */
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
|
/* The field domainname of struct utsname is Linux specific. */
|
||||||
struct utsname uts;
|
struct utsname uts;
|
||||||
uname(&uts);
|
uname(&uts);
|
||||||
return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
|
return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
|
||||||
#else
|
#else
|
||||||
return xstrdup("?");
|
/* We really don't care about people with domain names wider than most screens */
|
||||||
|
char buf[256];
|
||||||
|
int r = getdomainname(buf, sizeof(buf));
|
||||||
|
buf[sizeof(buf)-1] = '\0';
|
||||||
|
return xstrdup(r < 0 ? "?" : buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user