|
|
@ -28,11 +28,14 @@ |
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_MCAST_ADDR "239.255.186.1" |
|
|
|
#define DEFAULT_MCAST_ADDR "239.255.186.1" |
|
|
|
#define DEFAULT_MCAST_PORT "3370" |
|
|
|
#define DEFAULT_MCAST_PORT "3370" |
|
|
|
|
|
|
|
#define DEFAULT_PING_NUM 5 |
|
|
|
|
|
|
|
|
|
|
|
struct _config { |
|
|
|
struct _config { |
|
|
|
char name[ID_MAX + 1]; |
|
|
|
char name[ID_MAX + 1]; |
|
|
|
char error[256]; |
|
|
|
char error[256]; |
|
|
|
bool shared; |
|
|
|
bool shared; |
|
|
|
|
|
|
|
uint8_t ping_num; /*< current number of ping() call */ |
|
|
|
|
|
|
|
uint8_t ping_max; /*< max ping() calls before actually send CMD_PING packet */ |
|
|
|
char maddr[INET_ADDRSTRLEN]; /**< multicast address */ |
|
|
|
char maddr[INET_ADDRSTRLEN]; /**< multicast address */ |
|
|
|
char mport[6]; /**< multicast port */ |
|
|
|
char mport[6]; /**< multicast port */ |
|
|
|
char iface[IF_NAMESIZE]; /**< bind interface */ |
|
|
|
char iface[IF_NAMESIZE]; /**< bind interface */ |
|
|
@ -47,6 +50,7 @@ create(const char *id) { |
|
|
|
|
|
|
|
|
|
|
|
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL) |
|
|
|
if ((cfg = calloc(1, sizeof(cfg_t))) == NULL) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
cfg->ping_max = DEFAULT_PING_NUM; |
|
|
|
strlcpy(cfg->name, id, sizeof(cfg->name)); |
|
|
|
strlcpy(cfg->name, id, sizeof(cfg->name)); |
|
|
|
strlcpy(cfg->maddr, DEFAULT_MCAST_ADDR, sizeof(cfg->maddr)); |
|
|
|
strlcpy(cfg->maddr, DEFAULT_MCAST_ADDR, sizeof(cfg->maddr)); |
|
|
|
strlcpy(cfg->mport, DEFAULT_MCAST_PORT, sizeof(cfg->mport)); |
|
|
|
strlcpy(cfg->mport, DEFAULT_MCAST_PORT, sizeof(cfg->mport)); |
|
|
@ -76,6 +80,10 @@ config(cfg_t *cfg, const char *key, const char *value) { |
|
|
|
strlcpy(cfg->iface, value, sizeof(cfg->iface)); |
|
|
|
strlcpy(cfg->iface, value, sizeof(cfg->iface)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strcmp(key, "ping") == 0) { |
|
|
|
|
|
|
|
cfg->ping_max = atoi(value); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -151,6 +159,12 @@ bool |
|
|
|
ping(cfg_t *cfg) { |
|
|
|
ping(cfg_t *cfg) { |
|
|
|
assert(cfg != NULL); |
|
|
|
assert(cfg != NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cfg->ping_num++; |
|
|
|
|
|
|
|
if (cfg->ping_num < cfg->ping_max) |
|
|
|
|
|
|
|
return true; /* skip this try */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* max empty calls reached, make real ping */ |
|
|
|
|
|
|
|
cfg->ping_num = 0; |
|
|
|
/* TODO */ |
|
|
|
/* TODO */ |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|