tnat64 icon indicating copy to clipboard operation
tnat64 copied to clipboard

Fix buffer size issue for AF_NETLINK

Open Leseratte10 opened this issue 1 year ago • 20 comments

This should hopefully fix #5 in all cases, by almost completely rewriting getsockname and getpeername It does fix the issue with AF_NETLINK I had with my application in particular.

It also fixes another issue with the buffer size. Previously, if the __addr buffer in getsockname or getpeername was too small for the struct, your code just aborted and returned -1.

According to the documentation though, the returned data is supposed to be truncated to fit into the buffer, and the real needed buffer size is supposed to be returned through __len so the calling application can either decide to retry with a larger buffer, or be satisfied with the partial response.

Also, getsockname is the IP address the local side of the socket is working on/with (your IP). So if you open a socket and connect to a remote server, getsockname is supposed to return your own IP. What happens currently is that in this case the library just "throws" the IPv6 address back to the application, which is probably not going to end well when an IPv4-only application actually tries to use this. I've modded it to return the IPv4 address 0.0.0.0 instead for the local socket.

Leseratte10 avatar Jan 01 '23 18:01 Leseratte10