| 84 | | static int errcount = 0; |
| 85 | | struct ifreq ifreq; |
| 86 | | double value = 1.0; // netdev exists |
| 87 | | |
| 88 | | if (socknr < 0) { |
| 89 | | /* no open socket */ |
| 90 | | value = 0.0; |
| 91 | | SetResult(&result, R_NUMBER, &value); |
| 92 | | return; |
| 93 | | } |
| 94 | | |
| 95 | | strncpy(ifreq.ifr_name, R2S(arg1), sizeof(ifreq.ifr_name)); |
| 96 | | if (ioctl(socknr, SIOCGIFFLAGS, &ifreq) < 0) { |
| 97 | | if (errno == ENODEV) { |
| 98 | | /* device does not exists */ |
| 99 | | value = 0.0; |
| 100 | | } else { |
| 101 | | errcount++; |
| 102 | | if (1 == errcount % 1000) { |
| 103 | | error("%s: ioctl(FLAGS %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| 104 | | error(" (skip next 1000 errors)"); |
| 105 | | } |
| 106 | | return; |
| 107 | | } |
| 108 | | } |
| 109 | | |
| 110 | | /* device exists */ |
| | 84 | char buf[10240]; |
| | 85 | struct ifconf ifcnf; |
| | 86 | struct ifreq *ifreq; |
| | 87 | int len; |
| | 88 | double value = 0.0; // netdev doesn't exists |
| | 89 | char devname[80]; |
| | 90 | |
| | 91 | if (socknr < 0) { |
| | 92 | /* no open socket */ |
| | 93 | SetResult(&result, R_NUMBER, &value); |
| | 94 | return; |
| | 95 | } |
| | 96 | |
| | 97 | ifcnf.ifc_len = sizeof(buf); |
| | 98 | ifcnf.ifc_buf = buf; |
| | 99 | if (ioctl(socknr, SIOCGIFCONF, &ifcnf) < 0) { |
| | 100 | /* error getting list of devices */ |
| | 101 | error("%s: ioctl(IFCONF) for %s failed: %s", "plugin_netinfo", R2S(arg1), strerror(errno)); |
| | 102 | SetResult(&result, R_NUMBER, &value); |
| | 103 | return; |
| | 104 | } |
| | 105 | if (0 == ifcnf.ifc_len) { |
| | 106 | /* no interfaces found */ |
| | 107 | SetResult(&result, R_NUMBER, &value); |
| | 108 | return; |
| | 109 | } |
| | 110 | |
| | 111 | ifreq = (struct ifreq *) buf; |
| | 112 | len = sizeof(struct ifreq); |
| | 113 | strncpy(devname, R2S(arg1), sizeof(devname)); |
| | 114 | |
| | 115 | while (ifreq && *((char *) ifreq) && ((char *) ifreq) < buf + ifcnf.ifc_len) { |
| | 116 | if (*((char *) ifreq) && strncmp(ifreq->ifr_name, devname, sizeof(devname)) == 0) { |
| | 117 | /* found */ |
| | 118 | value = 1.0; |
| | 119 | SetResult(&result, R_NUMBER, &value); |
| | 120 | return; |
| | 121 | } |
| | 122 | |
| | 123 | (*(char **) &ifreq) += len; |
| | 124 | } |
| | 125 | |
| | 126 | /* device doesn't exists */ |
| 131 | | errcount++; |
| 132 | | if (1 == errcount % 1000) { |
| 133 | | error("%s: ioctl(IFHWADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| 134 | | error(" (skip next 1000 errors)"); |
| 135 | | } |
| 136 | | SetResult(&result, R_STRING, ""); |
| 137 | | return; |
| 138 | | } |
| 139 | | hw = (unsigned char*)ifreq.ifr_hwaddr.sa_data; |
| | 147 | errcount++; |
| | 148 | if (1 == errcount % 1000) { |
| | 149 | error("%s: ioctl(IFHWADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| | 150 | error(" (skip next 1000 errors)"); |
| | 151 | } |
| | 152 | SetResult(&result, R_STRING, ""); |
| | 153 | return; |
| | 154 | } |
| | 155 | hw = (unsigned char *) ifreq.ifr_hwaddr.sa_data; |
| 163 | | errcount++; |
| 164 | | if (1 == errcount % 1000) { |
| 165 | | error("%s: ioctl(IFADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| 166 | | error(" (skip next 1000 errors)"); |
| 167 | | } |
| 168 | | SetResult(&result, R_STRING, ""); |
| 169 | | return; |
| 170 | | } |
| 171 | | sin = (struct sockaddr_in *)&ifreq.ifr_addr; |
| | 179 | errcount++; |
| | 180 | if (1 == errcount % 1000) { |
| | 181 | error("%s: ioctl(IFADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| | 182 | error(" (skip next 1000 errors)"); |
| | 183 | } |
| | 184 | SetResult(&result, R_STRING, ""); |
| | 185 | return; |
| | 186 | } |
| | 187 | sin = (struct sockaddr_in *) &ifreq.ifr_addr; |
| 194 | | errcount++; |
| 195 | | if (1 == errcount % 1000) { |
| 196 | | error("%s: ioctl(IFNETMASK %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| 197 | | error(" (skip next 1000 errors)"); |
| 198 | | } |
| 199 | | SetResult(&result, R_STRING, ""); |
| 200 | | return; |
| 201 | | } |
| 202 | | sin = (struct sockaddr_in *)&ifreq.ifr_netmask; |
| | 210 | errcount++; |
| | 211 | if (1 == errcount % 1000) { |
| | 212 | error("%s: ioctl(IFNETMASK %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| | 213 | error(" (skip next 1000 errors)"); |
| | 214 | } |
| | 215 | SetResult(&result, R_STRING, ""); |
| | 216 | return; |
| | 217 | } |
| | 218 | sin = (struct sockaddr_in *) &ifreq.ifr_netmask; |
| 225 | | errcount++; |
| 226 | | if (1 == errcount % 1000) { |
| 227 | | error("%s: ioctl(IFBRDADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| 228 | | error(" (skip next 1000 errors)"); |
| 229 | | } |
| 230 | | SetResult(&result, R_STRING, ""); |
| 231 | | return; |
| 232 | | } |
| 233 | | sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr; |
| | 241 | errcount++; |
| | 242 | if (1 == errcount % 1000) { |
| | 243 | error("%s: ioctl(IFBRDADDR %s) failed: %s", "plugin_netinfo", ifreq.ifr_name, strerror(errno)); |
| | 244 | error(" (skip next 1000 errors)"); |
| | 245 | } |
| | 246 | SetResult(&result, R_STRING, ""); |
| | 247 | return; |
| | 248 | } |
| | 249 | sin = (struct sockaddr_in *) &ifreq.ifr_broadaddr; |