本文整理汇总了C++中rtnl_open_byproto函数的典型用法代码示例。如果您正苦于以下问题:C++ rtnl_open_byproto函数的具体用法?C++ rtnl_open_byproto怎么用?C++ rtnl_open_byproto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rtnl_open_byproto函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ipoe_nl_delete
void ipoe_nl_delete(int ifindex)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_ppp_error("ipoe: cannot open generic netlink socket\n");
return;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_DELETE;
addattr32(nlh, 128, IPOE_ATTR_IFINDEX, ifindex);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 )
log_ppp_error("ipoe: nl_delete: error talking to kernel\n");
rtnl_close(&rth);
}
示例2: do_ipl2tp
int do_ipl2tp(int argc, char **argv)
{
if (genl_family < 0) {
if (rtnl_open_byproto(&genl_rth, 0, NETLINK_GENERIC) < 0) {
fprintf(stderr, "Cannot open generic netlink socket\n");
exit(1);
}
genl_family = genl_resolve_family(&genl_rth, L2TP_GENL_NAME);
if (genl_family < 0)
exit(1);
}
if (argc < 1)
usage();
if (matches(*argv, "add") == 0)
return do_add(argc-1, argv+1);
if (matches(*argv, "delete") == 0)
return do_del(argc-1, argv+1);
if (matches(*argv, "show") == 0 ||
matches(*argv, "lst") == 0 ||
matches(*argv, "list") == 0)
return do_show(argc-1, argv+1);
if (matches(*argv, "help") == 0)
usage();
fprintf(stderr, "Command \"%s\" is unknown, try \"ip l2tp help\".\n", *argv);
exit(-1);
}
示例3: init
static void init(void)
{
int mcg_id = genl_resolve_mcg(IPOE_GENL_NAME, IPOE_GENL_MCG_PKT, &ipoe_genl_id);
if (mcg_id == -1) {
log_warn("ipoe: unclassified packet handling is disabled\n");
rth.fd = -1;
return;
}
if (rtnl_open_byproto(&rth, 1 << (mcg_id - 1), NETLINK_GENERIC)) {
log_error("ipoe: cannot open generic netlink socket\n");
rth.fd = -1;
return;
}
fcntl(rth.fd, F_SETFL, O_NONBLOCK);
fcntl(rth.fd, F_SETFD, fcntl(rth.fd, F_GETFD) | FD_CLOEXEC);
triton_context_register(&mc_ctx, NULL);
mc_hnd.fd = rth.fd;
triton_md_register_handler(&mc_ctx, &mc_hnd);
triton_md_enable_handler(&mc_hnd, MD_MODE_READ);
triton_context_wakeup(&mc_ctx);
ipoe_nl_del_exclude(0);
}
示例4: xfrm_spd_getinfo
static int xfrm_spd_getinfo(int argc, char **argv)
{
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
__u32 flags;
char ans[128];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(__u32));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_GETSPDINFO;
req.flags = 0XFFFFFFFF;
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1);
if (rtnl_talk(&rth, &req.n, 0, 0, &req.n, NULL, NULL) < 0)
exit(2);
print_spdinfo(&req.n, (void*)stdout);
rtnl_close(&rth);
return 0;
}
示例5: rtnl_do
int rtnl_do(int proto, struct nlmsghdr *sn, struct nlmsghdr *rn)
{
struct rtnl_handle rth;
int err;
if (rtnl_open_byproto(&rth, 0, proto) < 0) {
dbg("ERROR \n");
return -1;
}
err = rtnl_talk(&rth, sn, 0, 0, rn, NULL, NULL);
rtnl_close(&rth);
return err;
}
示例6: genl_acpi_family_open
int cthd_nl_wrapper::genl_acpi_family_open(cthd_engine *engine)
{
if (genl_get_family_status(ACPI_EVENT_FAMILY_NAME, 1) < 0)
return -1;
if (rtnl_open_byproto
(&rt_handle, nl_mgrp(acpi_event_mcast_group_id), NETLINK_GENERIC) < 0) {
fprintf(stderr, "Canot open generic netlink socket\n");
return -1;
}
thd_engine = engine;
return 0;
}
示例7: xfrm_policy_flush
static int xfrm_policy_flush(int argc, char **argv)
{
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
char buf[RTA_BUF_SIZE];
} req;
char *ptypep = NULL;
struct xfrm_userpolicy_type upt;
memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt));
req.n.nlmsg_len = NLMSG_LENGTH(0); /* nlmsg data is nothing */
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY;
while (argc > 0) {
if (strcmp(*argv, "ptype") == 0) {
if (ptypep)
duparg("ptype", *argv);
ptypep = *argv;
NEXT_ARG();
xfrm_policy_ptype_parse(&upt.type, &argc, &argv);
filter.dir_mask = XFRM_FILTER_MASK_FULL;
} else
invarg("unknown", *argv);
argc--; argv++;
}
if (ptypep) {
addattr_l(&req.n, sizeof(req), XFRMA_POLICY_TYPE,
(void *)&upt, sizeof(upt));
}
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1);
if (show_stats > 1)
fprintf(stderr, "Flush policy\n");
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
exit(2);
rtnl_close(&rth);
return 0;
}
示例8: ctrl_listen
static int ctrl_listen(int argc, char **argv)
{
struct rtnl_handle rth;
if (rtnl_open_byproto(&rth, nl_mgrp(GENL_ID_CTRL), NETLINK_GENERIC) < 0) {
fprintf(stderr, "Canot open generic netlink socket\n");
return -1;
}
if (rtnl_listen(&rth, print_ctrl, (void *) stdout) < 0)
return -1;
return 0;
}
示例9: memset
int cthd_nl_wrapper::genl_get_family_status(char *family_name, int type)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
int ret = -1;
struct {
struct nlmsghdr n;
char buf[4096];
} req;
memset(&req, 0, sizeof(req));
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = GENL_ID_CTRL;
ghdr = (struct genlmsghdr *)NLMSG_DATA(&req.n);
ghdr->cmd = CTRL_CMD_GETFAMILY;
/* send CTRL_CMD_GET_FAMILY message to controller */
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
fprintf(stderr, "Cannot open generic netlink socket\n");
exit(1);
}
addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME,
family_name, strlen(family_name) + 1);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL) < 0) {
fprintf(stderr, "Error talking to the kernel\n");
goto ctrl_done;
}
if (type) {
if (genl_get_mcast_group_id(nlh))
fprintf(stderr,
"Failed to get acpi_event multicast group\n");
} else
if (genl_print_ctrl_message(NULL, nlh, (void *)stdout) < 0)
fprintf(stderr,
"Failed to print acpi_event family status\n");
ret = 0;
ctrl_done:
rtnl_close(&rth);
return ret;
}
示例10: ipoe_nl_modify
int ipoe_nl_modify(int ifindex, uint32_t peer_addr, uint32_t addr, const char *ifname, uint8_t *hwaddr)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
int ret = 0;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
union {
uint8_t hwaddr[6];
uint64_t u64;
} u;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_ppp_error("ipoe: cannot open generic netlink socket\n");
return -1;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_MODIFY;
addattr32(nlh, 1024, IPOE_ATTR_IFINDEX, ifindex);
addattr32(nlh, 1024, IPOE_ATTR_PEER_ADDR, peer_addr);
addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr);
if (hwaddr) {
memcpy(u.hwaddr, hwaddr, 6);
addattr_l(nlh, 1024, IPOE_ATTR_HWADDR, &u.u64, 8);
}
if (ifname)
addattr_l(nlh, 1024, IPOE_ATTR_IFNAME, ifname, strlen(ifname) + 1);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) {
log_ppp_error("ipoe: nl_create: error talking to kernel\n");
ret = -1;
}
rtnl_close(&rth);
return ret;
}
示例11: genl_init_handle
int genl_init_handle(struct rtnl_handle *grth, const char *family,
int *genl_family)
{
if (*genl_family >= 0)
return 0;
if (rtnl_open_byproto(grth, 0, NETLINK_GENERIC) < 0) {
fprintf(stderr, "Cannot open generic netlink socket\n");
return -1;
}
*genl_family = genl_resolve_family(grth, family);
if (*genl_family < 0)
return -1;
return 0;
}
示例12: signaling_hipfw_feedback_init
/**
* Initialize the middlebox firewall application.
* This sets up the firewall's policies.
*
* @param policy_file the configuration file (in libconfig format) that specifies
* the firewall's policy. If NULL, a default policy is used.
*
* @return 0 on success, negative on error
*/
int signaling_hipfw_feedback_init(const char *key_file, const char *cert_file)
{
int err = 0;
/* Load the host identity */
if (HIP_DEFAULT_HIPFW_ALGO == HIP_HI_ECDSA) {
load_ecdsa_private_key(key_file, &ecdsa_key);
hip_any_key_to_hit(ecdsa_key, &our_hit, 0, HIP_HI_ECDSA);
} else if (HIP_DEFAULT_HIPFW_ALGO == HIP_HI_RSA) {
load_rsa_private_key(key_file, &rsa_key);
hip_any_key_to_hit(rsa_key, &our_hit, 0, HIP_HI_RSA);
}
HIP_DEBUG("Successfully Loaded the MiddleBox key.\n");
HIP_INFO_HIT("Our hit: ", &our_hit);
mb_cert = load_x509_certificate(cert_file);
/* Sockets */
hipfw_nat_sock_output_udp = init_raw_sock_v4(IPPROTO_UDP);
if (hipfw_nat_sock_output_udp > 0) {
HIP_DEBUG("Successfully initialized nat output socket. \n");
} else {
HIP_DEBUG("Failed to bind output socket. \n");
}
if (rtnl_open_byproto(&hipfw_nl_route,
RTMGRP_LINK | RTMGRP_IPV6_IFADDR | IPPROTO_IPV6
| RTMGRP_IPV4_IFADDR | IPPROTO_IP,
NETLINK_ROUTE) < 0) {
err = 1;
HIP_ERROR("Routing socket error: %s\n", strerror(errno));
goto out_err;
} else {
HIP_DEBUG("Successfully opened netlink socket \n");
}
/* flush ip table rules to not catch our own notify... */
system_print("iptables -D HIPFW-OUTPUT 1");
system_print("iptables -D HIPFW-OUTPUT 1");
out_err:
return err;
}
示例13: rtnl_iterate
int rtnl_iterate(int proto, int type, rtnl_filter_t func, void *extarg)
{
struct rtnl_handle rth;
if (rtnl_open_byproto(&rth, 0, proto) < 0)
return -1;
if (rtnl_wilddump_request(&rth, AF_INET6, type) < 0) {
rtnl_close(&rth);
return -1;
}
if (rtnl_dump_filter(&rth, func, extarg, NULL, NULL) < 0) {
rtnl_close(&rth);
return -1;
}
rtnl_close(&rth);
return 0;
}
示例14: mpls_list
int mpls_list(int cmd,int argc, char **argv)
{
struct genlmsghdr *ghdr;
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
char buf[4096];
} req;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC) < 0) {
fprintf (stderr, "Error opening nl socket\n");
//exit(-1);
return -1;
}
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.n.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.n.nlmsg_type = PF_MPLS;
req.n.nlmsg_seq = rth.dump = ++rth.seq;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = cmd;
if (rtnl_send(&rth, (const char *)&req.n, req.n.nlmsg_len) < 0) {
perror("Cannot send dump request");
//exit(1);
return 1;
}
if (rtnl_dump_filter(&rth, print_mpls, stdout, NULL, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
//exit(1);
return 1;
}
rtnl_close(&rth);
return 0;
}
示例15: ipoe_nl_add_vlan_mon_vid
int ipoe_nl_add_vlan_mon_vid(int ifindex, int vid)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
int r = 0;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_error("ipoe: cannot open generic netlink socket\n");
return -1;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_ADD_VLAN_MON_VID;
addattr32(nlh, 1024, IPOE_ATTR_IFINDEX, ifindex);
addattr32(nlh, 1024, IPOE_ATTR_ADDR, vid);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) {
log_error("ipoe: nl_add_vlan_mon_vid: error talking to kernel\n");
r = -1;
}
rtnl_close(&rth);
return r;
}