Skip to content

Commit 3243adc

Browse files
committed
fix bug of bind API
1 parent c681efa commit 3243adc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

httpd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ void serve_file(int client, const char *filename)
429429
int startup(u_short *port)
430430
{
431431
int httpd = 0;
432+
int on = 1;
432433
struct sockaddr_in name;
433434

434435
httpd = socket(PF_INET, SOCK_STREAM, 0);
@@ -438,6 +439,10 @@ int startup(u_short *port)
438439
name.sin_family = AF_INET;
439440
name.sin_port = htons(*port);
440441
name.sin_addr.s_addr = htonl(INADDR_ANY);
442+
if ((setsockopt(httpd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) < 0)
443+
{
444+
error_die("setsockopt failed");
445+
}
441446
if (bind(httpd, (struct sockaddr *)&name, sizeof(name)) < 0)
442447
error_die("bind");
443448
if (*port == 0) /* if dynamically allocating a port */

0 commit comments

Comments
 (0)