master slave mode working
This commit is contained in:
parent
ddf0b5ce2d
commit
51bbd571ad
@ -566,7 +566,9 @@ dsmbr_slave_accept_master(int slave_ctrl_sock)
|
||||
int ret;
|
||||
int conn_fd;
|
||||
struct sockaddr addr;
|
||||
struct sockaddr_in * inaddr;
|
||||
socklen_t addrlen;
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
|
||||
ret = accept(slave_ctrl_sock, &addr, &addrlen);
|
||||
if (ret < 0) {
|
||||
@ -574,7 +576,17 @@ dsmbr_slave_accept_master(int slave_ctrl_sock)
|
||||
}
|
||||
conn_fd = ret;
|
||||
|
||||
V("Accepted master connection %d.\n", conn_fd);
|
||||
ret = getpeername(conn_fd, &addr, &addrlen);
|
||||
if (ret < 0) {
|
||||
E("getpeername failed: %d\n", errno);
|
||||
}
|
||||
|
||||
inaddr = (struct sockaddr_in *)&addr;
|
||||
if (inet_ntop(AF_INET, &inaddr->sin_addr, ip, INET_ADDRSTRLEN) == NULL) {
|
||||
E("inet_ntop failed: %d\n", errno);
|
||||
}
|
||||
|
||||
V("Accepted master connection %d from %s.\n", conn_fd, ip);
|
||||
|
||||
return conn_fd;
|
||||
}
|
||||
|
22
ppd/ppd.cc
22
ppd/ppd.cc
@ -3,10 +3,8 @@
|
||||
#include <sys/event.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <openssl/err.h>
|
||||
@ -14,7 +12,6 @@
|
||||
#include <pthread.h>
|
||||
#include <pthread_np.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <bsock/bsock.h>
|
||||
|
||||
#include "logger.h"
|
||||
@ -34,9 +31,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
LOGGER_VAR_DECL;
|
||||
}
|
||||
|
||||
static constexpr int NEVENT = 64;
|
||||
static constexpr int SOCK_BACKLOG = 10000;
|
||||
@ -601,10 +596,10 @@ loop_main(int m_kq, std::vector<struct ppd_thread_ctx *> *workers)
|
||||
}
|
||||
|
||||
// new connection
|
||||
struct sockaddr_in client_addr;
|
||||
struct sockaddr client_addr;
|
||||
socklen_t client_addr_size = sizeof(client_addr);
|
||||
|
||||
int conn_fd = accept(kev.ident, (struct sockaddr *)&client_addr, &client_addr_size);
|
||||
int conn_fd = accept(kev.ident, &client_addr, &client_addr_size);
|
||||
|
||||
if (conn_fd < 0) {
|
||||
W("accept() failed: %d\n", errno);
|
||||
@ -622,11 +617,16 @@ loop_main(int m_kq, std::vector<struct ppd_thread_ctx *> *workers)
|
||||
}
|
||||
}
|
||||
|
||||
char ipaddr[INET_ADDRSTRLEN + 1];
|
||||
strncpy(ipaddr, inet_ntoa(client_addr.sin_addr), INET_ADDRSTRLEN);
|
||||
ipaddr[INET_ADDRSTRLEN] = 0;
|
||||
if (getpeername(conn_fd, &client_addr, &client_addr_size) < 0) {
|
||||
E("getpeername failed: %d\n", errno);
|
||||
}
|
||||
|
||||
V("Accepted new connection %d from %s\n", conn_fd, ipaddr);
|
||||
char client_ip[INET_ADDRSTRLEN];
|
||||
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)&client_addr)->sin_addr), client_ip, sizeof(client_ip)) == NULL) {
|
||||
E("inet_ntop failed: %d\n", errno);
|
||||
}
|
||||
|
||||
V("Accepted connection %d from %s.\n", conn_fd, client_ip);
|
||||
|
||||
struct ppd_conn *conn = new struct ppd_conn;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user