Obtaining essence through ioctl in ruby

In order not to rely on cordless tools, I want to get essays directly from the device using ioctl, in C this will not be a problem, but in Ruby it is completely different.

The problem is this: struct from wireless.h, which is used as ioctl login / response:

struct  iw_point
{
  void __user *pointer; /* Pointer to the data  (in user space) */
  __u16   length;   /* number of fields or size in bytes */
  __u16   flags;    /* Optional params */
};

The portion of the pointer must be a valid address of the memory region, followed by a length in bytes, followed by a flag field. I tried with an Array # pack array and a bit-struct gem, but haven't found a solution yet.

Is there a way around this memory pointer issue?

+3
source share
2 answers

, , , , "p" :

require "socket"

# Copied from wireless.h
SIOCGIWESSID      = 0x8B1B
IW_ESSID_MAX_SIZE = 32

iwreq = [ "wlan0", " " * IW_ESSID_MAX_SIZE, IW_ESSID_MAX_SIZE, 0 ].pack("a16pII")

sock = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)

sock.ioctl(SIOCGIWESSID, iwreq)

interface, essid, len, flags = iwreq.unpack("a16pII")

puts essid
+4

, Ruby- ( C) ioctl. ioctl Ruby. , ios.ioctl ioctl "write".

+1

Source: https://habr.com/ru/post/1718068/


All Articles