mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
ntohs() when reporting the port number.
Re-use addrin when fetching the port number.
This commit is contained in:
parent
28c382d454
commit
d28bb0c9f7
13
darkhttpd.c
13
darkhttpd.c
@ -789,11 +789,8 @@ static const char *url_content_type(const char *url) {
|
|||||||
*/
|
*/
|
||||||
static void init_sockin(void) {
|
static void init_sockin(void) {
|
||||||
struct sockaddr_in addrin;
|
struct sockaddr_in addrin;
|
||||||
|
socklen_t addrin_len;
|
||||||
int sockopt;
|
int sockopt;
|
||||||
struct sockaddr_in addrout;
|
|
||||||
socklen_t addrout_len;
|
|
||||||
|
|
||||||
addrout_len = sizeof(addrout);
|
|
||||||
|
|
||||||
/* create incoming socket */
|
/* create incoming socket */
|
||||||
sockin = socket(PF_INET, SOCK_STREAM, 0);
|
sockin = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
@ -833,12 +830,12 @@ static void init_sockin(void) {
|
|||||||
sizeof(struct sockaddr)) == -1)
|
sizeof(struct sockaddr)) == -1)
|
||||||
err(1, "bind(port %u)", bindport);
|
err(1, "bind(port %u)", bindport);
|
||||||
|
|
||||||
if (getsockname(sockin, (struct sockaddr *)&addrout,
|
addrin_len = sizeof(addrin);
|
||||||
&addrout_len) == -1)
|
if (getsockname(sockin, (struct sockaddr *)&addrin, &addrin_len) == -1)
|
||||||
err(1, "getsocketname(sockin)");
|
err(1, "getsockname()");
|
||||||
|
|
||||||
printf("listening on: http://%s:%u/\n",
|
printf("listening on: http://%s:%u/\n",
|
||||||
inet_ntoa(addrout.sin_addr), addrout.sin_port);
|
inet_ntoa(addrin.sin_addr), ntohs(addrin.sin_port));
|
||||||
|
|
||||||
/* listen on socket */
|
/* listen on socket */
|
||||||
if (listen(sockin, max_connections) == -1)
|
if (listen(sockin, max_connections) == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user