#include <ctype.h>
#include <errno.h>
#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <netinet/in.h>
#include <pthread.h>
#include "diskio.h"
memset(netstats, 0, sizeof(netstats));
}
+/* We should check if this is ok with OpenBSD and NetBSD as well. */
+int interface_up(const char *dev)
+{
+ int fd;
+ struct ifreq ifr;
+
+ if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+ CRIT_ERR("could not create sockfd");
+ return 0;
+ }
+ strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
+ /* if device does not exist, treat like not up */
+ if (errno != ENODEV && errno != ENXIO)
+ perror("SIOCGIFFLAGS");
+ goto END_FALSE;
+ }
+
+ if (!(ifr.ifr_flags & IFF_UP)) /* iface is not up */
+ goto END_FALSE;
+ if (ifup_strictness == IFUP_UP)
+ goto END_TRUE;
+
+ if (!(ifr.ifr_flags & IFF_RUNNING))
+ goto END_FALSE;
+ if (ifup_strictness == IFUP_LINK)
+ goto END_TRUE;
+
+ if (ioctl(fd, SIOCGIFADDR, &ifr)) {
+ perror("SIOCGIFADDR");
+ goto END_FALSE;
+ }
+ if (((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_addr))->sin_addr.s_addr)
+ goto END_TRUE;
+
+END_FALSE:
+ close(fd);
+ return 0;
+END_TRUE:
+ close(fd);
+ return 1;
+}
+
void free_dns_data(void)
{
int i;
};
void clear_net_stats(void);
struct net_stat *get_net_stat(const char *);
+int interface_up(const char *dev);
void get_adt746x_cpu(char *, size_t);
void get_adt746x_fan(char *, size_t);
case OBJ_disk_protect:
free(data.s);
break;
- case OBJ_if_up:
- free(data.ifblock.s);
- free(data.ifblock.str);
- break;
case OBJ_if_gw:
free(data.ifblock.s);
free(data.ifblock.str);
free(data.s);
break;
#endif
+#if (defined(__FreeBSD__) || defined(__linux__))
+ case OBJ_if_up:
+ free(data.ifblock.s);
+ free(data.ifblock.str);
+#endif
#ifdef XMMS2
case OBJ_xmms2_artist:
if (info.xmms2.artist) {
END OBJ(ibm_volume, 0)
END OBJ(ibm_brightness, 0)
#endif
- END OBJ_IF(if_up, 0)
- if (!arg) {
- ERR("if_up needs an argument");
- obj->data.ifblock.s = 0;
- } else
- obj->data.ifblock.s = strndup(arg, text_buffer_size);
END OBJ_IF(if_gw, 0)
END OBJ(ioscheduler, 0)
if (!arg) {
}
#endif /* __linux__ */
+#if (defined(__FreeBSD__) || defined(__linux__))
+ END OBJ_IF(if_up, 0)
+ if (!arg) {
+ ERR("if_up needs an argument");
+ obj->data.ifblock.s = 0;
+ } else
+ obj->data.ifblock.s = strndup(arg, text_buffer_size);
+#endif
#if defined(__OpenBSD__)
END OBJ(obsd_sensors_temp, 0)
if (!arg) {
get_ibm_acpi_brightness(p, p_max_size);
}
#endif /* IBM */
- OBJ(if_up) {
- if ((obj->data.ifblock.s)
- && (!interface_up(obj->data.ifblock.s))) {
- DO_JUMP;
- }
- }
OBJ(if_gw) {
if (!cur->gw_info.count) {
DO_JUMP;
get_powerbook_batt_info(p, p_max_size, obj->data.i);
}
#endif /* __linux__ */
-
+#if (defined(__FreeBSD__) || defined(__linux__))
+ OBJ(if_up) {
+ if ((obj->data.ifblock.s)
+ && (!interface_up(obj->data.ifblock.s))) {
+ DO_JUMP;
+ }
+ }
+#endif
#ifdef __OpenBSD__
OBJ(obsd_sensors_temp) {
obsd_sensors.device = sensor_device;
#include <sys/types.h>
#include <sys/vmmeter.h>
#include <sys/user.h>
-#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_mib.h>
#include <net/if_media.h>
#include <net/if_var.h>
-#include <netinet/in.h>
#include <devstat.h>
-#include <fcntl.h>
#include <ifaddrs.h>
#include <limits.h>
#include <unistd.h>
return strndup("n/a", text_buffer_size);
}
-int interface_up(const char *dev)
-{
- int fd;
- struct ifreq ifr;
-
- if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- CRIT_ERR("could not create sockfd");
- return 0;
- }
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
- if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
- /* if device does not exist, treat like not up */
- if (errno != ENODEV)
- perror("SIOCGIFFLAGS");
- goto END_FALSE;
- }
-
- if (!(ifr.ifr_flags & IFF_UP)) /* iface is not up */
- goto END_FALSE;
- if (ifup_strictness == IFUP_UP)
- goto END_TRUE;
-
- if (!(ifr.ifr_flags & IFF_RUNNING))
- goto END_FALSE;
- if (ifup_strictness == IFUP_LINK)
- goto END_TRUE;
-
- if (ioctl(fd, SIOCGIFADDR, &ifr)) {
- perror("SIOCGIFADDR");
- goto END_FALSE;
- }
- if (((struct sockaddr_in *)&(ifr.ifr_ifru.ifru_addr))->sin_addr.s_addr)
- goto END_TRUE;
-
-END_FALSE:
- close(fd);
- return 0;
-END_TRUE:
- close(fd);
- return 1;
-}
-
#define COND_FREE(x) if(x) free(x); x = 0
#define SAVE_SET_STRING(x, y) \
if (x && strcmp((char *)x, (char *)y)) { \
struct i8k_struct i8k;
-int interface_up(const char *dev);
char *get_ioscheduler(char *);
int get_laptop_mode(void);
void update_gateway_info(void);
OBJ_smapi_bat_power,
OBJ_if_smapi_bat_installed,
#endif /* IBM */
- OBJ_if_up,
OBJ_if_gw,
OBJ_ioscheduler,
OBJ_gw_iface,
OBJ_wireless_link_qual_perc,
OBJ_wireless_link_bar,
#endif /* __linux__ */
+#if defined(__FreeBSD__) || defined(__linux__)
+ OBJ_if_up,
+#endif
OBJ_if_empty,
OBJ_if_match,
OBJ_if_existing,