X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fncaps-net.c;h=8449bba4100db6351118fd3abecd48e7462764f4;hb=981064d039d0e7a5fd66b5369f2a0390728ca4be;hp=9154cb7d320dcd25f9c349f583730c3f9a252a6e;hpb=9c78378bebc1a9f3d400f422df8ede9efea57dea;p=util-vserver.git diff --git a/lib/ncaps-net.c b/lib/ncaps-net.c index 9154cb7..8449bba 100644 --- a/lib/ncaps-net.c +++ b/lib/ncaps-net.c @@ -25,19 +25,33 @@ #include #include +#include #include #define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } static struct Mapping_uint64 const VALUES[] = { -#warning Add the 'ncap' values here - DECL("", 0) + DECL("tun_create", VC_NXC_TUN_CREATE), + DECL("raw_icmp", VC_NXC_RAW_ICMP), }; +inline static char const * +removePrefix(char const *str, size_t *len) +{ + if ((len==0 || *len==0 || *len>4) && + strncasecmp("nxc_", str, 4)==0) { + if (len && *len>4) *len -= 4; + return str+4; + } + else + return str; +} + uint_least64_t vc_text2ncap(char const *str, size_t len) { - ssize_t idx = utilvserver_value2text_uint64(str, len, + char const * tmp = removePrefix(str, &len); + ssize_t idx = utilvserver_value2text_uint64(tmp, len, VALUES, DIM_OF(VALUES)); if (idx==-1) return 0; else return VALUES[idx].val;