void StrArrayAdd(StrArray* arr, const char* str) { char** old_table; if ((arr == NULL) || (arr->Table == NULL)) return; if (arr->Index == arr->Max) { arr->Max *= 2; old_table = arr->Table; arr->Table = (char**)realloc(arr->Table, arr->Max*sizeof(char*)); if (arr->Table == NULL) { free(old_table); uprintf("Could not reallocate string array\n"); return; } } arr->Table[arr->Index] = safe_strdup(str); if (arr->Table[arr->Index++] == NULL) { uprintf("Could not store string in array\n"); } }
/* You must free() this yourself. */ const vm_char *factor_vm::default_image_path() { vm_char full_path[MAX_UNICODE_PATH]; vm_char *ptr; vm_char temp_path[MAX_UNICODE_PATH]; if(!GetModuleFileName(NULL, full_path, MAX_UNICODE_PATH)) fatal_error("GetModuleFileName() failed", 0); if((ptr = wcsrchr(full_path, '.'))) *ptr = 0; wcsncpy(temp_path, full_path, MAX_UNICODE_PATH - 1); size_t full_path_len = wcslen(full_path); if (full_path_len < MAX_UNICODE_PATH - 1) wcsncat(temp_path, L".image", MAX_UNICODE_PATH - full_path_len - 1); temp_path[MAX_UNICODE_PATH - 1] = 0; return safe_strdup(temp_path); }
void lirc_channel_join(struct LIRCServer_struct* server, struct LIRCClientData_struct* client, char *channel) { char temp[MAX_IRC_MESSAGE_SIZE]; dlnode_t* client_node; LIRCChannelData* c = (LIRCChannelData*)find_element(server->channel_list, channel, lirc_channel_cmp); if (c == NULL) { /* The channel doesn't exist in the list so we * will need to create one */ c = lirc_channel_new_metadata(); c->name = safe_strdup(channel); insert_at_front(server->channel_list, c, sizeof(c)); } /* Add this client to the list */ insert_at_front(c->client_list, client, sizeof(client)); /* Add a weak reference to the joined channels list of the client */ insert_at_front(client->channel_list, c, sizeof(c)); /* Send a response message to all connected clients inside the * channel indicating that a join was made */ client_node = c->client_list->head; sprintf(temp, ":%s!~%[email protected] JOIN %s\r\n", client->nick, client->user, channel); while (client_node != NULL) { struct LIRCClientData_struct *client_node_data = (struct LIRCClientData_struct *)client_node->data; send(client_node_data->socket, temp, strlen(temp), 0); client_node = client_node->next; } }
// add by lijg, 2013-05-30, Find keyword @mention in firewall rule table = @table and chain = @chain // return : 0 - not found, 1 - found it . int iptables_fw_find_mention( const char * table, const char * chain, const char * mention ) { FILE *p = NULL; char *command = NULL; char line[MAX_BUF]; char *victim = safe_strdup(mention); int found = 0; // 1.1 @victim="WiFiDog_br-lan_Trusted" iptables_insert_gateway_id(&victim); debug(LOG_DEBUG, "Attempting to find all mention of %s from %s.%s", victim, table, chain); safe_asprintf(&command, "iptables -t %s -L %s -n --line-numbers -v", table, chain); iptables_insert_gateway_id(&command); //1.2 执行命令 iptables -t mangle -L PREROUTING -n --line-numbers -v, 逐行输出链中规则 if ((p = popen(command, "r"))) { /* Skip first 2 lines */ while (!feof(p) && fgetc(p) != '\n'); while (!feof(p) && fgetc(p) != '\n'); /* Loop over entries */ while (fgets(line, sizeof(line), p)) { // 匹配链中每条规则 /* Look for victim */ if (strstr(line, victim)) { // 根据客户端IP地址进行匹配 found = 1; break; } } pclose(p); } free(command); free(victim); return (found); }
static int w32g_add_playlist1(char *filename, int uniq, int refine) { PlayListEntry *entry; char *title; struct midi_file_info *info; if(uniq) { int i; for(i = 0; i < playlist.nfiles; i++) if(pathcmp(filename, playlist.list[i].filename, 0) == 0) return 0; } title = get_midi_title(filename); info = get_midi_file_info(filename, 1); if(refine && info->format < 0) return 0; if(playlist.allocated == 0) { playlist.allocated = 32; playlist.list = (PlayListEntry *)safe_malloc(playlist.allocated * sizeof(PlayListEntry)); } else if(playlist.nfiles == playlist.allocated) { playlist.allocated *= 2; playlist.list = (PlayListEntry *)safe_realloc(playlist.list, playlist.allocated * sizeof(PlayListEntry)); } entry = &playlist.list[playlist.nfiles]; entry->filename = safe_strdup(filename); entry->title = title; entry->info = info; playlist.nfiles++; w32g_shuffle_playlist_reset(1); return 1; }
char * get_iface_ip(const char ifname[]) { char addrbuf[INET6_ADDRSTRLEN+1]; const struct ifaddrs *cur; struct ifaddrs *addrs; s_config *config; if(getifaddrs(&addrs) < 0) { debug(LOG_ERR, "getifaddrs(): %s", strerror(errno)); return NULL; } config = config_get_config(); /* Set default address */ sprintf(addrbuf, config->ip6 ? "::" : "0.0.0.0"); /* Iterate all interfaces */ cur = addrs; while(cur != NULL) { if( (cur->ifa_addr != NULL) && (strcmp( cur->ifa_name, ifname ) == 0) ) { if(config->ip6 && cur->ifa_addr->sa_family == AF_INET6) { inet_ntop(AF_INET6, &((struct sockaddr_in6 *)cur->ifa_addr)->sin6_addr, addrbuf, sizeof(addrbuf)); break; } if(!config->ip6 && cur->ifa_addr->sa_family == AF_INET) { inet_ntop(AF_INET, &((struct sockaddr_in *)cur->ifa_addr)->sin_addr, addrbuf, sizeof(addrbuf)); break; } } cur = cur->ifa_next; } freeifaddrs(addrs); return safe_strdup(addrbuf); }
/*--------------------------------------------------------------------------- * Purpose: Return the string value of a builtin symbol. * * Return: Copy of the string value or NULL * * Programmer: Robb Matzke * Friday, June 2, 2000 * * Modifications: *--------------------------------------------------------------------------- */ char * sym_bi_gets(const char *name) { char fullname[1024], *retval; obj_t var, val; /* Add built-in prefix */ if (*name!='$') { fullname[0] = '$'; strcpy(fullname+1, name); name = fullname; } var = obj_new(C_SYM, name); val = sym_vboundp(var); var = obj_dest(var); retval = safe_strdup(obj_name(val)); obj_dest(val); return retval; }
/* Note this actually calculates the sockdir, so it never returns NULL. */ char * guestfs_impl_get_sockdir (guestfs_h *g) { const char *str; uid_t euid = geteuid (); if (euid == 0) { /* Use /tmp exclusively for root, as otherwise qemu (running as * qemu.qemu when launched by libvirt) will not be able to access * the directory. */ str = "/tmp"; } else { if (g->env_runtimedir) str = g->env_runtimedir; else str = "/tmp"; } return safe_strdup (g, str); }
char * guestfs__inspect_get_type (guestfs_h *g, const char *root) { struct inspect_fs *fs = guestfs___search_for_root (g, root); if (!fs) return NULL; char *ret; switch (fs->type) { case OS_TYPE_DOS: ret = safe_strdup (g, "dos"); break; case OS_TYPE_FREEBSD: ret = safe_strdup (g, "freebsd"); break; case OS_TYPE_HURD: ret = safe_strdup (g, "hurd"); break; case OS_TYPE_LINUX: ret = safe_strdup (g, "linux"); break; case OS_TYPE_NETBSD: ret = safe_strdup (g, "netbsd"); break; case OS_TYPE_OPENBSD: ret = safe_strdup (g, "openbsd"); break; case OS_TYPE_WINDOWS: ret = safe_strdup (g, "windows"); break; case OS_TYPE_UNKNOWN: default: ret = safe_strdup (g, "unknown"); break; } return ret; }
int c_locale_vsnprintf (char *str, size_t size, const char *format, va_list ap) { #ifdef _MSC_VER # define vsnprintf _vsnprintf #endif int result; char *locale; locale = safe_strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C"); result = vsnprintf(str, size, format, ap); setlocale(LC_ALL, locale); free(locale); return result; }
/** * @internal * Compiles a struct definition of a firewall rule into a valid iptables * command. * @arg table Table containing the chain. * @arg chain Chain that the command will be (-A)ppended to. * @arg rule Definition of a rule into a struct, from conf.c. */ static char * iptables_compile(const char * table, const char *chain, const t_firewall_rule *rule) { char command[MAX_BUF], *mode; memset(command, 0, MAX_BUF); switch (rule->target){ case TARGET_DROP: mode = safe_strdup("DROP"); break; case TARGET_REJECT: mode = safe_strdup("REJECT"); break; case TARGET_ACCEPT: mode = safe_strdup("ACCEPT"); break; case TARGET_LOG: mode = safe_strdup("LOG"); break; case TARGET_ULOG: mode = safe_strdup("ULOG"); break; } snprintf(command, sizeof(command), "-t %s -A %s ",table, chain); if (rule->mask != NULL) { snprintf((command + strlen(command)), (sizeof(command) - strlen(command)), "-d %s ", rule->mask); } if (rule->protocol != NULL) { snprintf((command + strlen(command)), (sizeof(command) - strlen(command)), "-p %s ", rule->protocol); } if (rule->port != NULL) { snprintf((command + strlen(command)), (sizeof(command) - strlen(command)), "--dport %s ", rule->port); } snprintf((command + strlen(command)), (sizeof(command) - strlen(command)), "-j %s", mode); free(mode); /* XXX The buffer command, an automatic variable, will get cleaned * off of the stack when we return, so we strdup() it. */ return(safe_strdup(command)); }
int guestfs__set_attach_method (guestfs_h *g, const char *method) { if (STREQ (method, "appliance")) { g->attach_method = ATTACH_METHOD_APPLIANCE; free (g->attach_method_arg); g->attach_method_arg = NULL; } else if (STRPREFIX (method, "unix:") && strlen (method) > 5) { g->attach_method = ATTACH_METHOD_UNIX; free (g->attach_method_arg); g->attach_method_arg = safe_strdup (g, method + 5); /* Note that we don't check the path exists until launch is called. */ } else { error (g, "invalid attach method: %s", method); return -1; } return 0; }
void guestfs_set_private (guestfs_h *g, const char *key, void *data) { if (g->pda == NULL) { g->pda = hash_initialize (16, NULL, hasher, comparator, freer); if (g->pda == NULL) g->abort_cb (); } struct pda_entry *new_entry = safe_malloc (g, sizeof *new_entry); new_entry->key = safe_strdup (g, key); new_entry->data = data; struct pda_entry *old_entry = hash_delete (g->pda, new_entry); freer (old_entry); struct pda_entry *entry = hash_insert (g->pda, new_entry); if (entry == NULL) g->abort_cb (); assert (entry == new_entry); }
int guestfs_impl_set_identifier (guestfs_h *g, const char *identifier) { size_t i, len; /* Check the identifier contains only permitted characters. */ len = strlen (identifier); for (i = 0; i < len; ++i) { char c = identifier[i]; if (!c_isalnum (c) && c != '_' && c != '-') { error (g, _("identifier must contain only alphanumeric characters, underscore or minus sign")); return -1; } } free (g->identifier); g->identifier = safe_strdup (g, identifier); return 0; }
static int update_tags(notmuch_message_t *msg, const char *tags) { char *tag = NULL, *end = NULL, *p; char *buf = safe_strdup(tags); if (!buf) return -1; notmuch_message_freeze(msg); for (p = buf; p && *p; p++) { if (!tag && isspace(*p)) continue; if (!tag) tag = p; /* begin of the tag */ if (*p == ',' || *p == ' ') end = p; /* terminate the tag */ else if (*(p + 1) == '\0') end = p + 1; /* end of optstr */ if (!tag || !end) continue; if (tag >= end) break; *end = '\0'; if (*tag == '-') { dprint(1, (debugfile, "nm: remove tag: '%s'\n", tag + 1)); notmuch_message_remove_tag(msg, tag + 1); } else { dprint(1, (debugfile, "nm: add tag: '%s'\n", *tag == '+' ? tag + 1 : tag)); notmuch_message_add_tag(msg, *tag == '+' ? tag + 1 : tag); } end = tag = NULL; } notmuch_message_thaw(msg); FREE(&buf); return 0; }
int main (int argc, char **argv) { int i; char *p; struct utsname utsname; /* determine the system's host name */ uname (&utsname); if (!(Hostname = safe_strdup (utsname.nodename))) return DL_EX_ERROR; if ((p = strchr (Hostname, '.'))) *p = '\0'; /* parse the command line options. */ DotlockFlags = 0; while ((i = getopt (argc, argv, "dtfur:")) != EOF) { switch (i) { /* actions, mutually exclusive */ case 't': check_flags (DotlockFlags); DotlockFlags |= DL_FL_TRY; break; case 'd': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLINK; break; case 'u': check_flags (DotlockFlags); DotlockFlags |= DL_FL_UNLOCK; break; /* other flags */ case 'f': DotlockFlags |= DL_FL_FORCE; break; case 'r': DotlockFlags |= DL_FL_RETRY; Retry = atoi (optarg); break; default: usage (argv[0]); } } if (optind == argc || Retry < 0) usage (argv[0]); return dotlock_dispatch (argv[optind], -1); }
static char * url_dumpfile(URL url, const char *ext) { char filename[1024]; char *tmpdir; int fd; FILE *fp; int n; char buff[BUFSIZ]; #ifdef TMPDIR tmpdir = TMPDIR; #else tmpdir = getenv("TMPDIR"); #endif if(tmpdir == NULL || strlen(tmpdir) == 0) tmpdir = PATH_STRING "tmp" PATH_STRING; if(IS_PATH_SEP(tmpdir[strlen(tmpdir) - 1])) snprintf(filename, sizeof(filename), "%sXXXXXX.%s", tmpdir, ext); else snprintf(filename, sizeof(filename), "%s" PATH_STRING "XXXXXX.%s", tmpdir, ext); fd = tmdy_mkstemp(filename); if (fd == -1) return NULL; if ((fp = fdopen(fd, "w")) == NULL) { close(fd); unlink(filename); return NULL; } while((n = url_read(url, buff, sizeof(buff))) > 0) fwrite(buff, 1, n, fp); fclose(fp); return safe_strdup(filename); }
/* * Function to register ourselves. This function is always called, regardless * of what DLT types are being used, so it shouldn't be allocating extra buffers * or anything like that (use the dlt_linuxsll_init() function below for that). * Tasks: * - Create a new plugin struct * - Fill out the provides/requires bit masks. Note: Only specify which fields are * actually in the header. * - Add the plugin to the context's plugin chain * Returns: TCPEDIT_ERROR | TCPEDIT_OK | TCPEDIT_WARN */ int dlt_linuxsll_register(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; assert(ctx); /* create a new plugin structure */ plugin = tcpedit_dlt_newplugin(); /* FIXME: set what we provide & require */ plugin->provides += PLUGIN_MASK_PROTO + PLUGIN_MASK_SRCADDR; plugin->requires += 0; /* what is our DLT value? */ plugin->dlt = dlt_value; /* set the prefix name of our plugin. This is also used as the prefix for our options */ plugin->name = safe_strdup(dlt_prefix); /* * Point to our functions, note, you need a function for EVERY method. * Even if it is only an empty stub returning success. */ plugin->plugin_init = dlt_linuxsll_init; plugin->plugin_cleanup = dlt_linuxsll_cleanup; plugin->plugin_parse_opts = dlt_linuxsll_parse_opts; plugin->plugin_decode = dlt_linuxsll_decode; plugin->plugin_encode = dlt_linuxsll_encode; plugin->plugin_proto = dlt_linuxsll_proto; plugin->plugin_l2addr_type = dlt_linuxsll_l2addr_type; plugin->plugin_l2len = dlt_linuxsll_l2len; plugin->plugin_get_layer3 = dlt_linuxsll_get_layer3; plugin->plugin_merge_layer3 = dlt_linuxsll_merge_layer3; plugin->plugin_get_mac = dlt_linuxsll_get_mac; /* add it to the available plugin list */ return tcpedit_dlt_addplugin(ctx, plugin); }
/* Add given MAC address to the config's allowed mac list. * Return 0 on success, nonzero on failure */ int add_to_allowed_mac_list(const char possiblemac[]) { char *mac = NULL; t_MAC *p = NULL; /* check for valid format */ if (!check_mac_format(possiblemac)) { debug(LOG_NOTICE, "[%s] not a valid MAC address to allow", possiblemac); return -1; } /* abort if not using ALLOW mechanism */ if (MAC_ALLOW != config.macmechanism) { debug(LOG_NOTICE, "Attempt to access allowed MAC list but control mechanism != allow"); return -1; } mac = safe_malloc(18); sscanf(possiblemac, "%17[A-Fa-f0-9:]", mac); /* See if MAC is already on the list; don't add duplicates */ for (p = config.allowedmaclist; p != NULL; p = p->next) { if (!strcasecmp(p->mac,mac)) { debug(LOG_INFO, "MAC address [%s] already on allowed list", mac); free(mac); return 1; } } /* Add MAC to head of list */ p = safe_malloc(sizeof(t_MAC)); p->mac = safe_strdup(mac); p->next = config.allowedmaclist; config.allowedmaclist = p; debug(LOG_INFO, "Added MAC address [%s] to allowed list", mac); free(mac); return 0; }
static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct btd_config *config = state->input; switch (key) { case 'q': btd_decr_log(); break; case 'v': btd_incr_log(); break; case ARGP_KEY_ARG: config->configpath = safe_strdup(arg); break; case ARGP_KEY_END: break; default: return ARGP_ERR_UNKNOWN; } return 0; }
/* Set the current backend. Notes: * (1) Callers must ensure this is only called in the config state. * (2) This shouldn't call 'error' since it may be called early in * handle initialization. It can return an error code however. */ int guestfs___set_backend (guestfs_h *g, const char *method) { struct backend *b; size_t len, arg_offs = 0; assert (g->state == CONFIG); for (b = backends; b != NULL; b = b->next) { if (STREQ (method, b->name)) break; len = strlen (b->name); if (STRPREFIX (method, b->name) && method[len] == ':') { arg_offs = len+1; break; } } if (b == NULL) return -1; /* Not found. */ /* At this point, we know it's a valid method. */ free (g->backend); g->backend = safe_strdup (g, method); if (arg_offs > 0) g->backend_arg = &g->backend[arg_offs]; else g->backend_arg = NULL; g->backend_ops = b->ops; free (g->backend_data); if (b->ops->data_size > 0) g->backend_data = safe_calloc (g, 1, b->ops->data_size); else g->backend_data = NULL; return 0; }
int guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars) { size_t i; for (i = 0; uefi_firmware[i] != NULL; i += 2) { const char *codefile = uefi_firmware[i]; const char *varsfile = uefi_firmware[i+1]; if (access (codefile, R_OK) == 0 && access (varsfile, R_OK) == 0) { CLEANUP_CMD_CLOSE struct command *copycmd = guestfs_int_new_command (g); char *varst; int r; /* Make a copy of NVRAM variables file. You can't just map it * into the address space read-only as that triggers a different * path inside UEFI. */ varst = safe_asprintf (g, "%s/vars.fd.%d", g->tmpdir, ++g->unique); guestfs_int_cmd_add_arg (copycmd, "cp"); guestfs_int_cmd_add_arg (copycmd, varsfile); guestfs_int_cmd_add_arg (copycmd, varst); r = guestfs_int_cmd_run (copycmd); if (r == -1 || !WIFEXITED (r) || WEXITSTATUS (r) != 0) { free (varst); return -1; } /* Caller frees. */ *code = safe_strdup (g, codefile); *vars = varst; return 0; } } /* Not found. */ *code = *vars = NULL; return 0; }
void mutt_update_tree (ATTACHPTR **idx, short idxlen) { char buf[STRING]; char *s; int x; for (x = 0; x < idxlen; x++) { idx[x]->num = x; if (2 * (idx[x]->level + 2) < sizeof (buf)) { if (idx[x]->level) { s = buf + 2 * (idx[x]->level - 1); *s++ = (idx[x]->content->next) ? M_TREE_LTEE : M_TREE_LLCORNER; *s++ = M_TREE_HLINE; *s++ = M_TREE_RARROW; } else s = buf; *s = 0; } if (idx[x]->tree) { if (mutt_strcmp (idx[x]->tree, buf) != 0) mutt_str_replace (&idx[x]->tree, buf); } else idx[x]->tree = safe_strdup (buf); if (2 * (idx[x]->level + 2) < sizeof (buf) && idx[x]->level) { s = buf + 2 * (idx[x]->level - 1); *s++ = (idx[x]->content->next) ? '\005' : '\006'; *s++ = '\006'; } } }
char * guestfs__get_attach_method (guestfs_h *g) { char *ret; switch (g->attach_method) { case ATTACH_METHOD_APPLIANCE: ret = safe_strdup (g, "appliance"); break; case ATTACH_METHOD_UNIX: ret = safe_malloc (g, strlen (g->attach_method_arg) + 5 + 1); strcpy (ret, "unix:"); strcat (ret, g->attach_method_arg); break; default: /* keep GCC happy - this is not reached */ abort (); } return ret; }
/* parse UIDL */ static int fetch_uidl(char *line, void *data) { int i, index; CONTEXT *ctx = (CONTEXT *)data; POP_DATA *pop_data = (POP_DATA *)ctx->data; char *endp; errno = 0; index = strtol(line, &endp, 10); if (errno) return -1; while (*endp == ' ') endp++; memmove(line, endp, strlen(endp) + 1); for (i = 0; i < ctx->msgcount; i++) if (!mutt_strcmp(line, ctx->hdrs[i]->data)) break; if (i == ctx->msgcount) { dprint(1, "pop_fetch_headers: new header %d %s\n", index, line); if (i >= ctx->hdrmax) mx_alloc_memory(ctx); ctx->msgcount++; ctx->hdrs[i] = mutt_new_header(); ctx->hdrs[i]->data = safe_strdup(line); } else if (ctx->hdrs[i]->index != index - 1) pop_data->clear_cache = 1; ctx->hdrs[i]->refno = index; ctx->hdrs[i]->index = index - 1; return 0; }
/** * Figures out if a MAC is listed in a comma delimited * string of MAC addresses. * returns TCPR_DIR_C2S if listed * returns TCPR_DIR_S2C if not listed */ tcpr_dir_t macinstring(const char *macstring, const u_char *mac) { char *tok, *tempstr, *ourstring; u_char tempmac[6]; int len = 6, ret = TCPR_DIR_S2C; ourstring = safe_strdup(macstring); tempstr = strtok_r(ourstring, ",", &tok); if (strlen(tempstr)) { mac2hex(tempstr, tempmac, len); if (memcmp(mac, tempmac, len) == 0) { dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac)); ret = TCPR_DIR_C2S; goto EXIT_MACINSTRING; } } else { goto EXIT_MACINSTRING; } while ((tempstr = strtok_r(NULL, ",", &tok)) != NULL) { mac2hex(tempstr, tempmac, len); if (memcmp(mac, tempmac, len) == 0) { ret = TCPR_DIR_C2S; dbgx(3, "Packet matches: " MAC_FORMAT " sending out primary.\n", MAC_STR(tempmac)); goto EXIT_MACINSTRING; } } EXIT_MACINSTRING: safe_free(ourstring); #ifdef DEBUG if (ret == TCPR_DIR_S2C) dbg(3, "Packet doesn't match any MAC addresses sending out secondary.\n"); #endif return ret; }
/** Add a firewall ruleset with the given name, and return it. * Do not allow duplicates. */ t_firewall_ruleset * add_ruleset(const char rulesetname[]) { t_firewall_ruleset * ruleset; ruleset = get_ruleset(rulesetname); if(ruleset != NULL) { debug(LOG_DEBUG, "add_ruleset(): FirewallRuleSet %s already exists.", rulesetname); return ruleset; } debug(LOG_DEBUG, "add_ruleset(): Creating FirewallRuleSet %s.", rulesetname); /* Create and place at head of config.rulesets */ ruleset = safe_malloc(sizeof(t_firewall_ruleset)); memset(ruleset, 0, sizeof(t_firewall_ruleset)); ruleset->name = safe_strdup(rulesetname); ruleset->next = config.rulesets; config.rulesets = ruleset; return ruleset; }
/** * Depending on what version of libpcap/WinPcap there are different ways to get * the version of the libpcap/WinPcap library. This presents a unified way to * get that information. */ const char * get_pcap_version(void) { #if defined HAVE_WINPCAP static char ourver[255]; char *last, *version; /* WinPcap returns a string like: * WinPcap version 4.0 (packet.dll version 4.0.0.755), based on libpcap version 0.9.5 */ version = safe_strdup(pcap_lib_version()); strtok_r(version, " ", &last); strtok_r(NULL, " ", &last); strlcpy(ourver, strtok_r(NULL, " ", &last), 255); safe_free(version); return ourver; #elif defined HAVE_PCAP_VERSION return pcap_version; #else return pcap_lib_version(); #endif }
void send_control(int sock, char *string, ...) { va_list args; char *line = NULL; char *newline; char *s = NULL; line = safe_strdup(string); va_start(args, string); s = va_arg(args, char *); while ( s ) { newline = strconcat(line, s, NULL); safe_free(line); line = newline; s = va_arg(args, char *); } va_end(args); S_WRITE(sock, line, strlen(line)); safe_free(line); }
/* This function allows the user to specify a command to read stdout from in place of a normal file. If the last character in the string is a pipe (|), then we assume it is a commmand to run instead of a normal file. */ FILE *mutt_open_read (const char *path, pid_t *thepid) { FILE *f; int len = mutt_strlen (path); if (path[len - 1] == '|') { /* read from a pipe */ char *s = safe_strdup (path); s[len - 1] = 0; endwin (); *thepid = mutt_create_filter (s, NULL, &f, NULL); safe_free ((void **) &s); } else { f = fopen (path, "r"); *thepid = -1; } return (f); }