int main(int argc, char *argv[]) { int o; while(-1 != (o = getopt(argc, argv, "f:m:hvVDpt"))) { switch(o) { case 'f': strcpy(g_scan_interface, optarg); break; } } //- Check if same process is running. FILE *fp = fopen(LIGHTTPD_ARPPING_PID_FILE_PATH, "r"); if (fp) { fclose(fp); exit(EXIT_FAILURE); return 0; } //- Write PID file pid_t pid = getpid(); fp = fopen(LIGHTTPD_ARPPING_PID_FILE_PATH, "w"); if (!fp) { exit(EXIT_FAILURE); } fprintf(fp, "%d\n", pid); fclose(fp); #if EMBEDDED_EANBLE sigset_t sigs_to_catch; //- set the signal handler sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGTERM); sigaddset(&sigs_to_catch, SIGUSR1); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGTERM, sigaction_handler); signal(SIGUSR1, sigaction_handler); #else struct sigaction act; memset(&act, 0, sizeof(act)); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); sigaction(SIGUSR1, &act, NULL); act.sa_sigaction = sigaction_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGALRM, &act, NULL); sigaction(SIGCHLD, &act, NULL); sigaction(SIGUSR1, &act, NULL); #endif //int dbglv = -1;//9; int dbglv = 0; smbc_init(get_auth_data_fn, dbglv); start_scan_sambaserver(0); time_t prv_ts = 0; while (!is_shutdown) { sleep(10); time_t cur_ts = time(NULL); #if EMBEDDED_EANBLE if(prv_ts == 0 || cur_ts - prv_ts >= ARP_TIME_INTERVAL){ dumparptable(); query_one_hostname(); prv_ts = cur_ts; } #else if( prv_ts == 0 || cur_ts - prv_ts >= ARP_TIME_INTERVAL ){ on_arpping_timer_handler2(0); prv_ts = cur_ts; } #endif if (g_kill_list) { smb_srv_info_t *c; smb_srv_info_t *tmp = NULL; g_kill_list = 0; c = smb_srv_info_list; if (c != NULL) { while (1) { int end = (c->next == NULL) ? 1 : 0; if (end == 0) { tmp = c->next; Cdbg(DBE, "next, ip=%s", tmp->ip->ptr); } else tmp = NULL; if (c) { Cdbg(DBE, "remove , ip=[%s]", c->ip->ptr); DLIST_REMOVE(smb_srv_info_list, c); free(c); } else break; if (end == 1) break; c = tmp; } } g_threadIndex = 0; } } Cdbg(DBE, "Success to terminate lighttpd-arpping....."); exit(EXIT_SUCCESS); return 0; }
int main(int argc, char *argv[]) { int o; while(-1 != (o = getopt(argc, argv, "f:m:hvVDpt"))) { switch(o) { case 'f': strcpy(g_scan_interface, optarg); break; } } //- Check if same process is running. FILE *fp = fopen(LIGHTTPD_ARPPING_PID_FILE_PATH, "r"); if (fp) { fclose(fp); Cdbg(DBE, "lighttpd-arpping is already exist!"); return 0; } //- Write PID file pid_t pid = getpid(); fp = fopen(LIGHTTPD_ARPPING_PID_FILE_PATH, "w"); if (!fp) { exit(EXIT_FAILURE); } fprintf(fp, "%d\n", pid); fclose(fp); #if EMBEDDED_EANBLE sigset_t sigs_to_catch; //- set the signal handler sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGTERM); sigaddset(&sigs_to_catch, SIGUSR1); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); signal(SIGTERM, sigaction_handler); signal(SIGUSR1, sigaction_handler); #else struct sigaction act; memset(&act, 0, sizeof(act)); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); sigaction(SIGUSR1, &act, NULL); act.sa_sigaction = sigaction_handler; sigemptyset(&act.sa_mask); act.sa_flags = SA_SIGINFO; sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); sigaction(SIGHUP, &act, NULL); sigaction(SIGALRM, &act, NULL); sigaction(SIGCHLD, &act, NULL); sigaction(SIGUSR1, &act, NULL); #endif int dbglv = 9; smbc_init(get_auth_data_fn, dbglv); Cdbg(DBE, "start arpping_thread..."); start_scan_sambaserver(0); time_t prv_ts = 0; while (!is_shutdown) { sleep(10); time_t cur_ts = time(NULL); #if EMBEDDED_EANBLE if(prv_ts == 0 || cur_ts - prv_ts >= ARP_TIME_INTERVAL){ dumparptable(); query_one_hostname(); prv_ts = cur_ts; } #else if(cur_ts - prv_ts >= ARP_TIME_INTERVAL){ on_arpping_timer_handler2(0); prv_ts = cur_ts; } #endif } fprintf(stderr, "Success to terminate lighttpd-arpping.....\n"); exit(EXIT_SUCCESS); }