- int len = vsnprintf(message, sizeof message, format, ap);
- if(len > 0 && len < sizeof message && message[len - 1] == '\n')
- message[len - 1] = 0;
+ size_t msglen = sizeof message;
+
+ int len = vsnprintf(message, msglen, format, ap);
+ if(len > 0 && len < sizeof message) {
+ 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);
+ }