+ switch (st->ifconfig_type) {
+ case TUN_CONFIG_LINUX:
+ sys_cmd(st->ifconfig_path,"ifconfig",st->interface_name,
+ hostaddr,"netmask","255.255.255.255","-broadcast",
+ "-multicast",
+ "pointopoint",secnetaddr,"mtu",mtu,"up",(char *)0);
+ break;
+ case TUN_CONFIG_BSD:
+ sys_cmd(st->ifconfig_path,"ifconfig",st->interface_name,
+ hostaddr,"netmask","255.255.255.255",
+ secnetaddr,"mtu",mtu,"up",(char *)0);
+ break;
+ case TUN_CONFIG_SOLARIS25:
+ sys_cmd(st->ifconfig_path,"ifconfig",st->interface_name,
+ hostaddr,secnetaddr,"mtu",mtu,"up",(char *)0);
+ break;
+ case TUN_CONFIG_IOCTL:
+#if HAVE_NET_IF_H && ! __APPLE__
+ {
+ int fd;
+ struct ifreq ifr;
+ struct sockaddr_in *sa;
+ fd=socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+
+ /* Interface address */
+ strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
+ sa=(struct sockaddr_in *)&ifr.ifr_addr;
+ FILLZERO(*sa);
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(st->local_address);
+ if (ioctl(fd,SIOCSIFADDR, &ifr)!=0) {
+ fatal_perror("tun_apply: SIOCSIFADDR");
+ }
+#ifdef SIOCSIFNETMASK
+ /* Netmask */
+ strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
+ sa=(struct sockaddr_in *)&ifr.ifr_netmask;
+ FILLZERO(*sa);
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(0xffffffff);
+ if (ioctl(fd,SIOCSIFNETMASK, &ifr)!=0) {
+ fatal_perror("tun_apply: SIOCSIFNETMASK");
+ }
+#endif
+ /* Destination address (point-to-point) */
+ strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
+ sa=(struct sockaddr_in *)&ifr.ifr_dstaddr;
+ FILLZERO(*sa);
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(st->nl.secnet_address);
+ if (ioctl(fd,SIOCSIFDSTADDR, &ifr)!=0) {
+ fatal_perror("tun_apply: SIOCSIFDSTADDR");
+ }
+ /* MTU */
+ strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
+ ifr.ifr_mtu=st->nl.mtu;
+ if (ioctl(fd,SIOCSIFMTU, &ifr)!=0) {
+ fatal_perror("tun_apply: SIOCSIFMTU");
+ }
+ /* Flags */
+ strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
+ ifr.ifr_flags=IFF_UP|IFF_POINTOPOINT|IFF_RUNNING|IFF_NOARP;
+ if (ioctl(fd,SIOCSIFFLAGS, &ifr)!=0) {
+ fatal_perror("tun_apply: SIOCSIFFLAGS");
+ }