本文整理汇总了C++中IFLA_RTA函数的典型用法代码示例。如果您正苦于以下问题:C++ IFLA_RTA函数的具体用法?C++ IFLA_RTA怎么用?C++ IFLA_RTA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IFLA_RTA函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: memset
void linux_unicast_router::handle_intf_event(bool isnew, nlmsghdr *hdr) {
ifinfomsg *ifi = (ifinfomsg *)NLMSG_DATA(hdr);
if (isnew) {
rtattr *tb[IFLA_MAX + 1];
memset(tb, 0, sizeof(tb));
netlink_msg::parse_rtatable(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(hdr));
if (tb[IFLA_IFNAME] && tb[IFLA_MTU]) {
interface_desc desc;
desc.index = ifi->ifi_index;
desc.name = (const char *)RTA_DATA(tb[IFLA_IFNAME]);
desc.mtu = *(int *)RTA_DATA(tb[IFLA_MTU]);
desc.flags = ifi->ifi_flags;
desc.type = _conv_intf(ifi->ifi_type, ifi->ifi_flags);
desc.up = ((ifi->ifi_flags & IFF_UP) == IFF_UP);
if (rt_dumping) {
_interfaces.push_back(desc);
} else {
_install_interface(desc);
}
}
} else {
g_mrd->lost_interface(ifi->ifi_index);
}
}
开发者ID:hugosantos,项目名称:mrd6,代码行数:29,代码来源:linux_unicast_route.cpp
示例2: NLMSG_LENGTH
int TunManager::getLinkRespParser(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg) {
// only cares about RTM_NEWLINK
if (n->nlmsg_type != RTM_NEWLINK) {
return 0;
}
struct ifinfomsg *ifi = static_cast<struct ifinfomsg *>(NLMSG_DATA(n));
struct rtattr *tb[IFLA_MAX + 1];
int len = n->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
if (len < 0) {
throw FbossError("Wrong length for RTM_GETLINK response ", len, " vs ",
NLMSG_LENGTH(sizeof(*ifi)));
}
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == nullptr) {
throw FbossError("Device @ index ", static_cast<int>(ifi->ifi_index),
" does not have a nmae");
}
const auto name = rta_getattr_str(tb[IFLA_IFNAME]);
// match the interface name against intfPrefix
if (!TunIntf::isTunIntf(name)) {
VLOG(3) << "Ignore interface " << name
<< " because it is not a tun interface";
return 0;
}
// base on the name, get the router ID
auto rid = TunIntf::getRidFromName(name);
TunManager *mgr = static_cast<TunManager *>(arg);
mgr->addIntf(rid, std::string(name), ifi->ifi_index);
return 0;
}
开发者ID:superchild,项目名称:fboss,代码行数:35,代码来源:TunManager.cpp
示例3: getlink_callback
static void getlink_callback(unsigned int error, uint16_t type, const void *data,
uint32_t len, void *user_data)
{
const struct ifinfomsg *ifi = data;
struct rtattr *rta;
int bytes;
char ifname[IF_NAMESIZE];
uint32_t index, flags;
g_assert_cmpuint(error, ==, 0);
bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
memset(ifname, 0, sizeof(ifname));
index = ifi->ifi_index;
flags = ifi->ifi_flags;
for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes);
rta = RTA_NEXT(rta, bytes)) {
switch (rta->rta_type) {
case IFLA_IFNAME:
if (RTA_PAYLOAD(rta) <= IF_NAMESIZE)
strcpy(ifname, RTA_DATA(rta));
break;
}
}
printf("index=%d flags=0x%08x name=%s\n", index, flags, ifname);
g_main_loop_quit(mainloop);
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:32,代码来源:netlink-test.c
示例4: test_container
static void test_container(void) {
_cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
uint16_t type;
uint32_t u32_data;
void *data;
int r;
struct ifinfomsg *ifi;
assert_se(sd_rtnl_message_new_link(NULL, &m, RTM_NEWLINK, 0) >= 0);
assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) >= 0);
assert_se(sd_rtnl_message_open_container(m, IFLA_LINKINFO) == -ENOTSUP);
assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) >= 0);
assert_se(sd_rtnl_message_open_container(m, IFLA_INFO_DATA) == -ENOTSUP);
assert_se(sd_rtnl_message_append_u16(m, IFLA_VLAN_ID, 100) >= 0);
assert_se(sd_rtnl_message_close_container(m) >= 0);
assert_se(sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "kind") >= 0);
assert_se(sd_rtnl_message_close_container(m) >= 0);
assert_se(sd_rtnl_message_close_container(m) == -EINVAL);
assert_se(rtnl_message_seal(NULL, m) >= 0);
assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
assert_se(type == IFLA_LINKINFO);
assert_se(data == NULL);
/*
assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
assert_se(type == IFLA_INFO_KIND);
assert_se(streq("kind", (char *)data));
assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
assert_se(type == IFLA_INFO_DATA);
assert_se(data == NULL);
assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
assert_se(type == IFLA_VLAN_ID);
assert_se(*(uint16_t *)data == 100);
assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
assert_se(sd_rtnl_message_exit_container(m) >= 0);
assert_se(sd_rtnl_message_read(m, &type, &data) >= 0);
assert_se(type == IFLA_INFO_KIND);
assert_se(streq("kind", (char *)data));
assert_se(sd_rtnl_message_read(m, &type, &data) == 0);
assert_se(sd_rtnl_message_exit_container(m) >= 0);
*/
ifi = NLMSG_DATA(m->hdr);
r = rtnl_message_parse(m,
&m->rta_offset_tb,
&m->rta_tb_size,
IFLA_MAX,
IFLA_RTA(ifi),
IFLA_PAYLOAD(m->hdr));
if(r < 0)
return;
assert_se(sd_rtnl_message_read_u32(m, IFLA_LINKINFO, &u32_data) == 0);
assert_se(sd_rtnl_message_exit_container(m) == -EINVAL);
}
开发者ID:MOBO-OSS,项目名称:systemd-relative,代码行数:59,代码来源:test-rtnl.c
示例5: get_ipv6_address
boost::asio::ip::address_v6 get_ipv6_address(const nlmsghdr *in, const nlmsghdr *an)
{
boost::asio::ip::address_v6 unspec;
if (in->nlmsg_type != RTM_NEWLINK)
return unspec;
if (an->nlmsg_type != RTM_NEWADDR)
return unspec;
ifinfomsg* ifi = (ifinfomsg*)NLMSG_DATA(in);
ifaddrmsg* ifa = (ifaddrmsg*)NLMSG_DATA(an);
__u32 ilen = in->nlmsg_len;
if (ilen < NLMSG_LENGTH(sizeof(*ifi)))
return unspec;
ilen -= NLMSG_LENGTH(sizeof(*ifi));
__u32 alen = an->nlmsg_len;
if (alen < NLMSG_LENGTH(sizeof(*ifa)))
return unspec;
alen -= NLMSG_LENGTH(sizeof(*ifa));
/* NOTE: ifi_index and ifa_index should have the same type (int), but for
* some reason they are not... So instead of a normal (in)equality comparison
* we do a bit-wise compare.
*/
if (ifi->ifi_index ^ ifa->ifa_index)
return unspec;
if (ifi->ifi_family != AF_INET6 || ifa->ifa_family != AF_INET6)
return unspec;
rtattr* tbi[IFLA_MAX+1];
memset(tbi, 0, sizeof(tbi));
parse_rtattr(tbi, IFLA_MAX, IFLA_RTA(ifi), ilen);
if (tbi[IFLA_IFNAME] == NULL)
return unspec;
rtattr* tba[IFA_MAX+1];
memset(tba, 0, sizeof(tba));
parse_rtattr(tba, IFA_MAX, IFA_RTA(ifa), alen);
char abuf[256];
rt_addr_n2a(ifa->ifa_family,
RTA_PAYLOAD(tba[IFA_ADDRESS]),
RTA_DATA(tba[IFA_ADDRESS]),
abuf, sizeof(abuf));
std::string ipaddr = abuf;
try {
boost::asio::ip::address_v6 addr(boost::asio::ip::address_v6::from_string(ipaddr));
addr.scope_id(ifi->ifi_index);
return addr;
} catch(...) {
return unspec;
}
}
开发者ID:dgeelen,项目名称:uftt,代码行数:57,代码来源:ipaddr_watcher_osimpl_v6linux.cpp
示例6: ril_mtu_watch_handle_ifinfomsg
static void ril_mtu_watch_handle_ifinfomsg(struct ril_mtu_watch *self,
const struct ifinfomsg *ifi, int len)
{
if (ifi->ifi_flags & IFF_UP) {
const struct rtattr *rta = IFLA_RTA(ifi);
ril_mtu_watch_handle_rtattr(self, rta,
len - ((char*)rta - (char*)ifi));
}
}
开发者ID:Herrie82,项目名称:ofono-fix2,代码行数:9,代码来源:ril_mtu.c
示例7: if_info_save_interface
int if_info_save_interface(struct nlmsghdr *hdr, void *arg)
{
struct rtattr *attrs[IFLA_MAX + 1];
struct ifinfomsg *info = NLMSG_DATA(hdr);
parse_rtattrs(attrs, IFLA_MAX, IFLA_RTA(info), IFLA_PAYLOAD(hdr));
return if_info_update_interface(hdr, attrs) ? 0 : -1;
}
开发者ID:a170785,项目名称:buildroot,代码行数:9,代码来源:if_info.c
示例8: vlan_get_link_parse
/**
* vlan_get_link_parse - parse a get_link rtnl message and extract the important
* data
* @nh: the reply header
* @iface: pointer to the buffer where the link interface has to be stored (it
* is allocated by this function)
*
* Return the vid in case of success or -1 otherwise
*/
static int vlan_get_link_parse(struct nlmsghdr *nh, char **iface)
{
struct ifinfomsg *ifi = NLMSG_DATA(nh);
size_t vlan_len, info_len, len = nh->nlmsg_len;
struct rtattr *rta, *info, *vlan;
int idx = -1, vid = -1;
*iface = NULL;
rta = IFLA_RTA(ifi);
while (RTA_OK(rta, len)) {
/* check if the interface is a vlan */
if (rta->rta_type == IFLA_LINKINFO) {
info = RTA_DATA(rta);
info_len = RTA_PAYLOAD(rta);
while (RTA_OK(info, info_len)) {
if (info->rta_type == IFLA_INFO_KIND &&
strcmp(RTA_DATA(info), "vlan"))
goto err;
if (info->rta_type == IFLA_INFO_DATA) {
vlan = RTA_DATA(info);
vlan_len = RTA_PAYLOAD(info);
while (RTA_OK(vlan, vlan_len)) {
if (vlan->rta_type == IFLA_VLAN_ID)
vid = *(int *)RTA_DATA(vlan);
vlan = RTA_NEXT(vlan, vlan_len);
}
}
info = RTA_NEXT(info, info_len);
}
}
/* extract the name of the "link" interface */
if (rta->rta_type == IFLA_LINK) {
idx = *(int *)RTA_DATA(rta);
*iface = malloc(IFNAMSIZ + 1);
if (!if_indextoname(idx, *iface))
goto err;
}
rta = RTA_NEXT(rta, len);
}
if (vid == -1)
goto err;
if (idx <= 0)
goto err;
return vid;
err:
free(*iface);
return -1;
}
开发者ID:hunghtbk,项目名称:batman-shell,代码行数:66,代码来源:functions.c
示例9: print_vlan
static int print_vlan(const struct sockaddr_nl *who,
struct nlmsghdr *n,
void *arg)
{
FILE *fp = arg;
struct ifinfomsg *ifm = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[IFLA_MAX+1];
if (n->nlmsg_type != RTM_NEWLINK) {
fprintf(stderr, "Not RTM_NEWLINK: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
return 0;
}
len -= NLMSG_LENGTH(sizeof(*ifm));
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
return -1;
}
if (ifm->ifi_family != AF_BRIDGE)
return 0;
if (filter_index && filter_index != ifm->ifi_index)
return 0;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifm), len);
/* if AF_SPEC isn't there, vlan table is not preset for this port */
if (!tb[IFLA_AF_SPEC]) {
fprintf(fp, "%s\tNone\n", ll_index_to_name(ifm->ifi_index));
return 0;
} else {
struct rtattr *i, *list = tb[IFLA_AF_SPEC];
int rem = RTA_PAYLOAD(list);
fprintf(fp, "%s", ll_index_to_name(ifm->ifi_index));
for (i = RTA_DATA(list); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) {
struct bridge_vlan_info *vinfo;
if (i->rta_type != IFLA_BRIDGE_VLAN_INFO)
continue;
vinfo = RTA_DATA(i);
fprintf(fp, "\t %hu", vinfo->vid);
if (vinfo->flags & BRIDGE_VLAN_INFO_PVID)
fprintf(fp, " PVID");
if (vinfo->flags & BRIDGE_VLAN_INFO_UNTAGGED)
fprintf(fp, " Egress Untagged");
fprintf(fp, "\n");
}
}
fprintf(fp, "\n");
fflush(fp);
return 0;
}
开发者ID:sivasankariit,项目名称:iproute2,代码行数:57,代码来源:vlan.c
示例10: netlink_if_link_filter
/* Netlink interface link lookup filter */
static int
netlink_if_link_filter(struct sockaddr_nl *snl, struct nlmsghdr *h)
{
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
interface_t *ifp;
int len, status;
char *name;
ifi = NLMSG_DATA(h);
if (h->nlmsg_type != RTM_NEWLINK)
return 0;
len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifinfomsg));
if (len < 0)
return -1;
/* Interface name lookup */
memset(tb, 0, sizeof (tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL)
return -1;
name = (char *) RTA_DATA(tb[IFLA_IFNAME]);
/* Return if loopback */
if (ifi->ifi_type == ARPHRD_LOOPBACK)
return 0;
/* Skip it if already exist */
ifp = if_get_by_ifname(name);
if (ifp) {
#ifdef _HAVE_VRRP_VMAC_
if (!ifp->vmac)
#endif
{
#ifdef _HAVE_VRRP_VMAC_
if_vmac_reflect_flags(ifi->ifi_index, ifi->ifi_flags);
#endif
ifp->flags = ifi->ifi_flags;
}
return 0;
}
/* Fill the interface structure */
ifp = (interface_t *) MALLOC(sizeof(interface_t));
status = netlink_if_link_populate(ifp, tb, ifi);
if (status < 0) {
FREE(ifp);
return -1;
}
/* Queue this new interface_t */
if_add_queue(ifp);
return 0;
}
开发者ID:disigma,项目名称:keepalived,代码行数:57,代码来源:vrrp_netlink.c
示例11: print_link_stats
static void print_link_stats(FILE *fp, struct nlmsghdr *n)
{
struct ifinfomsg *ifi = NLMSG_DATA(n);
struct rtattr * tb[IFLA_MAX+1];
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi),
n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifi)));
__print_link_stats(fp, tb);
fprintf(fp, "%s", _SL_);
}
开发者ID:sostheim,项目名称:iproute2-lib,代码行数:10,代码来源:ipaddress.c
示例12: rtnl_iface_get
static int rtnl_iface_get(struct nlmsghdr *h,
int (*if_callback)(struct iface *))
{
struct rtattr *tb[IFLA_MAX + 1];
struct ifinfomsg *ifi;
int len;
struct iface iface;
if (h->nlmsg_type != RTM_NEWLINK)
return 0;
ifi = NLMSG_DATA(h);
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
if (len < 0)
return -1;
netlink_parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (!tb[IFLA_IFNAME] || !tb[IFLA_ADDRESS]) {
DEBUGP("Error: getting interface info");
return -1;
}
iface.haddr_len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
if (iface.haddr_len < MAX_ADDR_LEN) {
memcpy(iface.haddr, RTA_DATA(tb[IFLA_ADDRESS]),
iface.haddr_len);
} else {
DEBUGP("Warning: Hardware address is too large: %d",
iface.haddr_len);
return -1;
}
strcpy(iface.name, (char *)RTA_DATA(tb[IFLA_IFNAME]));
strcpy(iface.qdisc, (char *)RTA_DATA(tb[IFLA_QDISC]));
iface.index = ifi->ifi_index;
iface.type = ifi->ifi_type;
iface.flags = ifi->ifi_flags & 0x0000fffff;
iface.mtu = (tb[IFLA_MTU]) ? *(int *)RTA_DATA(tb[IFLA_MTU]) : 0;
iface.weight = (tb[IFLA_WEIGHT]) ? *(int *)RTA_DATA(tb[IFLA_WEIGHT]) : 0;
iface.txqueuelen = *(int *)RTA_DATA(tb[IFLA_TXQLEN]);
iface.stats = *(struct net_device_stats *)RTA_DATA(tb[IFLA_STATS]);
return if_callback(&iface);
}
开发者ID:chentschel,项目名称:opencli,代码行数:51,代码来源:route.c
示例13: ll_remember_index
int ll_remember_index(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
int h;
struct ifinfomsg *ifi = NLMSG_DATA(n);
struct ll_cache *im, **imp;
struct rtattr *tb[IFLA_MAX+1];
UNUSED(who);
UNUSED(arg);
if (n->nlmsg_type != RTM_NEWLINK)
return 0;
if (n->nlmsg_len < NLMSG_LENGTH(sizeof(ifi)))
return -1;
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), IFLA_PAYLOAD(n));
if (tb[IFLA_IFNAME] == NULL)
return 0;
h = ifi->ifi_index & (IDXMAP_SIZE - 1);
for (imp = &idx_head[h]; (im=*imp)!=NULL; imp = &im->idx_next)
if (im->index == ifi->ifi_index)
break;
if (im == NULL) {
im = malloc(sizeof(*im));
if (im == NULL)
return 0;
im->idx_next = *imp;
im->index = ifi->ifi_index;
*imp = im;
}
im->type = ifi->ifi_type;
im->flags = ifi->ifi_flags;
if (tb[IFLA_ADDRESS]) {
size_t alen;
im->alen = alen = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
if (alen > sizeof(im->addr))
alen = sizeof(im->addr);
memcpy(im->addr, RTA_DATA(tb[IFLA_ADDRESS]), alen);
} else {
im->alen = 0;
memset(im->addr, 0, sizeof(im->addr));
}
strcpy(im->name, RTA_DATA(tb[IFLA_IFNAME]));
return 0;
}
开发者ID:AltraMayor,项目名称:xiaconf,代码行数:51,代码来源:ll_map.c
示例14: netlink_interface
/* Called from interface_lookup_netlink(). This function is only used
during bootstrap. */
static int
netlink_interface (struct sockaddr_nl *snl, struct nlmsghdr *h)
{
int len;
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
struct interface *ifp;
char *name;
ifi = NLMSG_DATA (h);
if (h->nlmsg_type != RTM_NEWLINK)
return 0;
len = h->nlmsg_len - NLMSG_LENGTH (sizeof (struct ifinfomsg));
if (len < 0)
return -1;
/* Looking up interface name. */
memset (tb, 0, sizeof tb);
netlink_parse_rtattr (tb, IFLA_MAX, IFLA_RTA (ifi), len);
#ifdef IFLA_WIRELESS
/* check for wireless messages to ignore */
if ((tb[IFLA_WIRELESS] != NULL) && (ifi->ifi_change == 0))
{
if (IS_DEBUG_HA(kroute, KROUTE))
zlog_debug ("%s: ignoring IFLA_WIRELESS message", __func__);
return 0;
}
#endif /* IFLA_WIRELESS */
if (tb[IFLA_IFNAME] == NULL)
return -1;
name = (char *) RTA_DATA (tb[IFLA_IFNAME]);
/* Add interface. */
ifp = if_get_by_name (name);
set_ifindex(ifp, ifi->ifi_index);
ifp->flags = ifi->ifi_flags & 0x0000fffff;
ifp->mtu6 = ifp->mtu = *(uint32_t *) RTA_DATA (tb[IFLA_MTU]);
ifp->metric = 1;
/* Hardware type and address. */
ifp->hw_type = ifi->ifi_type;
netlink_interface_update_hw_addr (tb, ifp);
if_add_update (ifp);
return 0;
}
开发者ID:rgmabs19357,项目名称:HA,代码行数:53,代码来源:rt_netlink.c
示例15: handle_link_msg
static int handle_link_msg(struct nlmsghdr *nlh, int n)
{
struct ifinfomsg *ifla_msg = NLMSG_DATA(nlh);
struct rtattr *tb[IFLA_MAX];
int atts = parse_rt_attrs(tb, IFLA_MAX, IFLA_RTA(ifla_msg), IFLA_PAYLOAD(nlh));
parse_ifinfomsg(ifla_msg);
handle_link_attrs(ifla_msg, tb, nlh->nlmsg_type);
return 0;
}
开发者ID:alfmatos,项目名称:neteventd,代码行数:14,代码来源:rtnl.c
示例16: IFLA_RTA
rtnetlink::if_addr& rtnetlink::if_addr::operator=(message& msg)
{
static_cast<data&>(*this) = msg;
std::pair<const void*, size_t> pl = msg.payload();
if (msg.type() < 20 || msg.type() > 23 || pl.second < sizeof(::ifaddrmsg))
throw "bad msg type";
const ::ifaddrmsg* ifa = reinterpret_cast<const ifaddrmsg*>(pl.first);
_family = ifa->ifa_family;
_prefixlen = ifa->ifa_prefixlen;
_scope = ifa->ifa_scope;
_flags = ifa->ifa_flags;
_index = ifa->ifa_index;
const ::rtattr* rta = IFLA_RTA(ifa);
size_t attrlen = IFLA_PAYLOAD(reinterpret_cast<const ::nlmsghdr*>(_msg->header()));
for (; RTA_OK(rta, attrlen); rta = RTA_NEXT(rta, attrlen)) {
switch (rta->rta_type) {
case IFA_ADDRESS:
_address = attr<void>(RTA_DATA(rta), RTA_PAYLOAD(rta));
break;
case IFA_LOCAL:
_local = attr<void>(RTA_DATA(rta), RTA_PAYLOAD(rta));
break;
case IFA_LABEL:
_label = attr<char>(RTA_DATA(rta), RTA_PAYLOAD(rta));
break;
case IFA_BROADCAST:
_broadcast = attr<void>(RTA_DATA(rta), RTA_PAYLOAD(rta));
break;
case IFA_ANYCAST:
_anycast = attr<void>(RTA_DATA(rta), RTA_PAYLOAD(rta));
break;
default:
std::cout << "IFA_UNSPEC(" << rta->rta_type << ", " << RTA_PAYLOAD(rta) << ")\n";
}
}
return *this;
}
开发者ID:ATNoG,项目名称:EMICOM,代码行数:49,代码来源:rtnetlink.cpp
示例17: netlink_reflect_filter
/* Netlink flag Link update */
static int
netlink_reflect_filter(struct sockaddr_nl *snl, struct nlmsghdr *h)
{
struct ifinfomsg *ifi;
struct rtattr *tb[IFLA_MAX + 1];
interface_t *ifp;
int len;
ifi = NLMSG_DATA(h);
if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK))
return 0;
len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifinfomsg));
if (len < 0)
return -1;
/* Interface name lookup */
memset(tb, 0, sizeof (tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL)
return -1;
/* ignore loopback device */
if (ifi->ifi_type == ARPHRD_LOOPBACK)
return 0;
/* find the VMAC interface (if any) */
ifp = if_get_by_vmac_base_ifindex(ifi->ifi_index);
/* if found, reflect base interface flags on VMAC interface */
if (ifp)
ifp->flags = ifi->ifi_flags;
/* find the interface_t */
ifp = if_get_by_ifindex(ifi->ifi_index);
if (!ifp)
return -1;
/*
* Update flags.
* VMAC interfaces should never update it own flags, only be reflected
* by the base interface flags, see above.
*/
if (!ifp->vmac)
ifp->flags = ifi->ifi_flags;
return 0;
}
开发者ID:jonasj76,项目名称:keepalived,代码行数:49,代码来源:vrrp_netlink.c
示例18: get_rtstat_nlmsg
int get_rtstat_nlmsg(struct sockaddr_nl *who, struct nlmsghdr *m, void *arg)
{
#ifndef IFLA_RTSTATS
return -1;
#else
struct ifinfomsg *ifi = NLMSG_DATA(m);
struct rtattr * tb[IFLA_MAX+1];
int len = m->nlmsg_len;
struct rtstat_ent *n;
unsigned long ival[RTMAXS];
int i;
if (m->nlmsg_type != RTM_NEWLINK)
return 0;
len -= NLMSG_LENGTH(sizeof(*ifi));
if (len < 0)
return -1;
if (!(ifi->ifi_flags&IFF_UP))
return 0;
memset(tb, 0, sizeof(tb));
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
if (tb[IFLA_IFNAME] == NULL || tb[IFLA_RTSTATS] == NULL)
return 0;
n = malloc(sizeof(*n));
if (!n)
abort();
n->ifindex = ifi->ifi_index;
n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
memcpy(&ival, RTA_DATA(tb[IFLA_RTSTATS]), sizeof(ival));
for (i=0; i<RTMAXS; i++) {
n->ival[i] = ival[i];
}
n->next = rtstat_db;
rtstat_db = n;
return 0;
#endif
}
开发者ID:JackieXie168,项目名称:connect,代码行数:47,代码来源:ifnetlink-linux-lib1.c
示例19: is_wireless_status_message
static gboolean
is_wireless_status_message (struct nlmsghdr *header)
{
int rt_attr_len;
struct rtattr *rt_attr;
rt_attr = IFLA_RTA (NLMSG_DATA (header));
rt_attr_len = IFLA_PAYLOAD (header);
while (RT_ATTR_OK (rt_attr, rt_attr_len)) {
if (rt_attr->rta_type == IFLA_WIRELESS)
return TRUE;
rt_attr = RTA_NEXT (rt_attr, rt_attr_len);
}
return FALSE;
}
开发者ID:Ham22,项目名称:gupnp,代码行数:17,代码来源:gupnp-linux-context-manager.c
示例20: extract_info
static void
extract_info (struct nlmsghdr *header, char **label)
{
int rt_attr_len;
struct rtattr *rt_attr;
rt_attr = IFLA_RTA (NLMSG_DATA (header));
rt_attr_len = IFLA_PAYLOAD (header);
while (RT_ATTR_OK (rt_attr, rt_attr_len)) {
if (rt_attr->rta_type == IFA_LABEL) {
*label = g_strdup ((char *) RTA_DATA (rt_attr));
break;
}
rt_attr = RTA_NEXT (rt_attr, rt_attr_len);
}
}
开发者ID:Ham22,项目名称:gupnp,代码行数:17,代码来源:gupnp-linux-context-manager.c
注:本文中的IFLA_RTA函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论