+ int arp_fd = -1;
+
+ if(device_type == DEVICE_TYPE_TAP) {
+ struct lifreq ifr = {};
+
+ if(ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0) {
+ logger(LOG_ERR, "Could not set flags on %s %s!", device_info, device);
+ return false;
+ }
+
+ strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name));
+ ifr.lifr_ppa = ppa;
+
+ /* Assign ppa according to the unit number returned by tun device */
+ if(ioctl(if_fd, SIOCSLIFNAME, &ifr) < 0) {
+ logger(LOG_ERR, "Could not set PPA %d on %s %s!", ppa, device_info, device);
+ return false;
+ }
+
+ if(ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0) {
+ logger(LOG_ERR, "Could not set flags on %s %s!", device_info, device);
+ return false;
+ }
+
+ /* Push arp module to if_fd */
+ if(ioctl(if_fd, I_PUSH, "arp") < 0) {
+ logger(LOG_ERR, "Could not push ARP module onto %s %s!", device_info, device);
+ return false;
+ }
+
+ /* Pop any modules on the stream */
+ while(true) {
+ if(ioctl(ip_fd, I_POP, NULL) < 0) {
+ break;
+ }
+ }
+
+ /* Push arp module to ip_fd */
+ if(ioctl(ip_fd, I_PUSH, "arp") < 0) {
+ logger(LOG_ERR, "Could not push ARP module onto %s!", IP_DEVICE);
+ return false;
+ }
+
+ /* Open arp_fd */
+ if((arp_fd = open(device, O_RDWR, 0)) < 0) {
+ logger(LOG_ERR, "Could not open %s: %s\n", device, strerror(errno));
+ return false;
+ }
+
+ /* Push arp module to arp_fd */
+ if(ioctl(arp_fd, I_PUSH, "arp") < 0) {
+ logger(LOG_ERR, "Could not push ARP module onto %s %s!", device_info, device);
+ return false;
+ }
+
+ /* Set ifname to arp */
+ struct strioctl strioc_if = {
+ .ic_cmd = SIOCSLIFNAME,
+ .ic_len = sizeof(ifr),
+ .ic_dp = (char *) &ifr,
+ };
+
+ if(ioctl(arp_fd, I_STR, &strioc_if) < 0) {
+ logger(LOG_ERR, "Could not set ifname to %s %s", device_info, device);
+ return false;
+ }
+ }