LIBVDESLIRP(3)

πŸ’– LIBVDESLIRP(3) β€” the library functions manual, but make it cute πŸ’–

okay so bestie, welcome to LIBVDESLIRP(3) from the Library Functions Manual. this is the whole entire slirp API and it's genuinely iconic, no cap. sit down, grab a strawberry πŸ“, and let's go.


✨ NAME ✨

vdeslirp_open, vdeslirp_send, vdeslirp_recv, vdeslirp_fd, vdeslirp_close β€” the simple API for slirp πŸ¦‹


🌸 SYNOPSIS 🌸

#include *libvdeslirp.h*

struct vdeslirp *vdeslirp_open(SlirpConfig *cfg);

ssize_t vdeslirp_send(struct vdeslirp *slirp, const void *buf, size_t
count);

ssize_t vdeslirp_recv(struct vdeslirp *slirp, void *buf, size_t count);

int vdeslirp_fd(struct vdeslirp *slirp);

int vdeslirp_close(struct vdeslirp *slirp);

these functions are provided by libvdeslirp. link with -lvdeslirp, periodt. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

slirp is a TCP/IP emulator. it generates a virtual network using standard user privileges β€” so no root access needed, no CAP_NET_ADMIN, none of that 😌✨. this particular implementation uses libslirp.

vdeslirp_open creates a slirp network. the SlirpConfig structure is defined by libslirp and it contains these fields, ok? look at her, she's everything πŸ‘‘

typedef struct SlirpConfig {
    /* Version must be provided */
    uint32_t version;
    /*
     * Fields introduced in SlirpConfig version 1 begin
     */
    int restricted;
    bool in_enabled;
    struct in_addr vnetwork;
    struct in_addr vnetmask;
    struct in_addr vhost;
    bool in6_enabled;
    struct in6_addr vprefix_addr6;
    uint8_t vprefix_len;
    struct in6_addr vhost6;
    const char *vhostname;
    const char *tftp_server_name;
    const char *tftp_path;
    const char *bootfile;
    struct in_addr vdhcp_start;
    struct in_addr vnameserver;
    struct in6_addr vnameserver6;
    const char **vdnssearch;
    const char *vdomainname;
    /* Default: IF_MTU_DEFAULT */
    size_t if_mtu;
    /* Default: IF_MRU_DEFAULT */
    size_t if_mru;
    /* Prohibit connecting to 127.0.0.1:* */
    bool disable_host_loopback;
    /*
     * Enable emulation code (*warning*: this code isn't safe, it is not
     * recommended to enable it)
     */
    bool enable_emu;
    /*
     * Fields introduced in SlirpConfig version 2 begin
     */
} SlirpConfig;
⚠️ heads up bestie: version is mandatory, you literally have to provide it. and enable_emu turns on emulation code β€” the original says, and i quote, warning: this code isn't safe, it is not recommended to enable it. so like... don't πŸ™ˆ. also don't forget if_mtu defaults to IF_MTU_DEFAULT and if_mru defaults to IF_MRU_DEFAULT, and disable_host_loopback prohibits connecting to 127.0.0.1:*. πŸ’€

libvdeslirp provides helper functions to fill in the fields of this structure β€” go check libvdeslirpcfg(3) for those.

programs using libvdeslirp can send and receive packets with vdeslirp_send and vdeslirp_recv, and it feels exactly like being plugged into the host network (commonly the Internet, iykyk) through a NAT/Masquerading router 🌈. vdeslirp_fd hands you a valid file descriptor you can use to wait for incoming packets β€” with select or poll β€” and vdeslirp_close terminates a slirp network that vdeslirp_open created. clean up after yourself bestie 🧚


⭐ RETURN VALUE ⭐

vdeslirp_open returns the struct vdeslirp pointer when it works out πŸ’–. NULL is returned otherwise, sadly 😭. the return value of vdeslirp_open is the descriptor that must be passed as the first argument to every other function on this man page β€” yes, all of them, so hold onto it.

  • vdeslirp_send and vdeslirp_recv return the number of bytes sent or received, and -1 in case of error.
  • vdeslirp_fd returns a valid file descriptor which can be used to wait for incoming packets (using select or poll).
  • vdeslirp_close returns zero in case of success, -1 in case of error.

in case of failure, errno is set to indicate the type of error. classic errno behaviour, she ate πŸ”₯


🫢 SEE ALSO 🫢

libvdeslirpfwd(3), libvdeslirpcfg(3)


πŸ’€ BUGS πŸ’€

found a bug? not the vibe. bug reports should be addressed to info@virtualsquare.org πŸ“§


πŸ‘‘ AUTHOR πŸ‘‘

VirtualSquare. project leader: Renzo Davoli.


okay that's the whole page bestie, you're so smart for reading all of it πŸŽ€βœ¨ this absolute banger of a man page is brought to you by VirtualSquare, dated January 2024, and it lives at LIBVDESLIRP(3). bye love you, go write some packets πŸ’…πŸ’–

πŸ“¦ where this page comes from