本文整理汇总了C++中duparg2函数的典型用法代码示例。如果您正苦于以下问题:C++ duparg2函数的具体用法?C++ duparg2怎么用?C++ duparg2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duparg2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_rxsci_args
static int parse_rxsci_args(int *argcp, char ***argvp, struct rxsc_desc *rxsc)
{
int argc = *argcp;
char **argv = *argvp;
bool active_set = false;
while (argc > 0) {
if (strcmp(*argv, "on") == 0) {
if (active_set)
duparg2("on/off", "on");
rxsc->active = true;
active_set = true;
} else if (strcmp(*argv, "off") == 0) {
if (active_set)
duparg2("on/off", "off");
rxsc->active = false;
active_set = true;
} else {
fprintf(stderr, "macsec: unknown command \"%s\"?\n",
*argv);
ipmacsec_usage();
}
argv++; argc--;
}
*argvp = argv;
*argcp = argc;
return 0;
}
开发者ID:dtaht,项目名称:tc-adv,代码行数:30,代码来源:ipmacsec.c
示例2: parse_encap_ip6
static int parse_encap_ip6(struct rtattr *rta, size_t len, int *argcp, char ***argvp)
{
int id_ok = 0, dst_ok = 0, tos_ok = 0, ttl_ok = 0;
char **argv = *argvp;
int argc = *argcp;
while (argc > 0) {
if (strcmp(*argv, "id") == 0) {
__u64 id;
NEXT_ARG();
if (id_ok++)
duparg2("id", *argv);
if (get_be64(&id, *argv, 0))
invarg("\"id\" value is invalid\n", *argv);
rta_addattr64(rta, len, LWTUNNEL_IP6_ID, id);
} else if (strcmp(*argv, "dst") == 0) {
inet_prefix addr;
NEXT_ARG();
if (dst_ok++)
duparg2("dst", *argv);
get_addr(&addr, *argv, AF_INET6);
rta_addattr_l(rta, len, LWTUNNEL_IP6_DST, &addr.data, addr.bytelen);
} else if (strcmp(*argv, "tc") == 0) {
__u32 tc;
NEXT_ARG();
if (tos_ok++)
duparg2("tc", *argv);
if (rtnl_dsfield_a2n(&tc, *argv))
invarg("\"tc\" value is invalid\n", *argv);
rta_addattr8(rta, len, LWTUNNEL_IP6_TC, tc);
} else if (strcmp(*argv, "hoplimit") == 0) {
__u8 hoplimit;
NEXT_ARG();
if (ttl_ok++)
duparg2("hoplimit", *argv);
if (get_u8(&hoplimit, *argv, 0))
invarg("\"hoplimit\" value is invalid\n", *argv);
rta_addattr8(rta, len, LWTUNNEL_IP6_HOPLIMIT, hoplimit);
} else {
break;
}
argc--; argv++;
}
/* argv is currently the first unparsed argument,
* but the lwt_parse_encap() caller will move to the next,
* so step back */
*argcp = argc + 1;
*argvp = argv - 1;
return 0;
}
开发者ID:multipath-tcp,项目名称:iproute-mptcp,代码行数:56,代码来源:iproute_lwtunnel.c
示例3: parse_sa_args
static int parse_sa_args(int *argcp, char ***argvp, struct sa_desc *sa)
{
int argc = *argcp;
char **argv = *argvp;
int ret;
bool active_set = false;
while (argc > 0) {
if (strcmp(*argv, "pn") == 0) {
if (sa->pn != 0)
duparg2("pn", "pn");
NEXT_ARG();
ret = get_u32(&sa->pn, *argv, 0);
if (ret)
invarg("expected pn", *argv);
if (sa->pn == 0)
invarg("expected pn != 0", *argv);
} else if (strcmp(*argv, "key") == 0) {
unsigned int len;
NEXT_ARG();
if (!hexstring_a2n(*argv, sa->key_id, MACSEC_KEYID_LEN,
&len))
invarg("expected key id", *argv);
NEXT_ARG();
if (!hexstring_a2n(*argv, sa->key, MACSEC_MAX_KEY_LEN,
&sa->key_len))
invarg("expected key", *argv);
} else if (strcmp(*argv, "on") == 0) {
if (active_set)
duparg2("on/off", "on");
sa->active = true;
active_set = true;
} else if (strcmp(*argv, "off") == 0) {
if (active_set)
duparg2("on/off", "off");
sa->active = false;
active_set = true;
} else {
fprintf(stderr, "macsec: unknown command \"%s\"?\n",
*argv);
ipmacsec_usage();
}
argv++; argc--;
}
*argvp = argv;
*argcp = argc;
return 0;
}
开发者ID:dtaht,项目名称:tc-adv,代码行数:51,代码来源:ipmacsec.c
示例4: multiaddr_list
static int multiaddr_list(int argc, char **argv)
{
struct ma_info *list = NULL;
if (!filter.family)
filter.family = preferred_family;
while (argc > 0) {
if (1) {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
} else if (matches(*argv, "help") == 0)
usage();
if (filter.dev)
duparg2("dev", *argv);
filter.dev = *argv;
}
argv++; argc--;
}
if (!filter.family || filter.family == AF_PACKET)
read_dev_mcast(&list);
if (!filter.family || filter.family == AF_INET)
read_igmp(&list);
if (!filter.family || filter.family == AF_INET6)
read_igmp6(&list);
print_mlist(stdout, list);
return 0;
}
开发者ID:kinvolk,项目名称:iproute2,代码行数:29,代码来源:ipmaddr.c
示例5: check_duparg
static void check_duparg(__u64 *attrs, int type, const char *key,
const char *argv)
{
if (!VXLAN_ATTRSET(*attrs, type)) {
*attrs |= (1L << type);
return;
}
duparg2(key, argv);
}
开发者ID:greearb,项目名称:iproute2-ct,代码行数:9,代码来源:iplink_vxlan.c
示例6: ipneigh_modify
static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;
struct ndmsg ndm;
char buf[256];
} req;
char *d = NULL;
int dst_ok = 0;
int lladdr_ok = 0;
char * lla = NULL;
inet_prefix dst;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
req.ndm.ndm_family = preferred_family;
req.ndm.ndm_state = NUD_PERMANENT;
while (argc > 0) {
if (matches(*argv, "lladdr") == 0) {
NEXT_ARG();
if (lladdr_ok)
duparg("lladdr", *argv);
lla = *argv;
lladdr_ok = 1;
} else if (strcmp(*argv, "nud") == 0) {
unsigned state;
NEXT_ARG();
if (nud_state_a2n(&state, *argv))
invarg("nud state is bad", *argv);
req.ndm.ndm_state = state;
} else if (matches(*argv, "proxy") == 0) {
NEXT_ARG();
if (matches(*argv, "help") == 0)
usage();
if (dst_ok)
duparg("address", *argv);
get_addr(&dst, *argv, preferred_family);
dst_ok = 1;
req.ndm.ndm_flags |= NTF_PROXY;
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
d = *argv;
} else {
if (strcmp(*argv, "to") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0) {
NEXT_ARG();
}
if (dst_ok)
duparg2("to", *argv);
get_addr(&dst, *argv, preferred_family);
dst_ok = 1;
}
argc--; argv++;
}
if (d == NULL || !dst_ok || dst.family == AF_UNSPEC) {
fprintf(stderr, "Device and destination are required arguments.\n");
exit(-1);
}
req.ndm.ndm_family = dst.family;
addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen);
if (lla && strcmp(lla, "null")) {
char llabuf[20];
int l;
l = ll_addr_a2n(llabuf, sizeof(llabuf), lla);
addattr_l(&req.n, sizeof(req), NDA_LLADDR, llabuf, l);
}
ll_init_map(&rth);
if ((req.ndm.ndm_ifindex = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d);
return -1;
}
if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0)
exit(2);
return 0;
}
开发者ID:AngelicFlower,项目名称:iproute-mptcp,代码行数:87,代码来源:ipneigh.c
示例7: do_set
//.........这里部分代码省略.........
flags &= ~IFF_ALLMULTI;
} else
return on_off("allmulticast", *argv);
} else if (strcmp(*argv, "promisc") == 0) {
NEXT_ARG();
mask |= IFF_PROMISC;
if (strcmp(*argv, "on") == 0) {
flags |= IFF_PROMISC;
} else if (strcmp(*argv, "off") == 0) {
flags &= ~IFF_PROMISC;
} else
return on_off("promisc", *argv);
} else if (strcmp(*argv, "trailers") == 0) {
NEXT_ARG();
mask |= IFF_NOTRAILERS;
if (strcmp(*argv, "off") == 0) {
flags |= IFF_NOTRAILERS;
} else if (strcmp(*argv, "on") == 0) {
flags &= ~IFF_NOTRAILERS;
} else
return on_off("trailers", *argv);
} else if (strcmp(*argv, "arp") == 0) {
NEXT_ARG();
mask |= IFF_NOARP;
if (strcmp(*argv, "on") == 0) {
flags &= ~IFF_NOARP;
} else if (strcmp(*argv, "off") == 0) {
flags |= IFF_NOARP;
} else
return on_off("noarp", *argv);
} else if (matches(*argv, "dynamic") == 0) {
NEXT_ARG();
mask |= IFF_DYNAMIC;
if (strcmp(*argv, "on") == 0) {
flags |= IFF_DYNAMIC;
} else if (strcmp(*argv, "off") == 0) {
flags &= ~IFF_DYNAMIC;
} else
return on_off("dynamic", *argv);
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0)
usage();
if (dev)
duparg2("dev", *argv);
dev = *argv;
}
argc--; argv++;
}
if (!dev) {
fprintf(stderr, "Not enough of information: \"dev\" argument is required.\n");
exit(-1);
}
if (newaddr || newbrd) {
halen = get_address(dev, &htype);
if (halen < 0)
return -1;
if (newaddr) {
if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0)
return -1;
}
if (newbrd) {
if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0)
return -1;
}
}
if (newname && strcmp(dev, newname)) {
if (strlen(newname) == 0)
invarg("\"\" is not a valid device identifier\n", "name");
if (do_changename(dev, newname) < 0)
return -1;
dev = newname;
}
if (qlen != -1) {
if (set_qlen(dev, qlen) < 0)
return -1;
}
if (mtu != -1) {
if (set_mtu(dev, mtu) < 0)
return -1;
}
if (newaddr || newbrd) {
if (newbrd) {
if (set_address(&ifr1, 1) < 0)
return -1;
}
if (newaddr) {
if (set_address(&ifr0, 0) < 0)
return -1;
}
}
if (mask)
return do_chflags(dev, flags, mask);
return 0;
}
开发者ID:gowthamramesh,项目名称:CSC573,代码行数:101,代码来源:iplink.c
示例8: parse_args
static int parse_args(int argc, char **argv, struct ifreq *ifr, uid_t *uid, gid_t *gid)
{
int count = 0;
memset(ifr, 0, sizeof(*ifr));
ifr->ifr_flags |= IFF_NO_PI;
while (argc > 0) {
if (matches(*argv, "mode") == 0) {
NEXT_ARG();
if (matches(*argv, "tun") == 0) {
if (ifr->ifr_flags & IFF_TAP) {
fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
exit(-1);
}
ifr->ifr_flags |= IFF_TUN;
} else if (matches(*argv, "tap") == 0) {
if (ifr->ifr_flags & IFF_TUN) {
fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
exit(-1);
}
ifr->ifr_flags |= IFF_TAP;
} else {
fprintf(stderr,"Unknown tunnel mode \"%s\"\n", *argv);
exit(-1);
}
} else if (uid && matches(*argv, "user") == 0) {
char *end;
unsigned long user;
NEXT_ARG();
if (**argv && ((user = strtol(*argv, &end, 10)), !*end))
*uid = user;
else {
struct passwd *pw = getpwnam(*argv);
if (!pw) {
fprintf(stderr, "invalid user \"%s\"\n", *argv);
exit(-1);
}
*uid = pw->pw_uid;
}
} else if (gid && matches(*argv, "group") == 0) {
char *end;
unsigned long group;
NEXT_ARG();
if (**argv && ((group = strtol(*argv, &end, 10)), !*end))
*gid = group;
else {
struct group *gr = getgrnam(*argv);
if (!gr) {
fprintf(stderr, "invalid group \"%s\"\n", *argv);
exit(-1);
}
*gid = gr->gr_gid;
}
} else if (matches(*argv, "pi") == 0) {
ifr->ifr_flags &= ~IFF_NO_PI;
} else if (matches(*argv, "one_queue") == 0) {
ifr->ifr_flags |= IFF_ONE_QUEUE;
} else if (matches(*argv, "vnet_hdr") == 0) {
ifr->ifr_flags |= IFF_VNET_HDR;
} else if (matches(*argv, "multi_queue") == 0) {
ifr->ifr_flags |= IFF_MULTI_QUEUE;
} else if (matches(*argv, "dev") == 0) {
NEXT_ARG();
strncpy(ifr->ifr_name, *argv, IFNAMSIZ-1);
} else {
if (matches(*argv, "name") == 0) {
NEXT_ARG();
} else if (matches(*argv, "help") == 0)
usage();
if (ifr->ifr_name[0])
duparg2("name", *argv);
strncpy(ifr->ifr_name, *argv, IFNAMSIZ);
}
count++;
argc--; argv++;
}
if (!(ifr->ifr_flags & TUN_TYPE_MASK)) {
fprintf(stderr, "You failed to specify a tunnel mode\n");
return -1;
}
return 0;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:89,代码来源:iptuntap.c
示例9: ipaddr_modify
//.........这里部分代码省略.........
}
case 4: /* anycast */
{
inet_prefix addr;
NEXT_ARG();
if (any_len) {
duparg("anycast", *argv);
}
get_addr(&addr, *argv, req.ifa.ifa_family);
if (req.ifa.ifa_family == AF_UNSPEC) {
req.ifa.ifa_family = addr.family;
}
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
any_len = addr.bytelen;
break;
}
case 5: /* scope */
{
uint32_t scope = 0;
NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv)) {
invarg(*argv, "scope");
}
req.ifa.ifa_scope = scope;
scoped = 1;
break;
}
case 6: /* dev */
NEXT_ARG();
d = *argv;
break;
case 7: /* label */
NEXT_ARG();
l = *argv;
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
break;
case 8: /* local */
NEXT_ARG();
default:
if (local_len) {
duparg2("local", *argv);
}
get_prefix(&lcl, *argv, req.ifa.ifa_family);
if (req.ifa.ifa_family == AF_UNSPEC) {
req.ifa.ifa_family = lcl.family;
}
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
local_len = lcl.bytelen;
}
argc--;
argv++;
}
if (d == NULL) {
bb_error_msg(bb_msg_requires_arg,"\"dev\"");
return -1;
}
if (l && strncmp(d, l, strlen(d)) != 0) {
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
}
if (peer_len == 0 && local_len && cmd != RTM_DELADDR) {
peer = lcl;
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &lcl.data, lcl.bytelen);
}
if (req.ifa.ifa_prefixlen == 0)
req.ifa.ifa_prefixlen = lcl.bitlen;
if (brd_len < 0 && cmd != RTM_DELADDR) {
inet_prefix brd;
int i;
if (req.ifa.ifa_family != AF_INET) {
bb_error_msg_and_die("broadcast can be set only for IPv4 addresses");
}
brd = peer;
if (brd.bitlen <= 30) {
for (i=31; i>=brd.bitlen; i--) {
if (brd_len == -1)
brd.data[0] |= htonl(1<<(31-i));
else
brd.data[0] &= ~htonl(1<<(31-i));
}
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &brd.data, brd.bytelen);
brd_len = brd.bytelen;
}
}
if (!scoped && cmd != RTM_DELADDR)
req.ifa.ifa_scope = default_scope(&lcl);
xrtnl_open(&rth);
ll_init_map(&rth);
req.ifa.ifa_index = xll_name_to_index(d);
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
return 2;
return 0;
}
开发者ID:hajuuk,项目名称:R7000,代码行数:101,代码来源:ipaddress.c
示例10: parse_args
//.........这里部分代码省略.........
} else if (strcmp(*argv, "oseq") == 0) {
p->o_flags |= GRE_SEQ;
} else if (strcmp(*argv, "csum") == 0) {
p->i_flags |= GRE_CSUM;
p->o_flags |= GRE_CSUM;
} else if (strcmp(*argv, "icsum") == 0) {
p->i_flags |= GRE_CSUM;
} else if (strcmp(*argv, "ocsum") == 0) {
p->o_flags |= GRE_CSUM;
} else if (strcmp(*argv, "nopmtudisc") == 0) {
p->iph.frag_off = 0;
} else if (strcmp(*argv, "pmtudisc") == 0) {
p->iph.frag_off = htons(IP_DF);
} else if (strcmp(*argv, "remote") == 0) {
NEXT_ARG();
if (strcmp(*argv, "any"))
p->iph.daddr = get_addr32(*argv);
} else if (strcmp(*argv, "local") == 0) {
NEXT_ARG();
if (strcmp(*argv, "any"))
p->iph.saddr = get_addr32(*argv);
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
strncpy(medium, *argv, IFNAMSIZ-1);
} else if (strcmp(*argv, "ttl") == 0) {
unsigned uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (get_unsigned(&uval, *argv, 0))
invarg(*argv, "TTL");
if (uval > 255)
invarg(*argv, "TTL must be <=255");
p->iph.ttl = uval;
}
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (rtnl_dsfield_a2n(&uval, *argv))
invarg(*argv, "TOS");
p->iph.tos = uval;
} else
p->iph.tos = 1;
} else {
if (strcmp(*argv, "name") == 0) {
NEXT_ARG();
}
if (p->name[0])
duparg2("name", *argv);
strncpy(p->name, *argv, IFNAMSIZ);
if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip_tunnel_parm old_p;
memset(&old_p, 0, sizeof(old_p));
if (do_get_ioctl(*argv, &old_p))
return -1;
*p = old_p;
}
}
count++;
argc--; argv++;
}
if (p->iph.protocol == 0) {
if (memcmp(p->name, "gre", 3) == 0)
p->iph.protocol = IPPROTO_GRE;
else if (memcmp(p->name, "ipip", 4) == 0)
p->iph.protocol = IPPROTO_IPIP;
else if (memcmp(p->name, "sit", 3) == 0)
p->iph.protocol = IPPROTO_IPV6;
}
if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) {
if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
bb_error_msg("Keys are not allowed with ipip and sit.");
return -1;
}
}
if (medium[0]) {
p->link = do_ioctl_get_ifindex(medium);
if (p->link == 0)
return -1;
}
if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
p->i_key = p->iph.daddr;
p->i_flags |= GRE_KEY;
}
if (p->o_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
p->o_key = p->iph.daddr;
p->o_flags |= GRE_KEY;
}
if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
bb_error_msg("Broadcast tunnel requires a source address.");
return -1;
}
return 0;
}
开发者ID:alhazred,项目名称:busybox-solaris,代码行数:101,代码来源:iptunnel.c
示例11: ipaddr_modify
//.........这里部分代码省略.........
if (any_len) {
duparg("anycast", *argv);
}
get_addr(&addr, *argv, req.ifa.ifa_family);
if (req.ifa.ifa_family == AF_UNSPEC) {
req.ifa.ifa_family = addr.family;
}
addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen);
any_len = addr.bytelen;
break;
}
case 5: /* scope */
{
int scope = 0;
NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv)) {
invarg(*argv, "invalid scope value.");
}
req.ifa.ifa_scope = scope;
scoped = 1;
break;
}
case 6: /* dev */
NEXT_ARG();
d = *argv;
break;
case 7: /* label */
NEXT_ARG();
l = *argv;
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
break;
case 8: /* local */
NEXT_ARG();
default:
if (local_len) {
duparg2("local", *argv);
}
get_prefix(&lcl, *argv, req.ifa.ifa_family);
if (req.ifa.ifa_family == AF_UNSPEC) {
req.ifa.ifa_family = lcl.family;
}
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
local_len = lcl.bytelen;
}
argc--;
argv++;
}
if (d == NULL) {
bb_error_msg("Not enough information: \"dev\" argument is required.");
return -1;
}
if (l && matches(d, l) != 0) {
bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s).", d, l);
}
if (peer_len == 0 && local_len && cmd != RTM_DELADDR) {
peer = lcl;
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &lcl.data, lcl.bytelen);
}
if (req.ifa.ifa_prefixlen == 0)
req.ifa.ifa_prefixlen = lcl.bitlen;
if (brd_len < 0 && cmd != RTM_DELADDR) {
inet_prefix brd;
int i;
if (req.ifa.ifa_family != AF_INET) {
bb_error_msg("Broadcast can be set only for IPv4 addresses");
return -1;
}
brd = peer;
if (brd.bitlen <= 30) {
for (i=31; i>=brd.bitlen; i--) {
if (brd_len == -1)
brd.data[0] |= htonl(1<<(31-i));
else
brd.data[0] &= ~htonl(1<<(31-i));
}
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &brd.data, brd.bytelen);
brd_len = brd.bytelen;
}
}
if (!scoped && cmd != RTM_DELADDR)
req.ifa.ifa_scope = default_scope(&lcl);
if (rtnl_open(&rth, 0) < 0)
exit(1);
ll_init_map(&rth);
if ((req.ifa.ifa_index = ll_name_to_index(d)) == 0) {
bb_error_msg("Cannot find device \"%s\"", d);
return -1;
}
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
exit(2);
exit(0);
}
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:101,代码来源:ipaddress.c
示例12: macsec_parse_opt
//.........这里部分代码省略.........
if (ret != 0)
return ret;
es = i;
addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ES, es);
} else if (strcmp(*argv, "scb") == 0) {
NEXT_ARG();
int i;
ret = one_of("scb", *argv, values_on_off,
ARRAY_SIZE(values_on_off), &i);
if (ret != 0)
return ret;
scb = i;
addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_SCB, scb);
} else if (strcmp(*argv, "protect") == 0) {
NEXT_ARG();
int i;
ret = one_of("protect", *argv, values_on_off,
ARRAY_SIZE(values_on_off), &i);
if (ret != 0)
return ret;
addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i);
} else if (strcmp(*argv, "replay") == 0) {
NEXT_ARG();
int i;
ret = one_of("replay", *argv, values_on_off,
ARRAY_SIZE(values_on_off), &i);
if (ret != 0)
return ret;
replay_protect = !!i;
} else if (strcmp(*argv, "window") == 0) {
NEXT_ARG();
ret = get_u32(&window, *argv, 0);
if (ret)
invarg("expected replay window size", *argv);
} else if (strcmp(*argv, "validate") == 0) {
NEXT_ARG();
ret = one_of("validate", *argv,
validate_str, ARRAY_SIZE(validate_str),
(int *)&validate);
if (ret != 0)
return ret;
addattr8(n, MACSEC_BUFLEN,
IFLA_MACSEC_VALIDATION, validate);
} else if (strcmp(*argv, "encodingsa") == 0) {
if (encoding_sa != 0xff)
duparg2("encodingsa", "encodingsa");
NEXT_ARG();
ret = get_an(&encoding_sa, *argv);
if (ret)
invarg("expected an { 0..3 }", *argv);
} else {
fprintf(stderr, "macsec: unknown command \"%s\"?\n",
*argv);
usage(stderr);
return -1;
}
argv++; argc--;
}
if (!check_txsc_flags(es, scb, send_sci)) {
fprintf(stderr,
"invalid combination of send_sci/end_station/scb\n");
return -1;
}
if (window != -1 && replay_protect == -1) {
fprintf(stderr,
"replay window set, but replay protection not enabled. did you mean 'replay on window %u'?\n",
window);
return -1;
} else if (window == -1 && replay_protect == 1) {
fprintf(stderr,
"replay protection enabled, but no window set. did you mean 'replay on window VALUE'?\n");
return -1;
}
if (cipher.id)
addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_CIPHER_SUITE,
&cipher.id, sizeof(cipher.id));
if (cipher.icv_len)
addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ICV_LEN,
&cipher.icv_len, sizeof(cipher.icv_len));
if (replay_protect != -1) {
addattr32(n, MACSEC_BUFLEN, IFLA_MACSEC_WINDOW, window);
addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_REPLAY_PROTECT,
replay_protect);
}
if (encoding_sa != 0xff) {
addattr_l(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCODING_SA,
&encoding_sa, sizeof(encoding_sa));
}
return 0;
}
开发者ID:dtaht,项目名称:tc-adv,代码行数:101,代码来源:ipmacsec.c
示例13: ipaddr_list_or_flush
static int ipaddr_list_or_flush(int argc, char **argv, int flush)
{
struct nlmsg_list *linfo = NULL;
struct nlmsg_list *ainfo = NULL;
struct nlmsg_list *l, *n;
char *filter_dev = NULL;
int no_link = 0;
ipaddr_reset_filter(oneline);
filter.showqueue = 1;
if (filter.family == AF_UNSPEC)
filter.family = preferred_family;
if (flush) {
if (argc <= 0) {
fprintf(stderr, "Flush requires arguments.\n");
return -1;
}
if (filter.family == AF_PACKET) {
fprintf(stderr, "Cannot flush link addresses.\n");
return -1;
}
}
while (argc > 0) {
if (strcmp(*argv, "to") == 0) {
NEXT_ARG();
get_prefix(&filter.pfx, *argv, filter.family);
if (filter.family == AF_UNSPEC)
filter.family = filter.pfx.family;
} else if (strcmp(*argv, "scope") == 0) {
unsigned scope = 0;
NEXT_ARG();
filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) {
if (strcmp(*argv, "all") != 0)
invarg("invalid \"scope\"\n", *argv);
scope = RT_SCOPE_NOWHERE;
filter.scopemask = 0;
}
filter.scope = scope;
} else if (strcmp(*argv, "up") == 0) {
filter.up = 1;
} else if (strcmp(*argv, "dynamic") == 0) {
filter.flags &= ~IFA_F_PERMANENT;
filter.flagmask |= IFA_F_PERMANENT;
} else if (strcmp(*argv, "permanent") == 0) {
filter.flags |= IFA_F_PERMANENT;
filter.flagmask |= IFA_F_PERMANENT;
} else if (strcmp(*argv, "secondary") == 0 ||
strcmp(*argv, "temporary") == 0) {
filter.flags |= IFA_F_SECONDARY;
filter.flagmask |= IFA_F_SECONDARY;
} else if (strcmp(*argv, "primary") == 0) {
filter.flags &= ~IFA_F_SECONDARY;
filter.flagmask |= IFA_F_SECONDARY;
} else if (strcmp(*argv, "tentative") == 0) {
filter.flags |= IFA_F_TENTATIVE;
filter.flagmask |= IFA_F_TENTATIVE;
} else if (strcmp(*argv, "deprecated") == 0) {
filter.flags |= IFA_F_DEPRECATED;
filter.flagmask |= IFA_F_DEPRECATED;
} else if (strcmp(*argv, "home") == 0) {
filter.flags |= IFA_F_HOMEADDRESS;
filter.flagmask |= IFA_F_HOMEADDRESS;
} else if (strcmp(*argv, "nodad") == 0) {
filter.flags |= IFA_F_NODAD;
filter.flagmask |= IFA_F_NODAD;
} else if (strcmp(*argv, "dadfailed") == 0) {
filter.flags |= IFA_F_DADFAILED;
filter.flagmask |= IFA_F_DADFAILED;
} else if (strcmp(*argv, "label") == 0) {
NEXT_ARG();
filter.label = *argv;
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0)
usage();
if (filter_dev)
duparg2("dev", *argv);
filter_dev = *argv;
}
argv++; argc--;
}
if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
perror("Cannot send dump request");
exit(1);
}
if (rtnl_dump_filter(&rth, store_nlmsg, &linfo, NULL, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
exit(1);
}
if (filter_dev) {
filter.ifindex = ll_name_to_index(filter_dev);
//.........这里部分代码省略.........
开发者ID:mptcp-arndale,项目名称:android_external_iproute2,代码行数:101,代码来源:ipaddress.c
示例14: parse_args
//.........这里部分代码省略.........
} else if (strcmp(*argv, "ttl") == 0 ||
strcmp(*argv, "hoplimit") == 0 ||
strcmp(*argv, "hlim") == 0) {
__u8 uval;
NEXT_ARG();
if (strcmp(*argv, "inherit") != 0) {
if (get_u8(&uval, *argv, 0))
invarg("invalid TTL\n", *argv);
p->iph.ttl = uval;
}
} else if (strcmp(*argv, "tos") == 0 ||
strcmp(*argv, "tclass") == 0 ||
matches(*argv, "dsfield") == 0) {
char *dsfield;
__u32 uval;
NEXT_ARG();
dsfield = *argv;
strsep(&dsfield, "/");
if (strcmp(*argv, "inherit") != 0) {
dsfield = *argv;
p->iph.tos = 0;
} else
p->iph.tos = 1;
if (dsfield) {
if (rtnl_dsfield_a2n(&uval, dsfield))
invarg("bad TOS value", *argv);
p->iph.tos |= uval;
}
} else {
if (strcmp(*argv, "name") == 0)
NEXT_ARG();
else if (matches(*argv, "help") == 0)
usage();
if (p->name[0])
duparg2("name", *argv);
if (get_ifname(p->name, *argv))
invarg("\"name\" not a valid ifname", *argv);
if (cmd == SIOCCHGTUNNEL && count == 0) {
struct ip_tunnel_parm old_p = {};
if (tnl_get_ioctl(*argv, &old_p))
return -1;
*p = old_p;
}
}
count++;
argc--; argv++;
}
if (p->iph.protocol == 0) {
if (memcmp(p->name, "gre", 3) == 0)
p->iph.protocol = IPPROTO_GRE;
else if (memcmp(p->name, "ipip", 4) == 0)
p->iph.protocol = IPPROTO_IPIP;
else if (memcmp(p->name, "sit", 3) == 0)
p->iph.protocol = IPPROTO_IPV6;
else if (memcmp(p->name, "isatap", 6) == 0) {
p->iph.protocol = IPPROTO_IPV6;
isatap++;
} else if (memcmp(p->name, "vti", 3) == 0) {
p->iph.protocol = IPPROTO_IPIP;
p->i_flags |= VTI_ISVTI;
}
}
if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
if (!(p->i_flags & VTI_ISVTI) &&
(p->iph.protocol != IPPROTO_GRE)) {
fprintf(stderr, "Keys are not allowed with ipip and sit tunnels\n");
return -1;
}
}
if (medium) {
p->link = ll_name_to_index(medium);
if (!p->link)
return nodev(medium);
}
if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
p->i_key = p->iph.daddr;
p->i_flags |= GRE_KEY;
}
if (p->o_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
p->o_key = p->iph.daddr;
p->o_flags |= GRE_KEY;
}
if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
fprintf(stderr, "A broadcast tunnel requires a source address\n");
return -1;
}
if (isatap)
p->i_flags |= SIT_ISATAP;
return 0;
}
开发者ID:dtaht,项目名称:tc-adv,代码行数:101,代码来源:iptunnel.c
示例15: ipaddr_modify
//.........这里部分代码省略.........
NEXT_ARG();
if (rtnl_rtscope_a2n(&scope, *argv))
invarg(*argv, "invalid scope value.");
req.ifa.ifa_scope = scope;
scoped = 1;
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
d = *argv;
} else if (strcmp(*argv, "label") == 0) {
NEXT_ARG();
l = *argv;
addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
} else if (matches(*argv, "valid_lft") == 0) {
if (valid_lftp)
duparg("valid_lft", *argv);
NEXT_ARG();
valid_lftp = *argv;
if (set_lifetime(&valid_lft, *argv))
invarg("valid_lft value", *argv);
} else if (matches(*argv, "preferred_lft") == 0) {
if (preferred_lftp)
duparg("preferred_lft", *argv);
NEXT_ARG();
preferred_lftp = *argv;
if (set_lifetime(&preferred_lft, *argv))
invarg("preferred_lft value", *argv);
} else {
if (strcmp(*argv, "local") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0)
usage();
if (local_len)
duparg2("local", *argv);
get_prefix(&lcl, *argv, req.ifa.ifa_family);
if (req.ifa.ifa_family == AF_UNSPEC)
req.ifa.ifa_family = lcl.family;
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
local_len = lcl.bytelen;
}
argc--; argv++;
}
if (d == NULL) {
fprintf(stderr, "Not enough information: \"dev\" argument is required.\n");
return -1;
}
if (l && matches(d, l) != 0) {
fprintf(stderr, "\"dev\" (%s) must match \"label\" (%s).\n", d, l);
exit(1);
}
if (peer_len == 0 && local_len && cmd != RTM_DELADDR) {
peer = lcl;
addattr_l(&req.n, sizeof(req), IFA_ADDRESS, &lcl.data, lcl.bytelen);
}
if (req.ifa.ifa_prefixlen == 0)
req.ifa.ifa_prefixlen = lcl.bitlen;
if (brd_len < 0 && cmd != RTM_DELADDR) {
inet_prefix brd;
int i;
if (req.ifa.ifa_family != AF_INET) {
fprintf(stderr, "Broadcast can be set only for IPv4 addresses\n");
return -1;
}
brd = peer;
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-ef_fw-20-20-8,代码行数:67,代码来源:ipaddress.c
示例16: ipaddr_list_or_flush
int ipaddr_list_or_flush(int argc, char **argv, int flush)
{
struct nlmsg_list *linfo = NULL;
struct nlmsg_list *ainfo = NULL;
struct nlmsg_list *l;
struct rtnl_handle rth;
char *filter_dev = NULL;
int no_link = 0;
ipaddr_reset_filter(oneline);
filter.showqueue = 1;
if (filter.family == AF_UNSPEC)
filter.family = preferred_family;
if (flush) {
if (argc <= 0) {
fprintf(stderr, "Flush requires arguments.\n");
return -1;
}
if (filter.family == AF_PACKET) {
fprintf(stderr, "Cannot flush link addresses.\n");
return -1;
}
}
while (argc > 0) {
if (strcmp(*argv, "to") == 0) {
NEXT_ARG();
get_prefix(&filter.pfx, *argv, filter.family);
if (filter.family == AF_UNSPEC)
filter.family = filter.pfx.family;
} else if (strcmp(*argv, "scope") == 0) {
int scope = 0;
NEXT_ARG();
filter.scopemask = -1;
if (rtnl_rtscope_a2n(&scope, *argv)) {
if (strcmp(*argv, "all") != 0)
invarg("invalid \"scope\"\n", *argv);
scope = RT_SCOPE_NOWHERE;
filter.scopemask = 0;
}
filter.scope = scope;
} else if (strcmp(*argv, "up") == 0) {
filter.up = 1;
} else if (strcmp(*argv, "dynamic") == 0) {
filter.flags &= ~IFA_F_PERMANENT;
filter.flagmask |= IFA_F_PERMANENT;
} else if (strcmp(*argv, "permanent") == 0) {
filter.flags |= IFA_F_PERMANENT;
filter.flagmask |= IFA_F_PERMANENT;
} else if (strcmp(*argv, "secondary") == 0) {
filter.flags |= IFA_F_SECONDARY;
filter.flagmask |= IFA_F_SECONDARY;
} else if (strcmp(*argv, "primary") == 0) {
filter.flags &= ~IFA_F_SECONDARY;
filter.flagmask |= IFA_F_SECONDARY;
} else if (strcmp(*argv, "tentative") == 0) {
filter.flags |= IFA_F_TENTATIVE;
filter.flagmask |= IFA_F_TENTATIVE;
} else if (strcmp(*argv, "deprecated") == 0) {
filter.flags |= IFA_F_DEPRECATED;
filter.flagmask |= IFA_F_DEPRECATED;
} else if (strcmp(*argv, "label") == 0) {
NEXT_ARG();
filter.label = *argv;
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0)
usage();
if (filter_dev)
duparg2("dev", *argv);
filter_dev = *argv;
}
argv++; argc--;
}
if (rtnl_open(&rth, 0) < 0)
exit(1);
if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) {
perror("Cannot send dump request");
exit(1);
}
if (rtnl_dump_filter(&rth, store_nlmsg, &linfo, NULL, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
exit(1);
}
if (filter_dev) {
filter.ifindex = ll_name_to_index(filter_dev);
if (filter.ifindex <= 0) {
fprintf(stderr, "Device \"%s\" does not exist.\n", filter_dev);
return -1;
}
}
//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:actiontec_opensrc_mi424wr-rev-ef_fw-20-20-8,代码行数:101,代码来源:ipaddress.c
示例17: iplink_parse
//.........这里部分代码省略.........
duparg("txqueuelen", *argv);
if (get_integer(&qlen, *argv, 0))
invarg("Invalid \"txqueuelen\" value\n", *argv);
addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4);
} else if (strcmp(*argv, "mtu") == 0) {
NEXT_ARG();
if (mtu != -1)
duparg("mtu", *argv);
if (get_integer(&mtu, *argv, 0))
invarg("Invalid \"mtu\" value\n", *argv);
addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4);
} else if (strcmp(*argv, "netns") == 0) {
NEXT_ARG();
if (netns != -1)
duparg("netns", *argv);
if (get_integer(&netns, *argv, 0))
invarg("Invalid \"netns\" value\n", *argv);
addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4);
} else if (strcmp(*argv, "multicast") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_MULTICAST;
if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags |= IFF_MULTICAST;
} else if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags &= ~IFF_MULTICAST;
} else
return on_off("multicast");
} else if (strcmp(*argv, "allmulticast") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_ALLMULTI;
if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags |= IFF_ALLMULTI;
} else if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags &= ~IFF_ALLMULTI;
} else
return on_off("allmulticast");
} else if (strcmp(*argv, "promisc") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_PROMISC;
if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags |= IFF_PROMISC;
} else if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags &= ~IFF_PROMISC;
} else
return on_off("promisc");
} else if (strcmp(*argv, "trailers") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_NOTRAILERS;
if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags |= IFF_NOTRAILERS;
} else if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags &= ~IFF_NOTRAILERS;
} else
return on_off("trailers");
} else if (strcmp(*argv, "arp") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_NOARP;
if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags &= ~IFF_NOARP;
} else if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags |= IFF_NOARP;
} else
return on_off("noarp");
#ifdef IFF_DYNAMIC
} else if (matches(*argv, "dynamic") == 0) {
NEXT_ARG();
req->i.ifi_change |= IFF_DYNAMIC;
if (strcmp(*argv, "on") == 0) {
req->i.ifi_flags |= IFF_DYNAMIC;
} else if (strcmp(*argv, "off") == 0) {
req->i.ifi_flags &= ~IFF_DYNAMIC;
} else
return on_off("dynamic");
#endif
} else if (matches(*argv, "type") == 0) {
NEXT_ARG();
*type = *argv;
argc--; argv++;
break;
} else if (matches(*argv, "alias") == 0) {
NEXT_ARG();
addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS,
*argv, strlen(*argv));
argc--; argv++;
break;
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
}
if (matches(*argv, "help") == 0)
usage();
if (*dev)
duparg2("dev", *argv);
*dev = *argv;
}
argc--; argv++;
}
return ret - argc;
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:101,代码来源:iplink.c
示例18: ipneigh_modify
static int ipneigh_modify(int cmd, int flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;
struct ndmsg ndm;
char buf[256];
} req = {
.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg)),
.n.nlmsg_flags = NLM_F_REQUEST | flags,
.n.nlmsg_type = cmd,
.ndm.ndm_family = preferred_family,
.ndm.ndm_state = NUD_PERMANENT,
};
char *dev = NULL;
int dst_ok = 0;
int dev_ok = 0;
int lladdr_ok = 0;
char *lla = NULL;
inet_prefix dst;
while (argc > 0) {
if (matches(*argv, "lladdr") == 0) {
NEXT_ARG();
if (lladdr_ok)
duparg("lladdr", *argv);
lla = *argv;
lladdr_ok = 1;
} else if (strcmp(*argv, "nud") == 0) {
unsigned int state;
NEXT_ARG();
if (nud_state_a2n(&state, *argv))
invarg("nud state is bad", *argv);
req.ndm.ndm_state = state;
} else if (matches(*argv, "proxy") == 0) {
NEXT_ARG();
if (matches(*argv, "help") == 0)
usage();
if (dst_ok)
duparg("address", *argv);
get_addr(&dst, *argv, preferred_family);
dst_ok = 1;
dev_ok = 1;
req.ndm.ndm_flags |= NTF_PROXY;
} else if (strcmp(*argv, "router") == 0) {
req.ndm.ndm_flags |= NTF_ROUTER;
}
|
请发表评论