Socket...eneric(3pm)

πŸ“¦
version 0.05 Β· 2 versions
, in fedora 43

so bestie… welcome to the manual page for Socket::Netlink::Generic, a User Contributed Perl Documentation page (manual section 3pm, she's iconic like that). This is the low-level ✨interface✨ to Linux's NETLINK_GENERIC netlink socket protocol. Let's get into it. πŸ¦‹


🌸 NAME 🌸

Socket::Netlink::Generic β€” interface to Linux's NETLINK_GENERIC netlink socket protocol. periodt. πŸ’…


✨ SYNOPSIS ✨

okay so here's the whole vibe, in code, verbatim, don't touch a single character bestie:

use Socket;
use Socket::Netlink qw( :DEFAULT
   pack_nlmsghdr unpack_nlmsghdr pack_nlattrs unpack_nlattrs );
use Socket::Netlink::Generic qw( :DEFAULT pack_genlmsghdr unpack_genlmsghdr );

socket( my $sock, PF_NETLINK, SOCK_RAW, NETLINK_GENERIC ) or die "socket: $!";

send( $sock, pack_nlmsghdr( NETLINK_GENERIC, NLM_F_REQUEST, 0, 0,
                pack_genlmsghdr( CTRL_CMD_GETFAMILY, 0,
                   pack_nlattrs( CTRL_ATTR_FAMILY_NAME, "TASKSTATS\0" )
                ),
             ),
   0 ) or die "send: $!";

recv( $sock, my $buffer, 65536, 0 ) or die "recv: $!";

my %attrs = unpack_nlattrs(
              (unpack_genlmsghdr( (unpack_nlmsghdr $buffer )[4] ) )[2]
            );

printf "TASKSTATS family ID is %d\n",
   unpack( "S", $attrs{CTRL_ATTR_FAMILY_ID()} );

look at her go 😭 she really did that. πŸŽ€


🫢 DESCRIPTION 🫢

So basically, this module is holding all the low-level constants and the structure handling functions you need to actually use the NETLINK_GENERIC protocol from Linux's PF_NETLINK socket family. That's the whole job. πŸ’ͺ

But ngl bestie β€” the module itself literally suggests you use the high-level object interface instead. See IO::Socket::Netlink::Generic. She said "I'm the internals, go talk to my more polished sister." πŸ‘‘


πŸ’… CONSTANTS πŸ’…

The following sets of constants are exported. Yes, all of them. We're not skipping. the way that I listed every single one…

NETLINK_GENERIC

that's her. the moment. the icon. ⭐

πŸŽ€ Control commands πŸŽ€

CTRL_CMD_NEWFAMILY    CTRL_CMD_DELFAMILY    CTRL_CMD_GETFAMILY
CTRL_CMD_NEWOPS       CTRL_CMD_DELOPS       CTRL_CMD_GETOPS
CTRL_CMD_NEWMCAST_GRP CTRL_CMD_DELMCAST_GRP CTRL_CMD_GETMCAST_GRP

πŸ¦‹ Attribute IDs πŸ¦‹

CTRL_ATTR_FAMILY_ID    CTRL_ATTR_FAMILY_NAME CTRL_ATTR_VERSION
CTRL_ATTR_HDRSIZE      CTRL_ATTR_MAXATTR     CTRL_ATTR_OPS
CTRL_ATTR_MCAST_GROUPS

πŸ“ Nested attribute IDs πŸ“

CTRL_ATTR_OP_ID CTRL_ATTR_OP_FLAGS
CTRL_ATTR_MCAST_GRP_NAME CTRL_ATTR_MCAST_GRP_ID
⚠️ heads up bestie, this one's important: if your kernel headers are particularly old, not all of these constants may be available. And if they're unavailable at compile time, no constant functions will be generated. so like… keep your headers updated, fr fr. 😭

🧚 STRUCTURE FUNCTIONS 🧚

✨ pack_genlmsghdr ✨

$buffer = pack_genlmsghdr( $cmd, $version, $body )

πŸ’œ unpack_genlmsghdr πŸ’œ

( $cmd, $version, $body ) = unpack_genlmsghdr( $buffer )

Pack or unpack a struct genlmsghdr and its payload body. that's it. that's the whole function. she's simple, she's effective, she ate. πŸ”₯


πŸ‘€ SEE ALSO πŸ‘€

  • Socket::Netlink β€” interface to Linux's PF_NETLINK socket family
  • IO::Socket::Netlink::Generic β€” Object interface to NETLINK_GENERIC netlink protocol sockets

go read those too bestie, iykyk πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk> β€” shoutout to the main character who wrote this. 🫢


and that's the whole page, bestie!! βœ¨πŸ’–πŸŽ€

signing off: this was perl v5.42.0, dated 2025-07-25, and she came to you as Socket...eneric(3pm). slay, bye!! πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from