getprotobyname replacement?

I've been tasked with converting our software from strictly an IPv4 environment to handling both IPv4 and IPv6. I'm very nearly done and everything seems to be progressing just fine. There's just one thing that's been nagging me for a while now, so I thought I'd enquire about this.

I've read that getprotobyname(), and it's reentrant counterpart (getprotobyname_r()) are obsolete. I've found links indicating this, but they don't say what the replacement for these are. If it's getaddrinfo(), (which I've been using to replace just about everything) then I'm a little confused. getaddrinfo() always seems to return IPPROTO_IP, regardless of the combination of hints. For example, calling getprotobyname_r ("UDP"...) returns IPPROTO_UDP for the protocol. Calling getaddrinfo(NULL, "0", hints,...) with hints set to...

family = AF_UNSPEC
socktype = SOCK_DGRAM
protocol = IPPROTO_UDP

...returns IPPROTO_IP for the info returned for both IPv4 and IPv6. It also doesn't matter whether or not an actual host and/or port (replacing the NULL and "0" respectively) are put in the call to getaddrinfo().

If the result of this is then to be used to create a socket, then won't the socket get created with the wrong protocol value?

What's weird is everything actually works just fine. That includes TCP, UDP, and multicast sockets. I'm just a little confused and don't quite understand what exactly is going on.

I'd appreciate any insight anyone can provide. Thanks.

AFAIK getprotobyname_r and it's other related _r friends are obsolescent.

getprotobyname is not. SUSv3 (POSIX) lists it as a required function. Use getprotobyname in threaded applications instead.