本文整理汇总了C++中NIPQUAD函数的典型用法代码示例。如果您正苦于以下问题:C++ NIPQUAD函数的具体用法?C++ NIPQUAD怎么用?C++ NIPQUAD使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NIPQUAD函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: route
/* Try to route the packet according to the routing keys specified in
* route_info. Keys are :
* - ifindex :
* 0 if no oif preferred,
* otherwise set to the index of the desired oif
* - route_info->gw :
* 0 if no gateway specified,
* otherwise set to the next host to which the pkt must be routed
* If success, skb->dev is the output device to which the packet must
* be sent and skb->dst is not NULL
*
* RETURN: -1 if an error occured
* 1 if the packet was succesfully routed to the
* destination desired
* 0 if the kernel routing table could not route the packet
* according to the keys specified
*/
static int route(struct sk_buff *skb,
unsigned int ifindex,
const struct ipt_route_target_info *route_info)
{
int err;
struct rtable *rt;
struct iphdr *iph =ip_hdr(skb);
struct flowi fl = {
.oif = ifindex,
.nl_u = {
.ip4_u = {
.daddr = iph->daddr,
.saddr = 0,
.tos = RT_TOS(iph->tos),
.scope = RT_SCOPE_UNIVERSE,
}
}
};
/* The destination address may be overloaded by the target */
if (route_info->gw)
fl.fl4_dst = route_info->gw;
/* Trying to route the packet using the standard routing table. */
// if ((err = ip_route_output_key(dev_net(dev),,&rt, &fl))) {
if ((err = ip_route_output_key(&init_net,&rt, &fl))) {
if (net_ratelimit())
DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err);
return -1;
}
/* Drop old route. */
dst_release(skb->dst);
skb->dst = NULL;
/* Success if no oif specified or if the oif correspond to the
* one desired */
if (!ifindex || rt->u.dst.dev->ifindex == ifindex) {
skb->dst = &rt->u.dst;
skb->dev = skb->dst->dev;
skb->protocol = htons(ETH_P_IP);
return 1;
}
/* The interface selected by the routing table is not the one
* specified by the user. This may happen because the dst address
* is one of our own addresses.
*/
if (net_ratelimit())
DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n",
NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex);
return 0;
}
示例2: rxrpc_call_seq_show
static int rxrpc_call_seq_show(struct seq_file *seq, void *v)
{
struct rxrpc_transport *trans;
struct rxrpc_call *call;
char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1];
if (v == &rxrpc_calls) {
seq_puts(seq,
"Proto Local Remote "
" SvID ConnID CallID End Use State Abort "
" UserID\n");
return 0;
}
call = list_entry(v, struct rxrpc_call, link);
trans = call->conn->trans;
sprintf(lbuff, NIPQUAD_FMT":%u",
NIPQUAD(trans->local->srx.transport.sin.sin_addr),
ntohs(trans->local->srx.transport.sin.sin_port));
sprintf(rbuff, NIPQUAD_FMT":%u",
NIPQUAD(trans->peer->srx.transport.sin.sin_addr),
ntohs(trans->peer->srx.transport.sin.sin_port));
seq_printf(seq,
"UDP %-22.22s %-22.22s %4x %08x %08x %s %3u"
" %-8.8s %08x %lx\n",
lbuff,
rbuff,
ntohs(call->conn->service_id),
ntohl(call->conn->cid),
ntohl(call->call_id),
call->conn->in_clientflag ? "Svc" : "Clt",
atomic_read(&call->usage),
rxrpc_call_states[call->state],
call->abort_code,
call->user_call_ID);
return 0;
}
示例3: delip_kernel
static int
delip_kernel(struct ip_set *set,
const struct sk_buff *skb,
ip_set_ip_t *hash_ip,
const u_int32_t *flags,
unsigned char index)
{
ip_set_ip_t port;
if (flags[index+1] == 0)
return -EINVAL;
port = get_port(skb, flags[index+1]);
DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
flags[index] & IPSET_SRC ? "SRC" : "DST",
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
NIPQUAD(ip_hdr(skb)->saddr),
NIPQUAD(ip_hdr(skb)->daddr));
#else
NIPQUAD(skb->nh.iph->saddr),
NIPQUAD(skb->nh.iph->daddr));
#endif
DP("flag %s port %u",
flags[index+1] & IPSET_SRC ? "SRC" : "DST",
port);
if (port == INVALID_PORT)
return -EINVAL;
return __delip(set,
ntohl(flags[index] & IPSET_SRC
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
? ip_hdr(skb)->saddr
: ip_hdr(skb)->daddr),
#else
? skb->nh.iph->saddr
: skb->nh.iph->daddr),
#endif
port,
hash_ip);
}
示例4: nat_t120
static int nat_t120(struct sk_buff *skb, struct nf_conn *ct,
enum ip_conntrack_info ctinfo,
unsigned char **data, int dataoff,
H245_TransportAddress *taddr, __be16 port,
struct nf_conntrack_expect *exp)
{
int dir = CTINFO2DIR(ctinfo);
u_int16_t nated_port = ntohs(port);
/* Set expectations for NAT */
exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
exp->expectfn = nf_nat_follow_master;
exp->dir = !dir;
/* Try to get same port: if not, try to change it. */
for (; nated_port != 0; nated_port++) {
exp->tuple.dst.u.tcp.port = htons(nated_port);
if (nf_conntrack_expect_related(exp) == 0)
break;
}
if (nated_port == 0) { /* No port available */
if (net_ratelimit())
printk("nf_nat_h323: out of TCP ports\n");
return 0;
}
/* Modify signal */
if (set_h245_addr(skb, data, dataoff, taddr,
&ct->tuplehash[!dir].tuple.dst.u3,
htons(nated_port)) < 0) {
nf_conntrack_unexpect_related(exp);
return -1;
}
DEBUGP("nf_nat_h323: expect T.120 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n",
NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port),
NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port));
return 0;
}
示例5: atm_mpoa_disp_qos
/* this is buggered - we need locking for qos_head */
void atm_mpoa_disp_qos(struct seq_file *m)
{
unsigned char *ip;
char ipaddr[16];
struct atm_mpoa_qos *qos;
qos = qos_head;
seq_printf(m, "QoS entries for shortcuts:\n");
seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n");
ipaddr[sizeof(ipaddr)-1] = '\0';
while (qos != NULL) {
ip = (unsigned char *)&qos->ipaddr;
sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(ip));
seq_printf(m, "%u.%u.%u.%u\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n",
NIPQUAD(ipaddr),
qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu,
qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu);
qos = qos->next;
}
}
示例6: iprange_mt_v0
static bool
iprange_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
{
const struct ipt_iprange_info *info = par->matchinfo;
const struct iphdr *iph = ip_hdr(skb);
if (info->flags & IPRANGE_SRC) {
if ((ntohl(iph->saddr) < ntohl(info->src.min_ip)
|| ntohl(iph->saddr) > ntohl(info->src.max_ip))
^ !!(info->flags & IPRANGE_SRC_INV)) {
pr_debug("src IP %u.%u.%u.%u NOT in range %s"
"%u.%u.%u.%u-%u.%u.%u.%u\n",
NIPQUAD(iph->saddr),
info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
NIPQUAD(info->src.min_ip),
NIPQUAD(info->src.max_ip));
return false;
}
}
if (info->flags & IPRANGE_DST) {
if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip)
|| ntohl(iph->daddr) > ntohl(info->dst.max_ip))
^ !!(info->flags & IPRANGE_DST_INV)) {
pr_debug("dst IP %u.%u.%u.%u NOT in range %s"
"%u.%u.%u.%u-%u.%u.%u.%u\n",
NIPQUAD(iph->daddr),
info->flags & IPRANGE_DST_INV ? "(INV) " : "",
NIPQUAD(info->dst.min_ip),
NIPQUAD(info->dst.max_ip));
return false;
}
}
return true;
}
示例7: mms_nat_expected
static unsigned int
mms_nat_expected(struct sk_buff **pskb,
unsigned int hooknum,
struct ip_conntrack *ct,
struct ip_nat_info *info)
{
struct ip_nat_multi_range mr;
u_int32_t newdstip, newsrcip, newip;
struct ip_conntrack *master = master_ct(ct);
IP_NF_ASSERT(info);
IP_NF_ASSERT(master);
IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum))));
DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n");
newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip;
DEBUGP("ip_nat_mms: mms_nat_expected: hook %s: newsrc->newdst %u.%u.%u.%u->%u.%u.%u.%u\n",
hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
: hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
: hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???",
NIPQUAD(newsrcip), NIPQUAD(newdstip));
if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC)
newip = newsrcip;
else
newip = newdstip;
DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip));
mr.rangesize = 1;
/* We don't want to manip the per-protocol, just the IPs. */
mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
mr.range[0].min_ip = mr.range[0].max_ip = newip;
return ip_nat_setup_info(ct, &mr, hooknum);
}
示例8: gr_log_start
static int gr_log_start(int audit)
{
char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
if (audit == GR_DO_AUDIT)
goto set_fmt;
if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
grsec_alert_wtime = jiffies;
grsec_alert_fyet = 0;
} else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
grsec_alert_fyet++;
} else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
grsec_alert_wtime = jiffies;
grsec_alert_fyet++;
printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
return FLOODING;
} else return FLOODING;
set_fmt:
memset(buf, 0, PAGE_SIZE);
if (current->signal->curr_ip && gr_acl_is_enabled()) {
sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
} else if (current->signal->curr_ip) {
sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
} else if (gr_acl_is_enabled()) {
sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
} else {
sprintf(fmt, "%s%s", loglevel, "grsec: ");
strcpy(buf, fmt);
}
return NO_FLOODING;
}
示例9: ipv4_subnet_to_string
/* Convert an IPv4 subnet to human-readable a.b.c.d/e format. */
static int ipv4_subnet_to_string(char *buffer, int size,
const struct ipv4_subnet *net)
{
int mask_len;
if (net->mask == 0) {
mask_len = 0;
} else {
/* count trailing zeroes */
mask_len = 32 - __builtin_ctz(be32_to_cpu(net->mask));
}
return snprintf(buffer, size, "%u.%u.%u.%u/%d",
NIPQUAD(net->ip), mask_len);
}
示例10: rds_recv_route
static void
rds_recv_route(struct rds_connection *conn, struct rds_incoming *inc,
gfp_t gfp)
{
struct rds_connection *nconn;
struct rds_nf_hdr *dst, *org;
/* pull out the rds header */
dst = rds_nf_hdr_dst(inc->i_skb);
org = rds_nf_hdr_org(inc->i_skb);
/* special case where we are swapping the message back on the same connection */
if (dst->saddr == org->daddr && dst->daddr == org->saddr) {
nconn = conn;
} else {
/* reroute to a new conn structure, possibly the same one */
nconn = rds_conn_find(dst->saddr, dst->daddr, conn->c_trans,
conn->c_tos);
}
/* cannot find a matching connection so drop the request */
if (NULL == nconn) {
printk(KERN_ALERT "cannot find matching conn for inc %p, %u.%u.%u.%u -> %u.%u.%u.%u\n",
inc, NIPQUAD(dst->saddr), NIPQUAD(dst->daddr));
rdsdebug("cannot find matching conn for inc %p, %u.%u.%u.%u -> %u.%u.%u.%u",
inc, NIPQUAD(dst->saddr), NIPQUAD(dst->daddr));
rds_recv_drop(conn, dst->saddr, dst->daddr, inc, gfp);
}
/* this is a request for our local node, but potentially a different source
* either way we process it locally */
else if (conn->c_trans->skb_local(inc->i_skb)) {
rds_recv_local(nconn, dst->saddr, dst->daddr, inc, gfp);
}
/* looks like this request is going out to another node */
else {
rds_recv_forward(nconn, inc, gfp);
}
}
示例11: create_socket
/** Create a socket.
* The flags can include values from enum VsockFlag.
*
* @param socktype socket type
* @param saddr address
* @param port port
* @param flags flags
* @param val return value for the socket connection
* @return 0 on success, error code otherwise
*/
int create_socket(int socktype, uint32_t saddr, uint32_t port, int flags, int *val){
int err = 0;
int sock;
struct sockaddr_in addr_in;
struct sockaddr *addr = (struct sockaddr *)&addr_in;
int addr_n = sizeof(addr_in);
int sockproto = 0;
//dprintf(">\n");
addr_in.sin_family = AF_INET;
addr_in.sin_addr.s_addr = saddr;
addr_in.sin_port = port;
dprintf("> flags=%s addr=%u.%u.%u.%u port=%d\n",
socket_flags(flags),
NIPQUAD(saddr), ntohs(port));
switch(socktype){
case SOCK_DGRAM: sockproto = IPPROTO_UDP; break;
case SOCK_STREAM: sockproto = IPPROTO_TCP; break;
}
sock = socket(AF_INET, socktype, sockproto);
if(sock < 0) goto exit;
if(flags & VSOCK_REUSE){
err = setsock_reuse(sock, 1);
if(err < 0) goto exit;
}
if(flags & VSOCK_BROADCAST){
err = setsock_broadcast(sock, 1);
if(err < 0) goto exit;
}
if(flags & VSOCK_MULTICAST){
err = setsock_multicast(sock, saddr);
if(err < 0) goto exit;
}
if(flags & VSOCK_CONNECT){
err = connect(sock, addr, addr_n);
if(err < 0) goto exit;
}
if(flags & VSOCK_BIND){
err = bind(sock, addr, addr_n);
if(err < 0) goto exit;
}
if(flags & VSOCK_NONBLOCK){
err = fcntl(sock, F_SETFL, O_NONBLOCK);
if(err < 0) goto exit;
}
exit:
*val = (err ? -1 : sock);
if(err) eprintf("> err=%d errno=%d\n", err, errno);
return err;
}
示例12: ah_conn_in_get
static struct ip_vs_conn *
ah_conn_in_get(const struct sk_buff *skb,
struct ip_vs_protocol *pp,
const struct iphdr *iph,
unsigned int proto_off,
int inverse)
{
struct ip_vs_conn *cp;
if (likely(!inverse)) {
cp = ip_vs_conn_in_get(IPPROTO_UDP,
iph->saddr,
htons(PORT_ISAKMP),
iph->daddr,
htons(PORT_ISAKMP));
} else {
cp = ip_vs_conn_in_get(IPPROTO_UDP,
iph->daddr,
htons(PORT_ISAKMP),
iph->saddr,
htons(PORT_ISAKMP));
}
if (!cp) {
/*
* We are not sure if the packet is from our
* service, so our conn_schedule hook should return NF_ACCEPT
*/
IP_VS_DBG(12, "Unknown ISAKMP entry for outin packet "
"%s%s %u.%u.%u.%u->%u.%u.%u.%u\n",
inverse ? "ICMP+" : "",
pp->name,
NIPQUAD(iph->saddr),
NIPQUAD(iph->daddr));
}
return cp;
}
示例13: nlmsvc_grant_callback
/*
* This is the callback from the RPC layer when the NLM_GRANTED_MSG
* RPC call has succeeded or timed out.
* Like all RPC callbacks, it is invoked by the rpciod process, so it
* better not sleep. Therefore, we put the blocked lock on the nlm_blocked
* chain once more in order to have it removed by lockd itself (which can
* then sleep on the file semaphore without disrupting e.g. the nfs client).
*/
static void
nlmsvc_grant_callback(struct rpc_task *task)
{
struct nlm_rqst *call = (struct nlm_rqst *) task->tk_calldata;
struct nlm_block *block;
unsigned long timeout;
struct sockaddr_in *peer_addr = RPC_PEERADDR(task->tk_client);
dprintk("lockd: GRANT_MSG RPC callback\n");
dprintk("callback: looking for cookie %s, host %u.%u.%u.%u\n",
nlmdbg_cookie2a(&call->a_args.cookie),
NIPQUAD(peer_addr->sin_addr.s_addr));
if (!(block = nlmsvc_find_block(&call->a_args.cookie, peer_addr))) {
dprintk("lockd: no block for cookie %s, host %u.%u.%u.%u\n",
nlmdbg_cookie2a(&call->a_args.cookie),
NIPQUAD(peer_addr->sin_addr.s_addr));
return;
}
/* Technically, we should down the file semaphore here. Since we
* move the block towards the head of the queue only, no harm
* can be done, though. */
if (task->tk_status < 0) {
/* RPC error: Re-insert for retransmission */
timeout = 10 * HZ;
} else if (block->b_done) {
/* Block already removed, kill it for real */
timeout = 0;
} else {
/* Call was successful, now wait for client callback */
timeout = 60 * HZ;
}
nlmsvc_insert_block(block, timeout);
svc_wake_up(block->b_daemon);
block->b_incall = 0;
nlm_release_host(call->a_host);
}
示例14: validate_ipv4_address
bool validate_ipv4_address(const char *ip) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
__be32 result_;
return (in4_pton(ip, strlen(ip), (__u8 *) &result_, '\0', NULL) == 1);
#else
char src_ip_[50];
__be32 result_ = in_aton(ip);
sprintf(src_ip_, "%d.%d.%d.%d", NIPQUAD(result_));
src_ip_[strlen(ip)] = '\0';
return strcmp(ip, src_ip_) == 0;
#endif
}
示例15: execute_command2
/* Parses and executes the command using, if necessary, omega_interrupt */
int execute_command2(fd_set *dset) {
char command[100];
char cmd;
unsigned int gid;
int candidate, notif_type;
unsigned int TdU, TmU, TmrL;
struct omega_proc_struct leader;
int retval = 0;
scanf("%s", command);
switch(command[0]) {
case 'b' : scanf("%c", &cmd);
retval = omega_unregister(omega_interrupt);
if (retval >= 0) {
FD_CLR(omega_interrupt, dset);
omega_interrupt = 0;
}
return retval;
case 'c' : scanf("%c %u %d %d %u %u %u", &cmd, &gid, &candidate,
¬if_type, &TdU, &TmU, &TmrL);
candidate = ((candidate == 1) ?
CANDIDATE : NOT_CANDIDATE);
notif_type = ((notif_type == 1) ?
OMEGA_INTERRUPT_ANY_CHANGE : OMEGA_INTERRUPT_NONE);
retval = omega_startOmega(omega_interrupt, gid,
candidate, notif_type, TdU, TmU, TmrL);
return retval;
case 'd' : scanf("%c %u", &cmd, &gid);
retval = omega_stopOmega(omega_interrupt, gid);
return retval;
case 'e' : scanf("%c %u", &cmd, &gid);
retval = omega_getleader(omega_interrupt, gid, &leader);
if (retval >= 0)
printf("Current leader of group: %u is pid: %u address:"
" %u.%u.%u.%u\n", leader.gid, leader.pid,
NIPQUAD(&leader.addr));
return retval;
case 'f' : scanf("%c %u", &cmd, &gid);
retval = omega_interrupt_any_change(omega_interrupt,
gid);
return retval;
case 'g' : scanf("%c %u", &cmd, &gid);
retval = omega_interrupt_none(omega_interrupt, gid);
return retval;
case 'h' : exit(0);
break;
default: return -1;
}
}