changed the default greeting to hostname

This commit is contained in:
cylgom 2018-06-30 11:43:05 +02:00
parent 80080026db
commit c5f0d28481
4 changed files with 42 additions and 3 deletions

View File

@ -2,7 +2,6 @@
#define _LANG_H_ #define _LANG_H_
/* UI strings */ /* UI strings */
#define LY_LANG_GREETING "Welcome to ly !"
#define LY_LANG_VALID_CREDS "Logged In" #define LY_LANG_VALID_CREDS "Logged In"
#define LY_LANG_LOGOUT "Logged out" #define LY_LANG_LOGOUT "Logged out"
#define LY_LANG_SHELL "shell" #define LY_LANG_SHELL "shell"

View File

@ -160,10 +160,12 @@ void init_scene(struct ncwin* win, struct ncform* form)
void init_draw(struct ncwin* win, struct ncform* form) void init_draw(struct ncwin* win, struct ncform* form)
{ {
char line[LY_LIM_LINE_CONSOLE]; char line[LY_LIM_LINE_CONSOLE];
char *greeting;
/* frame */ /* frame */
box(win->win, 0, 0); box(win->win, 0, 0);
/* initializes error output and prints greeting message */ /* initializes error output and prints greeting message */
error_init(win->win, win->width, LY_LANG_GREETING); hostname(&greeting);
error_init(win->win, win->width, greeting);
/* prints shutdown & reboot hints */ /* prints shutdown & reboot hints */
snprintf(line, sizeof(line), "F1 %s F2 %s", LY_LANG_SHUTDOWN, snprintf(line, sizeof(line), "F1 %s F2 %s", LY_LANG_SHUTDOWN,
LY_LANG_REBOOT); LY_LANG_REBOOT);
@ -174,6 +176,7 @@ void init_draw(struct ncwin* win, struct ncform* form)
post_form(form->form); post_form(form->form);
/* dumps window buffer */ /* dumps window buffer */
wrefresh(win->win); wrefresh(win->win);
free(greeting);
} }
void end_form(struct ncform* form) void end_form(struct ncform* form)

View File

@ -1,5 +1,6 @@
#define _XOPEN_SOURCE 500 #define _XOPEN_SOURCE 500
#define _DEFAULT_SOURCE
#define _POSIX_C_SOURCE 200809L
/* std lib */ /* std lib */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -14,6 +15,11 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
/* sockets */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
void kernel_log(int mode) void kernel_log(int mode)
{ {
@ -58,6 +64,36 @@ char* trim(char* s)
return s; return s;
} }
void hostname(char** out) {
struct addrinfo hints;
struct addrinfo *info;
char hostname[1024];
char* dot;
int result;
hostname[1023] = '\0';
gethostname(hostname, 1023);
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
result = getaddrinfo(hostname, "http", &hints, &info);
if(result == 0 && info != NULL)
{
dot = strchr(info->ai_canonname, '.');
*out = strndup(info->ai_canonname, dot - info->ai_canonname);
}
else
{
*out = strdup("");
}
freeaddrinfo(info);
}
void error_init(WINDOW* win, int width, const char* s) void error_init(WINDOW* win, int width, const char* s)
{ {
static WINDOW* win_stack = NULL; static WINDOW* win_stack = NULL;

View File

@ -7,6 +7,7 @@
void kernel_log(int mode); void kernel_log(int mode);
char* trim(char* s); char* trim(char* s);
char* strdup(const char* src); char* strdup(const char* src);
void hostname(char** out);
void error_init(WINDOW* win, int width, const char* s); void error_init(WINDOW* win, int width, const char* s);
void error_print(const char* s); void error_print(const char* s);
chtype get_curses_char(int y, int x); chtype get_curses_char(int y, int x);