/* * Show registered IKE algorithms */ void ike_alg_show_status(void) { unsigned alg, i; struct ike_alg *algo; IKE_EALG_FOR_EACH(algo) { passert(algo != NULL); alg=algo->algo_id; whack_log(RC_COMMENT, "algorithm IKE encrypt: id=%d, name=%s, blocksize=%d, keydeflen=%d" , alg , enum_name(&oakley_enc_names, alg) , ((struct encrypt_desc *)algo)->enc_blocksize , ((struct encrypt_desc *)algo)->keydeflen ); } IKE_HALG_FOR_EACH(algo) { whack_log(RC_COMMENT, "algorithm IKE hash: id=%d, name=%s, hashsize=%d" , algo->algo_id , enum_name(&oakley_hash_names, algo->algo_id) , ((struct hash_desc *)algo)->hash_digest_size ); } #define IKE_DH_ALG_FOR_EACH(idx) for(idx = 0; idx != elemsof(oakley_group); idx++) IKE_DH_ALG_FOR_EACH(i) { const struct oakley_group_desc *gdesc=oakley_group+i; whack_log(RC_COMMENT, "algorithm IKE dh group: id=%d, name=%s, bits=%d" , gdesc->group , enum_name(&oakley_group_names, gdesc->group) , gdesc->bytes*BITS_PER_BYTE ); } }
static int doit(unsigned protoid, const char *str) { struct alg_info *ai; enum_names *enames, *anames, *gnames; const char *err; int i; switch (protoid) { case PROTO_IPSEC_ESP: { struct alg_info_esp *ai_esp; struct esp_info *esp_info; enames=&esp_transformid_names; anames=&auth_alg_names; gnames=NULL; ai_esp=alg_info_esp_create_from_str(str, &err); ai = (struct alg_info *) ai_esp; if (!ai) goto err; alg_info_addref(ai); ALG_INFO_ESP_FOREACH(ai_esp, esp_info, i) { printf("(%d = \"%s\" [%d], ", esp_info->esp_ealg_id, enum_name(enames, esp_info->esp_ealg_id), esp_info->esp_ealg_keylen); printf("%d = \"%s\" [%d])\n", esp_info->esp_aalg_id, enum_name(anames, esp_info->esp_aalg_id), esp_info->esp_aalg_keylen); } break; } case PROTO_ISAKMP: { struct alg_info_ike *ai_ike; struct ike_info *ike_info; enames=&oakley_enc_names; anames=&oakley_hash_names; gnames=&oakley_group_names; ai_ike = alg_info_ike_create_from_str(str, &err); ai = (struct alg_info *) ai_ike; if (!ai) goto err; alg_info_addref(ai); ALG_INFO_IKE_FOREACH(ai_ike, ike_info, i) { printf("(%d = \"%s\" [%d], ", ike_info->ike_ealg, enum_name(enames, ike_info->ike_ealg), ike_info->ike_eklen); printf("%d = \"%s\" [%d], ", ike_info->ike_halg, enum_name(anames, ike_info->ike_halg), ike_info->ike_hklen); printf("%d = \"%s\")\n", ike_info->ike_modp, ike_info->ike_modp ? enum_name(gnames, ike_info->ike_modp): "<default>"); } break; }
char *alg_info_snprint_ike1(struct ike_info *ike_info , int eklen, int aklen , char *buf , int buflen) { snprintf(buf, buflen-1, "%s(%d)_%03d-%s(%d)_%03d-%s(%d)" , enum_name(&oakley_enc_names, ike_info->ike_ealg)+ sizeof("OAKLEY") , ike_info->ike_ealg, eklen , enum_name(&oakley_hash_names, ike_info->ike_halg)+ sizeof("OAKLEY") , ike_info->ike_halg, aklen , enum_name(&oakley_group_names, ike_info->ike_modp)+ sizeof("OAKLEY_GROUP") , ike_info->ike_modp); return buf; }
/* * Show registered IKE algorithms */ void ike_alg_show_status(void) { unsigned i; struct ike_alg *algo; whack_log(RC_COMMENT, "IKE algorithms supported:"); whack_log(RC_COMMENT, " "); /* spacer */ IKE_EALG_FOR_EACH(algo) { struct esb_buf v1namebuf, v2namebuf; passert(algo != NULL); passert(algo->algo_id != 0 || algo->algo_v2id != 0); whack_log(RC_COMMENT, "algorithm IKE encrypt: v1id=%d, v1name=%s, v2id=%d, v2name=%s, blocksize=%zu, keydeflen=%u", algo->algo_id, enum_showb(&oakley_enc_names, algo->algo_id, &v1namebuf), algo->algo_v2id, enum_showb(&ikev2_trans_type_encr_names, algo->algo_v2id, &v2namebuf), ((struct encrypt_desc *)algo)->enc_blocksize, ((struct encrypt_desc *)algo)->keydeflen); } IKE_HALG_FOR_EACH(algo) { /* * ??? we think that hash_integ_len is meaningless * (and 0) for IKE hashes */ pexpect(((struct hash_desc *)algo)->hash_integ_len == 0); whack_log(RC_COMMENT, "algorithm IKE hash: id=%d, name=%s, hashlen=%zu", algo->algo_id, enum_name(&oakley_hash_names, algo->algo_id), ((struct hash_desc *)algo)->hash_digest_len); } #define IKE_DH_ALG_FOR_EACH(idx) for ((idx) = 0; (idx) != oakley_group_size; (idx)++) IKE_DH_ALG_FOR_EACH(i) { const struct oakley_group_desc *gdesc = oakley_group + i; whack_log(RC_COMMENT, "algorithm IKE dh group: id=%d, name=%s, bits=%d", gdesc->group, enum_name(&oakley_group_names, gdesc->group), (int)gdesc->bytes * BITS_PER_BYTE); } whack_log(RC_COMMENT, " "); /* spacer */ }
static void db_prop_print(struct db_prop *p) { struct db_trans *t; struct db_attr *a; int ti, ai; enum_names *n, *n_at, *n_av; DBG_log("protoid=\"%s\"\n", enum_name(&protocol_names, p->protoid)); for (ti=0, t=p->trans; ti< p->trans_cnt; ti++, t++) { switch( p->protoid) { case PROTO_ISAKMP: n=&isakmp_transformid_names; break; case PROTO_IPSEC_ESP: n=&esp_transformid_names; break; case PROTO_IPSEC_AH: n=&ah_transformid_names; break; default: continue; } DBG_log(" transid=\"%s\"\n", enum_name(n, t->transid)); for (ai=0, a=t->attrs; ai < t->attr_cnt; ai++, a++) { int i; switch( p->protoid) { case PROTO_ISAKMP: n_at=&oakley_attr_names; i=a->type|ISAKMP_ATTR_AF_TV; n_av=oakley_attr_val_descs[(i)&ISAKMP_ATTR_RTYPE_MASK]; break; case PROTO_IPSEC_AH: case PROTO_IPSEC_ESP: n_at=&ipsec_attr_names; i=a->type|ISAKMP_ATTR_AF_TV; n_av=ipsec_attr_val_descs[(i)&ISAKMP_ATTR_RTYPE_MASK]; break; default: continue; } DBG_log(" type=\"%s\" value=\"%s\"\n", enum_name(n_at, i), enum_name(n_av, a->val)); } } }
static void log_sa_attr_oakley(struct db_attr *at) { const struct enum_names *en = NULL; if (at->type.oakley == OAKLEY_ATTR_undefined) return; if (at->type.oakley < oakley_attr_val_descs_roof) en = oakley_attr_val_descs[at->type.oakley]; DBG_log(" type: %u(%s) val: %u(%s)\n", at->type.oakley, enum_name(&oakley_attr_names, at->type.oakley + ISAKMP_ATTR_AF_TV), at->val, en ? enum_name(en, at->val) : "unknown"); }
static void log_sa_attr_ipsec(struct db_attr *at) { const struct enum_names *en = NULL; if (at->type.ipsec == 0) return; if (at->type.ipsec < ipsec_attr_val_descs_roof) en = ipsec_attr_val_descs[at->type.ipsec]; DBG_log(" type: %u(%s) val: %u(%s)\n", at->type.ipsec, enum_name(&ipsec_attr_names, at->type.ipsec + ISAKMP_ATTR_AF_TV), at->val, en ? enum_name(en, at->val) : "unknown"); }
static void dump_sdt (GstMpegTsSection * section) { const GstMpegTsSDT *sdt = gst_mpegts_section_get_sdt (section); guint i, len; g_assert (sdt); g_printf (" original_network_id : 0x%04x\n", sdt->original_network_id); g_printf (" actual_ts : %s\n", sdt->actual_ts ? "TRUE" : "FALSE"); len = sdt->services->len; g_printf (" %d Services:\n", len); for (i = 0; i < len; i++) { GstMpegTsSDTService *service = g_ptr_array_index (sdt->services, i); g_print (" service_id:0x%04x, EIT_schedule_flag:%d, EIT_present_following_flag:%d\n", service->service_id, service->EIT_schedule_flag, service->EIT_present_following_flag); g_print (" running_status:0x%02x (%s), free_CA_mode:%d (%s)\n", service->running_status, enum_name (GST_TYPE_MPEG_TS_RUNNING_STATUS, service->running_status), service->free_CA_mode, service->free_CA_mode ? "MAYBE SCRAMBLED" : "NOT SCRAMBLED"); dump_descriptors (service->descriptors, 9); } }
static void dump_pmt (GstMpegtsSection * section, ATS_METADATA* data) { const GstMpegtsPMT *pmt = gst_mpegts_section_get_pmt (section); guint i, len; ATS_CH_DATA* channel; channel = ats_metadata_find_channel(data, pmt->program_number); if (!channel) return; len = pmt->streams->len; channel->pids_num = 0; for (i = 0; i < len; i++) { const gchar* type; GstMpegtsPMTStream *stream = g_ptr_array_index (pmt->streams, i); if (stream->stream_type == 0x86) continue; /* Unknown type */ /* Getting pid's codec type */ type = enum_name (GST_TYPE_MPEGTS_STREAM_TYPE, stream->stream_type); if (type[0] != 'a' && type[0] != 'v') continue; channel->pids[channel->pids_num].to_be_analyzed = FALSE; channel->pids[channel->pids_num].pid = stream->pid; channel->pids[channel->pids_num].type = stream->stream_type; channel->pids[channel->pids_num].codec = g_strdup(type); channel->pids_num++; } }
static void test_enum_enum(const char *title, enum_enum_names *een, unsigned long table, enum_names *en, unsigned long val, bool val_ok) { printf("%s:\n", title); { printf(PREFIX "enum_enum_table %lu: ", table); if (en == enum_enum_table(een, table)) { printf("OK\n"); } else { printf("ERROR\n"); } } printf(PREFIX "enum_enum_name %lu %lu: ", table, val); const char *name = enum_enum_name(een, table, val); if ((val_ok) == (name != NULL)) { printf("OK\n"); } else { printf("ERROR\n"); } printf(PREFIX "enum_name table %lu: ", val); if (en == NULL) { printf("N/A\n"); } else if (name == enum_name(en, val)) { printf("OK\n"); } else { printf("ERROR\n"); } LSWBUF(buf) { printf(PREFIX "lswlog_enum_enum %lu %lu: ", table, val); lswlog_enum_enum(buf, een, table, val); /* ??? clang says that name might be NULL */ if (val_ok && name == NULL) { printf("name == NULL\n"); } else if (val_ok && streq(buf->array, name)) { printf("OK\n"); } else if (strlen(buf->array) > 0) { printf("OK\n"); } else { printf("ERROR [empty]\n"); } } LSWBUF(buf) { printf(PREFIX "lswlog_enum_enum_short %lu %lu: ", table, val); lswlog_enum_enum_short(buf, een, table, val); if (val_ok && streq(buf->array, enum_short_name(en, val))) { printf("OK\n"); } else if (strlen(buf->array) > 0) { printf("OK\n"); } else { printf("ERROR [empty]\n"); } } }
static char * readline_set_generator(const char *text, int state) { static const char *words[] = { #define DEFINE_OPTION_NAME(name, type, flags) #name " = ", OPTION_INFO(DEFINE_OPTION_NAME) #undef DEFINE_OPTION_NAME NULL }; static int index, len; const char *name; char *match = NULL; /* No match */ /* If it is a new word to complete, initialize */ if (!state) { index = 0; len = strlen(text); } /* Return the next name which partially matches */ while ((name = words[index])) { name = enum_name(name); index++; if (strncmp(name, text, len) == 0) { /* Ignore exact completion */ if (strlen(name) > len) match = strdup(name); break; } } return match; }
void print_sa_attr_ipsec(struct db_attr *at) { const struct enum_names *en = NULL; if(at->type.ipsec == 0) { return; } if(at->type.ipsec <= ipsec_attr_val_descs_size) { en = ipsec_attr_val_descs[at->type.ipsec]; } printf(" type: %u(%s) val: %u(%s)\n" , at->type.ipsec, enum_name(&ipsec_attr_names, at->type.ipsec+ISAKMP_ATTR_AF_TV) , at->val, en ? enum_name(en, at->val) : "unknown"); }
void print_sa_attr_oakley(struct db_attr *at) { const struct enum_names *en = NULL; if(at->type.oakley == 0) { return; } if(at->type.oakley <= oakley_attr_val_descs_size) { en = oakley_attr_val_descs[at->type.oakley]; } printf(" type: %u(%s) val: %u(%s)\n" , at->type.oakley, enum_name(&oakley_attr_names, at->type.oakley+ISAKMP_ATTR_AF_TV) , at->val, en ? enum_name(en, at->val) : "unknown"); }
/* * Show registered IKE algorithms */ void ike_alg_show_status(void) { whack_log(RC_COMMENT, "IKE algorithms supported:"); whack_log(RC_COMMENT, " "); /* spacer */ for (const struct encrypt_desc **algp = next_ike_encrypt_desc(NULL); algp != NULL; algp = next_ike_encrypt_desc(algp)) { struct esb_buf v1namebuf, v2namebuf; const struct encrypt_desc *alg = (*algp); passert(alg->common.ikev1_oakley_id != 0 || alg->common.ikev2_id != 0); whack_log(RC_COMMENT, "algorithm IKE encrypt: v1id=%d, v1name=%s, v2id=%d, v2name=%s, blocksize=%zu, keydeflen=%u", alg->common.ikev1_oakley_id, enum_showb(&oakley_enc_names, alg->common.ikev1_oakley_id, &v1namebuf), alg->common.ikev2_id, enum_showb(&ikev2_trans_type_encr_names, alg->common.ikev2_id, &v2namebuf), alg->enc_blocksize, alg->keydeflen); } for (const struct prf_desc **algp = next_ike_prf_desc(NULL); algp != NULL; algp = next_ike_prf_desc(algp)) { const struct prf_desc *alg = (*algp); whack_log(RC_COMMENT, "algorithm IKE hash: id=%d, name=%s, hashlen=%zu", alg->common.ikev1_oakley_id, enum_name(&oakley_hash_names, alg->common.ikev1_oakley_id), alg->prf_output_size); } const struct oakley_group_desc *gdesc; for (gdesc = next_oakley_group(NULL); gdesc != NULL; gdesc = next_oakley_group(gdesc)) { whack_log(RC_COMMENT, "algorithm IKE dh group: id=%d, name=%s, bits=%d", gdesc->group, enum_name(&oakley_group_names, gdesc->group), (int)gdesc->bytes * BITS_PER_BYTE); } whack_log(RC_COMMENT, " "); /* spacer */ }
/* * print which ESP algorithm has actually been selected, based upon which * ones are actually loaded. */ int alg_info_snprint_esp(char *buf, int buflen, struct alg_info_esp *alg_info) { char *ptr=buf; int ret; struct esp_info *esp_info; int cnt; int eklen, aklen; const char *sep=""; ptr=buf; buf[0]=0; strncat(buf, "none", buflen); ALG_INFO_ESP_FOREACH(alg_info, esp_info, cnt) { if (kernel_alg_esp_enc_ok(esp_info->esp_ealg_id, 0, NULL)) { DBG_log("esp algid=%d not available", esp_info->esp_ealg_id); continue; } if (kernel_alg_esp_auth_ok(esp_info->esp_aalg_id, NULL)) { DBG_log("auth algid=%d not available", esp_info->esp_aalg_id); continue; } eklen=esp_info->esp_ealg_keylen; if (!eklen) eklen=kernel_alg_esp_enc_keylen(esp_info->esp_ealg_id)*BITS_PER_BYTE; aklen=esp_info->esp_aalg_keylen; if (!aklen) aklen=kernel_alg_esp_auth_keylen(esp_info->esp_aalg_id)*BITS_PER_BYTE; ret=snprintf(ptr, buflen, "%s%s(%d)_%03d-%s(%d)_%03d" , sep , enum_name(&esp_transformid_names, esp_info->esp_ealg_id)+sizeof("ESP") , esp_info->esp_ealg_id, eklen , enum_name(&auth_alg_names, esp_info->esp_aalg_id)+sizeof("AUTH_ALGORITHM_HMAC") , esp_info->esp_aalg_id, aklen); ptr+=ret; buflen-=ret; if (buflen<0) break; sep = ", "; } return ptr-buf; }
/** * DPD Timeout Function * * This function is called when a timeout DPD_EVENT occurs. We set clear/trap * both the SA and the eroutes, depending on what the connection definition * tells us (either 'hold' or 'clear') * * @param st A state structure that is fully negotiated * @return void */ void dpd_timeout(struct state *st) { struct connection *c = st->st_connection; int action = c->dpd_action; /** delete the state, which is probably in phase 2 */ set_cur_connection(c); libreswan_log("DPD: No response from peer - declaring peer dead"); switch (action) { case DPD_ACTION_HOLD: /** dpdaction=hold - Wipe the SA's but %trap the eroute so we don't leak traffic. Also, being in %trap means new packets will force an initiation of the conn again. */ libreswan_log("DPD: Putting connection into %%trap"); if (c->kind == CK_INSTANCE) { DBG(DBG_DPD, DBG_log( "DPD: warning dpdaction=hold on instance futile - will be deleted")); } delete_states_by_connection(c, TRUE); break; case DPD_ACTION_CLEAR: /** dpdaction=clear - Wipe the SA & eroute - everything */ libreswan_log("DPD: Clearing Connection"); /* * For CK_INSTANCE, delete_states_by_connection() will clear * Note that delete_states_by_connection changes c->kind but we need * to remember what it was to know if we still need to unroute after delete */ if (c->kind == CK_INSTANCE) { delete_states_by_connection(c, TRUE); } else { flush_pending_by_connection(c); /* remove any partial negotiations that are failing */ delete_states_by_connection(c, TRUE); DBG(DBG_DPD, DBG_log("DPD: unrouting connection (%s)", enum_name(&connection_kind_names, c->kind))); unroute_connection(c); /* --unroute */ } break; case DPD_ACTION_RESTART: /* dpdaction=restart - immediately renegotiate connections to the same peer. */ libreswan_log( "DPD: Restarting all connections that share this peer"); restart_connections_by_peer(c); break; default: bad_case(action); } reset_cur_connection(); }
int alg_info_snprint_ike(char *buf, int buflen, struct alg_info_ike *alg_info) { char *ptr=buf; int ret; struct ike_info *ike_info; int cnt; int eklen, aklen; const char *sep=""; struct encrypt_desc *enc_desc; struct hash_desc *hash_desc; ALG_INFO_IKE_FOREACH(alg_info, ike_info, cnt) { if (ike_alg_enc_present(ike_info->ike_ealg) && (ike_alg_hash_present(ike_info->ike_halg)) && (lookup_group(ike_info->ike_modp))) { enc_desc=ike_alg_get_encrypter(ike_info->ike_ealg); passert(enc_desc != NULL); hash_desc=ike_alg_get_hasher(ike_info->ike_halg); passert(hash_desc != NULL); eklen=ike_info->ike_eklen; if (!eklen) eklen=enc_desc->keydeflen; aklen=ike_info->ike_hklen; if (!aklen) aklen=hash_desc->hash_digest_len * BITS_PER_BYTE; ret=snprintf(ptr, buflen, "%s%s(%d)_%03d-%s(%d)_%03d-%s(%d)" , sep , enum_name(&oakley_enc_names, ike_info->ike_ealg)+sizeof("OAKLEY") , ike_info->ike_ealg, eklen , enum_name(&oakley_hash_names, ike_info->ike_halg)+sizeof("OAKLEY") , ike_info->ike_halg, aklen , enum_name(&oakley_group_names, ike_info->ike_modp)+sizeof("OAKLEY_GROUP") , ike_info->ike_modp); ptr+=ret; buflen-=ret; if (buflen<0) break; sep = ", "; } } return ptr-buf; }
static int snprint_esp_info(char *ptr, size_t buflen, const char *sep, const struct esp_info *esp_info) { unsigned eklen = esp_info->enckeylen; unsigned aklen = esp_info->authkeylen; return snprintf(ptr, buflen, "%s%s(%d)_%03d-%s(%d)_%03d", sep, strip_prefix(enum_name(&esp_transformid_names, esp_info->transid), "ESP_"), esp_info->transid, eklen, strip_prefix(strip_prefix(enum_name(&auth_alg_names, esp_info->auth), "AUTH_ALGORITHM_HMAC_"), "AUTH_ALGORITHM_"), esp_info->auth, aklen); }
/* * Show registered IKE algorithms */ void ike_alg_show_status(void) { unsigned i; struct ike_alg *algo; whack_log(RC_COMMENT, "IKE algorithms supported:"); whack_log(RC_COMMENT, " "); /* spacer */ IKE_EALG_FOR_EACH(algo) { static char v1namebuf[ENUM_SHOW_BUF_LEN]; static char v2namebuf[ENUM_SHOW_BUF_LEN]; passert(algo != NULL); passert(algo->algo_id != 0 || algo->algo_v2id != 0); whack_log(RC_COMMENT, "algorithm IKE encrypt: v1id=%d, v1name=%s, v2id=%d, v2name=%s, blocksize=%d, keydeflen=%d", algo->algo_id, enum_showb(&oakley_enc_names, algo->algo_id, v1namebuf, sizeof(v1namebuf)), algo->algo_v2id, enum_showb(&ikev2_trans_type_encr_names, algo->algo_v2id, v2namebuf, sizeof(v2namebuf)), (int)((struct encrypt_desc *)algo)->enc_blocksize, ((struct encrypt_desc *)algo)->keydeflen); } IKE_HALG_FOR_EACH(algo) { whack_log(RC_COMMENT, "algorithm IKE hash: id=%d, name=%s, hashsize=%d", algo->algo_id, enum_name(&oakley_hash_names, algo->algo_id), (int)((struct hash_desc *)algo)->hash_digest_len ); } #define IKE_DH_ALG_FOR_EACH(idx) for (idx = 0; idx != oakley_group_size; idx++) IKE_DH_ALG_FOR_EACH(i) { const struct oakley_group_desc *gdesc = oakley_group + i; whack_log(RC_COMMENT, "algorithm IKE dh group: id=%d, name=%s, bits=%d", gdesc->group, enum_name(&oakley_group_names, gdesc->group), (int)gdesc->bytes * BITS_PER_BYTE ); } whack_log(RC_COMMENT, " "); /* spacer */ }
/* * used by responder, for extracting PPK_ID from IKEv2 Notify * PPK_ID Payload, we store PPK_ID and its type in payl */ bool extract_ppk_id(pb_stream *pbs, struct ppk_id_payload *payl) { size_t len = pbs_left(pbs); u_char dst[PPK_ID_MAXLEN]; int idtype; if (len > PPK_ID_MAXLEN) { loglog(RC_LOG_SERIOUS, "PPK ID length is too big"); return FALSE; } if (len <= 1) { loglog(RC_LOG_SERIOUS, "PPK ID data must be at least 1 byte (received %zd bytes including ppk type byte)", len); return FALSE; } if (!in_raw(dst, len, pbs, "Unified PPK_ID Payload")) { loglog(RC_LOG_SERIOUS, "PPK ID data could not be read"); return FALSE; } DBG(DBG_CONTROL, DBG_log("received PPK_ID type: %s", enum_name(&ikev2_ppk_id_type_names, dst[0]))); idtype = (int)dst[0]; switch (idtype) { case PPK_ID_FIXED: DBG(DBG_CONTROL, DBG_log("PPK_ID of type PPK_ID_FIXED.")); break; case PPK_ID_OPAQUE: default: loglog(RC_LOG_SERIOUS, "PPK_ID type %d (%s) not supported", idtype, enum_name(&ikev2_ppk_id_type_names, idtype)); return FALSE; } /* clone ppk id data without ppk id type byte */ clonetochunk(payl->ppk_id, dst + 1, len - 1, "PPK_ID data"); DBG(DBG_CONTROL, DBG_dump_chunk("Extracted PPK_ID", payl->ppk_id)); return TRUE; }
/* find or construct a string to describe an enum value * Result may be in STATIC buffer -- NOT RE-ENTRANT! * * One consequence is that you cannot have two or more calls * as arguments in a single logging call. Use enum_name instead. * (Of course that means that unnamed values will be shown * badly.) */ const char *enum_showb(enum_names *ed, unsigned long val, char *buf, size_t blen) { const char *p = enum_name(ed, val); if (p == NULL) { snprintf(buf, blen, "%lu??", val); p = buf; } return p; }
const char * get_request_name(enum request request) { int i; for (i = 0; i < ARRAY_SIZE(req_info); i++) if (req_info[i].request == request) return enum_name(req_info[i].name); return request == REQ_UNKNOWN ? "unknown" : "run request"; }
void print_sa_v2_trans(struct db_v2_trans *tr) { unsigned int i; const struct enum_names *en = NULL; if(tr->transform_type <= ikev2_transid_val_descs_size) { en = ikev2_transid_val_descs[tr->transform_type]; } printf(" type: %u(%s) value: %u(%s) attr_cnt: %u\n" , tr->transform_type , enum_name(&trans_type_names, tr->transform_type) , tr->transid, en ? enum_name(en, tr->transid) : "unknown" , tr->attr_cnt); for(i=0; i<tr->attr_cnt; i++) { print_sa_v2_attr(&tr->attrs[i]); } }
static void log_sa_prop(struct db_sa *f, struct db_prop *dp) { unsigned int i; DBG_log(" protoid: %u (%s) cnt: %u\n", dp->protoid, enum_name(&protocol_names, dp->protoid), dp->trans_cnt); for (i = 0; i < dp->trans_cnt; i++) log_sa_trans(f, &dp->trans[i]); }
/* * Dump view data to file. * * FIXME: Add support for more line state and column data. */ bool save_view(struct view *view, const char *path) { struct view_column_data column_data = {0}; FILE *file = fopen(path, "w"); size_t i; if (!file) return false; fprintf(file, "View: %s\n", view->name); if (view->parent && view->parent != view) fprintf(file, "Parent: %s\n", view->parent->name); fprintf(file, "Ref: %s\n", view->ref); fprintf(file, "Dimensions: height=%d width=%d\n", view->height, view->width); fprintf(file, "Position: offset=%ld column=%ld lineno=%ld\n", view->pos.offset, view->pos.col, view->pos.lineno); for (i = 0; i < view->lines; i++) { struct line *line = &view->line[i]; fprintf(file, "line[%3zu] type=%s selected=%d\n", i, enum_name(get_line_type_name(line->type)), line->selected); if (!view->ops->get_column_data(view, line, &column_data)) return true; if (column_data.box) { const struct box *box = column_data.box; size_t j; size_t offset; fprintf(file, "line[%3zu] cells=%zu text=", i, box->cells); for (j = 0, offset = 0; j < box->cells; j++) { const struct box_cell *cell = &box->cell[j]; fprintf(file, "[%.*s]", (int) cell->length, box->text + offset); offset += cell->length; } fprintf(file, "\n"); } } fclose(file); return true; }
void print_sa_prop(struct db_sa *f, struct db_prop *dp) { unsigned int i; printf(" protoid: %u (%s) cnt: %u\n" , dp->protoid , enum_name(&protocol_names, dp->protoid) , dp->trans_cnt); for(i=0; i<dp->trans_cnt; i++) { print_sa_trans(f, &dp->trans[i]); } }
/* find or construct a string to describe an enum value * Result may be in STATIC buffer -- NOT RE-ENTRANT! */ const char *enum_show(enum_names *ed, unsigned long val) { const char *p = enum_name(ed, val); if (p == NULL) { static char buf[12]; /* only one! I hope that it is big enough */ snprintf(buf, sizeof(buf), "%lu??", val); p = buf; } return p; }
static enum status_code check_view_config(struct option_info *option, const char *argv[]) { const char *name = enum_name(option->name); int i; for (i = 0; i < ARRAY_SIZE(view_configs); i++) if (!strcmp(name, view_configs[i].name)) return parse_view_config(name, argv); return SUCCESS; }
static int wifi_scan(uint32_t index, bool now) { async_sess_t *sess = get_wifi_by_index(index); if (sess == NULL) { printf("Specified WIFI doesn't exist or cannot connect to " "it.\n"); return EINVAL; } ieee80211_scan_results_t scan_results; int rc = ieee80211_get_scan_results(sess, &scan_results, now); if (rc != EOK) { if (rc == EREFUSED) printf("Device is not ready yet.\n"); else printf("Failed to fetch scan results. Error: %d\n", rc); return rc; } if (scan_results.length == 0) return EOK; printf("%16.16s %17s %4s %5s %5s %7s %7s\n", "SSID", "MAC", "CHAN", "TYPE", "AUTH", "UNI-ALG", "GRP-ALG"); for (uint8_t i = 0; i < scan_results.length; i++) { ieee80211_scan_result_t result = scan_results.results[i]; printf("%16.16s %17s %4d %5s %5s %7s %7s\n", result.ssid, nic_addr_format(&result.bssid), result.channel, enum_name(ieee80211_security_type_strs, result.security.type), enum_name(ieee80211_security_auth_strs, result.security.auth), enum_name(ieee80211_security_alg_strs, result.security.pair_alg), enum_name(ieee80211_security_alg_strs, result.security.group_alg)); } return EOK; }
static char * readline_toggle_generator(const char *text, int state) { static const char **words; static int index, len; const char *name; char *match = NULL; /* No match */ if (!words) { /* TODO: Only complete column options that are defined * for the view. */ #define DEFINE_OPTION_WORD(name, type, flags) argv_append(&words, #name); #define DEFINE_COLUMN_OPTIONS_WORD(name, type, flags) #name, #define DEFINE_COLUMN_OPTIONS_WORDS(name, id, options) \ if (VIEW_COLUMN_##id != VIEW_COLUMN_SECTION) { \ const char *vars[] = { \ options(DEFINE_COLUMN_OPTIONS_WORD) \ }; \ char buf[SIZEOF_STR]; \ int i; \ for (i = 0; i < ARRAY_SIZE(vars); i++) { \ if (enum_name_prefixed(buf, sizeof(buf), #name, vars[i])) \ argv_append(&words, buf); \ } \ } OPTION_INFO(DEFINE_OPTION_WORD) COLUMN_OPTIONS(DEFINE_COLUMN_OPTIONS_WORDS); } /* If it is a new word to complete, initialize */ if (!state) { index = 0; len = strlen(text); } /* Return the next name which partially matches */ while ((name = words[index])) { name = enum_name(name); index++; if (strncmp(name, text, len) == 0) { /* Ignore exact completion */ if (strlen(name) > len) match = strdup(name); break; } } return match; }