/* * Destroy subwindow. */ static inline void pad_destroy(void) { if(delwin(main_pad->wd) == ERR) prg_exit("Cannot delete details window."); if(delwin(border_wd) == ERR) prg_exit("Cannot delete details window."); main_pad->wd = 0; redrawwin(main_win); }
/* * Create ncurses pad with a frame. */ static void pad_create(struct subwin *w) { assert(sub_current); main_pad->wd = newpad(SUBWIN_ROWS, SUBWIN_COLS); if(!main_pad->wd) prg_exit("pad_create(): cannot create details window. [1]"); set_size(main_pad); w->offset = w->lines = w->xoffset = 0; border_wd = newpad(BORDER_ROWS+1, BORDER_COLS+1); if(!border_wd) prg_exit("pad_create(): cannot create details window. [2]"); wbkgd(border_wd, COLOR_PAIR(8)); werase(border_wd); box(border_wd, ACS_VLINE, ACS_HLINE); print_titles(); wbkgd(main_pad->wd, COLOR_PAIR(8)); werase(main_pad->wd); }
int read_server_cooked(int sockfd, char *response) { char buf[MAX_RECV_LINE]; char status_code[16]; ssize_t n; int space_offset; if ((n = readline(sockfd, buf, MAX_RECV_LINE)) < 0) { return(-1); } chomp(buf); if (log_verbose) { sprintf(msg,"update server --> %s", buf); logwrite(msg); } space_offset = strindex(buf, " "); substr(buf, status_code, 0, space_offset); substr(buf, response, space_offset +1, -1); if (strcmp(status_code,"ERR") == 0) { /* fatal error */ sprintf(msg,"!!FATAL ERROR!! %s", response); logwrite(msg); prg_exit(1); } return(n); }
static void get_rows_cols(int *y, int *x) { struct winsize win; if (ioctl(1,TIOCGWINSZ,&win) != -1){ *y = win.ws_row; *x = win.ws_col; return; } prg_exit("get_row_cols(): ioctl error: cannot read screen size."); }
void subwin_init(void) { sub_main.plugin_init = plugin_dummy; sub_main.plugin_draw = dummy_draw; sub_main.plugin_clear = dummy; sub_main.plugin_cleanup = dummy; main_pad = calloc(1, sizeof(struct pad_t)); if(!main_pad) prg_exit("subwin_init(): cannot allocate memory."); sub_main.arrow = -1; memcpy(&sub_proc, &sub_main, sizeof(sub_main)); memcpy(&sub_user, &sub_main, sizeof(sub_main)); memcpy(&sub_signal, &sub_main, sizeof(sub_main)); memcpy(&sub_info, &sub_main, sizeof(sub_main)); sub_proc.flags |= PERIODIC; sub_main.flags |= PERIODIC; sub_signal.flags |= PERIODIC; sub_signal.arrow = 0; //sub_user.flags |= INSERT; sub_current = &sub_user; /* set builtin plugins */ builtin_set(); dolog("%s: %d %d\n", __FUNCTION__, sub_main.arrow, sub_proc.arrow); }
int getifaddr(const char *ifname, char *ipaddr) { /* init vars */ int numreqs = 30, sd, n, tick, found=0; struct ifconf ifc; struct ifreq *ifr; struct in_addr *ia; char *tmpip; /* cheap way to empty the result */ *ipaddr = '\0'; sd=socket(AF_INET, SOCK_STREAM, 0); ifc.ifc_buf = NULL; ifc.ifc_len = sizeof(struct ifreq) * numreqs; if ((ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len)) == NULL) { logwrite("getifaddr: Fatal error in memory allocation"); close(sd); prg_exit(EXIT_FAILURE); return(-1); } if (ioctl(sd, SIOCGIFCONF, &ifc) < 0) { free(ifc.ifc_buf); close(sd); logwrite("getifaddr: error in ioctl call"); return(-1); } ifr = ifc.ifc_req; for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { ia= (struct in_addr *) ((ifr->ifr_ifru.ifru_addr.sa_data)+2); if ((tick = strcmp(ifr->ifr_ifrn.ifrn_name, ifname)) == 0) { tmpip = inet_ntoa(*ia); if (log_verbose) { sprintf(msg, "getifaddr: IP of %s:%s", ifname, tmpip); logwrite(msg); } if (sscanf(tmpip, "%u.%u.%u.%u", &int_tmp,&int_tmp,&int_tmp,&int_tmp) == 4) { strncpy(ipaddr, tmpip, IPADDR_LEN); found = 1; } else { if (log_verbose) logwrite("getifaddr: error in IP format"); } break; } ifr++; } free(ifc.ifc_buf); close(sd); if (found) { return(0); } else { return(-1); } }
void sigterm_handler() { prg_exit(0); }