I was writing a program to assign IP address to beaglebone black in python using ioctl.
(reference How to assign IP address to interface in python? and Getting IP address of the beagleboard using python )
Since IOCTL method implemented in Linux Kernel needs all the parameters to be passed into a particular structure. Hence I constructed all those parameters as a struct and then passed to IOCTL.
bin_ip = socket.inet_aton('192.168.0.1')
ifreq = struct.pack('16sH2s4s8s', 'eth0', socket.AF_INET, '\x00'*2, bin_ip, '\x00'*8)
found partial meaning of first argument at https://docs.python.org/3.0/library/struct.html as s= char[] and H = unsigned short what is meaning of numbers 16 2 4 8 written with s and H
edit: For the 's' format character, the count is interpreted as the length of the bytes, for example, 16s means a single 16-byte string followed by 1 unsigned short, 2-byte string ,4-byte string , 8-byte string
why 4th argument is '\x00\x00'and last argument is '\x00\x00\x00\x00\x00\x00\x00\x00'? Is this the standard format / expected format?