diff --git a/mongoose.c b/mongoose.c index 14a9218f..4deea5c4 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3910,7 +3910,7 @@ mg_socketpair_accept(sock_t sock, union socket_address *sa, socklen_t sa_len) { } int mg_socketpair(sock_t sp[2], int sock_type) { - union socket_address sa; + union socket_address sa, sa2; sock_t sock; socklen_t len = sizeof(sa.sin); int ret = 0; @@ -3919,18 +3919,20 @@ int mg_socketpair(sock_t sp[2], int sock_type) { (void) memset(&sa, 0, sizeof(sa)); sa.sin.sin_family = AF_INET; - sa.sin.sin_port = htons(0); sa.sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */ + sa2 = sa; if ((sock = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) { } else if (bind(sock, &sa.sa, len) != 0) { } else if (sock_type == SOCK_STREAM && listen(sock, 1) != 0) { } else if (getsockname(sock, &sa.sa, &len) != 0) { } else if ((sp[0] = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) { - } else if (connect(sp[0], &sa.sa, len) != 0) { + } else if (sock_type == SOCK_STREAM && connect(sp[0], &sa.sa, len) != 0) { } else if (sock_type == SOCK_DGRAM && - (getsockname(sp[0], &sa.sa, &len) != 0 || - connect(sock, &sa.sa, len) != 0)) { + (bind(sp[0], &sa2.sa, len) != 0 || + getsockname(sp[0], &sa2.sa, &len) != 0 || + connect(sp[0], &sa.sa, len) != 0 || + connect(sock, &sa2.sa, len) != 0)) { } else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock : mg_socketpair_accept( sock, &sa, len))) == INVALID_SOCKET) { diff --git a/mongoose.h b/mongoose.h index eecbbeff..f8030d52 100644 --- a/mongoose.h +++ b/mongoose.h @@ -4680,9 +4680,9 @@ int mg_http_parse_header2(struct mg_str *hdr, const char *var_name, char **buf, int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size) #ifdef __GNUC__ - __attribute__((deprecated)); + __attribute__((deprecated)) #endif -; + ; /* * Gets and parses the Authorization: Basic header diff --git a/src/mg_http_server.h b/src/mg_http_server.h index c4dfee4d..eacc5721 100644 --- a/src/mg_http_server.h +++ b/src/mg_http_server.h @@ -64,9 +64,9 @@ int mg_http_parse_header2(struct mg_str *hdr, const char *var_name, char **buf, int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size) #ifdef __GNUC__ - __attribute__((deprecated)); + __attribute__((deprecated)) #endif -; + ; /* * Gets and parses the Authorization: Basic header diff --git a/src/mg_net_if_socket.c b/src/mg_net_if_socket.c index 0d15764c..c13c300a 100644 --- a/src/mg_net_if_socket.c +++ b/src/mg_net_if_socket.c @@ -652,7 +652,7 @@ mg_socketpair_accept(sock_t sock, union socket_address *sa, socklen_t sa_len) { } int mg_socketpair(sock_t sp[2], int sock_type) { - union socket_address sa; + union socket_address sa, sa2; sock_t sock; socklen_t len = sizeof(sa.sin); int ret = 0; @@ -661,18 +661,20 @@ int mg_socketpair(sock_t sp[2], int sock_type) { (void) memset(&sa, 0, sizeof(sa)); sa.sin.sin_family = AF_INET; - sa.sin.sin_port = htons(0); sa.sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */ + sa2 = sa; if ((sock = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) { } else if (bind(sock, &sa.sa, len) != 0) { } else if (sock_type == SOCK_STREAM && listen(sock, 1) != 0) { } else if (getsockname(sock, &sa.sa, &len) != 0) { } else if ((sp[0] = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) { - } else if (connect(sp[0], &sa.sa, len) != 0) { + } else if (sock_type == SOCK_STREAM && connect(sp[0], &sa.sa, len) != 0) { } else if (sock_type == SOCK_DGRAM && - (getsockname(sp[0], &sa.sa, &len) != 0 || - connect(sock, &sa.sa, len) != 0)) { + (bind(sp[0], &sa2.sa, len) != 0 || + getsockname(sp[0], &sa2.sa, &len) != 0 || + connect(sp[0], &sa.sa, len) != 0 || + connect(sock, &sa2.sa, len) != 0)) { } else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock : mg_socketpair_accept( sock, &sa, len))) == INVALID_SOCKET) {