| 57 | } clone_match_type; |
| 58 | |
| 59 | static void |
| 60 | list_cloners(void) |
| 61 | { |
| 62 | #ifndef FSTACK |
| 63 | ifconfig_handle_t *lifh; |
| 64 | char *cloners; |
| 65 | size_t cloners_count; |
| 66 | |
| 67 | lifh = ifconfig_open(); |
| 68 | if (lifh == NULL) |
| 69 | return; |
| 70 | |
| 71 | if (ifconfig_list_cloners(lifh, &cloners, &cloners_count) < 0) |
| 72 | errc(1, ifconfig_err_errno(lifh), "unable to list cloners"); |
| 73 | ifconfig_close(lifh); |
| 74 | |
| 75 | for (const char *name = cloners; |
| 76 | name < cloners + cloners_count * IFNAMSIZ; |
| 77 | name += IFNAMSIZ) { |
| 78 | if (name > cloners) |
| 79 | putchar(' '); |
| 80 | printf("%s", name); |
| 81 | } |
| 82 | putchar('\n'); |
| 83 | free(cloners); |
| 84 | #else |
| 85 | struct if_clonereq ifcr; |
| 86 | char *cp, *buf; |
| 87 | int idx; |
| 88 | int s; |
| 89 | |
| 90 | s = socket(AF_LOCAL, SOCK_DGRAM, 0); |
| 91 | if (s == -1) |
| 92 | err(1, "socket(AF_LOCAL,SOCK_DGRAM)"); |
| 93 | |
| 94 | memset(&ifcr, 0, sizeof(ifcr)); |
| 95 | |
| 96 | if (ioctl(s, SIOCIFGCLONERS, &ifcr) < 0) |
| 97 | err(1, "SIOCIFGCLONERS for count"); |
| 98 | |
| 99 | buf = malloc(ifcr.ifcr_total * IFNAMSIZ); |
| 100 | if (buf == NULL) |
| 101 | err(1, "unable to allocate cloner name buffer"); |
| 102 | |
| 103 | ifcr.ifcr_count = ifcr.ifcr_total; |
| 104 | ifcr.ifcr_buffer = buf; |
| 105 | |
| 106 | size_t offset = (char *)&(ifcr.ifcr_buffer) - (char *)&(ifcr); |
| 107 | size_t clen = ifcr.ifcr_total * IFNAMSIZ; |
| 108 | if (ioctl_va(s, SIOCIFGCLONERS, &ifcr, 3, offset, buf, clen) < 0) |
| 109 | err(1, "SIOCIFGCLONERS for names"); |
| 110 | |
| 111 | /* |
| 112 | * In case some disappeared in the mean time, clamp it down. |
| 113 | */ |
| 114 | if (ifcr.ifcr_count > ifcr.ifcr_total) |
| 115 | ifcr.ifcr_count = ifcr.ifcr_total; |
| 116 | |