本文整理汇总了C++中__constant_htons函数的典型用法代码示例。如果您正苦于以下问题:C++ __constant_htons函数的具体用法?C++ __constant_htons怎么用?C++ __constant_htons使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了__constant_htons函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ktrcv
ktrcv(iskb);
if ((oskb = skb_dequeue(&skb_outq)))
dev_queue_xmit(oskb);
} while (iskb || oskb);
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&ktwaitq, &wait);
schedule();
remove_wait_queue(&ktwaitq, &wait);
} while (!kthread_should_stop());
__set_current_state(TASK_RUNNING);
complete(&ktrendez);
return 0;
}
static struct packet_type pt = {
.type = __constant_htons(ETH_P_AOE),
.func = rcv,
};
static int __init kvblade_module_init(void)
{
skb_queue_head_init(&skb_outq);
skb_queue_head_init(&skb_inq);
spin_lock_init(&lock);
init_completion(&ktrendez);
init_waitqueue_head(&ktwaitq);
task = kthread_run(kthread, NULL, "kvblade");
if (task == NULL || IS_ERR(task))
开发者ID:Centuriondan,项目名称:kvblade,代码行数:31,代码来源:kvblade.c
示例2: __skb_flow_dissect
//.........这里部分代码省略.........
}
case htons(ETH_P_8021AD):
case htons(ETH_P_8021Q): {
const struct vlan_hdr *vlan;
struct vlan_hdr _vlan;
vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), data, hlen, &_vlan);
if (!vlan)
return false;
proto = vlan->h_vlan_encapsulated_proto;
nhoff += sizeof(*vlan);
goto again;
}
case htons(ETH_P_PPP_SES): {
struct {
struct pppoe_hdr hdr;
__be16 proto;
} *hdr, _hdr;
hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
if (!hdr)
return false;
proto = hdr->proto;
nhoff += PPPOE_SES_HLEN;
switch (proto) {
case htons(PPP_IP):
goto ip;
case htons(PPP_IPV6):
goto ipv6;
default:
return false;
}
}
case __constant_htons(ETH_P_MAP): {
struct {
struct rmnet_map_header_s map;
uint8_t proto;
} *map, _map;
unsigned int maplen;
map = skb_header_pointer(skb, nhoff, sizeof(_map), &_map);
if (!map)
return false;
/* Is MAP command? */
if (map->map.cd_bit)
return false;
/* Is aggregated frame? */
maplen = ntohs(map->map.pkt_len);
maplen += map->map.pad_len;
maplen += sizeof(struct rmnet_map_header_s);
if (maplen < skb->len)
return false;
nhoff += sizeof(struct rmnet_map_header_s);
switch (map->proto & RMNET_IP_VER_MASK) {
case RMNET_IPV4:
proto = htons(ETH_P_IP);
goto ip;
case RMNET_IPV6:
proto = htons(ETH_P_IPV6);
goto ipv6;
default:
return false;
}
开发者ID:sztablet2016,项目名称:Android-kernel-msm-3.10,代码行数:67,代码来源:flow_dissector.c
示例3: __fsm_dev_init
void __fsm_dev_init(struct net_device *dev);
int __fsm_dev_open(struct net_device *dev);
int __fsm_dev_stop(struct net_device *dev);
int __fsm_dev_set_config(struct net_device *dev, struct ifmap *p_ifmap);
int __fsm_dev_recv(struct sk_buff *skb ,struct net_device *dev1, struct packet_type *pktype, struct net_device *dev2);
int __fsm_dev_tx(struct sk_buff *skb, struct net_device *dev);
int __fsm_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
struct net_device_stats* __fsm_dev_get_stats(struct net_device *dev);
void __fsm_dev_tx_timeout(struct net_device *p_net_device);
void __fsm_dev_init(struct net_device *dev);
/*---------------------------------------------------------------------------*/
/* this is used for register the special packet type that processed by DYS */
struct packet_type pk_t = {
.type = __constant_htons(MY_PROTOCOL),
.func = __fsm_dev_recv,
};
static const struct net_device_ops fsm_netdev_ops = {
.ndo_open = __fsm_dev_open,
.ndo_stop = __fsm_dev_stop,
.ndo_start_xmit = __fsm_dev_tx,
.ndo_get_stats = __fsm_dev_get_stats,
.ndo_do_ioctl = __fsm_dev_ioctl,
.ndo_set_config = __fsm_dev_set_config,
.ndo_tx_timeout = __fsm_dev_tx_timeout,
};
typedef struct fsm_priv
{
开发者ID:yugefei,项目名称:LTE-SRIO,代码行数:31,代码来源:mac.c
示例4: llc_sap_close
* @sap: SAP to be closed.
*
* Close interface function to upper layer. Each one who wants to
* close an open SAP (for example NetBEUI) should call this function.
* Removes this sap from the list of saps in the station and then
* frees the memory for this sap.
*/
void llc_sap_close(struct llc_sap *sap)
{
WARN_ON(!hlist_empty(&sap->sk_list.list));
llc_del_sap(sap);
kfree(sap);
}
static struct packet_type llc_packet_type = {
.type = __constant_htons(ETH_P_802_2),
.func = llc_rcv,
};
static struct packet_type llc_tr_packet_type = {
.type = __constant_htons(ETH_P_TR_802_2),
.func = llc_rcv,
};
static int __init llc_init(void)
{
struct net_device *dev;
dev = first_net_device(&init_net);
if (dev != NULL)
dev = next_net_device(dev);
开发者ID:johnny,项目名称:CobraDroidBeta,代码行数:31,代码来源:llc_core.c
示例5: ip_hdr
/**
根据tcp数据生成数据包
根据tcp数据,生成数据包,并填充 mac/ip/tcp 头部信息
@param skb 原始的sk_buff结构地址
@param names 网卡名称结构首地址
@param num 网卡个数
@param tcpdata tcp数据地址
@param tcpdatalen tcp数据长度
@return 成功返回数据包地址,失败返回NULL。
*/
struct sk_buff *pkg_skbuff_generate(struct sk_buff *skb, struct client_nicname *names, int num, char *tcpdata, int tcpdatalen)
{
struct sk_buff *new_skb = NULL;
struct net_device *dev = NULL;
struct iphdr *iph = NULL,*new_iph = NULL;
struct tcphdr *tcph = NULL,*new_tcph = NULL;
struct ethhdr *ethdr = NULL;
char *newpdata = NULL;
unsigned char * mac_header_addr = NULL;
int i = 0;
if(!skb || !names)
{
goto out;
}
iph = ip_hdr(skb);
if(iph == NULL)
{
goto out;
}
tcph = (struct tcphdr *)((char *)iph + iph->ihl*4);
if(tcph == NULL)
{
goto out;
}
ethdr = eth_hdr(skb);
if(ethdr == NULL)
{
goto out;
}
for (i=0; names[i].index != -1; i++)
{
#if (LINUX_VERSION_CODE < KERNEL_VERSION (2, 6, 24))//不确定版本号是否应该更早
dev = dev_get_by_name(names[i].name);
#else
dev = dev_get_by_name(&init_net, names[i].name);
#endif
if (dev != NULL)
break;
}
if (dev == NULL)
{
goto out;
}
new_skb = alloc_skb(tcpdatalen + iph->ihl*4 + tcph->doff*4 + 14, GFP_ATOMIC);
if(new_skb == NULL)
{
goto out;
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION (3, 11, 0))
new_skb->mac_header = new_skb->data;
skb_reserve(new_skb,14);
new_skb->transport_header = new_skb->data;
new_skb->network_header = new_skb->data;
//get_route_mac(iph->saddr, iph->daddr);
memcpy(&new_skb->mac_header[0], ethdr->h_source, 6);
memcpy(&new_skb->mac_header[6], ethdr->h_dest, 6);
new_skb->mac_header[12] = 0x08;
new_skb->mac_header[13] = 0x00;
#else
skb_reset_mac_header(new_skb);
skb_reserve(new_skb,14);
skb_reset_transport_header(new_skb);
skb_reset_network_header(new_skb);
mac_header_addr=skb_mac_header(new_skb);
if(mac_header_addr==NULL)
{
printk("Can't get header address!\n");
goto out;
}
//get_route_mac(iph->saddr, iph->daddr);
memcpy(mac_header_addr, ethdr->h_source, 6);
memcpy(mac_header_addr+6, ethdr->h_dest, 6);
mac_header_addr[12] = 0x08;
mac_header_addr[13] = 0x00;
#endif
skb_put(new_skb, iph->ihl*4 + tcph->doff*4);
new_skb->mac_len = 14;
new_skb->dev = dev;
new_skb->pkt_type = PACKET_OTHERHOST;
new_skb->protocol = __constant_htons(ETH_P_IP);
new_skb->ip_summed = CHECKSUM_NONE;
new_skb->priority = 0;
/*
//.........这里部分代码省略.........
开发者ID:angelkyo,项目名称:openwrt-maz1,代码行数:101,代码来源:pkgoper.c
示例6: vlan_skb_recv
//.........这里部分代码省略.........
// stats->broadcast ++; // no such counter :-(
break;
case PACKET_MULTICAST:
stats->multicast++;
break;
case PACKET_OTHERHOST:
/* Our lower layer thinks this is not local, let's make sure.
* This allows the VLAN to have a different MAC than the underlying
* device, and still route correctly.
*/
if (memcmp(skb->mac.ethernet->h_dest, skb->dev->dev_addr, ETH_ALEN) == 0) {
/* It is for our (changed) MAC-address! */
skb->pkt_type = PACKET_HOST;
}
break;
default:
break;
};
/* Was a VLAN packet, grab the encapsulated protocol, which the layer
* three protocols care about.
*/
/* proto = get_unaligned(&vhdr->h_vlan_encapsulated_proto); */
proto = vhdr->h_vlan_encapsulated_proto;
skb->protocol = proto;
if (ntohs(proto) >= 1536) {
/* place it back on the queue to be handled by
* true layer 3 protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
rawp = skb->data;
/*
* This is a magic hack to spot IPX packets. Older Novell breaks
* the protocol design and runs IPX over 802.3 without an 802.2 LLC
* layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
* won't work for fault tolerant netware but does for the rest.
*/
if (*(unsigned short *)rawp == 0xFFFF) {
skb->protocol = __constant_htons(ETH_P_802_3);
/* place it back on the queue to be handled by true layer 3 protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
/*
* Real 802.2 LLC
*/
skb->protocol = __constant_htons(ETH_P_802_2);
/* place it back on the queue to be handled by upper layer protocols.
*/
/* See if we are configured to re-write the VLAN header
* to make it look like ethernet...
*/
skb = vlan_check_reorder_header(skb);
/* Can be null if skb-clone fails when re-ordering */
if (skb) {
netif_rx(skb);
} else {
/* TODO: Add a more specific counter here. */
stats->rx_errors++;
}
spin_unlock_bh(&vlan_group_lock);
return 0;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,代码来源:vlan_dev.c
示例7: in_dev_put
do {
in_dev_put(xdst->u.rt.idev);
xdst->u.rt.idev = loopback_idev;
in_dev_hold(loopback_idev);
xdst = (struct xfrm_dst *)xdst->u.dst.child;
} while (xdst->u.dst.xfrm);
__in_dev_put(loopback_idev);
}
xfrm_dst_ifdown(dst, dev);
}
static struct dst_ops xfrm4_dst_ops = {
.family = AF_INET,
.protocol = __constant_htons(ETH_P_IP),
.gc = xfrm4_garbage_collect,
.update_pmtu = xfrm4_update_pmtu,
.destroy = xfrm4_dst_destroy,
.ifdown = xfrm4_dst_ifdown,
.gc_thresh = 1024,
.entry_size = sizeof(struct xfrm_dst),
};
static struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
.family = AF_INET,
.dst_ops = &xfrm4_dst_ops,
.dst_lookup = xfrm4_dst_lookup,
.get_saddr = xfrm4_get_saddr,
.find_bundle = __xfrm4_find_bundle,
.bundle_create = __xfrm4_bundle_create,
开发者ID:possiblybhavin,项目名称:mx27_drv,代码行数:31,代码来源:xfrm4_policy.c
示例8: MODULE_DESCRIPTION
MODULE_DESCRIPTION("ltemac kernel module");
MODULE_AUTHOR("");
MODULE_LICENSE("GPL");
#include "../fsm/fsmdec.h"
#include "../lte_system.h"
#include "../debug.h"
#include "virtual_srio.h"
/* this is used for register the special packet type that processed by DYS */
struct packet_type pk_t = {
.type = __constant_htons(DEV_PROTO_SRIO),
.func = fsm_dev_recv,
};
static const struct net_device_ops srio_netdev_ops = {
.ndo_open = fsm_dev_open,
.ndo_stop = fsm_dev_stop,
.ndo_start_xmit = fsm_dev_tx,
.ndo_get_stats = fsm_dev_get_stats,
.ndo_do_ioctl = fsm_dev_ioctl,
.ndo_set_config = fsm_dev_set_config,
.ndo_tx_timeout = fsm_dev_tx_timeout,
};
开发者ID:yugefei,项目名称:LTE-SRIO,代码行数:27,代码来源:virtual_srio.c
示例9: rt_arp_rcv
/***
* arp_rcv: Receive an arp request by the device layer.
*/
int rt_arp_rcv(struct rtskb *skb, struct rtpacket_type *pt)
{
struct rtnet_device *rtdev = skb->rtdev;
struct arphdr *arp = skb->nh.arph;
unsigned char *arp_ptr= (unsigned char *)(arp+1);
unsigned char *sha, *tha;
u32 sip, tip;
u16 dev_type = rtdev->type;
/*
* The hardware length of the packet should match the hardware length
* of the device. Similarly, the hardware types should match. The
* device should be ARP-able. Also, if pln is not 4, then the lookup
* is not from an IP number. We can't currently handle this, so toss
* it.
*/
if ((arp->ar_hln != rtdev->addr_len) ||
(rtdev->flags & IFF_NOARP) ||
(skb->pkt_type == PACKET_OTHERHOST) ||
(skb->pkt_type == PACKET_LOOPBACK) ||
(arp->ar_pln != 4))
goto out;
switch (dev_type) {
default:
if ((arp->ar_pro != __constant_htons(ETH_P_IP)) &&
(htons(dev_type) != arp->ar_hrd))
goto out;
break;
case ARPHRD_ETHER:
/*
* ETHERNET devices will accept ARP hardware types of either
* 1 (Ethernet) or 6 (IEEE 802.2).
*/
if ((arp->ar_hrd != __constant_htons(ARPHRD_ETHER)) &&
(arp->ar_hrd != __constant_htons(ARPHRD_IEEE802))) {
goto out;
}
if (arp->ar_pro != __constant_htons(ETH_P_IP)) {
goto out;
}
break;
}
/* Understand only these message types */
if ((arp->ar_op != __constant_htons(ARPOP_REPLY)) &&
(arp->ar_op != __constant_htons(ARPOP_REQUEST)))
goto out;
/*
* Extract fields
*/
sha=arp_ptr;
arp_ptr += rtdev->addr_len;
memcpy(&sip, arp_ptr, 4);
arp_ptr += 4;
tha=arp_ptr;
arp_ptr += rtdev->addr_len;
memcpy(&tip, arp_ptr, 4);
/* process only requests/replies directed to us */
if (tip == rtdev->local_ip) {
rt_ip_route_add_host(sip, sha, rtdev);
if (arp->ar_op == __constant_htons(ARPOP_REQUEST))
rt_arp_send(ARPOP_REPLY, ETH_P_ARP, sip, rtdev, tip, sha,
rtdev->dev_addr, sha);
}
out:
kfree_rtskb(skb);
return 0;
}
开发者ID:BackupTheBerlios,项目名称:rtnet-svn,代码行数:77,代码来源:arp.c
示例10: rt_arp_send
/***
* arp_send: Create and send an arp packet. If (dest_hw == NULL),
* we create a broadcast message.
*/
void rt_arp_send(int type,
int ptype,
u32 dest_ip,
struct rtnet_device *rtdev,
u32 src_ip,
unsigned char *dest_hw,
unsigned char *src_hw,
unsigned char *target_hw)
{
struct rtskb *skb;
struct arphdr *arp;
unsigned char *arp_ptr;
if (rtdev->flags & IFF_NOARP)
return;
if (!(skb=alloc_rtskb(sizeof(struct arphdr) + 2*(rtdev->addr_len+4) +
rtdev->hard_header_len+15, &global_pool)))
return;
rtskb_reserve(skb, (rtdev->hard_header_len+15)&~15);
skb->nh.raw = skb->data;
arp = (struct arphdr *)rtskb_put(skb, sizeof(struct arphdr) +
2*(rtdev->addr_len+4));
skb->rtdev = rtdev;
skb->protocol = __constant_htons (ETH_P_ARP);
skb->priority = RT_ARP_SKB_PRIO;
if (src_hw == NULL)
src_hw = rtdev->dev_addr;
if (dest_hw == NULL)
dest_hw = rtdev->broadcast;
/*
* Fill the device header for the ARP frame
*/
if (rtdev->hard_header &&
(rtdev->hard_header(skb,rtdev,ptype,dest_hw,src_hw,skb->len) < 0))
goto out;
arp->ar_hrd = htons(rtdev->type);
arp->ar_pro = __constant_htons(ETH_P_IP);
arp->ar_hln = rtdev->addr_len;
arp->ar_pln = 4;
arp->ar_op = htons(type);
arp_ptr=(unsigned char *)(arp+1);
memcpy(arp_ptr, src_hw, rtdev->addr_len);
arp_ptr+=rtdev->addr_len;
memcpy(arp_ptr, &src_ip,4);
arp_ptr+=4;
if (target_hw != NULL)
memcpy(arp_ptr, target_hw, rtdev->addr_len);
else
memset(arp_ptr, 0, rtdev->addr_len);
arp_ptr+=rtdev->addr_len;
memcpy(arp_ptr, &dest_ip, 4);
/* send the frame */
rtdev_xmit(skb);
return;
out:
kfree_rtskb(skb);
}
开发者ID:BackupTheBerlios,项目名称:rtnet-svn,代码行数:76,代码来源:arp.c
示例11: vnet_start_xmit
static int vnet_start_xmit(struct sk_buff *skb, struct net_device *net)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
struct pdp_info *dev = (struct pdp_info *)net->ml_priv;
#else
struct pdp_info *dev = (struct pdp_info *)net->priv;
#endif
//printk("============> vnet_start_xmit() Called .. !!\n");
#ifdef USE_LOOPBACK_PING
int ret;
struct sk_buff *skb2;
struct icmphdr *icmph;
struct iphdr *iph;
#endif
#ifdef USE_LOOPBACK_PING
dev->vn_dev.stats.tx_bytes += skb->len;
dev->vn_dev.stats.tx_packets++;
skb2 = alloc_skb(skb->len, GFP_ATOMIC);
if (skb2 == NULL) {
DPRINTK(1, "alloc_skb() failed\n");
dev_kfree_skb_any(skb);
return -ENOMEM;
}
memcpy(skb2->data, skb->data, skb->len);
skb_put(skb2, skb->len);
dev_kfree_skb_any(skb);
icmph = (struct icmphdr *)(skb2->data + sizeof(struct iphdr));
iph = (struct iphdr *)skb2->data;
icmph->type = __constant_htons(ICMP_ECHOREPLY);
ret = iph->daddr;
iph->daddr = iph->saddr;
iph->saddr = ret;
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
skb2->dev = net;
skb2->protocol = __constant_htons(ETH_P_IP);
netif_rx(skb2);
dev->vn_dev.stats.rx_packets++;
dev->vn_dev.stats.rx_bytes += skb->len;
#else
if (vnet_start_xmit_flag != 0) {
return NETDEV_TX_BUSY;
}
vnet_start_xmit_flag = 1;
workqueue_data = (unsigned long)skb;
PREPARE_WORK(&dev->vn_dev.xmit_task,vnet_defer_xmit);
schedule_work(&dev->vn_dev.xmit_task);
netif_stop_queue(net);
#endif
return 0;
}
开发者ID:sirgatez,项目名称:Android-Eclair-Kernel-Samsung-Modules-Source-v2.6.29.6,代码行数:63,代码来源:multipdp.c
示例12: module_param_named
/*
* Module parameters
*/
#ifdef CONFIG_IRDA_DEBUG
unsigned int irda_debug = IRDA_DEBUG_LEVEL;
module_param_named(debug, irda_debug, uint, 0);
MODULE_PARM_DESC(debug, "IRDA debugging level");
EXPORT_SYMBOL(irda_debug);
#endif
/* Packet type handler.
* Tell the kernel how IrDA packets should be handled.
*/
static struct packet_type irda_packet_type = {
.type = __constant_htons(ETH_P_IRDA),
.func = irlap_driver_rcv, /* Packet type handler irlap_frame.c */
};
/*
* Function irda_notify_init (notify)
*
* Used for initializing the notify structure
*
*/
void irda_notify_init(notify_t *notify)
{
notify->data_indication = NULL;
notify->udata_indication = NULL;
notify->connect_confirm = NULL;
notify->connect_indication = NULL;
开发者ID:274914765,项目名称:C,代码行数:30,代码来源:irmod.c
示例13: cp_dev_xmit_tcp
int cp_dev_xmit_tcp (char * eth, u_char * smac, u_char * dmac,
u_char * pkt, int pkt_len,
u_long sip, u_long dip,
u_short sport, u_short dport, u_long seq, u_long ack_seq, u_char psh, u_char fin)
{
struct sk_buff * skb = NULL;
struct net_device * dev = NULL;
struct ethhdr * ethdr = NULL;
struct iphdr * iph = NULL;
struct tcphdr * tcph = NULL;
u_char * pdata = NULL;
int nret = 1;
if (NULL == smac || NULL == dmac) goto out;
//dev = dev_get_by_name(eth);
dev = dev_get_by_name(&init_net, eth);
if (NULL == dev)
goto out;
printk("dev name: %s\n", dev->name);
//skb = alloc_skb (ETH_HLEN + pkt_len + sizeof (struct iphdr) + sizeof (struct tcphdr) + LL_RESERVED_SPACE (dev), GFP_ATOMIC);
skb = alloc_skb (pkt_len + sizeof (struct iphdr) + sizeof (struct tcphdr) + ETH_HLEN, GFP_ATOMIC);
if (NULL == skb)
goto out;
//skb_reserve (skb, LL_RESERVED_SPACE (dev));
skb_reserve (skb, 2);
skb->dev = dev;
skb->pkt_type = PACKET_OTHERHOST;
skb->protocol = __constant_htons(ETH_P_IP);
skb->ip_summed = CHECKSUM_NONE;
skb->priority = 0;
//skb->nh.iph = (struct iphdr*)skb_put(skb, sizeof (struct iphdr));
//skb->h.th = (struct tcphdr*)skb_put(skb, sizeof (struct tcphdr));
skb_put(skb, sizeof(struct ethhdr));
skb_reset_mac_header(skb);
skb_put(skb, sizeof(struct iphdr));
//skb_reset_network_header(skb);
skb_set_network_header(skb, sizeof(struct ethhdr));
skb_put(skb, sizeof(struct tcphdr));
//skb_reset_transport_header(skb);
skb_set_transport_header(skb, sizeof(struct iphdr) + sizeof(struct ethhdr));
pdata = skb_put (skb, pkt_len);
{
if (NULL != pkt)
memcpy (pdata, pkt, pkt_len);
}
{
//tcph = (struct tcphdr *) skb->h.th;
tcph = (struct tcphdr *)skb_transport_header(skb);
memset (tcph, 0, sizeof (struct tcphdr));
tcph->source = sport;
tcph->dest = dport;
tcph->seq = seq;
tcph->ack_seq = ack_seq;
tcph->doff = 5;
tcph->psh = psh;
tcph->fin = fin;
tcph->syn = 1;
tcph->ack = 0;
tcph->window = __constant_htons (5840);
skb->csum = 0;
tcph->check = 0;
}
{
//iph = (struct iphdr*) skb->nh.iph;
iph = (struct iphdr*)skb_network_header(skb);
memset(iph, 0, sizeof(struct iphdr));
iph->version = 4;
iph->ihl = sizeof(struct iphdr)>>2;
iph->frag_off = 0;
iph->protocol = IPPROTO_TCP;
iph->tos = 0;
iph->daddr = dip;
iph->saddr = sip;
iph->ttl = 0x40;
iph->tot_len = __constant_htons(skb->len);
iph->check = 0;
iph->check = ip_fast_csum(iph, iph->ihl);
}
{
int i = 0;
printk("len0: %02x\n\n", skb->len);
//.........这里部分代码省略.........
开发者ID:rootman1549,项目名称:every,代码行数:101,代码来源:testnetfiltercreate.c
示例14: ip_vs_out
/*
* It is hooked at the NF_IP_FORWARD chain, used only for VS/NAT.
* Check if outgoing packet belongs to the established ip_vs_conn,
* rewrite addresses of the packet and send it on its way...
*/
static unsigned int
ip_vs_out(unsigned int hooknum, struct sk_buff **pskb,
const struct net_device *in, const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *skb = *pskb;
struct iphdr *iph;
struct ip_vs_protocol *pp;
struct ip_vs_conn *cp;
int ihl;
EnterFunction(11);
if (skb->ipvs_property)
return NF_ACCEPT;
iph = skb->nh.iph;
if (unlikely(iph->protocol == IPPROTO_ICMP)) {
int related, verdict = ip_vs_out_icmp(pskb, &related);
if (related)
return verdict;
skb = *pskb;
iph = skb->nh.iph;
}
pp = ip_vs_proto_get(iph->protocol);
if (unlikely(!pp))
return NF_ACCEPT;
/* reassemble IP fragments */
if (unlikely(iph->frag_off & __constant_htons(IP_MF|IP_OFFSET) &&
!pp->dont_defrag)) {
skb = ip_vs_gather_frags(skb, IP_DEFRAG_VS_OUT);
if (!skb)
return NF_STOLEN;
iph = skb->nh.iph;
*pskb = skb;
}
ihl = iph->ihl << 2;
/*
* Check if the packet belongs to an existing entry
*/
cp = pp->conn_out_get(skb, pp, iph, ihl, 0);
if (unlikely(!cp)) {
if (sysctl_ip_vs_nat_icmp_send &&
(pp->protocol == IPPROTO_TCP ||
pp->protocol == IPPROTO_UDP)) {
__u16 _ports[2], *pptr;
pptr = skb_header_pointer(skb, ihl,
sizeof(_ports), _ports);
if (pptr == NULL)
return NF_ACCEPT; /* Not for me */
if (ip_vs_lookup_real_service(iph->protocol,
iph->saddr, pptr[0])) {
/*
* Notify the real server: there is no
* existing entry if it is not RST
* packet or not TCP packet.
*/
if (iph->protocol != IPPROTO_TCP
|| !is_tcp_reset(skb)) {
icmp_send(skb,ICMP_DEST_UNREACH,
ICMP_PORT_UNREACH, 0);
return NF_DROP;
}
}
}
IP_VS_DBG_PKT(12, pp, skb, 0,
"packet continues traversal as normal");
return NF_ACCEPT;
}
IP_VS_DBG_PKT(11, pp, skb, 0, "Outgoing packet");
if (!ip_vs_make_skb_writable(pskb, ihl))
goto drop;
/* mangle the packet */
if (pp->snat_handler && !pp->snat_handler(pskb, pp, cp))
goto drop;
skb = *pskb;
skb->nh.iph->saddr = cp->vaddr;
ip_send_check(skb->nh.iph);
/* For policy routing, packets originating from this
* machine itself may be routed differently to packets
* passing through. We want this packet to be routed as
* if it came from this machine itself. So re-compute
* the routing information.
*/
//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:20-4-4,代码行数:101,代码来源:ip_vs_core.c
示例15: ip_conntrack_expect_put
ip_conntrack_expect_put(exp);
}
out:
spin_unlock_bh(&amanda_buffer_lock);
return ret;
}
static struct ip_conntrack_helper amanda_helper = {
.max_expected = ARRAY_SIZE(conns),
.timeout = 180,
.me = THIS_MODULE,
.help = help,
.name = "amanda",
.tuple = { .src = { .u = { __constant_htons(10080) } },
.dst = { .protonum = IPPROTO_UDP },
},
.mask = { .src = { .u = { 0xFFFF } },
.dst = { .protonum = 0xFF },
},
};
static void __exit fini(void)
{
ip_conntrack_helper_unregister(&amanda_helper);
kfree(amanda_buffer);
}
static int __init init(void)
{
开发者ID:BackupTheBerlios,项目名称:tew632-brp-svn,代码行数:31,代码来源:ip_conntrack_amanda.c
示例16: ip_vs_in_icmp
/*
* Handle ICMP messages in the outside-to-inside direction (incoming).
* Find any that might be relevant, check against existing connections,
* forward to the right destination host if relevant.
* Currently handles error types - unreachable, quench, ttl exceeded.
*/
static int
ip_vs_in_icmp(struct sk_buff **pskb, int *related, unsigned int hooknum)
{
struct sk_buff *skb = *pskb;
struct iphdr *iph;
struct icmphdr _icmph, *ic;
struct iphdr _ciph, *cih; /* The ip header contained within the ICMP */
struct ip_vs_conn *cp;
struct ip_vs_protocol *pp;
unsigned int offset, ihl, verdict;
*related = 1;
/* reassemble IP fragments */
if (skb->nh.iph->frag_off & __constant_htons(IP_MF|IP_OFFSET)) {
skb = ip_vs_gather_frags(skb,
hooknum == NF_IP_LOCAL_IN ?
IP_DEFRAG_VS_IN : IP_DEFRAG_VS_FWD);
if (!skb)
return NF_STOLEN;
*pskb = skb;
}
iph = skb->nh.iph;
offset = ihl = iph->ihl * 4;
ic = skb_header_pointer(skb, offset, sizeof(_icmph), &_icmph);
if (ic == NULL)
return NF_DROP;
IP_VS_DBG(12, "Incoming ICMP (%d,%d) %u.%u.%u.%u->%u.%u.%u.%u\n",
ic->type, ntohs(icmp_id(ic)),
NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
/*
* Work through seeing if this is for us.
* These checks are supposed to be in an order that means easy
* things are checked first to speed up processing.... however
* this means that some packets will manage to get a long way
* down this stack and then be rejected, but that's life.
*/
if ((ic->type != ICMP_DEST_UNREACH) &&
(ic->type != ICMP_SOURCE_QUENCH) &&
(ic->type != ICMP_TIME_EXCEEDED)) {
*related = 0;
return NF_ACCEPT;
}
/* Now find the contained IP header */
offset += sizeof(_icmph);
cih = skb_header_pointer(skb, offset, sizeof(_ciph), &_ciph);
if (cih == NULL)
return NF_ACCEPT; /* The packet looks wrong, ignore */
pp = ip_vs_proto_get(cih->protocol);
if (!pp)
return NF_ACCEPT;
/* Is the embedded protocol header present? */
if (unlikely(cih->frag_off & __constant_htons(IP_OFFSET) &&
pp->dont_defrag))
return NF_ACCEPT;
IP_VS_DBG_PKT(11, pp, skb, offset, "Checking incoming ICMP for");
offset += cih->ihl * 4;
/* The embedded headers contain source and dest in reverse order */
cp = pp->conn_in_get(skb, pp, cih, offset, 1);
if (!cp)
return NF_ACCEPT;
verdict = NF_DROP;
/* Ensure the checksum is correct */
if (skb->ip_summed != CHECKSUM_UNNECESSARY &&
ip_vs_checksum_complete(skb, ihl)) {
/* Failed checksum! */
IP_VS_DBG(1, "Incoming ICMP: failed checksum from %d.%d.%d.%d!\n",
NIPQUAD(iph->saddr));
goto out;
}
/* do the statistics and put it back */
ip_vs_in_stats(cp, skb);
if (IPPROTO_TCP == cih->protocol || IPPROTO_UDP == cih->protocol)
offset += 2 * sizeof(__u16);
verdict = ip_vs_icmp_xmit(skb, cp, pp, offset);
/* do not touch skb anymore */
out:
__ip_vs_conn_put(cp);
return verdict;
}
开发者ID:jameshilliard,项目名称:20-4-4,代码行数:100,代码来源:ip_vs_core.c
示例17: packet_init
void * packet_init(struct sk_buff *skb, const struct net_device *out)
{
struct sk_buff *newskb = NULL;
struct ethhdr *ethh = NULL;
struct tcphdr *tcph = NULL;
struct iphdr *iph = NULL;
unsigned char *pdata = NULL;
struct tcphdr *old_tcph = NULL;
struct iphdr *old_iph = NULL;
struct ethhdr *old_ethh = NULL;
struct net_device *dev = NULL;
unsigned short old_data_len = 0;
unsigned char dest[6] = {0x08, 0x00, 0x27, 0xc4, 0xe6, 0x3b};
unsigned char src[6] = {0x52, 0x54, 0x00, 0x12, 0x35, 0x02};
char pkt302[] =
"HTTP/1.1 302 Found\r\n"
"Location: http://www.126.com/\r\n"
"Content-Length: 0\r\n"
"Connection: close\r\n\r\n";
//char pkt301[] =
//"HTTP/1.1 301 Moved Permanently\r\n"
//"Location: http://www.jd.com\r\n"
//"Content-Type: text/html; charset=iso-8859-1\r\n"
//"Content-length: 0\r\n"
//"Cache-control: no-cache\r\n"
//"\r\n";
// malloc skb space
// l4
// l3
// l2
// return newskb
dev = dev_get_by_name(&init_net, "eth0");
{
// old skb info
old_tcph = (struct tcphdr *)skb_transport_header(skb);
old_iph = (struct iphdr *)skb_network_header(skb);
old_ethh = (struct ethhdr *)skb_mac_header(skb);
}
newskb = alloc_skb(strlen(pkt302) + sizeof(struct tcphdr) + sizeof(struct iphdr) + ETH_HLEN + 2, GFP_ATOMIC);
if (newskb == NULL)
{
return NULL;
}
skb_reserve(skb, 2);
// skb padding
newskb->dev = out;
//newskb->dev = dev;
newskb->pkt_type = PACKET_HOST;
newskb->protocol = __constant_htons(ETH_P_IP);
newskb->ip_summed = CHECKSUM_NONE;
newskb->priority = 0;
skb_put(newskb, sizeof(struct ethhdr));
skb_reset_mac_header(newskb);
skb_put(newskb, sizeof(struct iphdr));
skb_set_network_header(newskb, sizeof(struct ethhdr));
skb_put(newskb, sizeof(struct tcphdr));
skb_set_transport_header(newskb, sizeof(struct iphdr) + sizeof(struct ethhdr));
//skb_put(newskb, sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct tcphdr));
pdata = skb_put(newskb, strlen(pkt302));
if (pdata != NULL)
{
memcpy(pdata, pkt302, strlen(pkt302));
}
{
//fill l4
tcph = (struct tcphdr *)skb_transport_header(newskb);
memset(tcph, 0, sizeof(struct tcphdr));
tcph->source = old_tcph->dest;
tcph->dest = old_tcph->source;
//tcph->seq = old_tcph->seq;
//tcph->ack_seq = old_tcph->ack_seq;
old_data_len = __constant_ntohs(old_iph->tot_len) - old_iph->ihl * 4 - old_tcph->doff * 4;
printk("---------old seq : %08x\r\n", old_tcph->seq);
printk("---------old ack : %08x\r\n", old_tcph->ack_seq);
printk("---------old data_len : %d\r\n", old_data_len);
tcph->seq = old_tcph->ack_seq;
//tcph->ack_seq = __constant_htonl(__constant_ntohl(old_tcph->seq) + strlen(pkt302));
tcph->ack_seq = __constant_htonl(__constant_ntohl(old_tcph->seq) + old_data_len);
tcph->doff = 5;
tcph->psh = 1;
tcph->ack = 1;
tcph->window = old_tcph->window;
newskb->csum = 0;
tcph->check = 0;
tcph->urg_ptr = 0;
}
//.........这里部分代码省略.........
开发者ID:rootman1549,项目名称:every,代码行数:101,代码来源:test.c
示例18: vlan_dev_hard_start_xmit
int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct net_device_stats *stats = vlan_dev_get_stats(dev);
struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
/* Handle non-VLAN frames if they are sent to us, for example by DHCP.
*
* NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
* OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
*/
if (veth->h_vlan_proto != __constant_htons(ETH_P_8021Q)) {
unsigned short veth_TCI;
/* This is not a VLAN frame...but we can fix that! */
VLAN_DEV_INFO(dev)->cnt_encap_on_xmit++;
#ifdef VLAN_DEBUG
printk(VLAN_DBG "%s: proto to encap: 0x%hx (hbo)\n",
__FUNCTION__, htons(veth->h_vlan_proto));
#endif
if (skb_headroom(skb) < VLAN_HLEN) {
struct sk_buff *sk_tmp = skb;
skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
kfree_skb(sk_tmp);
if (skb == NULL) {
stats->tx_dropped++;
return 0;
}
VLAN_DEV_INFO(dev)->cnt_inc_headroom_on_tx++;
} else {
if (!(skb = skb_unshare(skb, GFP_ATOMIC))) {
printk(KERN_ERR "vlan: failed to unshare skbuff\n");
stats->tx_dropped++;
return 0;
}
}
veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
/* Move the mac addresses to the beginning of the new header. */
memmove(skb->data, skb->data + VLAN_HLEN, 12);
/* first, the ethernet type */
/* put_unaligned(__constant_htons(ETH_P_8021Q), &veth->h_vlan_proto); */
veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
/* Now, construct the second two bytes. This field looks something
* like:
* usr_priority: 3 bits (high bits)
* CFI 1 bit
* VLAN ID 12 bits (low bits)
*/
veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
veth->h_vlan_TCI = htons(veth_TCI);
}
skb->dev = VLAN_DEV_INFO(dev)->real_dev;
#ifdef VLAN_DEBUG
printk(VLAN_DBG "%s: about to send skb: %p to dev: %s\n",
__FUNCTION__, skb, skb->dev->name);
printk(VLAN_DBG " %2hx.%2hx.%2hx.%2xh.%2hx.%2hx %2hx.%2hx.%2hx.%2hx.%2hx.%2hx %4hx %4hx %4hx\n",
veth->h_dest[0], veth->h_dest[1], veth->h_dest[2], veth->h_dest[3], veth->h_dest[4], veth->h_dest[5],
veth->h_source[0], veth->h_source[1], veth->h_source[2], veth->h_source[3], veth->h_source[4], veth->h_source[5],
veth->h_vlan_proto, veth->h_vlan_TCI, veth->h_vlan_encapsulated_proto);
#endif
stats->tx_packets++; /* for statics only */
stats->tx_bytes += skb->len;
dev_queue_xmit(skb);
return 0;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:77,代码来源:vlan_dev.c
示例19: printk
printk("send skb size[%d]maclen[%d]\n", nskb->len, nskb->mac_len);
for (i=0; i<nskb->len; i++)
{
printk("%.2x ", nskb->data[i]);
}
printk("count[%d]\n", i);
dev_queue_xmit(nskb);
}
out:
kfree_skb (skb);
return NET_RX_SUCCESS;
}
static struct packet_type mirror_proto = {
/* Capture all protocols. */
.type = __constant_htons(ETH_P_ALL),
.func = mirror_func,
};
int option_setup (char *opt)
{
char *from, *to, *cur, tmp;
struct net_device *dev;
int count = 0;
printk ("args: %s\n", opt);
/* Get mirror port. */
if ((to = strchr(opt, '@')) == NULL)
return -EINVAL;
*to = '\0';
开发者ID:houwentaoff,项目名称:ldd_examle_test,代码行数:31,代码来源:mirror.c
示例20: ak_client_inform_port
//.........这里部分代码省略.........
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
if (ip_route_output_key(&rt, &flp))
#else
if (ip_route_output_key(&init_net, &rt, &flp))
#endif
{
kfree_skb(skb);
PRINT("Erro ao alocar rota de saida\n");
continue;
}
#else
rt = ip_route_output_key(&init_net, &flp);
if (IS_ERR(rt))
{
kfree_skb(skb);
PRINT("Erro ao alocar rota de saida\n");
continue;
}
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31))
skb->dst = dst_clone(&rt->u.dst);
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36))
skb_dst_set(skb, dst_clone(&rt->u.dst));
#else
skb_dst_set(skb, dst_clone(&rt->dst));
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36))
skb->dev = rt->u.dst.dev;
#else
skb->dev = rt->dst.dev;
#endif
skb->protocol = __constant_htons(ETH_P_IP);
// Preenche dados do usuario
port_ctl->ip_src.s_addr = 0;
port_ctl->seq = ntohl(logon->seq); // ak_client_get_user_list() ja incrementou seq
port_ctl->user_num = ntohl(logon->logon_data.ak_user_num);
port_ctl->port = port_src;
port_ctl->protocol = protocol;
port_ctl->reserved = 0;
MD5Init(&contexto);
MD5Update(&contexto, (u_char *) logon->logon_data.secret, 16);
MD5Update(&contexto, (u_char *) &port_ctl->ip_src, sizeof(struct in_addr));
MD5Update(&contexto, (u_char *) &port_ctl
|
请发表评论