📄 common.c
字号:
/*************************************************************************** common.c - description ------------------- begin : Thu Sep 27 08:08:03 EET 2001 copyright : (C) 2001-2002 by Petri Turunen email : petri.turunen@pete.fi.eu.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include <respmd.h>#include<stdio.h>#include <sys/types.h> //open#include <sys/stat.h> //open#include <fcntl.h> //open#include <stdlib.h> //atof#include <stdarg.h> //va_end//Global variablesextern char SERVER_IP[]; //defined in respmd.cextern char SERVER_PORT[]; //defined in respmd.cextern char LOCALHOSTN[]; //defined in respmd.cchar *rm_first_spaces(char *k){ int lenght,tmp = 0; lenght = strlen(k); while(*k==' ' || *k=='\t'){ k++; if(tmp >= lenght) break; tmp++; } return(k);}int is_comment(char *c){if(*c=='#' || *c=='\0'){ return 0;} else { return 1;}}int slog(int k, char *fmt, ...){//1=no pid & 2= with pidchar message[1024];va_list ap;va_start (ap, fmt);vsnprintf(message, 1024, fmt, ap);if (k==1) { openlog("respmd",LOG_PID,LOG_USER); syslog(LOG_INFO, message); closelog(); return 0; }if (k==2) { openlog("respmd",LOG_PID,LOG_USER); syslog(LOG_ERR, message); closelog(); return 0; }va_end(ap);return 0;}//Writes stuff to socketint send_tcp(unsigned char *buf, int buf_len, int sockfd){ int len; while( buf_len > 0) { len = write(sockfd, buf, buf_len); buf_len -= len; buf += buf_len; } return 0;}int send_to_server(char *service, char *status, int updown, struct smtps_t *smtppointer, char *fmt, ...){//if updown=1 machine is up//if updown=2 machine is downchar message[1024];va_list ap;va_start (ap, fmt);vsnprintf(message, 1024, fmt, ap);if(updown==1) { if(client(SERVER_IP, SERVER_PORT, LOCALHOSTN, status, message, smtppointer->name, "NONE", "UP", service) < 0) slog(2, "common.c: error while sending to server.");}if(updown==2) { if(client(SERVER_IP, SERVER_PORT, LOCALHOSTN, status, message, smtppointer->name, "NONE", "DOWN", service) < 0) slog(2, "common.c: error while sending to server.");}if(updown==1){ smtppointer->down=0; smtppointer->up=1;}if(updown==2) { smtppointer->down=1; smtppointer->up=0;}va_end(ap);return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -