st r uct sockadd r _ll { unsigned sho r t sll_family; / * Always AF_PACKET * / unsigned sho r t sll_p r otocol; / * Physical - laye r p r otocol * / int sll_if i ndex; / * Inte r face numbe r * / unsigned sho r t sll_hatype; / * ARP ha r dwa r e type * / unsigned cha r sll_pkttype; / * Packet type * / unsigned cha r sll_halen; / * Length of add r ess * / unsigned cha r sll_add r [8]; / * Physical - laye r add r ess * / }; ᾇ https://man7.org/linux/man-pages/man7/packet.7.html
st r uct sockadd r _ll { unsigned sho r t sll_family; / * Always AF_PACKET * / unsigned sho r t sll_p r otocol; / * Physical - laye r p r otocol * / int sll_if i ndex; / * Inte r face numbe r * / unsigned sho r t sll_hatype; / * ARP ha r dwa r e type * / unsigned cha r sll_pkttype; / * Packet type * / unsigned cha r sll_halen; / * Length of add r ess * / unsigned cha r sll_add r [8]; / * Physical - laye r add r ess * / }; ᾇ https://man7.org/linux/man-pages/man7/packet.7.html この3つに詰める
st r uct sockadd r _ll { unsigned sho r t sll_family; / * Always AF_PACKET * / unsigned sho r t sll_p r otocol; / * Physical - laye r p r otocol * / int sll_if i ndex; / * Inte r face numbe r * / unsigned sho r t sll_hatype; / * ARP ha r dwa r e type * / unsigned cha r sll_pkttype; / * Packet type * / unsigned cha r sll_halen; / * Length of add r ess * / unsigned cha r sll_add r [8]; / * Physical - laye r add r ess * / }; ᾇ https://man7.org/linux/man-pages/man7/packet.7.html ushort, ushort, intの順
sll_family unsigned short (2byte) sll_protocol int (4byte) sll_i fi ndex 12byte Not set 34 Cの構造体のように詰める方法 pack('SSa16') [Socket : : AF_PACKET, PACKED_ETH_P_ALL, m r _if i ndex]
short (2byte) sll_family unsigned short (2byte) sll_protocol int (4byte) sll_i fi ndex 12byte Not set pack('SSa16') [Socket : : AF_PACKET, PACKED_ETH_P_ALL, m r _if i ndex] Arrayに設定したい値を詰める
short (2byte) sll_family unsigned short (2byte) sll_protocol int (4byte) sll_i fi ndex 12byte Not set .pack('SSa16') [Socket : : AF_PACKET, PACKED_ETH_P_ALL, m r _if i ndex] バイナリとしてパックした文字列にする
st r uct packet_m r eq { int m r _if i ndex; / * inte r face index * / unsigned sho r t m r _type; / * action * / unsigned sho r t m r _alen; / * add r ess length * / unsigned cha r m r _add r ess[8]; / * physical - laye r add r ess * / }; ᾇ https://man7.org/linux/man-pages/man7/packet.7.html
m r _if i ndex i = Socket.getifadd r s.f i nd { |ifadd r | ifadd r .name = = @ifname }&.if i ndex [[i].pack('c')].pack('a4') end def m r _type PACKET_MR_PROMISC = 0 x 0001 # NOTE : netpacket/packet.h [PACKET_MR_PROMISC].pack('S') end def m r _alen [0].pack('S') end def m r _add r ess [0].pack('C') * 8 end
m r _if i ndex i = Socket.getifadd r s.f i nd { |ifadd r | ifadd r .name = = @ifname }&.if i ndex [[i].pack('c')].pack('a4') end def m r _type PACKET_MR_PROMISC = 0 x 0001 # NOTE : netpacket/packet.h [PACKET_MR_PROMISC].pack('S') end def m r _alen [0].pack('S') end def m r _add r ess [0].pack('C') * 8 end Socket.getifaddrs でI/F名から indexを取得する
m r _if i ndex i = Socket.getifadd r s.f i nd { |ifadd r | ifadd r .name = = @ifname }&.if i ndex [[i].pack('c')].pack('a4') end def m r _type PACKET_MR_PROMISC = 0 x 0001 # NOTE : netpacket/packet.h [PACKET_MR_PROMISC].pack('S') end def m r _alen [0].pack('S') end def m r _add r ess [0].pack('C') * 8 end PACKET_MR_PROMISC を設定
m r _if i ndex i = Socket.getifadd r s.f i nd { |ifadd r | ifadd r .name = = @ifname }&.if i ndex [[i].pack('c')].pack('a4') end def m r _type PACKET_MR_PROMISC = 0 x 0001 # NOTE : netpacket/packet.h [PACKET_MR_PROMISC].pack('S') end def m r _alen [0].pack('S') end def m r _add r ess [0].pack('C') * 8 end mr_alen と mr_address は0埋め