Re: FFI and endian conversion

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 26 Jul 2012 19:18:31 +0100

On Thu, Jul 26, 2012 at 2:08 PM, Luke Gorrie <luke@xxxxxxxx> wrote:
> On 25 July 2012 13:18, Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx> wrote:
>> I have been using ffi metatypes to add these accessors so you do not need
>> to explicitly convert. Eg so x.sin_port is in network byte order but you can
>> use x.port to get the host byte order using the metatable.
>> You could also hide any alignment issues using metatables.
> I'd be interested to see example code for this. (I'm a Lua newbie so it's
> not completely obvious how you're doing this.)

From around line 3044 of for
the port parts. Most of the Linux API is host endian so only a few
parts like networking are endian depdendent.


Other related posts: