[fpc-pascal] TUN/TAP

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Wed Oct 7 04:27:48 CEST 2009


ifreq becomes

Const

TUNSETIFF = $400454ca
IFF_TUN   = $0001
IFF_TAP   = $0002

type
     ifreq = record
          ifr_ifrn : record
              case longint of
                 0 : ( ifrn_name : array[0..15] of char );
              end;
          ifr_ifru : record
              case longint of
                 0 : ( ifru_addr : sockaddr );
                 1 : ( ifru_dstaddr : sockaddr );
                 2 : ( ifru_broadaddr : sockaddr );
                 3 : ( ifru_netmask : sockaddr );
                 4 : ( ifru_hwaddr : sockaddr );
                 5 : ( ifru_flags : smallint );
                 6 : ( ifru_ivalue : longint );
                 7 : ( ifru_mtu : longint );
                 8 : ( ifru_map : ifmap );
                 9 : ( ifru_slave : array[0..15] of char );
                 10 : ( ifru_newname : array[0..15] of char );
                 11 : ( ifru_data : __caddr_t );
              end;
       end;


now i need to translate sockaddr, ifmap, __caddr_t etc

but thanks !

2009/10/5 Henry Vermaak <henry.vermaak at gmail.com>

> 2009/10/3 Jorge Aldo G. de F. Junior <jagfj80 at gmail.com>:
> > Can anyone help me decypher the following code :
> >
> > int tun_alloc(char *dev)
> >   {
> >       struct ifreq ifr;
>
> First, you need to get a pascal definition of struct ifreq, so look in
> /usr/include/linux/if.h and translate it to pascal (or try and use
> h2pas).
>
> >       int fd, err;
> >
> >       if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )
> >          return tun_alloc_old(dev);
>
> You will have to use fpopen here.
>
> >
> >
> >       memset(&ifr, 0, sizeof(ifr));
>
> Use fillchar.
>
> >
> >       /* Flags: IFF_TUN   - TUN device (no Ethernet headers)
> >        *        IFF_TAP   - TAP device
> >        *
> >        *        IFF_NO_PI - Do not provide packet information
> >
> >        */
>
> These flags are defined int /sys/include/linux/if_tun.h.
>
> >       ifr.ifr_flags = IFF_TUN;
> >       if( *dev )
> >          strncpy(ifr.ifr_name, dev, IFNAMSIZ);
>
> ifr_name is defined to be ifr_ifrn.ifrn_name in if.h.
>
> >
> >       if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
>
> lol.  TUNSETIFF (_IOW('T', 202, int)) is generated by the various
> macros in /usr/include/asm-generic/ioctl.h.  Work it out, or write a c
> program to give you the number.  Then use fpioctl.
>
> The rest should be straight forward.
>
> Henry
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20091006/f663f63b/attachment.html>


More information about the fpc-pascal mailing list