[fpc-pascal] TUN/TAP
Henry Vermaak
henry.vermaak at gmail.com
Mon Oct 5 11:10:25 CEST 2009
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
More information about the fpc-pascal
mailing list