Teonet library
0.4.7
|
#include <time.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdint.h>
#include <libgen.h>
#include <syslog.h>
#include <errno.h>
#include "config/config.h"
#include "config/conf.h"
#include "rlutil.h"
#include "utils.h"
#include "ev_mgr.h"
#include <sys/types.h>
#include <ifaddrs.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Macros | |
#define | ADDRSTRLEN 128 |
Functions | |
void | teoLoggingClientSend (void *ke, const char *message) |
Send log data to logging servers. More... | |
unsigned char | teoFilterFlagCheck (void *ke) |
unsigned char | teoLogCheck (void *ke, void *log) |
void | KSN_SET_TEST_MODE (int test_mode) |
int | KSN_GET_TEST_MODE () |
int | ksnet_printf (teonet_cfg *teo_cfg, int type, const char *format,...) |
KSNet printf. More... | |
int | teoLogPuts (teonet_cfg *teo_cfg, const char *module, int type, const char *message) |
char * | removeTEsc (char *str) |
Remove terminal escape substrings from string. More... | |
char * | ksnet_formatMessage (const char *fmt,...) |
Create formated message in new null terminated string. More... | |
char * | ksnet_sformatMessage (char *str_to_free, const char *fmt,...) |
Create formated message in new null terminated string, and free str_to_free. More... | |
char * | ksnet_vformatMessage (const char *fmt, va_list ap) |
char * | trimlf (char *str) |
Remove trailing line feeds characters from null terminated string. More... | |
char * | trim (char *str) |
Remove trailing or leading space. More... | |
void * | memdup (const void *d, size_t s) |
Duplicate memory. More... | |
int | calculate_lines (char *str) |
Calculate number of lines in string. More... | |
char * | getRandomHostName (void) |
Get random host name. More... | |
char * | getDataPath (void) |
Get path to teonet data folder. More... | |
int | set_reuseaddr (int sd) |
Make socket reusable. More... | |
char * | ksnet_getSysConfigDir (void) |
Getting path to ksnet configuration folder. More... | |
int | inarray (int val, const int *arr, int size) |
Check if a value exist in a array. More... | |
ksnet_stringArr | getIPs (teonet_cfg *conf) |
Get IPs. More... | |
int | addr_port_equal (addr_port_t *ap_obj, char *addr, uint16_t port) |
addr_port_t * | addr_port_init () |
void | addr_port_free (addr_port_t *ap_obj) |
addr_port_t * | wr__ntop (const struct sockaddr *sa) |
addr_port_t * | wrap_inet_ntop (const struct sockaddr *sa) |
int | ip_to_array (char *ip, uint8_t *arr) |
Convert IP to bytes array. More... | |
void | printHexDump (void *addr, size_t len) |
void | resolveDnsName (teonet_cfg *conf) |
int | ip_is_private (char *ip) |
Detect if input IP address is private. More... | |
size_t | get_num_of_tags (char *data, size_t data_length) |
Calculate number of tags in json string. More... | |
#define ADDRSTRLEN 128 |
Referenced by addr_port_init(), and wr__ntop().
int addr_port_equal | ( | addr_port_t * | ap_obj, |
char * | addr, | ||
uint16_t | port | ||
) |
References addr_port::addr, and addr_port::port.
Referenced by addr_port_init().
void addr_port_free | ( | addr_port_t * | ap_obj | ) |
References addr_port::addr, and free().
Referenced by find_arp_by_addr_cb(), ksnCoreProcessPacket(), ksnTRUDPsendto(), resolveDnsName(), teo_recvfrom(), teo_sendto(), and trudp_send_event_ack_to_app().
addr_port_t* addr_port_init | ( | ) |
References addr_port::addr, addr_port_equal(), ADDRSTRLEN, addr_port::equal, malloc(), and addr_port::port.
Referenced by wr__ntop().
int calculate_lines | ( | char * | str | ) |
Calculate number of lines in string.
Calculate number of line with line feed \n at the end in null input terminated string
str | Input null terminated string |
Referenced by ksnetArpShow(), and ksnTRUDPstatShow().
size_t get_num_of_tags | ( | char * | data, |
size_t | data_length | ||
) |
Calculate number of tags in json string.
data | |
data_length |
char* getDataPath | ( | void | ) |
Get path to teonet data folder.
References free(), KSN_BUFFER_SIZE, and ksnet_formatMessage().
Referenced by teo::Teonet::getPath(), ksnet_optRead(), ksnetEvMgrRun(), read_config(), teowebConfigRead(), and uconfigFileName().
ksnet_stringArr getIPs | ( | teonet_cfg * | conf | ) |
Get IPs.
Get IP address of this host
References ksnet_stringArrAdd(), ksnet_stringArrCreate(), and teonet_cfg::vpn_ip.
Referenced by createCmdConnectRPacketUdp(), and open_local_port().
char* getRandomHostName | ( | void | ) |
Get random host name.
Create random host name. Should be free after use.
References ksnet_formatMessage().
Referenced by set_defaults().
int inarray | ( | int | val, |
const int * | arr, | ||
int | size | ||
) |
Check if a value exist in a array.
val | Integer value |
arr | Integer array |
size | Array size |
int ip_is_private | ( | char * | ip | ) |
Detect if input IP address is private.
ip |
References ip_to_array().
Referenced by createCmdConnectRPacketUdp(), and open_local_port().
int ip_to_array | ( | char * | ip, |
uint8_t * | arr | ||
) |
Convert IP to bytes array.
ip | |
arr |
References free().
Referenced by ip_is_private(), and open_local_port().
|
inline |
Referenced by ksnet_printf().
|
inline |
Referenced by main().
char* ksnet_formatMessage | ( | const char * | fmt, |
... | |||
) |
Create formated message in new null terminated string.
fmt | Format string like in printf function |
... | Parameter |
References ksnet_vformatMessage().
Referenced by cmd_disconnected_cb(), event_cb(), teo::Teonet::formatMessage(), getDataPath(), getRandomHostName(), ksnet_optRead(), ksnetArpShowHeader(), ksnetArpShowLine(), ksnetArpShowStr(), ksnetEvMgrRestart(), ksnMultiShowListStr(), open_local_port(), read_config(), teowebConfigRead(), and uconfigFileName().
char* ksnet_getSysConfigDir | ( | void | ) |
Getting path to ksnet configuration folder.
Referenced by read_config(), teowebConfigRead(), and uconfigFileName().
int ksnet_printf | ( | teonet_cfg * | teo_cfg, |
int | type, | ||
const char * | format, | ||
... | |||
) |
KSNet printf.
Make format output to stdout. Instead of standard printf function this function has type parameter which define type of print. It should be used this function instead of standard printf function.
teo_cfg | Pointer to teonet_cfg |
type | MESSAGE – print always; CONNECT – print if connect show flag connect is set; DEBUG – print if debug show flag is set on; DEBUG_VV – print if debug extra show flag is set on; ERROR_M – print always. |
format | Format like in standard printf function |
... | Parameters |
References _ANSI_NONE, teonet_cfg::color_output_disable_f, CONNECT, data, DEBUG, DEBUG_VV, DEBUG_VVV, DISPLAY_M, ERROR_M, free(), teonet_cfg::ke, KSN_GET_TEST_MODE(), ksnet_vformatMessage(), ksnetEvMgrGetTime(), teonet_cfg::log_prefix, teonet_cfg::log_priority, MESSAGE, removeTEsc(), teonet_cfg::show_connect_f, teonet_cfg::show_debug_f, teonet_cfg::show_debug_vv_f, teonet_cfg::show_debug_vvv_f, teoFilterFlagCheck(), teoLogCheck(), teoLoggingClientSend(), and trimlf().
Referenced by event_cb(), ksnetArpShow(), main(), start_stop_daemon(), tcp_read_cb(), teoLogPuts(), and test2().
char* ksnet_sformatMessage | ( | char * | str_to_free, |
const char * | fmt, | ||
... | |||
) |
Create formated message in new null terminated string, and free str_to_free.
str_to_free | |
fmt | Format string like in printf function |
... | Parameter |
References free(), and ksnet_vformatMessage().
Referenced by event_cb(), ksnet_optRead(), ksnetArpShowHeader(), ksnetArpShowStr(), ksnMultiShowListStr(), and teoGetFullAppTypeFromHostInfo().
char* ksnet_vformatMessage | ( | const char * | fmt, |
va_list | ap | ||
) |
References free(), KSN_BUFFER_SM_SIZE, malloc(), and va_copy.
Referenced by ksnet_formatMessage(), ksnet_printf(), and ksnet_sformatMessage().
void* memdup | ( | const void * | d, |
size_t | s | ||
) |
Duplicate memory.
Allocate memory and copy selected value to it
d | Pointer to value to copy |
s | Length of value |
References malloc().
Referenced by event_cb(), and get_cb().
void printHexDump | ( | void * | addr, |
size_t | len | ||
) |
char* removeTEsc | ( | char * | str | ) |
void resolveDnsName | ( | teonet_cfg * | conf | ) |
References addr_port::addr, addr_port_free(), KSN_BUFFER_SM_SIZE, teonet_cfg::r_host_addr, teonet_cfg::r_host_addr_opt, and wrap_inet_ntop().
Referenced by connect_r_host_cb(), and ksnet_optRead().
int set_reuseaddr | ( | int | sd | ) |
Make socket reusable.
sd |
unsigned char teoFilterFlagCheck | ( | void * | ke | ) |
References khv.
Referenced by ksnet_printf().
unsigned char teoLogCheck | ( | void * | ke, |
void * | log | ||
) |
References khv, and log_string_match().
Referenced by ksnet_printf().
void teoLoggingClientSend | ( | void * | ke, |
const char * | message | ||
) |
Send log data to logging servers.
ke | Pointer to ksnetEvMgrClass |
message | Pointer to cstring message |
References kev, and ksnetEvMgrAsync().
Referenced by ksnet_printf().
int teoLogPuts | ( | teonet_cfg * | teo_cfg, |
const char * | module, | ||
int | type, | ||
const char * | message | ||
) |
References _ANSI_GREEN, _ANSI_NONE, _ksn_printf_type_, teonet_cfg::app_name, and ksnet_printf().
char* trim | ( | char * | str | ) |
Remove trailing or leading space.
Remove trailing or leading space or tabulation characters in input null terminated string
str | Null terminated input string to remove trailing and leading spaces in |
char* trimlf | ( | char * | str | ) |
Remove trailing line feeds characters from null terminated string.
str |
Referenced by hotkeys_cb(), and ksnet_printf().
addr_port_t* wr__ntop | ( | const struct sockaddr * | sa | ) |
References addr_port::addr, addr_port_init(), ADDRSTRLEN, and addr_port::port.
Referenced by wrap_inet_ntop().
addr_port_t* wrap_inet_ntop | ( | const struct sockaddr * | sa | ) |
References wr__ntop().
Referenced by find_arp_by_addr_cb(), ksnCoreProcessPacket(), ksnTRUDPsendto(), resolveDnsName(), teo_recvfrom(), teo_sendto(), and trudp_send_event_ack_to_app().