/** * Pretty-printing of node information for logs into the supplied buffers. * * IP address is followed by '*' if the contact's address/port was patched. * IP address is followed by '?' if the UDP message came from another IP * * A "zombie" node is a node retrieved from the persisted routing table that * is not alive. Normally, only alive hosts from which we get traffic are * added, but here we have an instance that is not alive -- a zombie. * * A "cached" node is a node coming from the k-closest root cache. * * A firewalled node is indicated by a trailing "fw" indication. * * @return the buffer where printing was done. */ const char * knode_to_string_buf(const knode_t *kn, char buf[], size_t len) { char host_buf[HOST_ADDR_PORT_BUFLEN]; char vc_buf[VENDOR_CODE_BUFLEN]; char kuid_buf[KUID_HEX_BUFLEN]; knode_check(kn); bin_to_hex_buf(kn->id, KUID_RAW_SIZE, kuid_buf, sizeof kuid_buf); host_addr_port_to_string_buf(kn->addr, kn->port, host_buf, sizeof host_buf); vendor_code_to_string_buf(kn->vcode.u32, vc_buf, sizeof vc_buf); str_bprintf(buf, len, "%s%s%s (%s v%u.%u) [%s] \"%s\", ref=%d%s%s%s%s [%s]", host_buf, (kn->flags & KNODE_F_PCONTACT) ? "*" : "", (kn->flags & KNODE_F_FOREIGN_IP) ? "?" : "", vc_buf, kn->major, kn->minor, kuid_buf, knode_status_to_string(kn->status), kn->refcnt, (kn->status != KNODE_UNKNOWN && !(kn->flags & KNODE_F_ALIVE)) ? " zombie" : "", (kn->flags & KNODE_F_CACHED) ? " cached" : "", (kn->flags & KNODE_F_RPC) ? " RPC" : "", (kn->flags & KNODE_F_FIREWALLED) ? " fw" : "", compact_time(delta_time(tm_time(), kn->first_seen))); return buf; }
const char * host_addr_port_to_string2(const host_addr_t ha, uint16 port) { static char buf[HOST_ADDR_PORT_BUFLEN]; size_t n; n = host_addr_port_to_string_buf(ha, port, buf, sizeof buf); g_assert(n < sizeof buf); return buf; }
const char * host_addr_port_to_string2(const host_addr_t ha, uint16 port) { buf_t *b = buf_private(G_STRFUNC, HOST_ADDR_PORT_BUFLEN); char *p = buf_data(b); size_t len, n = buf_size(b); len = host_addr_port_to_string_buf(ha, port, p, n); g_assert(len < n); return p; }
/** * Prints the host address ` followed by ``port'' to ``buf''. The string * written to ``buf'' is always NUL-terminated unless ``len'' is zero. If * ``len'' is too small, the string will be truncated. * * @param h the packet IP:port address. * @param buf the destination buffer; may be NULL iff ``len'' is zero. * @param len the size of ``buf'' in bytes. * * @return The length of the resulting string assuming ``len'' is sufficient. */ size_t gnet_host_to_string_buf(const gnet_host_t *h, void *buf, size_t len) { host_addr_t addr; uint16 port; g_assert(h != NULL); packed_host_unpack_addr(&h->data, &addr); port = gnet_host_get_port(h); return host_addr_port_to_string_buf(addr, port, buf, len); }
const char * host_port_to_string(const char *hostname, host_addr_t addr, uint16 port) { static char buf[MAX_HOSTLEN + 32]; if (hostname) { char port_buf[UINT32_DEC_BUFLEN]; uint32_to_string_buf(port, port_buf, sizeof port_buf); concat_strings(buf, sizeof buf, hostname, ":", port_buf, (void *) 0); } else { host_addr_port_to_string_buf(addr, port, buf, sizeof buf); } return buf; }
const char * host_port_to_string(const char *hostname, host_addr_t addr, uint16 port) { buf_t *b = buf_private(G_STRFUNC, MAX_HOSTLEN + HOST_ADDR_PORT_BUFLEN); char *p = buf_data(b); if (hostname != NULL) { char port_buf[UINT32_DEC_BUFLEN]; uint32_to_string_buf(port, port_buf, sizeof port_buf); concat_strings(p, buf_size(b), hostname, ":", port_buf, NULL_PTR); } else { host_addr_port_to_string_buf(addr, port, p, buf_size(b)); } return p; }
/* * @return stringified host vector as newly allocated string via halloc() */ char * gnet_host_vec_to_string(const gnet_host_vec_t *hvec) { str_t *s; uint i, n; g_return_val_if_fail(hvec, NULL); s = str_new(0); n = gnet_host_vec_count(hvec); for (i = 0; i < n; i++) { gnet_host_t host; gchar buf[128]; if (i > 0) { STR_CAT(s, ", "); } host = gnet_host_vec_get(hvec, i); host_addr_port_to_string_buf(gnet_host_get_addr(&host), gnet_host_get_port(&host), buf, sizeof buf); str_cat(s, buf); } return str_s2c_null(&s); }