[tor-bugs] #18105 [Core Tor/Tor]: Replace getsockname with tor_getsockname

Tor Bug Tracker & Wiki blackhole at torproject.org
Thu Nov 16 16:03:47 UTC 2017

#18105: Replace getsockname with tor_getsockname
 Reporter:  teor                                 |          Owner:
                                                 |  eewayhsu
     Type:  enhancement                          |         Status:
                                                 |  needs_revision
 Priority:  Medium                               |      Milestone:  Tor:
                                                 |  0.3.3.x-final
Component:  Core Tor/Tor                         |        Version:
 Severity:  Normal                               |     Resolution:
 Keywords:  easy, intro, api, code-              |  Actual Points:
  simplification                                 |
Parent ID:                                       |         Points:  small
 Reviewer:                                       |        Sponsor:

Comment (by callumw):

 Replying to [comment:17 teor]:
 > Hi, thanks for your persistence, sorry it has taken a while for someone
 to reply.
 > `struct sockaddr_storage` is large enough to hold an IPv4 or IPv6
 address. So we can pass a local variable of that type to getsockname(),
 even if we don't know the size of the address. On return, it will have the
 right address in it.
 > Similarly, we can initialise a local `socklen_t` variable to the size of
 sockaddr_storage. On return, it will have the right size in it.
 > Then, we can call tor_addr_from_sockaddr() to populate the tor_addr_t.
 And it turns out we don't even need the size for this.
 > Does that help?

 Thanks! This has clarified the issue much more.

 I have implemented the function as you suggested and will submit another
 patch when I can. For now I have hit a compilation problem when attempting
 to include address.h in compat.h so that the type tor_addr_t can be used
 in the new function

Ticket URL: <https://trac.torproject.org/projects/tor/ticket/18105#comment:19>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online

More information about the tor-bugs mailing list