Fix crash is sptps_logger().
Unfortunately, sptps_logger() cannot know if s->handle is pointing to a connection_t or a node_t. But it needs to print name and hostname in both cases. So make sure both types have name and hostname fields at the start with the same offset.
This commit is contained in:
parent
bfe231b977
commit
45a46f068c
3 changed files with 4 additions and 2 deletions
|
@ -59,9 +59,9 @@ typedef struct connection_status_t {
|
|||
|
||||
typedef struct connection_t {
|
||||
char *name; /* name he claims to have */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
|
||||
union sockaddr_t address; /* his real (internet) ip */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
int protocol_major; /* used protocol */
|
||||
int protocol_minor; /* used protocol */
|
||||
|
||||
|
|
|
@ -127,6 +127,8 @@ static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap
|
|||
if(message[len - 1] == '\n')
|
||||
message[--len] = 0;
|
||||
|
||||
// WARNING: s->handle can point to a connection_t or a node_t,
|
||||
// but both types have the name and hostname fields at the same offsets.
|
||||
connection_t *c = s->handle;
|
||||
if(c)
|
||||
snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname);
|
||||
|
|
|
@ -45,12 +45,12 @@ typedef struct node_status_t {
|
|||
|
||||
typedef struct node_t {
|
||||
char *name; /* name of this node */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
node_id_t id; /* unique node ID (name hash) */
|
||||
uint32_t options; /* options turned on for this node */
|
||||
|
||||
int sock; /* Socket to use for outgoing UDP packets */
|
||||
sockaddr_t address; /* his real (internet) ip to send UDP packets to */
|
||||
char *hostname; /* the hostname of its real ip */
|
||||
|
||||
node_status_t status;
|
||||
time_t last_state_change;
|
||||
|
|
Loading…
Reference in a new issue