static void add_s (MatchState *ms, luaL_Buffer *b, const lua_WChar *s, const lua_WChar *e) { lua_State *L = ms->L; if (lua_iswstring(L, 3)) { const lua_WChar *news = lua_towstring(L, 3); size_t l = lua_strlen(L, 3); size_t i; for (i=0; i<l; i++) { if (news[i] != ESC) luaL_putwchar(b, news[i]); else { i++; /* skip ESC */ if (!iswdigit(news[i])) luaL_putwchar(b, news[i]); else { int level = check_capture(ms, news[i]); push_onecapture(ms, level); luaL_addvalue(b); /* add capture to accumulated result */ } } } } else { /* is a function */ int n; lua_pushvalue(L, 3); n = push_captures(ms, s, e); lua_call(L, n, 1); if (lua_iswstring(L, -1)) luaL_addvalue(b); /* add return to accumulated result */ else lua_pop(L, 1); /* function result is not a string: pop it */ } }
static void add_s (lua_State *L, luaL_Buffer *b, struct Capture *cap) { if (lua_isstring(L, 3)) { const char *news = lua_tostring(L, 3); size_t l = lua_strlen(L, 3); size_t i; for (i=0; i<l; i++) { if (news[i] != ESC) luaL_putchar(b, news[i]); else { i++; /* skip ESC */ if (!isdigit((unsigned char)news[i])) luaL_putchar(b, news[i]); else { int level = check_capture(L, news[i], cap); luaL_addlstring(b, cap->capture[level].init, cap->capture[level].len); } } } } else { /* is a function */ int n; lua_pushvalue(L, 3); n = push_captures(L, cap); lua_rawcall(L, n, 1); if (lua_isstring(L, -1)) luaL_addvalue(b); /* add return to accumulated result */ else lua_pop(L, 1); /* function result is not a string: pop it */ } }
static const char *match_capture (MatchState *ms, const char *s, int l) { size_t len; l = check_capture(ms, l); len = ms->capture[l].len; if ((size_t)(ms->src_end-s) >= len && memcmp(ms->capture[l].init, s, len) == 0) return s+len; else return NULL; }
static const char *match_capture (lua_State *L, const char *s, int level, struct Capture *cap) { int l = check_capture(L, level, cap); size_t len = cap->capture[l].len; if ((size_t)(cap->src_end-s) >= len && memcmp(cap->capture[l].init, s, len) == 0) return s+len; else return NULL; }
void dev_info(const char *regex) { int err, idx; pcap_if_t *devs = NULL, *cur; char errbuf[PCAP_ERRBUF_SIZE]; bool dev_found = false; bool rfmon_ok, promisc_ok, capture_ok; err = pcap_findalldevs(&devs, errbuf); if(err) die(0, "%s", errbuf); for(idx = 0, cur = devs; cur; cur = cur->next, ++idx) if(regex_matches_or_is_null(regex, cur->name)) { dev_found = true; errbuf[0] = '\0'; capture_ok = check_capture(errbuf, cur->name); rfmon_ok = capture_ok ? check_rfmon(cur->name) : false; promisc_ok = capture_ok ? check_promisc(cur->name) : false; printf("%3d: ", idx); printf("%-22s %s%s%s%s%s%s\n", cur->name , cur->flags & PCAP_IF_LOOPBACK ? "[loopback]" : "" , cur->flags & PCAP_IF_UP ? "[up]" : "[down]" , cur->flags & PCAP_IF_RUNNING ? "[running]" : "" , promisc_ok ? "[promisc_ok]" : "" , rfmon_ok ? "[rfmon_ok]" : "" , capture_ok ? "[usable]" : "[unusable]"); if(options.verbose) { if(cur->description) printf(" %s\n", cur->description); if(errbuf[0]) printf(" %s\n", errbuf); print_pcap_addrs(cur->addresses); print_datalinks(cur->name); print_timestamp_types(cur->name); } } if(!dev_found) fprintf(stderr, "No matching devices found\n"); pcap_freealldevs(devs); }