We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0) error_die("bind"); if (port == 0) / if dynamically allocating a port */ { socklen_t namelen = sizeof(name); if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1) error_die("getsockname"); *port = ntohs(name.sin_port); }
为什么不在bind前判断端口是否为0,为0就调用getsockname让系统自动分配。 现在在bind后,如果bind的端口为0,bind失败、分配了也没用,代码里也没有重新bind。
The text was updated successfully, but these errors were encountered:
bind的过程才自动分配端口(如果bind时相应的端口为0)
Sorry, something went wrong.
No branches or pull requests
if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
error_die("bind");
if (port == 0) / if dynamically allocating a port */
{
socklen_t namelen = sizeof(name);
if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1)
error_die("getsockname");
*port = ntohs(name.sin_port);
}
为什么不在bind前判断端口是否为0,为0就调用getsockname让系统自动分配。
现在在bind后,如果bind的端口为0,bind失败、分配了也没用,代码里也没有重新bind。
The text was updated successfully, but these errors were encountered: