Socket...o::Emul(3pm)

✨ NAME ✨

Socket::GetAddrInfo::Emul β€” bestie, this is a pure Perl emulation of getaddrinfo and getnameinfo, built on the IPv4-only legacy resolvers πŸ¦‹ (the manual page you're reading rn is Socket...o::Emul(3pm), iykyk πŸ’…)


πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea β˜•: Socket::GetAddrInfo tries to give you the getaddrinfo and getnameinfo functions via some XS code that calls the real, actual functions living in libc. Iconic. Gorgeous. The dream. πŸŽ€

But sometimes that just cannot happen, and not for dramatic reasons either β€” maybe there's no C compiler hanging around, or maybe libc simply doesn't provide those functions at all 😭. When that's the case, they get emulated using the legacy resolvers like gethostbyname, etc. etc.

Heads up bestie: these emulations are not a complete replacement of the real functions, because they only support IPv4 β€” that's the AF_INET socket family, and nothing else. So in this case, the following restrictions apply πŸ‘‡

🌸 getaddrinfo

  • If the family hint is supplied, it must be AF_INET. Any other value and you're getting an error thrown by croak. Periodt. πŸ’€
  • The only supported flags hint values are AI_PASSIVE, AI_CANONNAME, AI_NUMERICSERV and AI_NUMERICHOST.

The flags AI_V4MAPPED and AI_ALL are recognised but ignored, because they just don't apply to AF_INET lookups. And since this function only ever returns AF_INET addresses, it doesn't need to probe the system for configured addresses in other families β€” so the AI_ADDRCONFIG flag is ignored too. Not me casually ignoring three flags ✨

Lowkey important note: AI_NUMERICSERV is an extension that is not defined by RFC 2553, but most OSes provide it anyway. It is possible (though unlikely) that even the native XS implementation doesn't recognise this constant. So like… don't be shocked if it ghosts you πŸ™ˆ

πŸ¦‹ getnameinfo

  • If the sockaddr family of $addr is anything other than AF_INET, an error will be thrown with croak. No exceptions, no negotiation, no vibe check. πŸ’…
  • The only supported $flags values are NI_NUMERICHOST, NI_NUMERICSERV, NI_NOFQDN, NI_NAMEREQD and NI_DGRAM.

πŸ‘‘ IDN SUPPORT πŸ‘‘

This pure-perl emulation does provide the IDN constants such as AI_IDN and NI_IDN β€” yes, they're there, they exist, they're giving main character energy 🌈 β€” but the getaddrinfo and getnameinfo functions will croak if you actually pass these flags in. 😭

Why is that a slay, you ask? Because it lets a program probe for their support and then gracefully fall back to some other behaviour instead. That's the whole point, bestie 🫢


⭐ AUTHOR ⭐

Paul Evans <leonerd@leonerd.org.uk>


That's the whole page, fr fr πŸ’œ β€” brought to you by User Contributed Perl Documentation, perl v5.40.0, dated 2025-02-01. Go forth and resolve responsibly, queen πŸ‘‘βœ¨

πŸ“¦ where this page comes from