Browse Source

trimmed open_socket() down by one parameter (#768)

pull/770/head
Logan oos Even 3 years ago
committed by GitHub
parent
commit
b6e865aac7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      include/n2n.h
  2. 2
      src/edge.c
  3. 6
      src/edge_utils.c
  4. 4
      src/example_sn_embed.c
  5. 11
      src/n2n.c
  6. 6
      src/sn.c

2
include/n2n.h

@ -220,7 +220,7 @@ int memxor (uint8_t *destination, const uint8_t *source, size_t len);
char* sock_to_cstr (n2n_sock_str_t out,
const n2n_sock_t * sock);
char * ip_subnet_to_str (dec_ip_bit_str_t buf, const n2n_ip_subnet_t *ipaddr);
SOCKET open_socket (int local_port, int bind_any, in_addr_t address, int type);
SOCKET open_socket (int local_port, in_addr_t address, int type);
int sock_equal (const n2n_sock_t * a,
const n2n_sock_t * b);

2
src/edge.c

@ -592,7 +592,7 @@ static int setOption (int optkey, char *optargument, n2n_tuntap_priv_config_t *e
case 'b': {
if(optargument) {
conf->bind_address = inet_addr(optargument);
conf->bind_address = ntohl(inet_addr(optargument));
if(conf->bind_address == INADDR_NONE) {
traceEvent(TRACE_WARNING, "Bad address to bind to, binding to any IP address.");

6
src/edge_utils.c

@ -215,7 +215,7 @@ int supernode_connect(n2n_edge_t *eee) {
(eee->conf.connect_tcp) ? 0 : eee->conf.local_port);
eee->sock = open_socket((eee->conf.connect_tcp) ? 0 : eee->conf.local_port,
2 /* bind as provided with next parameter */, eee->conf.bind_address,
eee->conf.bind_address,
eee->conf.connect_tcp);
if(eee->sock < 0) {
@ -3098,7 +3098,7 @@ static int edge_init_sockets (n2n_edge_t *eee) {
closesocket(eee->udp_multicast_sock);
#endif
eee->udp_mgmt_sock = open_socket(eee->conf.mgmt_port, 0 /* bind LOOPBACK */, 0, 0 /* UDP */);
eee->udp_mgmt_sock = open_socket(eee->conf.mgmt_port, INADDR_LOOPBACK, 0 /* UDP */);
if(eee->udp_mgmt_sock < 0) {
traceEvent(TRACE_ERROR, "failed to bind management UDP port %u", eee->conf.mgmt_port);
return(-2);
@ -3113,7 +3113,7 @@ static int edge_init_sockets (n2n_edge_t *eee) {
eee->multicast_peer.addr.v4[2] = 0;
eee->multicast_peer.addr.v4[3] = 68;
eee->udp_multicast_sock = open_socket(N2N_MULTICAST_PORT, 1 /* bind ANY */, 0, 0 /* UDP */);
eee->udp_multicast_sock = open_socket(N2N_MULTICAST_PORT, INADDR_ANY, 0 /* UDP */);
if(eee->udp_multicast_sock < 0)
return(-3);
else {

4
src/example_sn_embed.c

@ -29,12 +29,12 @@ int main () {
sss_node.daemon = 0; // Whether to daemonize
sss_node.lport = 1234; // Main UDP listen port
sss_node.sock = open_socket(sss_node.lport, 1, 0, 0);
sss_node.sock = open_socket(sss_node.lport, INADDR_ANY, 0 /* UDP */);
if(-1 == sss_node.sock) {
exit(-2);
}
sss_node.mgmt_sock = open_socket(5645, 0, 0, 0); // Main UDP management port
sss_node.mgmt_sock = open_socket(5645, INADDR_LOOPBACK, 0 /* UDP */); // Main UDP management port
if(-1 == sss_node.mgmt_sock) {
exit(-2);
}

11
src/n2n.c

@ -28,7 +28,7 @@
/* ************************************** */
SOCKET open_socket (int local_port, int bind_any, in_addr_t address, int type /* 0 = UDP, TCP otherwise */) {
SOCKET open_socket (int local_port, in_addr_t address, int type /* 0 = UDP, TCP otherwise */) {
SOCKET sock_fd;
struct sockaddr_in local_address;
@ -50,14 +50,7 @@ SOCKET open_socket (int local_port, int bind_any, in_addr_t address, int type /*
memset(&local_address, 0, sizeof(local_address));
local_address.sin_family = AF_INET;
local_address.sin_port = htons(local_port);
if(bind_any == 2) {
// use the provided address for binding
// REVISIT: allow for multiple addresses to be provided, i.e. through several '-b' at cli,
// internally requires a list of in_addr_t addresses
local_address.sin_addr.s_addr = address;
} else {
local_address.sin_addr.s_addr = htonl(bind_any ? INADDR_ANY : INADDR_LOOPBACK);
}
local_address.sin_addr.s_addr = htonl(address);
if(bind(sock_fd,(struct sockaddr*) &local_address, sizeof(local_address)) == -1) {
traceEvent(TRACE_ERROR, "Bind error on local port %u [%s]\n", local_port, strerror(errno));

6
src/sn.c

@ -577,7 +577,7 @@ int main (int argc, char * const argv[]) {
traceEvent(TRACE_DEBUG, "traceLevel is %d", getTraceLevel());
sss_node.sock = open_socket(sss_node.lport, 1 /*bind ANY*/, 0, 0 /* UDP */);
sss_node.sock = open_socket(sss_node.lport, INADDR_ANY, 0 /* UDP */);
if(-1 == sss_node.sock) {
traceEvent(TRACE_ERROR, "failed to open main socket. %s", strerror(errno));
exit(-2);
@ -586,7 +586,7 @@ int main (int argc, char * const argv[]) {
}
#ifdef N2N_HAVE_TCP
sss_node.tcp_sock = open_socket(sss_node.lport, 1 /*bind ANY*/, 0, 1 /* TCP */);
sss_node.tcp_sock = open_socket(sss_node.lport, INADDR_ANY, 1 /* TCP */);
if(-1 == sss_node.tcp_sock) {
traceEvent(TRACE_ERROR, "failed to open auxiliary TCP socket, %s", strerror(errno));
exit(-2);
@ -602,7 +602,7 @@ int main (int argc, char * const argv[]) {
}
#endif
sss_node.mgmt_sock = open_socket(sss_node.mport, 0 /* bind LOOPBACK */, 0, 0 /* UDP */);
sss_node.mgmt_sock = open_socket(sss_node.mport, INADDR_LOOPBACK, 0 /* UDP */);
if(-1 == sss_node.mgmt_sock) {
traceEvent(TRACE_ERROR, "failed to open management socket, %s", strerror(errno));
exit(-2);

Loading…
Cancel
Save