nbd_get_protocol(3)

πŸ’… nbd_get_protocol β€” bestie, which NBD flavour are we even on?

Okay so this is from the libnbd manual, section 3, and it's called nbd_get_protocol. She tells you which NBD protocol variant your connection is vibing with. That's it. That's the whole job. Iconic, honestly πŸ’–


✨ NAME ✨

nbd_get_protocol β€” return the NBD protocol variant πŸ¦‹


✨ SYNOPSIS ✨

#include <libnbd.h>

const char * nbd_get_protocol (
               struct nbd_handle *h
             );

Like, you hand her a handle and she hands you back a string. Simple as. πŸŽ€


🌸 DESCRIPTION 🌸

So the whole point: she returns the NBD protocol variant in use on the connection. Right now she gives you back exactly one of these three strings:

  • "oldstyle"
  • "newstyle"
  • "newstyle-fixed"
⚠️ and ngl, other strings might be returned in the future, so don't go assuming it's only ever these three, bestie 😭

Most modern NBD servers use "newstyle-fixed" β€” that's the main character of protocol variants fr fr πŸ‘‘


⭐ RETURN VALUE ⭐

She returns a statically allocated string. That means it's valid for the lifetime of the process, or until libnbd gets unloaded by dlclose(3). Whichever comes first.

🚨 Do not try to free the string. Not even a little. She did not ask for that. Put your free() down πŸ™ˆ

πŸ’€ ERRORS πŸ’€

On error, "NULL" is returned.

For how to get the actual deets on the error, peep "ERROR HANDLING" in libnbd(3).

Also, the following parameters must not be NULL: "h". For more on that, see "Non-NULL parameters" in libnbd(3). Like, no cap, h has to actually exist πŸ’…


🧚 NOTES 🧚

πŸ¦‹ Non-blocking call

This call does not block, because it just returns data that's already saved in the handle from the NBD protocol handshake. Nothing's being fetched, nothing's waiting around. It's giving instant gratification honestly ✨


πŸ‘‘ HANDLE STATE πŸ‘‘

nbd_get_protocol can be called when the handle is in the following states:

  • Handle created, before connecting β€” ❌ error 😭
  • Connecting β€” ❌ error 😭
  • Connecting & handshaking (opt_mode) β€” βœ… allowed 🫢
  • Connected to the server β€” βœ… allowed 🫢
  • Connection shut down β€” βœ… allowed 🫢
  • Handle dead β€” ❌ error πŸ’€

So basically: mid-handshake, connected, or shut down is all good. Before you connect at all? Nope. Dead handle? Absolutely not, she's gone 🌈


πŸ“ VERSION πŸ“

This function first appeared in libnbd 1.2. Baby's been around a minute πŸ’œ

If you need to test whether this function is available at compile time, check if the following macro is defined:

#define LIBNBD_HAVE_NBD_GET_PROTOCOL 1

πŸ”₯ SEE ALSO πŸ”₯

nbd_create(3), nbd_get_block_size(3), nbd_get_handshake_flags(3), nbd_get_structured_replies_negotiated(3), nbd_get_tls_negotiated(3), libnbd(3).

Go read those next, iykyk πŸ“š


πŸŽ€ AUTHORS πŸŽ€

Eric Blake

Richard W.M. Jones

Absolute legends, ty for your service πŸ«‘πŸ’–


Copyright Red Hat


✨ LICENSE ✨

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


🌈 and that's the whole page bestie, you're literally an NBD protocol variant expert now, periodt πŸ’…βœ¨

Source: libnbd-1.25.8 πŸ¦‹ dated 2026-10-13 β€” mwah, go slay some handshakes πŸ’–πŸŽ€

πŸ“¦ where this page comes from