mirror of https://github.com/fairyglade/ly.git
changed the default greeting to hostname
This commit is contained in:
parent
80080026db
commit
c5f0d28481
|
@ -2,7 +2,6 @@
|
|||
#define _LANG_H_
|
||||
|
||||
/* UI strings */
|
||||
#define LY_LANG_GREETING "Welcome to ly !"
|
||||
#define LY_LANG_VALID_CREDS "Logged In"
|
||||
#define LY_LANG_LOGOUT "Logged out"
|
||||
#define LY_LANG_SHELL "shell"
|
||||
|
|
|
@ -160,10 +160,12 @@ void init_scene(struct ncwin* win, struct ncform* form)
|
|||
void init_draw(struct ncwin* win, struct ncform* form)
|
||||
{
|
||||
char line[LY_LIM_LINE_CONSOLE];
|
||||
char *greeting;
|
||||
/* frame */
|
||||
box(win->win, 0, 0);
|
||||
/* 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 */
|
||||
snprintf(line, sizeof(line), "F1 %s F2 %s", LY_LANG_SHUTDOWN,
|
||||
LY_LANG_REBOOT);
|
||||
|
@ -174,6 +176,7 @@ void init_draw(struct ncwin* win, struct ncform* form)
|
|||
post_form(form->form);
|
||||
/* dumps window buffer */
|
||||
wrefresh(win->win);
|
||||
free(greeting);
|
||||
}
|
||||
|
||||
void end_form(struct ncform* form)
|
||||
|
|
38
src/utils.c
38
src/utils.c
|
@ -1,5 +1,6 @@
|
|||
#define _XOPEN_SOURCE 500
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
/* std lib */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -14,6 +15,11 @@
|
|||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
/* sockets */
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
void kernel_log(int mode)
|
||||
{
|
||||
|
@ -58,6 +64,36 @@ char* trim(char* 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)
|
||||
{
|
||||
static WINDOW* win_stack = NULL;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
void kernel_log(int mode);
|
||||
char* trim(char* s);
|
||||
char* strdup(const char* src);
|
||||
void hostname(char** out);
|
||||
void error_init(WINDOW* win, int width, const char* s);
|
||||
void error_print(const char* s);
|
||||
chtype get_curses_char(int y, int x);
|
||||
|
|
Loading…
Reference in New Issue