int main(int argc, char* argv[]) #endif { char *s, buf[1500]; int fd; FILE* f; long pos = 0; struct ifreq interface; memset(&interface, 0, sizeof(interface)); interface.ifr_addr.sa_family = AF_INET; if(argc > 1) strcpy(interface.ifr_name, argv[1]); else strcpy(interface.ifr_name, "eth0"); scache_init(&statistic, 20, free); get_actual_ifaces(&argc, argv); if(xap_init(argc, argv, 0) != 1) { fprintf(stderr, "error while initializing xAP\n"); scache_free(&statistic); return -1; } if(ioctl(g_xap_sender_sockfd, SIOCGIFADDR, &interface) != 0) { printf("error while determining address\n"); exit(-1); } else { sprintf(buf, "src\n{\naddr=%s\n}\n", inet_ntoa(((struct sockaddr_in*)(&interface.ifr_addr))->sin_addr)); s = buf + strlen(buf); } fd = open("/proc/net/dev", O_ASYNC | O_NONBLOCK); fcntl(fd, F_SETFL, O_ASYNC); f = fdopen(fd, "r"); s = fgets(s, 1400, f); s = fgets(s, 1400, f); pos = ftell(f); while(1) { xap_heartbeat_tick(HBEAT_INTERVAL); gather(f, s); xap_send_message(buf); sleep(1); fseek(f, pos, SEEK_SET); } scache_free(&statistic); return 0; }
static void cache_type(ARGV *argv) { struct cache_type *cp; if (argv->argc != 2) { msg_error("usage: %s mode", argv->argv[0]); return; } if (scache != 0) scache_free(scache); for (cp = cache_types; cp->mode != 0; cp++) { if (strcmp(cp->mode, argv->argv[1]) == 0) { scache = cp->create(); return; } } msg_error("unknown cache type: %s", argv->argv[1]); }
int main(int unused_argc, char **unused_argv) { VSTRING *buf = vstring_alloc(1); ARGV *argv; struct action *ap; int interactive = isatty(0); endp_prop = vstring_alloc(1); dest_prop = vstring_alloc(1); vstream_fileno(VSTREAM_ERR) = 1; while (get_buffer(buf, VSTREAM_IN, interactive) != VSTREAM_EOF) { argv = argv_split(STR(buf), CHARS_SPACE); if (argv->argc > 0 && argv->argv[0][0] != '#') { msg_verbose = verbose_level; for (ap = actions; ap->command != 0; ap++) { if (strcmp(ap->command, argv->argv[0]) == 0) { if ((ap->flags & FLAG_NEED_CACHE) != 0 && scache == 0) msg_error("no session cache"); else ap->action(argv); break; } } msg_verbose = 0; if (ap->command == 0) msg_error("bad command: %s", argv->argv[0]); } argv_free(argv); } scache_free(scache); vstring_free(endp_prop); vstring_free(dest_prop); vstring_free(buf); exit(0); }