1. 程式人生 > >lua中是 ffi 解析 【是如何處理數據包的/pkt是如何傳進去的】 fsfsfs

lua中是 ffi 解析 【是如何處理數據包的/pkt是如何傳進去的】 fsfsfs

and 賦值 true dst cati multipl 又是 -- light

lua中的ffi是如何解析的呢?

拿bcc中對proto的解析說起;

metatype是有大學問的:

ffi.metatype(ffi.typeof(‘struct ip_t‘), {
    __index = { 
        -- Skip IP header length (stored as number of words)
        -- e.g. hlen = 5, Header Length = 5 x sizeof(u32) = 20 octets
        -- Mask first nibble and shift by 2 (multiplication by 4)
        icmp = function(e, dst) next_offset(e, dst, ffi.typeof(‘uint8_t‘), 0, 0x0f, 2) end,
        udp  = function(e, dst) next_offset(e, dst, ffi.typeof(‘uint8_t‘), 0, 0x0f, 2) end,
        tcp  = function(e, dst) next_offset(e, dst, ffi.typeof(‘uint8_t‘), 0, 0x0f, 2) end,
    }   
})

其中,ip_t就是

_G(pkg) 這是變量的最後一道屏障,如果在這裏訪問不到變量,那麽lua就要報錯了!

lua中的表真是高度抽象的一個概念:

pkg.ip.proto, pkg是全局的包,然後ip是這類變量的回調函數,proto又是ip的局部變量

在函數中metatype(‘struct net_t‘) 是一個

pkt是一個全局變量表示數據包,那麽這個pkt變量是如何賦值的呢?

lua中是 ffi 解析 【是如何處理數據包的/pkt是如何傳進去的】 fsfsfs