Revision 534e126a src/net_helper-win32.c

View differences:

src/net_helper-win32.c
172 172
  return recv;
173 173
}
174 174

  
175
const char *node_addr(const struct nodeID *s)
175
int node_addr(const struct nodeID *s, char *addr, int len)
176 176
{
177
  static char addr[256];
177
  char buff[96];
178
  int n;
178 179

  
179
  sprintf(addr, "%s:%d", inet_ntoa(s->addr.sin_addr), ntohs(s->addr.sin_port));
180
  if (!inet_ntop(AF_INET, &(s->addr.sin_addr), addr, len)) {
181
    return -1;
182
  }
183
  n = snprintf(addr + strlen(addr), len - strlen(addr) - 1, ":%d", ntohs(s->addr.sin_port));
180 184

  
181
  return addr;
185
  return n;
182 186
}
183 187

  
184 188
struct nodeID *nodeid_dup(struct nodeID *s)
......
225 229
  free(s);
226 230
}
227 231

  
228
const char *node_ip(const struct nodeID *s)
232
int node_ip(const struct nodeID *s, char *ip, int len)
229 233
{
230
  static char ip[64];
231

  
232
  sprintf(ip, "%s", inet_ntoa(s->addr.sin_addr));
234
  if (inet_ntop(AF_INET, &(s->addr.sin_addr), ip, len) == 0) {
235
    return -1;
236
  }
233 237

  
234
  return ip;
238
  return 1;
235 239
}
240

  

Also available in: Unified diff