本文整理汇总了C++中RTA_ALIGN函数的典型用法代码示例。如果您正苦于以下问题:C++ RTA_ALIGN函数的具体用法?C++ RTA_ALIGN怎么用?C++ RTA_ALIGN使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTA_ALIGN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: debug_rta_str
/*
* debug string attribute
*/
void debug_rta_str(int lev, struct rtattr *rta, const char *name,
char *str, unsigned len)
{
if(RTA_PAYLOAD(rta) > len) {
rec_dbg(lev, "%s(%hu): -- payload too long --",
name, RTA_ALIGN(rta->rta_len));
return;
}
char *p = (char *)malloc(len);
if(p == NULL)
return;
memset(p, 0, len);
/* always p[len] == NULL */
strncpy(p, (char *)RTA_DATA(rta), len - 1);
rec_dbg(lev, "%s(%hu): %s", name, RTA_ALIGN(rta->rta_len), p);
if(str)
strncpy(str, p, len);
free(p);
return;
}
示例2: form_request_add
int form_request_add()
{
int ifcn = 1; //interface number
bzero(&req, sizeof(req));
req.nl.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
rtap = NLMSG_TAIL(&req.nl);
rtap->rta_type = RTA_DST;
rtap->rta_len = RTA_LENGTH(4);
inet_pton(AF_INET, dsts,
((char *)rtap) + sizeof(struct rtattr));
req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len);
rtap = NLMSG_TAIL(&req.nl);;
rtap->rta_type = RTA_OIF;//Output interface index
rtap->rta_len = RTA_LENGTH(sizeof(int));
memcpy(((char *)rtap) + sizeof(struct rtattr),
&ifcn, sizeof(int));
req.nl.nlmsg_len = NLMSG_ALIGN(req.nl.nlmsg_len) + RTA_ALIGN(rtap->rta_len);
req.nl.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
req.nl.nlmsg_type = RTM_NEWROUTE;
req.rt.rtm_family = AF_INET;
req.rt.rtm_table = RT_TABLE_MAIN;
req.rt.rtm_protocol = RTPROT_STATIC;
req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
req.rt.rtm_type = RTN_UNICAST;
req.rt.rtm_dst_len = pn;
return 0;
}
示例3: debug_tca_options_prio
/*
* debug prio options
*/
void debug_tca_options_prio(int lev, struct rtattr *tca, const char *name)
{
struct tc_prio_qopt *qopt;
char prio[MAX_STR_SIZE] = "";
char *p = prio;
int i, len = sizeof(prio);
if(debug_rta_len_chk(lev, tca, name, sizeof(*qopt)))
return;
qopt = (struct tc_prio_qopt *)RTA_DATA(tca);
for(i = 0; i < TC_PRIO_MAX + 1; i++) {
if(i == TC_PRIO_MAX)
APPEND_SNPRINTF(rc, p, len, "%d ", qopt->priomap[i]);
else
APPEND_SNPRINTF(rc, p, len, "%d-", qopt->priomap[i]);
}
if (p - prio == sizeof(prio)) {
rec_dbg(lev, "%s(%hu): -- priomap too long --",
name, RTA_ALIGN(tca->rta_len));
return;
}
rec_dbg(lev, "%s(%hu):", name, RTA_ALIGN(tca->rta_len));
rec_dbg(lev, " [ tc_prio_qopt(%d) ]", sizeof(*qopt));
rec_dbg(lev, " bands(%d): %d", sizeof(qopt->bands), qopt->bands);
rec_dbg(lev, " priomap(%d): %s", sizeof(qopt->priomap), prio);
}
示例4: __rta_fill
void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
{
struct rtattr *rta;
int size = RTA_LENGTH(attrlen);
rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
rta->rta_type = attrtype;
rta->rta_len = size;
memcpy(RTA_DATA(rta), data, attrlen);
memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
}
示例5: rta_addattr32
int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
{
int len = RTA_LENGTH(4);
struct rtattr *subrta;
if (RTA_ALIGN(rta->rta_len) + len > maxlen)
return -1;
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), &data, 4);
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
return 0;
}
示例6: rta_addattr_l
int rta_addattr_l(struct rtattr *rta, int maxlen, int type, void *data, int alen)
{
struct rtattr *subrta;
int len = RTA_LENGTH(alen);
if (RTA_ALIGN(rta->rta_len) + len > maxlen)
return -1;
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), data, alen);
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
return 0;
}
示例7: rta_addattr32
int FAST_FUNC rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
{
int len = RTA_LENGTH(4);
struct rtattr *subrta;
if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
return -1;
}
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
subrta->rta_type = type;
subrta->rta_len = len;
move_to_unaligned32(RTA_DATA(subrta), data);
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
return 0;
}
示例8: debug_rta_tc_addr
/*
* debug attribute
*/
void debug_rta_tc_addr(int lev, struct tcmsg *tcm, struct rtattr *rta, const char *name)
{
char addr[INET6_ADDRSTRLEN+1] = "";
int res;
res = inet_ntop_tc_addr(tcm, rta, addr, sizeof(addr));
if(res) {
rec_dbg(lev, "%s(%hu): -- %s --",
name, RTA_ALIGN(rta->rta_len),
(res == 1) ? strerror(errno) : "payload too short");
return;
}
rec_dbg(lev, "%s(%hu): %s", name, RTA_ALIGN(rta->rta_len), addr);
}
示例9: LinkCatcher
/*
* Respond to a single RTM_NEWLINK event from the rtnetlink socket.
*/
static int
LinkCatcher(struct nlmsghdr *nlh)
{
struct ifinfomsg* ifi;
#if 0
fprintf(stderr, "nlmsg_type = %d.\n", nlh->nlmsg_type);
#endif
ifi = NLMSG_DATA(nlh);
/* Code is ugly, but sort of works - Jean II */
/* If interface is getting destoyed */
if(nlh->nlmsg_type == RTM_DELLINK)
{
/* Remove from cache (if in cache) */
iw_del_interface_data(ifi->ifi_index);
return 0;
}
/* Only keep add/change events */
if(nlh->nlmsg_type != RTM_NEWLINK)
return 0;
/* Check for attributes */
if (nlh->nlmsg_len > NLMSG_ALIGN(sizeof(struct ifinfomsg)))
{
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
struct rtattr *attr = (void *) ((char *) ifi +
NLMSG_ALIGN(sizeof(struct ifinfomsg)));
while (RTA_OK(attr, attrlen))
{
/* Check if the Wireless kind */
if(attr->rta_type == IFLA_WIRELESS)
{
/* Go to display it */
print_event_stream(ifi->ifi_index,
(char *) attr + RTA_ALIGN(sizeof(struct rtattr)),
attr->rta_len - RTA_ALIGN(sizeof(struct rtattr)));
}
attr = RTA_NEXT(attr, attrlen);
}
}
return 0;
}
示例10: rta_addattr32
int rta_addattr32(struct rtattr *rta, int maxlen, int type, __u32 data)
{
int len = RTA_LENGTH(4);
struct rtattr *subrta;
if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
fprintf(stderr,"rta_addattr32: Error! max allowed bound %d exceeded\n",maxlen);
return -1;
}
subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), &data, 4);
rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
return 0;
}
示例11: debug_rta_cacheinfo
/*
* debug attribute RTA_CACHEINFO
*/
void debug_rta_cacheinfo(int lev, struct rtattr *rta, const char *name)
{
struct rta_cacheinfo *rtac;
if(debug_rta_len_chk(lev, rta, name, sizeof(*rtac)))
return;
rtac = (struct rta_cacheinfo *)RTA_DATA(rta);
rec_dbg(lev, "%s(%hu):", name, RTA_ALIGN(rta->rta_len));
rec_dbg(lev, " [ rta_cacheinfo(%d) ]", sizeof(*rtac));
rec_dbg(lev, " rta_clntref(%d): %u",
sizeof(rtac->rta_clntref), rtac->rta_clntref);
rec_dbg(lev, " rta_lastuse(%d): %u",
sizeof(rtac->rta_lastuse), rtac->rta_lastuse);
rec_dbg(lev, " rta_expires(%d): %d",
sizeof(rtac->rta_expires), rtac->rta_expires);
rec_dbg(lev, " rta_error(%d): %u",
sizeof(rtac->rta_error), rtac->rta_error);
rec_dbg(lev, " rta_used(%d): %u",
sizeof(rtac->rta_used), rtac->rta_used);
rec_dbg(lev, " rta_id(%d): %u",
sizeof(rtac->rta_id), rtac->rta_id);
rec_dbg(lev, " rta_ts(%d): %u",
sizeof(rtac->rta_ts), rtac->rta_ts);
rec_dbg(lev, " rta_tsage(%d): %u",
sizeof(rtac->rta_tsage), rtac->rta_tsage);
}
示例12: debug_tca_options_hfsc
/*
* debug hfsc options
*/
void debug_tca_options_hfsc(int lev, struct rtattr *tca, const char *name)
{
struct tc_hfsc_qopt *qopt;
struct rtattr *hfsc[__TCA_HFSC_MAX];
rec_dbg(lev, "%s(%hu):", name, RTA_ALIGN(tca->rta_len));
if(RTA_PAYLOAD(tca) == sizeof(*qopt)) {
qopt = (struct tc_hfsc_qopt *)RTA_DATA(tca);
rec_dbg(lev, " [ tc_hfsc_qopt(%d) ]", sizeof(*qopt));
rec_dbg(lev, " defcls(%d): 0x%x", sizeof(qopt->defcls), qopt->defcls);
return;
}
parse_nested_rtattr(hfsc, TCA_HFSC_MAX, tca);
if(hfsc[TCA_HFSC_RSC])
debug_tca_hfsc_sc(lev+1, hfsc[TCA_HFSC_RSC],
"TCA_HFSC_RSC");
if(hfsc[TCA_HFSC_FSC])
debug_tca_hfsc_sc(lev+1, hfsc[TCA_HFSC_FSC],
"TCA_HFSC_FSC");
if(hfsc[TCA_HFSC_USC])
debug_tca_hfsc_sc(lev+1, hfsc[TCA_HFSC_USC],
"TCA_HFSC_USC");
}
示例13: debug_rta_multipath
/*
* debug attribute RTA_MULTIPATH
*/
void debug_rta_multipath(int lev, struct rtmsg *rtm, struct rtattr *rta, const char *name)
{
struct rtnexthop *rtnh;
int rtnh_len = RTA_PAYLOAD(rta);
struct rtattr *rtnha[__RTA_MAX];
char ifname[IFNAMSIZ] = "";
char flags_list[MAX_STR_SIZE] = "";
if(debug_rta_len_chk(lev, rta, name, sizeof(*rtnh)))
return;
rec_dbg(lev, "%s(%hu):", name, RTA_ALIGN(rta->rta_len));
for(rtnh = RTA_DATA(rta); RTNH_OK(rtnh, rtnh_len);
rtnh = RTNH_NEXT(rtnh), rtnh_len -= RTNH_ALIGN(rtnh->rtnh_len)) {
conv_rtnh_flags(rtnh->rtnh_flags, flags_list, sizeof(flags_list));
if_indextoname_from_lists(rtnh->rtnh_ifindex, ifname);
rec_dbg(lev, " [ rtnexthop(%d) ]", sizeof(*rtnh));
rec_dbg(lev, " rtnh_len(%d): %hu",
sizeof(rtnh->rtnh_len), rtnh->rtnh_len);
rec_dbg(lev, " rtnh_flags(%d): %d(%s)",
sizeof(rtnh->rtnh_flags), rtnh->rtnh_flags, flags_list);
rec_dbg(lev, " rtnh_hops(%d): %d",
sizeof(rtnh->rtnh_hops), rtnh->rtnh_hops);
rec_dbg(lev, " rtnh_ifindex(%d): %d(%s)",
sizeof(rtnh->rtnh_ifindex), rtnh->rtnh_ifindex, ifname);
parse_rtattr(rtnha, RTA_MAX, RTNH_DATA(rtnh), rtnh->rtnh_len - sizeof(*rtnh));
if(rtnha[RTA_GATEWAY])
debug_rta_af(lev+3, rtnha[RTA_GATEWAY], "RTA_GATEWAY", rtm->rtm_family);
}
}
示例14: wpa_driver_wext_event_rtm_dellink
static void wpa_driver_wext_event_rtm_dellink(struct wpa_driver_wext_data *drv,
void *ctx, struct nlmsghdr *h,
int len)
{
struct ifinfomsg *ifi;
int attrlen, nlmsg_len, rta_len;
struct rtattr * attr;
if (len < sizeof(*ifi))
return;
ifi = NLMSG_DATA(h);
nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
attrlen = h->nlmsg_len - nlmsg_len;
if (attrlen < 0)
return;
attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
rta_len = RTA_ALIGN(sizeof(struct rtattr));
while (RTA_OK(attr, attrlen)) {
if (attr->rta_type == IFLA_IFNAME) {
wpa_driver_wext_event_link(drv, ctx,
((char *) attr) + rta_len,
attr->rta_len - rta_len, 1);
}
attr = RTA_NEXT(attr, attrlen);
}
}
示例15: debug_tca_rsvp_pinfo
/*
* debug attribute TCA_RSVP_PINFO
*/
void debug_tca_rsvp_pinfo(int lev, struct rtattr *rsvp, const char *name)
{
struct tc_rsvp_pinfo *pinfo;
struct tc_rsvp_gpi *dpi, *spi;
if(debug_rta_len_chk(lev, rsvp, name, sizeof(*pinfo)))
return;
pinfo = (struct tc_rsvp_pinfo *)RTA_DATA(rsvp);
dpi = &(pinfo->dpi);
spi = &(pinfo->spi);
rec_dbg(lev, "%s(%hu):", name, RTA_ALIGN(rsvp->rta_len));
rec_dbg(lev, " [ tc_rsvp_pinfo(%d) ]", sizeof(*pinfo));
rec_dbg(lev, " [ tc_rsvp_gpi dpi(%d) ]", sizeof(*dpi));
rec_dbg(lev, " key(%d): 0x%08x", sizeof(dpi->key), dpi->key);
rec_dbg(lev, " mask(%d): 0x%08x", sizeof(dpi->mask), dpi->mask);
rec_dbg(lev, " offset(%d): %d", sizeof(dpi->offset), dpi->offset);
rec_dbg(lev, " [ tc_rsvp_gpi spi(%d) ]", sizeof(*spi));
rec_dbg(lev, " key(%d): 0x%08x", sizeof(spi->key), spi->key);
rec_dbg(lev, " mask(%d): 0x%08x", sizeof(spi->mask), spi->mask);
rec_dbg(lev, " offset(%d): %d", sizeof(spi->offset), spi->offset);
rec_dbg(lev, " protocol(%d): %d", sizeof(pinfo->protocol), pinfo->protocol);
rec_dbg(lev, " tunnelid(%d): %d", sizeof(pinfo->tunnelid), pinfo->tunnelid);
rec_dbg(lev, " tunnelhdr(%d): %d", sizeof(pinfo->tunnelhdr), pinfo->tunnelhdr);
rec_dbg(lev, " pad(%d): %d", sizeof(pinfo->pad), pinfo->pad);
}