| 2508 | #endif |
| 2509 | |
| 2510 | void get_peer_info(rem_port* port) |
| 2511 | { |
| 2512 | /************************************** |
| 2513 | * |
| 2514 | * g e t _ p e e r _ i n f o |
| 2515 | * |
| 2516 | ************************************** |
| 2517 | * |
| 2518 | * Functional description |
| 2519 | * Port just connected. Obtain some info about connection and peer. |
| 2520 | * |
| 2521 | **************************************/ |
| 2522 | port->port_protocol_id = "TCPv4"; |
| 2523 | |
| 2524 | SockAddr address; |
| 2525 | if (address.getpeername(port->port_handle) == 0) |
| 2526 | { |
| 2527 | address.unmapV4(); // convert mapped IPv4 to regular IPv4 |
| 2528 | char host[64]; // 32 digits, 7 colons, 1 trailing null byte |
| 2529 | char serv[16]; |
| 2530 | int nameinfo = getnameinfo(address.ptr(), address.length(), host, sizeof(host), |
| 2531 | serv, sizeof(serv), NI_NUMERICHOST | NI_NUMERICSERV); |
| 2532 | |
| 2533 | if (!nameinfo) |
| 2534 | port->port_address.printf("%s/%s", host, serv); |
| 2535 | |
| 2536 | if (address.family() == AF_INET6) |
| 2537 | port->port_protocol_id = "TCPv6"; |
| 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | static void inet_gen_error(bool releasePort, rem_port* port, const Arg::StatusVector& v) |