int dcplugin_init(DCPlugin * const dcplugin, int argc, char *argv[]) { char *device_id; char *device_id_env; char *edns_hex; size_t edns_hex_size = sizeof EDNS_HEADER EDNS_DEV_ID; edns_hex = malloc(sizeof EDNS_HEADER EDNS_DEV_ID); dcplugin_set_user_data(dcplugin, edns_hex); if (edns_hex == NULL) { return -1; } memcpy(edns_hex, EDNS_HEADER EDNS_DEV_ID, edns_hex_size); assert(sizeof EDNS_DEV_ID - 1U == (size_t) 16U); device_id = device_id_env = getenv("OPENDNS_DEVICE_ID"); if (device_id != NULL) { memcpy(edns_hex + sizeof EDNS_HEADER - (size_t) 1U, device_id, sizeof EDNS_DEV_ID); } if (device_id_env != NULL) { memset(device_id_env, 0, strlen(device_id_env)); } return 0; }
int dcplugin_init(DCPlugin * const dcplugin, int argc, char *argv[]) { Blocking *blocking; int opt_flag; int option_index = 0; if ((blocking = calloc((size_t) 1U, sizeof *blocking)) == NULL) { return -1; } dcplugin_set_user_data(dcplugin, blocking); blocking->fp = NULL; blocking->domains = NULL; blocking->domains_rev = NULL; blocking->domains_substr = NULL; blocking->ips = NULL; blocking->ltsv = 0; optind = 0; #ifdef _OPTRESET optreset = 1; #endif while ((opt_flag = getopt_long(argc, argv, getopt_options, getopt_long_options, &option_index)) != -1) { switch (opt_flag) { case 'd': if (parse_domain_list(&blocking->domains, &blocking->domains_rev, &blocking->domains_substr, optarg) != 0) { return -1; } break; case 'i': if (parse_ip_list(&blocking->ips, optarg) != 0) { return -1; } break; case 'l': if (strncmp(optarg, "ltsv:", (sizeof "ltsv:") - 1U) == 0) { blocking->ltsv = 1; optarg += (sizeof "ltsv:") - 1U; } if ((blocking->fp = fopen(optarg, "a")) == NULL) { return -1; } break; default: return -1; } } return 0; }
int dcplugin_init(DCPlugin * const dcplugin, int argc, char *argv[]) { FILE *fp; if (argc != 2U) { fp = stdout; } else { if ((fp = fopen(argv[1], "a")) == NULL) { return -1; } } dcplugin_set_user_data(dcplugin, fp); return 0; }
int dcplugin_init(DCPlugin * const dcplugin, int argc, char *argv[]) { Context *context; GeoIP *geoip; int opt_flag; int option_index = 0; if ((context = calloc((size_t) 1U, sizeof *context)) == NULL) { return -1; } dcplugin_set_user_data(dcplugin, context); if (context == NULL) { return -1; } context->blacklist = NULL; context->geoip = NULL; optind = 0; #ifdef _OPTRESET optreset = 1; #endif while ((opt_flag = getopt_long(argc, argv, getopt_options, getopt_long_options, &option_index)) != -1) { switch (opt_flag) { case 'b': if ((context->blacklist = parse_str_list(optarg)) == NULL) { return -1; } break; case 'g': if ((context->geoip = GeoIP_open(optarg, GEOIP_MEMORY_CACHE)) == NULL) { return -1; } break; default: return -1; } } if (context->blacklist == NULL || context->geoip == NULL) { return -1; } return 0; }
int dcplugin_init(DCPlugin * const dcplugin, int argc, char *argv[]) { Blocking *blocking; int opt_flag; int option_index = 0; if ((blocking = calloc((size_t) 1U, sizeof *blocking)) == NULL) { return -1; } dcplugin_set_user_data(dcplugin, blocking); if (blocking == NULL) { return -1; } blocking->domains = blocking->ips = NULL; optind = 0; #ifdef _OPTRESET optreset = 1; #endif while ((opt_flag = getopt_long(argc, argv, getopt_options, getopt_long_options, &option_index)) != -1) { switch (opt_flag) { case 'd': if (parse_str_list(&blocking->domains, optarg) != 0) { return -1; } break; case 'i': if (parse_str_list(&blocking->ips, optarg) != 0) { return -1; } break; default: return -1; } } return 0; }