← index #1375Issue #3386
Likely Duplicate · high · value 0.849
QUERY · ISSUE

unix usocket: External representation of (binary) addresses

openby pfalconopened 2015-07-11updated 2016-07-22
rfc

Ok, https://github.com/micropython/micropython/pull/1002 was closed, because approach of requiring usage of getaddrinfo() to pass addresses to socket functions certainly works. But there's opposite problem - how to show to user an address received from a socket function, e.g. accept(), which doesn't have any solution now. I can imagine following choices:

  1. Give up and return Python-standard tuple representation of addresses, then almost certainly also need to accept them to all other functions. Bunch more extra code, memory required for minimal socket server grows.
  2. Stay stubborn and make sockaddr a separate object, which will do conversion only on str() or repr(). No extra RAM overhead with this solution, but object will be more or less involved, e.g. standard Python tuple should be emulated.
  3. Stay stubborn and low-profile - just provide a function to convert binary address to Python tuple.

Thoughts?

CANDIDATE · ISSUE

[RFC] usocket: way to create sockaddr from binary address

closedby pfalconopened 2017-10-24updated 2025-03-03
rfcneeds-info

This problem arises when e.g. implementing getaddrinfo() in Python. DNS returns a binary IP address, which somehow needs to be converted to sockaddr, as passed an an argument to most socket functions. There's also an opposite problem - given a sockaddr, split it into components. This is needed e.g. to handle return value of accept (e.g. to print in a human readable form).

Unix usocket actually already tackles the latter problem - it provides sockaddr() function, which takes a sockadr, and return a tuple of (addr_family, bin_addr, port, ...). bin_addr can be converted to textual presentation using inet_ntop().

So, the proposal is to make sockaddr() reversible: passed a single arg, sockaddr, it performs the transformation described above. And if passed more than one arg, it will vice versa construct sockaddr from components.

This function would be mandatory part of usocket API, ports which use tuple-textual sockaddr's, would emulate it.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied