nbd_connect_tcp(3)
π nbd_connect_tcp β like, the libnbd manual page, bestie
okay so this is nbd_connect_tcp(3) from the libnbd manual, and it's genuinely one of the easiest ways to slide into an NBD server's DMs. sit down, grab a strawberry drink π, and let's go.
β¨ NAME β¨
nbd_connect_tcp β connect to an NBD server over a TCP port. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
#include <libnbd.h>
int nbd_connect_tcp (
struct nbd_handle *h, const char *hostname,
const char *port
);
three params, one handle, zero drama. iconic signature fr fr.
π¦ DESCRIPTION π¦
So you wanna connect (synchronously, babe β like, this call waits) to the NBD server that's listening on hostname:port. π
the port can be a port name like "nbd" (cute, named, whimsical) or it can be a port number as a string like "10809" (a string, note that β not an int, it's giving string energy). both slay, pick your fave.
β RETURN VALUE β
if the call is successful? it returns 0. that's the good ending. π«Ά
π ERRORS π
on error, -1 is returned. yeah. not the vibe.
for the full rundown on how to get further deets on the error, go read "ERROR HANDLING" in libnbd(3) β it's all there, iykyk.
also π¨ the following parameters must not be NULL: h, hostname, port. for more info see "Non-NULL parameters" in libnbd(3). do not test this. it will not go well.
π NOTES π
π₯ Blocking connect call
this call returns when the connection has been made β it blocks, hence the name, no surprises bestie. π
by default it proceeds all the way to transmission phase, but heads up: you can use nbd_set_opt_mode(3) if you want manual control over the option negotiation that happens before transmission phase. main character energy: you, driving the negotiation yourself. π
π§ HANDLE STATE π§
nbd_connect_tcp can be called when the handle is in the following state β vibe check time:
- Handle created, before connecting β β allowed (this is YOUR moment)
- Connecting β β error
- Connecting & handshaking (opt_mode) β β error
- Connected to the server β β error
- Connection shut down β β error
- Handle dead β β error
so basically: fresh handle only. one shot. periodt. π
π VERSION π
this function first appeared in libnbd 1.0. a legend from the start, honestly.
if you need to test whether this function is available at compile time (fancy!), check if the following macro is defined:
#define LIBNBD_HAVE_NBD_CONNECT_TCP 1
π SEE ALSO π
(the async version for when you're multitasking, the handle-maker, the opt-mode-enabler, and the big main manpage itself π«Ά)
π AUTHORS π
- Eric Blake
- Richard W.M. Jones
absolute icons, no cap.
πΈ 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
okay that's the whole page!! this lil beauty is from libnbd-1.25.8, dated 2026-10-13 β so yes she's current, she's fresh, she ate. mwah πβ¨ go connect to something bestie π¦
π¦ 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