cks,
@cks@mastodon.social avatar

This is my face when Python's socket.gethostbyaddr() appears not to be able to return multiple names for a single IP address. Or at least it doesn't on Fedora and Ubuntu with their versions of Python 3.

(If you want to test it yourself, try 72.136.172.146, which right now returns 17 DNS PTR results for me. I would be interested if this works for you.)

cks,
@cks@mastodon.social avatar

The Python socket.gethostbyaddr() 'return single name' behavior appears to be an underlying issue in glibc's gethostbyaddr_r(). For me, it exists if /etc/nsswitch.conf is missing 'resolve' for hosts; if present, everything works. 'resolve' does name resolution directly through systemd-resolved, instead of via (theoretical) DNS queries.

(That is, 'hosts: files dns' does not go, 'hosts: files resolve dns' does go.)

cks,
@cks@mastodon.social avatar

Linux glibc itself considers gethostbyaddr_r() to be deprecated in favour of getnameinfo(). However, getnameinfo() specifically returns only a single name, in contrast to gethostbyaddr_r(). This makes me wonder if the glibc dns NSS module funnels the two through a single function that has the getnameinfo() single-name limitation.

(I could try to read the glibc source, but uh have you ever tried that? I have, and no. I am not that curious.)

cks,
@cks@mastodon.social avatar

My ultimate resolution to my Python problem was that I rewrote the little utility program involved in Go, which will return multiple names for an IP under the right circumstances on any system. Now I can theoretically resolve my sample IP address properly, presuming that the provider involved gave it working forward DNS (all of its claimed PTR names resolve to different IP addresses).

cks,
@cks@mastodon.social avatar

I got curious and looked at the Glibc source, where it turned out to be pretty easy to trace the gethostbyaddr_r() code flow in the nss_dns code. This code winds up explicitly only ever returning one name: https://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/nss_dns/dns-host.c;h=95a7b3f0e5b6855afcbac38b25f40a80c5003f56;hb=HEAD#l600

Thanks glibc, and it's possible glibc was doing this from the very first version of this code I can find in the repo, from 1996.

lanodan,
@lanodan@queer.hacktivis.me avatar

@cks Yeah, seems like it, just tried it with the 3 versions I have:

$ drill -Q -t -x 72.136.172.146 | wc -l
17
$ for i in python3.1{0,1,2}; do printf "$i: "; $i -c 'import socket; print(socket.gethostbyaddr("72.136.172.146"))'; done
python3.10: ('stchathamwireless.rogers.com', ['stchathamwireless.rogers.com'], ['72.136.172.146'])
python3.11: ('stthunderbaywireless.rogers.com', ['stthunderbaywireless.rogers.com'], ['72.136.172.146'])
python3.12: ('stkanatawireless.rogers.com', ['stkanatawireless.rogers.com'], ['72.136.172.146'])

fink,
@fink@chaos.social avatar

@lanodan @cks 3.12.2 works and retuns a shitload

fink,
@fink@chaos.social avatar

@lanodan @cks 3.11.8 the same. What does getent hosts 72.136.172.146 tell you?

lanodan,
@lanodan@queer.hacktivis.me avatar

@fink @cks 72.136.172.146 stgeorgetownwireless.rogers.com stgeorgetownwireless.rogers.com

cks,
@cks@mastodon.social avatar

@lanodan @fink I get a single result from getent (although the name in the result can be random).

fink,
@fink@chaos.social avatar

@cks @lanodan Afair that's what python uses too.

You could also 'strace -f xxx' where xxx is the command. There you can see what happens under the hood and which sys calls are being used. Should be the same at some point.

Which kernel?

fink,
@fink@chaos.social avatar

@cks @lanodan No, which glibc?

I tried on a rather recent archlinux wsl

lanodan,
@lanodan@queer.hacktivis.me avatar

@fink @cks Mine is on musl 1.2.5. :D

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • rosin
  • thenastyranch
  • ethstaker
  • osvaldo12
  • mdbf
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • ngwrru68w68
  • slotface
  • GTA5RPClips
  • kavyap
  • cubers
  • JUstTest
  • everett
  • cisconetworking
  • tacticalgear
  • anitta
  • khanakhh
  • normalnudes
  • Durango
  • modclub
  • tester
  • provamag3
  • Leos
  • megavids
  • lostlight
  • All magazines