int main(int argc, char *argv[]) { initGlobalParser(); setRegisterRootName("apoEditor"); if (argc == 1) { return runDevelopTool(argc, argv); } parser_args(argc, argv); if (__run_type == 1) { return runGm(argc, argv); } else if (__run_type == 2) { return runEditor(argc, argv); } else { return runDevelopTool(argc, argv); } }
/********************************************************* ****************** Main Function ****************** *********************************************************/ int main(int agrc, char *agrv[]) { int rt = 0; /* return value of function main */ char buf[128] = {0}; /** * Get paramters from the command line */ if (parser_args(agrc, agrv) < 0) { print_usage(); rt = -1; goto error; }; if (perm_flag) { rt = detect_permission(path, perm); switch (rt) { case 0: printf("\033[1;36m%s has permission %s? : \033[1;35mno\n\033[0m", path, perm); break; case 1: printf("\033[1;36m%s has permission %s? : \033[1;35myes\n\033[0m", path, perm); break; default: printf("\033[1;36m%s has permission %s? : \033[1;31mfailed\n\033[0m", path, perm); break; } } if (size_flag) { rt = get_file_size(path); if (rt > 0) printf("\033[1;34msize of %s is: \033[1;35m%d bytes\n\033[0m", path, rt); else printf("\033[1;31m%s get size failed\n\033[0m", path); } if (basename_flag) { if (basename(path, buf, sizeof(buf)) != NULL) printf("\033[1;34mbasename of %s is: \033[1;35m%s\n\033[0m", path, buf); else printf("\033[1;31m%s get basename failed\n\033[0m", path); } if (dirname_flag) { if (dirname(path, buf, sizeof(buf)) != NULL) printf("\033[1;34mdirname of %s is: \033[1;35m%s\n\033[0m", path, buf); else printf("\033[1;31m%s get dirname failed\n\033[0m", path); } if (create_flag) { if (!make_dir(path, 0755)) printf("\033[1;35mcreate dir %s success\n\033[0m", path); else printf("\033[1;31mcreate dir %s failed\n\033[0m", path); } error: /** * error handling */ return rt; }
int main(int ac, char **av) { t_all *all; all = (t_all *)malloc(sizeof(t_all)); all->ac = ac; init_all(all); parser_args(av, all); free_list(&all->args); free_list(&all->list); free_list(&all->list_bis); free(all); exit(EXIT_SUCCESS); }
/********************************************************* ****************** Main Function ****************** *********************************************************/ int main(int agrc, char *agrv[]) { int rt = 0; /* return value of function main */ int help_flag = 0; char *ip = NULL; int port = 0; struct options opts[] = { {"-h", "--help", 0, RET_INT, (void **)&help_flag }, {"-i", "--ip", 1, RET_STRING, (void **)&ip }, {"-p", "--port", 1, RET_INT, (void **)&port }, {"-t", "--t", 1, RET_INT, NULL }, {NULL, NULL, 0, 0, NULL} }; parser_args(agrc, agrv, opts); printf("help_flag: %d\n", help_flag); if (ip != NULL) printf("ip: %s\n", ip); printf("port: %d\n", port); return rt; }
/********************************************************* ****************** Main Function ****************** *********************************************************/ int main(int agrc, char *agrv[]) { int rt = 0; /* return value of function main */ /** * Get paramters from the command line */ if (parser_args(agrc, agrv) < 0) { //print_usage(); rt = -1; goto error; }; /** * get net mac address */ if (netmac_flag) { unsigned char buf[6]; struct timeval start = {0}, end = {0}; int tuse = 0; int ret = 0; gettimeofday(&start, NULL); if ((ret = get_net_mac(ip, buf, 0)) > 0) { gettimeofday(&end, NULL); tuse = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec); printf("\033[0;m%s MAC Address: \033[0;35m%02x:%02x:%02x:%02x:%02x:%02x\033[0m, used %d.%03ds.\n", ip, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], (int)ret/ 1000000, (int)(ret % 1000000)); } else { printf("\033[0;31mget %s net mac failed\n\033[0m", ip); return -1; } return 0; } /** * get mac address */ if (mac_flag) { if (!strlen(ether)) get_ifname(ether); unsigned char buf[6] = {0}; char *str = NULL, *save_str = NULL; for (str = ether; ; str = NULL) { save_str = strtok(str, " "); if (save_str == NULL) return -1; if (!get_mac_addr(save_str, buf)) { printf("\033[0;32m%s: \033[0;35m%02x:%02x:%02x:%02x:%02x:%02x\n\033[0m", save_str, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); } else { printf("\033[0;31m%s: -1\n\033[0m", save_str); return -1; } return 0; } } /** * aro cheating */ if (cheat_flag) { if (!strlen(ip)) { printf("\033[0;31minput ipaddress when arp cheating\n\033[0m"); return -1; } //if (!strlen(ether) || !strlen(gateway_ip)) // get_gateway(gateway_ip, ether); //rt = arp_cheat(ether, ip, gateway_ip); rt = arp_cheating(ip); return rt; } /** * get interface name */ if (eth_flag && !strlen(ether)) { if (!get_ifname(ether)) { printf("\033[0;35m%s\n\033[0m", ether); return 0; } else { printf("\033[0;31mget interface failed\n\033[0m"); return -1; } } /** * get gateway ip address */ if (gateway_flag && !strlen(gateway_ip)) { if (!strlen(ether)) { get_ifname(ether); } if (!strlen(ether)) { printf("\033[0;31mget interface failed\n\033[0m"); return -1; } char *str = NULL, *save_str = NULL; for (str = ether; ; str = NULL) { save_str = strtok(str, " "); if (save_str == NULL) return -1; if (!get_gateway(gateway_ip, save_str)) { printf("\033[0;32m%s\'s gateway address is:\033[0;35m %s\n\033[0m", save_str, gateway_ip); return 0; } else { printf("\033[0;31mget interface failed\n\033[0m"); return -1; } } } if (router_flag) { if (strlen(ip)) route(ip); return 0; } if (up_flag) { scan_router_ip_up(up_range, 4); return 0; } if (!strlen(ip)) strcpy(ip, "127.0.0.1"); if (proto_flag) { printf("\033[1;31mConfiguration: \n"); printf("\033[1;35m protocol : \033[1;32m%s\n", proto_str); printf("\033[1;35m ip : \033[1;32m%s\n", ip); printf("\033[1;35m port : \033[1;32m%d\n", port); printf("\033[1;35m ser : \033[1;32m%d\n", ser_flag); printf("\033[1;35m cli : \033[1;32m%d\n", cli_flag); printf("\033[1;35m times : \033[1;32m%d\n", times); printf("\033[1;35m wait time : \033[1;32m%d\n", sleep_time); printf("\033[0m\n"); switch (protocol) { case PROTO_TCP: if (ser_flag) net_tcp_ser(ip, port); else if (cli_flag) net_tcp_cli(ip, port); break; case PROTO_UDP: if (ser_flag) net_udp_ser(ip, port); else if (cli_flag) net_udp_cli(ip, port); break; case PROTO_BROADCAST: if (ser_flag) udp_broadcast_recv(ip, port, times, NULL, 0); else if (cli_flag) { if (strlen(message)) udp_broadcast_send(ip, port, times, message); else udp_broadcast_send(ip, port, times, NULL); } case PROTO_MULTICAST: if (ser_flag) udp_multicast_recv(ip, port, times, NULL, 0); else if (cli_flag) { if (strlen(message)) udp_multicast_send(ip, port, times, message); else udp_multicast_send(ip, port, times, NULL); } break; case '?': default: return -1; break; } return 0; } error: /** * error handling */ return rt; }