#include #include #include #include #include #include #include #include #include #include #include #include "client.h" int update_interval; char *progname="loadmonitor"; static void usage(FILE *stream, int exitstatus) { fprintf(stream, "LoadMonitor version 1.1 protocol 1\n" "Usage: %s [-options ...] [hostname]\n", progname); if (fflush(stream) || ferror(stream)) exit(1); exit(exitstatus); } void options_parse(int argc, char *argv[]) { struct hostent *hostent; char *slash; if (argc>0) progname=argv[0]; slash=strrchr(progname, '/'); if (slash) progname=slash+1; update_interval=PKT_INTERVAL_SEC; if (argc>2) { usage(stderr, 1); } host=argc>1?argv[1]:"localhost"; if (!(hostent=gethostbyname(host))) { fprintf(stderr, "%s: Can't lookup hostname '%s'\n", progname, host); exit(1); } if (hostent->h_length!=4) { fprintf(stderr, "%s: address length for %s != 4\n", progname, host); exit(1); } memcpy(&addr.sin_addr, hostent->h_addr, 4); leafname=strdup(host); if (!leafname) { fprintf(stderr, "%s: strdup: %s\n", progname, strerror(ENOMEM)); exit(1); } slash=strchr(leafname, '.'); if (slash) *slash=0; } void options_daemonize(void) { }