static int new_pstream(char *suffix, const char *name, struct pstream **pstreamp, int dscp, char *unlink_path, bool kernel_print_port) { struct sockaddr_storage ss; int error; int fd; fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp, kernel_print_port); if (fd < 0) { return -fd; } struct ds bound_name = DS_EMPTY_INITIALIZER; if (!name) { ds_put_format(&bound_name, "ptcp:%"PRIu16":", ss_get_port(&ss)); ss_format_address(&ss, &bound_name); } else { ds_put_cstr(&bound_name, name); } error = new_fd_pstream(ds_steal_cstr(&bound_name), fd, ptcp_accept, unlink_path, pstreamp); if (!error) { pstream_set_bound_port(*pstreamp, htons(ss_get_port(&ss))); } return error; }
static int new_pstream(char *suffix, const char *name, struct pstream **pstreamp, int dscp, char *unlink_path, bool kernel_print_port) { char bound_name[SS_NTOP_BUFSIZE + 16]; char addrbuf[SS_NTOP_BUFSIZE]; struct sockaddr_storage ss; int error; uint16_t port; int fd; char *conn_name = CONST_CAST(char *, name); fd = inet_open_passive(SOCK_STREAM, suffix, -1, &ss, dscp, kernel_print_port); if (fd < 0) { return -fd; } port = ss_get_port(&ss); if (!conn_name) { snprintf(bound_name, sizeof bound_name, "ptcp:%"PRIu16":%s", port, ss_format_address(&ss, addrbuf, sizeof addrbuf)); conn_name = bound_name; } error = new_fd_pstream(conn_name, fd, ptcp_accept, unlink_path, pstreamp); if (!error) { pstream_set_bound_port(*pstreamp, htons(port)); } return error; }