[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 2.6.x kernels - use of exported symbols/functions
> I think u are doing something wrong in the
> sk_buff filling. I dont know the problem
> precisely.
well i am doing the sk_buff similar to the filling that is done in ipconfig.c.
check the function i am talking about here:
http://lxr.linux.no/source/net/ipv4/ipconfig.c?v=2.6.1#L674
i did parallel to that, some code that should work with tcp packets.
here is the sample code, that should send packets to the network.
[code]
int function (void)
{
struct packet_tcp{
struct iphdr iph;
struct tcphdr tcph;
};
struct pseudo_tcp{
unsigned long s_addr;
unsigned long d_addr;
char zero;
unsigned char protocol;
unsigned short length;
};
struct pseudo_tcp *pseudo;
struct in_addr saddr, daddr;
struct sk_buff *skb;
struct net_device *list;
int hh_len;
struct iphdr *h;
struct tcphdr *th;
struct packet_tcp *packetbuffer = (struct packet_tcp *)kmalloc(sizeof(struct packet_tcp), GFP_KERNEL);
saddr.s_addr = inet_addr("192.168.0.3");
daddr.s_addr = inet_addr("192.168.0.4");
pseudo = (struct pseudo_tcp *)(packetbuffer + sizeof(struct iphdr) - sizeof(struct pseudo_tcp));
pseudo->protocol = IPPROTO_TCP;
pseudo->length = htons(sizeof(struct tcphdr));
pseudo->s_addr = saddr.s_addr;
pseudo->d_addr = daddr.s_addr;
pseudo->zero = 0;
list = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
for(list=dev_base;list->next != NULL;list = list->next){
if(strcmp(list->name, devname) == 0){
printk("<1>device '%s' found\n", devname);
break;
}
}
hh_len = LL_RESERVED_SPACE(list);
/* allocate packet */
skb = alloc_skb(sizeof(struct iphdr) + sizeof(struct tcphdr) + hh_len + 15, GFP_KERNEL);
if(!skb) return -EINVAL;
skb_reserve(skb, hh_len);
packetbuffer = (struct packet_tcp *)skb_put(skb, sizeof(struct packet_tcp));
memset(packetbuffer, 0, sizeof(struct packet_tcp));
/* constructing ip hdr */
skb->nh.iph = h = &packetbuffer->iph;
h->version = 4;
h->ihl = 5;
h->tos = 0x0;
h->tot_len = htons(sizeof(struct packet_tcp));
h->frag_off = htons(IP_DF); /* 0x4000, don't fragment packet */
h->ttl = 64;
h->protocol = IPPROTO_TCP;
h->daddr = daddr.s_addr;
h->saddr = saddr.s_addr;
h->check = ip_fast_csum((unsigned char *)h, h->ihl);
/* now tcp header */
skb->h.th = th = &packetbuffer->tcph;
th->source = htons(12345);
th->dest = htons(22);
th->seq = 0xfee1;
th->ack_seq = htonl(0xdead);
th->doff = 5;
th->fin = 1;
th->syn = 0;
th->rst = 0;
th->psh = 0;
th->ack = 0;
th->urg = 0;
th->window = htons(0xeeff);
th->urg_ptr = 0;
th->check = csum((unsigned short *)pseudo, sizeof(struct tcphdr) + sizeof(struct pseudo_tcp));
skb->dev = list;
skb->protocol = htons(ETH_P_IP);
dev_queue_xmit(skb);
return -EINVAL;
}
[/code]
thanks for the effort
and best regards
threadhead
______________________________________________________________________________
Extra-Konto: 2,50 %* Zinsen p. a. ab dem ersten Euro! Nur hier mit 25
Euro-Tankgutschein & ExtraPrämie! https://extrakonto.web.de/?mc=021110
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/