mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
59 lines
1.4 KiB
C
59 lines
1.4 KiB
C
#include "fastfetch.h"
|
|
#include "detection/title.h"
|
|
|
|
#include <limits.h>
|
|
#include <unistd.h>
|
|
#include <pthread.h>
|
|
#include <netdb.h>
|
|
|
|
#ifndef HOST_NAME_MAX
|
|
#define HOST_NAME_MAX 64
|
|
#endif
|
|
|
|
const FFTitleResult* ffDetectTitle(const FFinstance* instance)
|
|
{
|
|
static FFTitleResult result;
|
|
|
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
static bool init = false;
|
|
pthread_mutex_lock(&mutex);
|
|
if(init)
|
|
{
|
|
pthread_mutex_unlock(&mutex);
|
|
return &result;
|
|
}
|
|
init = true;
|
|
|
|
ffStrbufInit(&result.userName);
|
|
ffStrbufAppendS(&result.userName, instance->state.passwd->pw_name);
|
|
|
|
ffStrbufInitA(&result.hostname, HOST_NAME_MAX);
|
|
ffStrbufAppendS(&result.hostname, instance->state.utsname.nodename);
|
|
|
|
ffStrbufInitA(&result.fqdn, HOST_NAME_MAX);
|
|
|
|
struct addrinfo hints = {0};
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
hints.ai_flags = AI_CANONNAME;
|
|
|
|
struct addrinfo* info = NULL;
|
|
|
|
if(getaddrinfo(result.hostname.chars, "80", &hints, &info) == 0)
|
|
{
|
|
struct addrinfo* current = info;
|
|
while(result.fqdn.length == 0 && current != NULL)
|
|
{
|
|
ffStrbufAppendS(&result.fqdn, current->ai_canonname);
|
|
current = current->ai_next;
|
|
}
|
|
|
|
freeaddrinfo(info);
|
|
}
|
|
|
|
if(result.fqdn.length == 0)
|
|
ffStrbufAppend(&result.fqdn, &result.hostname);
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
return &result;
|
|
}
|