mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-06 15:51:25 +00:00
Show accepted IPv6 peer corrently
This commit is contained in:
1 parent
7c2499fc06
commit
eecf3d854b
2 files changed
+16
-3
No files matched your search
+8
-2
@@ -2821,7 +2821,7 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
|||||||
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||||
struct mg_connection *c = NULL;
|
struct mg_connection *c = NULL;
|
||||||
union usa usa;
|
union usa usa;
|
||||||
socklen_t sa_len = sizeof(usa.sin);
|
socklen_t sa_len = sizeof(usa);
|
||||||
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
||||||
if (fd == INVALID_SOCKET) {
|
if (fd == INVALID_SOCKET) {
|
||||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||||
@@ -2837,6 +2837,13 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
|||||||
char buf[40];
|
char buf[40];
|
||||||
c->peer.port = usa.sin.sin_port;
|
c->peer.port = usa.sin.sin_port;
|
||||||
memcpy(&c->peer.ip, &usa.sin.sin_addr, sizeof(c->peer.ip));
|
memcpy(&c->peer.ip, &usa.sin.sin_addr, sizeof(c->peer.ip));
|
||||||
|
#if MG_ENABLE_IPV6
|
||||||
|
if (sa_len == sizeof(usa.sin6)) {
|
||||||
|
memcpy(c->peer.ip6, &usa.sin6.sin6_addr, sizeof(c->peer.ip6));
|
||||||
|
c->peer.port = usa.sin6.sin6_port;
|
||||||
|
c->peer.is_ip6 = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
mg_straddr(c, buf, sizeof(buf));
|
mg_straddr(c, buf, sizeof(buf));
|
||||||
LOG(LL_DEBUG, ("%lu accepted %s", c->id, buf));
|
LOG(LL_DEBUG, ("%lu accepted %s", c->id, buf));
|
||||||
mg_set_non_blocking_mode(FD(c));
|
mg_set_non_blocking_mode(FD(c));
|
||||||
@@ -3254,7 +3261,6 @@ void mg_timer_poll(unsigned long now_ms) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <mbedtls/debug.h>
|
#include <mbedtls/debug.h>
|
||||||
#include <mbedtls/ssl.h>
|
#include <mbedtls/ssl.h>
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -366,7 +366,7 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
|||||||
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||||
struct mg_connection *c = NULL;
|
struct mg_connection *c = NULL;
|
||||||
union usa usa;
|
union usa usa;
|
||||||
socklen_t sa_len = sizeof(usa.sin);
|
socklen_t sa_len = sizeof(usa);
|
||||||
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
SOCKET fd = accept(FD(lsn), &usa.sa, &sa_len);
|
||||||
if (fd == INVALID_SOCKET) {
|
if (fd == INVALID_SOCKET) {
|
||||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||||
@@ -382,6 +382,13 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
|||||||
char buf[40];
|
char buf[40];
|
||||||
c->peer.port = usa.sin.sin_port;
|
c->peer.port = usa.sin.sin_port;
|
||||||
memcpy(&c->peer.ip, &usa.sin.sin_addr, sizeof(c->peer.ip));
|
memcpy(&c->peer.ip, &usa.sin.sin_addr, sizeof(c->peer.ip));
|
||||||
|
#if MG_ENABLE_IPV6
|
||||||
|
if (sa_len == sizeof(usa.sin6)) {
|
||||||
|
memcpy(c->peer.ip6, &usa.sin6.sin6_addr, sizeof(c->peer.ip6));
|
||||||
|
c->peer.port = usa.sin6.sin6_port;
|
||||||
|
c->peer.is_ip6 = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
mg_straddr(c, buf, sizeof(buf));
|
mg_straddr(c, buf, sizeof(buf));
|
||||||
LOG(LL_DEBUG, ("%lu accepted %s", c->id, buf));
|
LOG(LL_DEBUG, ("%lu accepted %s", c->id, buf));
|
||||||
mg_set_non_blocking_mode(FD(c));
|
mg_set_non_blocking_mode(FD(c));
|
||||||
|
|||||||
Reference in new issue
Block a user