Skip to content

Add a new option to set the local IP address#9

Open
jonasoberschweiber wants to merge 4 commits into
rumpeltux:masterfrom
jonasoberschweiber:add-local-ip-option
Open

Add a new option to set the local IP address#9
jonasoberschweiber wants to merge 4 commits into
rumpeltux:masterfrom
jonasoberschweiber:add-local-ip-option

Conversation

@jonasoberschweiber
Copy link
Copy Markdown

This commit adds a new option to explicitly set the local IP address instead of relying on autodetection. This is useful if you want to run the application inside of a Docker container, which will have a Docker-internal IP address instead of the external, device-visible one. The new option is called network.local-ip.

Without this option, brother-scand will manage to register functions at the device, but the device will not be able to reach brother-scand, because it will have received the registrations with an IP address it can't reach.

I'm using this in brother-scand-config to build a Docker container and have tested that it works locally. Not sure whether this is the best way to implement this -- my C is a little rusty.

This commit adds a new option to explicitly set the local IP address
instead of relying on autodetection. This is useful if you want to run
the application inside of a Docker container, which will have a
Docker-internal IP address instead of the external, device-visible one.

The new option is called `network.local-ip`.
Copy link
Copy Markdown
Owner

@rumpeltux rumpeltux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have some minor comments, once addressed should be good to merge.

Comment thread config.c Outdated

void init_item_config(struct item_config *item_config,
const struct item_config *template, char *name) {
const struct item_config *template, char name[1024]) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert. I pushed another change that should solve this compiler error.

Comment thread config.c Outdated
goto out;
}
dev_config->timeout = var_uint;
} else if (sscanf((char *)buf, "network.local-ip %64s", var_str) == 1) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You read 64 bytes but only strncpy 15 later. Should probably read 15 here at most, then we can strncpy 16 and have a guaranteed 0-byte termination.
(I also didn’t write the project initially, C is not a great choice…)

Comment thread device_handler.c Outdated

rc = brother_conn_get_local_ip(conn, local_ip);
if (config->local_ip != NULL) {
strncpy(local_ip, config->local_ip, 15);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be 16

Comment thread device_handler.c Outdated
dev->ip);
brother_conn_get_local_ip(g_dev_handler.button_conn, ip);
if (dev->config->local_ip != NULL) {
strncpy(ip, dev->config->local_ip, 15);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@jonasoberschweiber
Copy link
Copy Markdown
Author

Done. Could you recheck?

@ku-we
Copy link
Copy Markdown

ku-we commented Aug 22, 2024

I too look forward to see these changes merged. Currently we have to configure our docker container to use network_mode: "host" which gives it raw access to the host's network interface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants