[fpc-pascal] Translating c records

silvioprog silvioprog at gmail.com
Wed Apr 24 22:50:20 CEST 2019


On Wed, Apr 24, 2019 at 5:41 PM Rainer Stratmann <
rainerstratmann at t-online.de> wrote:

> struct sockaddr_ll {
>      unsigned short sll_family;
>      unsigned short sll_protocol;
>      int            sll_ifindex;
>      unsigned short sll_hatype;
>      unsigned char  sll_pkttype;
>      unsigned char  sll_halen;
>      unsigned char  sll_addr[8];
>  };
>
> type
>  sockaddr_ll = record
>   sll_family : word;
>   sll_protocol : word;
>   sll_ifindex : integer;
>   sll_hatype : word;
>   sll_pkttype : byte;
>   sll_halen : byte;
>   sll_addr: array[ 0 .. 7 ] of byte;
>  end;
>
> Is this correct?


It seems OK, however, if you want portability too, you should:

uses
  ctypes;

{$PACKRECORDS C} // already commented by Michael

type
  sockaddr_ll = record
    sll_family: cushort;
    sll_protocol: cushort;
    sll_ifindex: cint;
    sll_hatype: cushort;
    sll_pkttype: cuchar;
    sll_halen: cuchar;
    sll_addr: array[0..7] of cuchar;
 end;

cheers

--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190424/8c697c13/attachment.html>


More information about the fpc-pascal mailing list