NAME(3)

✨ NAME ✨

krb5_getportbyname β€” bestie, it gets you a port number by name πŸ’…

Okay so this is a page from the Library Functions Manual, section 3, and it's about one tiny little function that does exactly one thing and does it slayfully. Let's get into it 🫢


πŸ“š LIBRARY

This one lives in the Kerberos 5 Library β€” that's libkrb5, and you link it with -lkrb5. Iconic. No notes. ✨


🌸 SYNOPSIS

#include <krb5.h>

int
krb5_getportbyname(krb5_context context, const char *service,
    const char *proto, int default_port);

Yes she takes four arguments. Yes that's a lot of words for "gimme a port number." We move πŸ’–


πŸ’– DESCRIPTION

So here's the tea, bestie πŸ“ β€” krb5_getportbyname() goes and grabs the port number for a service / proto pair, pulling it straight out of the global service table, and hands it back to you in network order. Periodt.

But β€” and this is the part where it's giving safety net 🧚 β€” if that pair isn't in the global table at all? Not a problem. It just gives you default_port instead. And heads up, that default_port is given in host order, not network order. Lowkey important. Don't mix them up πŸ™ˆ

Two orders, two vibes: the real answer comes back in network order, the fallback you hand in is in host order. That's just how she is πŸ’…

πŸŽ€ EXAMPLE

Here's literally the whole thing in one line, bestie:

int port = krb5_getportbyname(context, "kerberos", "tcp", 88);

Look at her go. Service "kerberos", proto "tcp", and if the global table's got nothing to say about it, we're falling back to 88. Ate. πŸ”₯


πŸ‘‘ SEE ALSO

  • krb5(3) β€” the mothership. Go read her next, fr fr 🌈

This page comes to you from HEIMDAL, dated August 15, 2004 β€” yes she's vintage, yes she still eats, and she's filed under NAME(3) in the manual. Mwah, take care of her πŸ’œβœ¨

πŸ“¦ where this page comes from