ifreq becomes<br><br>Const<br><pre>TUNSETIFF = $400454ca<br>IFF_TUN = $0001<br>IFF_TAP = $0002</pre>type<br> ifreq = record<br> ifr_ifrn : record<br> case longint of<br> 0 : ( ifrn_name : array[0..15] of char );<br>
end;<br> ifr_ifru : record<br> case longint of<br> 0 : ( ifru_addr : sockaddr );<br> 1 : ( ifru_dstaddr : sockaddr );<br> 2 : ( ifru_broadaddr : sockaddr );<br>
3 : ( ifru_netmask : sockaddr );<br> 4 : ( ifru_hwaddr : sockaddr );<br> 5 : ( ifru_flags : smallint );<br> 6 : ( ifru_ivalue : longint );<br> 7 : ( ifru_mtu : longint );<br>
8 : ( ifru_map : ifmap );<br> 9 : ( ifru_slave : array[0..15] of char );<br> 10 : ( ifru_newname : array[0..15] of char );<br> 11 : ( ifru_data : __caddr_t );<br>
end;<br> end;<br><br><br>now i need to translate sockaddr, ifmap, __caddr_t etc<br><br>but thanks !<br><br><div class="gmail_quote">2009/10/5 Henry Vermaak <span dir="ltr"><<a href="mailto:henry.vermaak@gmail.com">henry.vermaak@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2009/10/3 Jorge Aldo G. de F. Junior <<a href="mailto:jagfj80@gmail.com">jagfj80@gmail.com</a>>:<br>
<div class="im">> Can anyone help me decypher the following code :<br>
><br>
> int tun_alloc(char *dev)<br>
> {<br>
> struct ifreq ifr;<br>
<br>
</div>First, you need to get a pascal definition of struct ifreq, so look in<br>
/usr/include/linux/if.h and translate it to pascal (or try and use<br>
h2pas).<br>
<div class="im"><br>
> int fd, err;<br>
><br>
> if( (fd = open("/dev/net/tun", O_RDWR)) < 0 )<br>
> return tun_alloc_old(dev);<br>
<br>
</div>You will have to use fpopen here.<br>
<div class="im"><br>
><br>
><br>
> memset(&ifr, 0, sizeof(ifr));<br>
<br>
</div>Use fillchar.<br>
<div class="im"><br>
><br>
> /* Flags: IFF_TUN - TUN device (no Ethernet headers)<br>
> * IFF_TAP - TAP device<br>
> *<br>
> * IFF_NO_PI - Do not provide packet information<br>
><br>
> */<br>
<br>
</div>These flags are defined int /sys/include/linux/if_tun.h.<br>
<div class="im"><br>
> ifr.ifr_flags = IFF_TUN;<br>
> if( *dev )<br>
> strncpy(ifr.ifr_name, dev, IFNAMSIZ);<br>
<br>
</div>ifr_name is defined to be ifr_ifrn.ifrn_name in if.h.<br>
<div class="im"><br>
><br>
> if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){<br>
<br>
</div>lol. TUNSETIFF (_IOW('T', 202, int)) is generated by the various<br>
macros in /usr/include/asm-generic/ioctl.h. Work it out, or write a c<br>
program to give you the number. Then use fpioctl.<br>
<br>
The rest should be straight forward.<br>
<font color="#888888"><br>
Henry<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br>