<div>Currently, I'm listening to NETLINK_KOBJECT_UEVENT messages with the following code:<br></div><div><br></div><div>union UeventBuffer {<br></div><div>  struct nlmsghdr netlink_header;<br></div><div>  char raw[8192];<br></div><div>};<br></div><div>  int sock = socket(PF_NETLINK, SOCK_RAW | SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);<br></div><div><br></div><div>  struct sockaddr_nl addr = {};<br></div><div>  addr.nl_family = AF_NETLINK;<br></div><div>  addr.nl_groups = 1 << 0;<br></div><div>  bind(sock, (struct sockaddr *)&addr, sizeof(addr));<br></div><div><br></div><div>  UeventBuffer buf = {};<br></div><div>  struct iovec iov = {};<br></div><div>  iov.iov_base = &buf;<br></div><div>  iov.iov_len = sizeof(buf);<br></div><div><br></div><div>  struct msghdr msg = {};<br></div><div>  struct sockaddr_nl src_addr = {};<br></div><div>  msg.msg_name = &src_addr;<br></div><div>  msg.msg_namelen = sizeof(src_addr);<br></div><div>  msg.msg_iov = &iov;<br></div><div>  msg.msg_iovlen = 1;<br></div><div><br></div><div>  int bytes = recvmsg(sock, &msg, 0);<br></div><div>  char *buf_str = buf.raw;<br></div><div>  // parse this buf_str ...<br></div><div><br></div><div>I have a few questions to clarify my understanding and to make this more robust:<br></div><div><div>1. If I add an Xbox One controller, which evtest shows to be /dev/input/event14 I get a whole host of messages, e.g:<br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0</i><br></div></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/input/input38</i><br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/input/input38/event14</i><br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/input/input38/js0</i><br></div><div><i>bind@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0</i><br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.1</i><br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.2</i><br></div><div><i>bind@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4</i><br></div><div><i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2</i><br></div><div><i>change@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2</i><br></div><div><div>Why so many? Can I filter them to just get the ones ending with /input/inputXX/eventXX?<br></div></div><div>2.
 Currently this only picks up input devices. How would I listen to /snd
devices, /hid devices, etc.? I assume some change to nl_groups, however
what should this be and where is this documented?<br></div><div>3.
Currently, I'm manually parsing the <b>buf_str</b> to extract the command and
device. Are there some supplied macros that parse this information in a
more robust way? (as is the case for RTNETLINK)<br></div><div><br></div><div>Thank you</div><div><br></div>