Revision 534e126a src/net_helper.c

View differences:

src/net_helper.c
184 184
  return recv;
185 185
}
186 186

  
187
const char *node_addr(const struct nodeID *s)
187
int node_addr(const struct nodeID *s, char *addr, int len)
188 188
{
189
  static char addr[256];
189
  int n;
190 190

  
191
  sprintf(addr, "%s:%d", inet_ntoa(s->addr.sin_addr), ntohs(s->addr.sin_port));
191
  if (!inet_ntop(AF_INET, &(s->addr.sin_addr), addr, len)) {
192
    return -1;
193
  }
194
  n = snprintf(addr + strlen(addr), len - strlen(addr) - 1, ":%d", ntohs(s->addr.sin_port));
192 195

  
193
  return addr;
196
  return n;
194 197
}
195 198

  
196 199
struct nodeID *nodeid_dup(struct nodeID *s)
......
237 240
  free(s);
238 241
}
239 242

  
240
const char *node_ip(const struct nodeID *s)
243
int node_ip(const struct nodeID *s, char *ip, int len)
241 244
{
242
  static char ip[64];
243

  
244
  sprintf(ip, "%s", inet_ntoa(s->addr.sin_addr));
245
  if (inet_ntop(AF_INET, &(s->addr.sin_addr), ip, len) == 0) {
246
    return -1;
247
  }
245 248

  
246
  return ip;
249
  return 1;
247 250
}

Also available in: Unified diff