Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra quotation mark for unix sockets in coap_print_addr #1460

Closed
anyc opened this issue Jul 8, 2024 · 2 comments
Closed

Extra quotation mark for unix sockets in coap_print_addr #1460

anyc opened this issue Jul 8, 2024 · 2 comments

Comments

@anyc
Copy link
Contributor

anyc commented Jul 8, 2024

Hello,

in the coap_print_addr() function, the path to a unix domain socket is enclosed in quotations marks:

snprintf((char *)buf, len, "'%s'", addr->addr.cun.sun_path);

Is there a specific reason why this is done?

In my code, I want to check over which endpoint a session has been started and I do a string comparison of the paths which becomes unnecessarily complicated with the quotation marks in my opinion. It is not a huge problem to work around this but if there is no need for the quotation marks I would open a PR to remove them. Or do you have concerns that this might break existing applications?

Thank you!

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 8, 2024

I think when I first put this in place, I wanted to differentiate between an IP address of 1.2.3.4 and a filename of 1.2.3.4 (albeit an unlikely overlap).

Certainly when parsing a CoAP URI, this was implemented as starting with coap://%2F (i.e. implicit leading / for the file name following discussion (coap+unix:// was considered at one point)). So a filename of 1.2.3.4 is very unlikely to be used, but there is nothing stopping this being done programmatically rather than using the examples coap-client or coap-server.

coap_resolve_address_info() now checks for leading %2F or / in the host name before treating it as a Unix Domain name, so 1.2.3.4 is not ambiguous.

So, from that perspective, there is no need for the 's around around the file name.

I think it unlikely that things will get broken if the change is made. However, if coap_session_get_addr_local(session)->addr.sa.sa_family == AF_UNIX, you just need to access coap_session_get_addr_local(session)->addr.cun.sun_path to do your comparisons.

@anyc
Copy link
Contributor Author

anyc commented Jul 10, 2024

Thanks!

@anyc anyc closed this as completed Jul 10, 2024
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

No branches or pull requests

2 participants