Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
net_arp.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ev_mgr.h"
#include "utils/rlutil.h"
#include "utils/utils.h"
#include "utils/teo_memory.h"

Macros

#define kev   ((ksnetEvMgrClass*)(ke))
 
#define kev   ((ksnetEvMgrClass*)ka->ke)
 

Typedefs

typedef struct find_arp_data find_arp_data
 

Functions

ksnetArpClassksnetArpInit (void *ke)
 File: net_arp.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru More...
 
void ksnetArpDestroy (ksnetArpClass *ka)
 Destroy ARP table. More...
 
ksnet_arp_data_ext * ksnetArpGet (ksnetArpClass *ka, char *name)
 Get ARP table data by Peer Name. More...
 
int ksnetArpSize (ksnetArpClass *ka)
 Returns the number of entries in arp map. More...
 
void ksnetArpAdd (ksnetArpClass *ka, char *name, ksnet_arp_data_ext *data)
 Add or update record in KSNet Peer ARP table. More...
 
void ksnetArpAddHost (ksnetArpClass *ka)
 Add (or update) this host to ARP table. More...
 
void * ksnetArpSetHostPort (ksnetArpClass *ka, char *name, int port)
 Change port at existing arp data associated with key (per name) More...
 
int ksnetArpRemove (ksnetArpClass *ka, char *name)
 Remove Peer from the ARP table. More...
 
void ksnetArpRemoveAll (ksnetArpClass *ka)
 Remove all records instead host from ARP table. More...
 
int ksnetArpGetAll_ (ksnetArpClass *ka, peer_callback cb, void *data, int flag)
 Get all known peer without current host. More...
 
int ksnetArpGetAll (ksnetArpClass *ka, peer_callback cb, void *data)
 Get all known peer without current host. More...
 
int ksnetArpGetAllH (ksnetArpClass *ka, peer_callback cb, void *data)
 Get all known peer with current host. More...
 
int find_arp_by_addr_cb (ksnetArpClass *ka, char *peer_name, ksnet_arp_data_ext *arp, void *data)
 
ksnet_arp_data * ksnetArpFindByAddr (ksnetArpClass *ka, __CONST_SOCKADDR_ARG addr, char **peer_name)
 Find ARP data by address. More...
 
ksnet_arp_data_ar * ksnetArpShowData (ksnetArpClass *ka)
 Return ARP table in digital format. More...
 
ksnet_arp_data_ext_ar * teoArpGetExtendedArpTable (ksnetArpClass *ka)
 Return extended ARP table. More...
 
void ksnetArpMetrics (ksnetArpClass *ka)
 Send arp table metrics. More...
 
char * ksnetArpShowDataJson (ksnet_arp_data_ar *peers_data, size_t *peers_data_json_len)
 Convert peers data to JSON. More...
 
char * teoArpGetExtendedArpTable_json (ksnet_arp_data_ext_ar *peers_data, size_t *peers_data_json_len)
 
void teoArpGetExtendedArpTable_json_delete (char *obj)
 
size_t ksnetArpShowDataLength (ksnet_arp_data_ar *peers_data)
 Return size of ksnet_arp_data_ar data. More...
 
size_t teoArpGetExtendedArpTableLength (ksnet_arp_data_ext_ar *peers_data)
 
char * ksnetArpShowHeader (int header_f)
 Show (return string) with KSNet ARP table header. More...
 
char * ksnetArpShowLine (int num, char *name, ksnet_arp_data *data)
 Show (return string) one record of KSNet ARP table. More...
 
char * ksnetArpShowStr (ksnetArpClass *ka)
 Show (return string) KSNet ARP table. More...
 
int ksnetArpShow (ksnetArpClass *ka)
 Show KSNet ARP table. More...
 

Macro Definition Documentation

#define kev   ((ksnetEvMgrClass*)(ke))

Referenced by ksnetArpMetrics().

#define kev   ((ksnetEvMgrClass*)ka->ke)

Typedef Documentation

typedef struct find_arp_data find_arp_data

Function Documentation

int find_arp_by_addr_cb ( ksnetArpClass ka,
char *  peer_name,
ksnet_arp_data_ext *  arp,
void *  data 
)
void ksnetArpAdd ( ksnetArpClass ka,
char *  name,
ksnet_arp_data_ext *  data 
)

Add or update record in KSNet Peer ARP table.

Parameters
ka
name
data

References ksnetArpClass::map.

Referenced by ksnCoreCheckNewPeer(), ksnetArpAddHost(), monitor_timer_one_cb(), and peer_type_cb().

void ksnetArpDestroy ( ksnetArpClass ka)

Destroy ARP table.

References free(), and ksnetArpClass::map.

Referenced by ksnCoreDestroy().

ksnet_arp_data* ksnetArpFindByAddr ( ksnetArpClass ka,
__CONST_SOCKADDR_ARG  addr,
char **  peer_name 
)

Find ARP data by address.

Parameters
kaPointer to ksnetArpClass
addrAddress
peer_name[out] Peer name (may be null)
Returns
Pointer to ARP data or NULL if not found

References find_arp_by_addr_cb(), and ksnetArpGetAllH().

Referenced by remove_peer_addr().

ksnet_arp_data_ext* ksnetArpGet ( ksnetArpClass ka,
char *  name 
)

Get ARP table data by Peer Name.

Parameters
kaPointer to ksnetArpClass
namePeer name
Returns
Pointer to ARP data or NULL if not found
Examples:
teoack.c, and teoackm.c.

References ksnetArpClass::map.

Referenced by event_cb(), ksnCoreCheckNewPeer(), ksnCoreSendCmdto(), and peer_type_cb().

int ksnetArpGetAll ( ksnetArpClass ka,
peer_callback  cb,
void *  data 
)
inline

Get all known peer without current host.

Send it too fnd_peer_cb callback

Parameters
ka
peer_callbackint peer_callback(ksnetArpClass *ka, char *peer_name, ksnet_arp_data *arp_data, void *data)
data

References ksnetArpGetAll_().

Referenced by idle_activity_cb(), ksnCoreCheckNewPeer(), ksnCoreDestroy(), ksnCoreSendCmdto(), monitor_timer_cb(), send_cmd_disconnect_peer_cb(), and teoBroadcastSend().

int ksnetArpGetAll_ ( ksnetArpClass ka,
peer_callback  cb,
void *  data,
int  flag 
)

Get all known peer without current host.

Send it too fnd_peer_cb callback

Parameters
ka
peer_callbackint peer_callback(ksnetArpClass *ka, char *peer_name, ksnet_arp_data *arp_data, void *data)
data
flagInclude this host if true

References ksnetArpClass::map.

Referenced by ksnetArpGetAll(), and ksnetArpGetAllH().

int ksnetArpGetAllH ( ksnetArpClass ka,
peer_callback  cb,
void *  data 
)
inline

Get all known peer with current host.

Send it too fnd_peer_cb callback

Parameters
ka
peer_callbackcb
data

References ksnetArpGetAll_().

Referenced by ksnetArpFindByAddr().

ksnetArpClass* ksnetArpInit ( void *  ke)

File: net_arp.c Author: Kirill Scherba kiril.nosp@m.l@sc.nosp@m.herba.nosp@m..ru

Created on April 12, 2015, 7:19 PM

KSNet ARP Table manager Initialize ARP table

References ksnetArpClass::ke, ke, ksnetArpAddHost(), ksnetArpClass::map, and teo_malloc().

Referenced by ksnCoreInit().

void ksnetArpMetrics ( ksnetArpClass ka)

Send arp table metrics.

References free(), kev, ksnetArpShowData(), and teoMetricGaugef().

Referenced by metric_teonet_count().

int ksnetArpRemove ( ksnetArpClass ka,
char *  name 
)

Remove Peer from the ARP table.

Parameters
kaPointer to ksnetArpClass
namePeer name to remove
Returns
1 if successfully removed

References free(), ksnetArpClass::ke, ksnStreamClosePeer(), and ksnetArpClass::map.

Referenced by cmd_disconnected_cb().

void ksnetArpRemoveAll ( ksnetArpClass ka)

Remove all records instead host from ARP table.

Free ARP Hash map, create new and add this host to created ARP Hash map

Parameters
ka

References free(), ksnetEvMgrClass::kc, ksnetArpClass::ke, ke, ksnetArpAddHost(), ksnCoreClass::ku, ksnetArpClass::map, teonet_cfg::r_host_name, and ksnetEvMgrClass::teo_cfg.

Referenced by ksnTCPProxyClientStop().

void* ksnetArpSetHostPort ( ksnetArpClass ka,
char *  name,
int  port 
)

Change port at existing arp data associated with key (per name)

Parameters
ka
name
port
Returns
Return NULL if name not found in the map

References ksnetArpClass::map.

Referenced by ksnCoreInit().

int ksnetArpShow ( ksnetArpClass ka)

Show KSNet ARP table.

Parameters
ka
Returns
Number of lines in shown text

References _ANSI_CLS, calculate_lines(), teonet_cfg::color_output_disable_f, DISPLAY_M, free(), ksnetArpClass::ke, ksnet_printf(), and ksnetArpShowStr().

Referenced by hotkeys_cb(), and peer_idle_cb().

ksnet_arp_data_ar* ksnetArpShowData ( ksnetArpClass ka)

Return ARP table in digital format.

Parameters
kaPointer to the ksnetArpClass
Returns
Return pointer to the ksnet_arp_data_ar data with ARP table data. Should be free after use.

References data, ksnetArpClass::ke, ksnetEvMgrGetTime(), ksnetArpClass::map, and teo_malloc().

Referenced by ksnetArpMetrics().

char* ksnetArpShowDataJson ( ksnet_arp_data_ar *  peers_data,
size_t *  peers_data_json_len 
)

Convert peers data to JSON.

Parameters
peers_dataPointer to ksnet_arp_data_ar
peers_data_json_len[out] Result json string length
Returns
String with ARP table in JSON format. Should be free after use

References malloc().

size_t ksnetArpShowDataLength ( ksnet_arp_data_ar *  peers_data)
inline

Return size of ksnet_arp_data_ar data.

Parameters
peers_data
Returns
Size of ksnet_arp_data_ar data
char* ksnetArpShowHeader ( int  header_f)

Show (return string) with KSNet ARP table header.

Parameters
header_fHeader flag. If 1 - return Header, if 0 - return Footer
Returns
Examples:
teol0cli.c.

References ksnet_formatMessage(), and ksnet_sformatMessage().

Referenced by tcp_read_cb().

char* ksnetArpShowLine ( int  num,
char *  name,
ksnet_arp_data *  data 
)

Show (return string) one record of KSNet ARP table.

Parameters
numRecord number
namePeer name
dataPointer to ksnet_arp_data structure
Returns
String with formated ARP table line. Should be free after use
Examples:
teol0cli.c.

References free(), ksnet_formatMessage(), LIGHTGREEN, and NONE.

Referenced by tcp_read_cb().

char* ksnetArpShowStr ( ksnetArpClass ka)

Show (return string) KSNet ARP table.

Parameters
ka
Returns
String with formated ARP table. Should be free after use

References data, free(), ksnetArpClass::ke, ksnet_formatMessage(), ksnet_sformatMessage(), LIGHTGREEN, ksnetArpClass::map, NONE, and null_str.

Referenced by ksnetArpShow().

int ksnetArpSize ( ksnetArpClass ka)

Returns the number of entries in arp map.

Parameters
kaPointer to ksnetArpClass
Returns
The number of entries in arp map.

References ksnetArpClass::map.

ksnet_arp_data_ext_ar* teoArpGetExtendedArpTable ( ksnetArpClass ka)

Return extended ARP table.

Parameters
kaPointer to the ksnetArpClass
Returns
Return pointer to the ksnet_arp_data_ext_ar data with extended ARP table data. Should be free after use.

References data, ksnetArpClass::map, and teo_malloc().

char* teoArpGetExtendedArpTable_json ( ksnet_arp_data_ext_ar *  peers_data,
size_t *  peers_data_json_len 
)

References malloc().

void teoArpGetExtendedArpTable_json_delete ( char *  obj)

References free().

size_t teoArpGetExtendedArpTableLength ( ksnet_arp_data_ext_ar *  peers_data)
inline