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 πΈ
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
- centos-stream 10: libnbd-devel 1.25.8-1.el10 Β· LGPL-2.0-or-later AND BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms