Skip to content

Commit

Permalink
main: Accept multiple addresses from config
Browse files Browse the repository at this point in the history
  • Loading branch information
any1 committed Nov 23, 2024
1 parent 122d7e2 commit 0c56fa3
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,34 @@ static int add_listening_address(struct wayvnc* self, const char* address,
return 0;
}

static int apply_addresses_from_config(struct wayvnc* self,
enum socket_type default_socket_type)
{
uint16_t port = self->cfg.port ? self->cfg.port : DEFAULT_PORT;

if (!self->cfg.address)
return add_listening_address(self, DEFAULT_ADDRESS, port,
default_socket_type);

char *addresses = strdup(self->cfg.address);
assert(addresses);

int rc = -1;

const char* delim = " ";
char* tok = strtok(addresses, delim);
while (tok) {
if (add_listening_address(self, tok, port, default_socket_type) < 0)
goto out;
tok = strtok(NULL, delim);
}

rc = 0;
out:
free(addresses);
return rc;
}

static int init_nvnc(struct wayvnc* self)
{
self->nvnc = nvnc_new();
Expand Down Expand Up @@ -2231,21 +2259,18 @@ int main(int argc, char* argv[])
goto nvnc_failure;
} else if (!option_parser_get_value_with_offset(&option_parser,
"address", 0)) {
address = self.cfg.address ? self.cfg.address : DEFAULT_ADDRESS;
port = self.cfg.port ? self.cfg.port : DEFAULT_PORT;

if (add_listening_address(&self, address, port,
default_socket_type))
if (apply_addresses_from_config(&self, default_socket_type) < 0)
goto nvnc_failure;
} else {
port = self.cfg.port ? self.cfg.port : DEFAULT_PORT;
for (int i = 0;; ++i) {
const char* address;
address = option_parser_get_value_with_offset(
&option_parser, "address", i);
if (!address)
break;

if (add_listening_address(&self, address, DEFAULT_PORT,
if (add_listening_address(&self, address, port,
default_socket_type) < 0)
goto nvnc_failure;
}
Expand Down

0 comments on commit 0c56fa3

Please sign in to comment.