| 460 | } |
| 461 | |
| 462 | void json_add_address(struct json_stream *response, const char *fieldname, |
| 463 | const struct wireaddr *addr) |
| 464 | { |
| 465 | json_object_start(response, fieldname); |
| 466 | if (addr->type == ADDR_TYPE_IPV4) { |
| 467 | char addrstr[INET_ADDRSTRLEN]; |
| 468 | inet_ntop(AF_INET, addr->addr, addrstr, INET_ADDRSTRLEN); |
| 469 | json_add_string(response, "type", "ipv4"); |
| 470 | json_add_string(response, "address", addrstr); |
| 471 | json_add_num(response, "port", addr->port); |
| 472 | } else if (addr->type == ADDR_TYPE_IPV6) { |
| 473 | char addrstr[INET6_ADDRSTRLEN]; |
| 474 | inet_ntop(AF_INET6, addr->addr, addrstr, INET6_ADDRSTRLEN); |
| 475 | json_add_string(response, "type", "ipv6"); |
| 476 | json_add_string(response, "address", addrstr); |
| 477 | json_add_num(response, "port", addr->port); |
| 478 | } else if (addr->type == ADDR_TYPE_TOR_V2_REMOVED) { |
| 479 | json_add_string(response, "type", "torv2"); |
| 480 | json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr)); |
| 481 | json_add_num(response, "port", addr->port); |
| 482 | } else if (addr->type == ADDR_TYPE_TOR_V3) { |
| 483 | json_add_string(response, "type", "torv3"); |
| 484 | json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr)); |
| 485 | json_add_num(response, "port", addr->port); |
| 486 | } else if (addr->type == ADDR_TYPE_DNS) { |
| 487 | json_add_string(response, "type", "dns"); |
| 488 | json_add_string(response, "address", fmt_wireaddr_without_port(tmpctx, addr)); |
| 489 | json_add_num(response, "port", addr->port); |
| 490 | } else if (addr->type == ADDR_TYPE_WEBSOCKET) { |
| 491 | json_add_string(response, "type", "websocket"); |
| 492 | json_add_num(response, "port", addr->port); |
| 493 | } |
| 494 | json_object_end(response); |
| 495 | } |
| 496 | |
| 497 | void json_add_address_internal(struct json_stream *response, |
| 498 | const char *fieldname, |
no test coverage detected