[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



#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 teor):

 Replying to [comment:15 callumw]:
 > Replying to [comment:14 nickm]:
 > > The idea would be to have a new, different function that only outputs
 the tor_addr_t -- not the sockaddr or the address_len.
 >
 > So would we want to pass the sockaddr and address_len by value instead
 of by reference? Otherwise I do not know another way to derive the
 tor_addr_t.

 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?

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/18105#comment:17>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs