Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stefano-garzarella
Created March 7, 2023 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefano-garzarella/b4971c2bed3c632b48c5e2a823c1cbe1 to your computer and use it in GitHub Desktop.
Save stefano-garzarella/b4971c2bed3c632b48c5e2a823c1cbe1 to your computer and use it in GitHub Desktop.
vsock: get local CID using the available ioctl
#!/usr/bin/env python3
import socket
import struct
import fcntl
with open("/dev/vsock", "rb") as fd:
r = fcntl.ioctl(fd, socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID, " ")
cid = struct.unpack("I", r)[0]
print("Local CID: {}".format(cid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment