Tarsnap / spiped

Spiped is a utility for creating symmetrically encrypted and authenticated pipes between socket addresses.
http://www.tarsnap.com/spiped.html
Other
858 stars 56 forks source link

Add sock_util_ensure_port() #358

Closed gperciva closed 2 years ago

gperciva commented 2 years ago

I extracted this from #353, and made a few style fixes and minor code fixes.

I'm not certain about the name. I think it makes sense to be in sock_util.h, since we'll need this for both spiped and spipe. I opted for sock_util_ instead of sock_addr_ since this operates on strings rather than struct sock_addr. However, I kind-of drew a blank for the rest of the name. I ended up with _ensure_port(), but that was more because I had to name it something.

gperciva commented 2 years ago

Ok, but:

cperciva commented 2 years ago

Yes it's the right file. Anything uses asprintf (or relies on code in any other .c file aside from warnp.c) should be in sock_util.c rather than sock.c.

Function name... hmm. Everything here is sock_addr_ so maybe sock_addr_add_port0? Or sock_addr_ensure_port, either works for me.

gperciva commented 2 years ago

Everything here is sockaddr so maybe sock_addr_add_port0?

Yes, but everything else acts on struct sock_addr *; whereas this function only acts on strings.

cperciva commented 2 years ago

Everything here is sockaddr so maybe sock_addr_add_port0?

Yes, but everything else acts on struct sock_addr *; whereas this function only acts on strings.

Meh. Sure, we're taking a string and returning a string, but it's a string which is going to be passed to other sock_addr_* functions.