mindstalk: (Default)
So, I've been working today on cloning my Ocaml chat program in C++. It's going slowly as I work on infrastructure, like exception-throwing wrappers to libc socket functions, and a RAII class for file descriptors.

In the process, I found something. I'd been using inet_pton() on the user provided server name, forgetting that I have to look it up first. I was getting away with it because testing has been local, client connect to localhost. My first code wasn't error checking inet_pton, but I got around to making the Inet_pton wrapper, which started throwing exceptions. inet_pton is supposed to return 1 on success (with the IP address written into a parameter), and 0 on invalid input. Turns out, given the string "localhost", it returns 0 but *also* writes in the local IP address.

That, or some weirder default was happening... yeah, on going the other way, I find the address (written or more likely just left over from the usual memset/bzero initialization) is 0.0.0.0... which connects to localhost, just like the well-known 127.0.0.1. Huh. Guess I should look up 0.0.0.0... which looks messy an multi-purpose, but yeah, this seems one potential behavior of it, especially on a DHCP machine. OTOH, neither of the remote servers I have access to will connect to themselves via that address, so it's not reliable.

Profile

mindstalk: (Default)
mindstalk

May 2025

S M T W T F S
    123
45678910
11 121314151617
1819202122 23 24
25262728293031

Most Popular Tags

Expand Cut Tags

No cut tags

Style Credit

Page generated 2025-05-29 17:36
Powered by Dreamwidth Studios