~ So, where are you from? */
| 389 | |
| 390 | /*~ So, where are you from? */ |
| 391 | static bool get_remote_address(struct io_conn *conn, |
| 392 | struct wireaddr_internal *addr) |
| 393 | { |
| 394 | struct sockaddr_storage s = {}; |
| 395 | socklen_t len = sizeof(s); |
| 396 | |
| 397 | /* The cast here is a weird Berkeley sockets API feature... */ |
| 398 | if (getpeername(io_conn_fd(conn), (struct sockaddr *)&s, &len) != 0) { |
| 399 | status_debug("Failed to get peername for incoming conn: %s", |
| 400 | strerror(errno)); |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | if (s.ss_family == AF_INET6) { |
| 405 | struct sockaddr_in6 *s6 = (void *)&s; |
| 406 | addr->itype = ADDR_INTERNAL_WIREADDR; |
| 407 | wireaddr_from_ipv6(&addr->u.wireaddr, |
| 408 | &s6->sin6_addr, ntohs(s6->sin6_port)); |
| 409 | } else if (s.ss_family == AF_INET) { |
| 410 | struct sockaddr_in *s4 = (void *)&s; |
| 411 | addr->itype = ADDR_INTERNAL_WIREADDR; |
| 412 | wireaddr_from_ipv4(&addr->u.wireaddr, |
| 413 | &s4->sin_addr, ntohs(s4->sin_port)); |
| 414 | } else if (s.ss_family == AF_UNIX) { |
| 415 | struct sockaddr_un *sun = (void *)&s; |
| 416 | addr->itype = ADDR_INTERNAL_SOCKNAME; |
| 417 | memcpy(addr->u.sockname, sun->sun_path, sizeof(sun->sun_path)); |
| 418 | } else { |
| 419 | status_broken("Unknown socket type %i for incoming conn", |
| 420 | s.ss_family); |
| 421 | return false; |
| 422 | } |
| 423 | return true; |
| 424 | } |
| 425 | |
| 426 | /*~ As so common in C, we need to bundle two args into a callback, so we |
| 427 | * allocate a temporary structure to hold them: */ |
no test coverage detected