Quote:
Originally Posted by kikilinux
I believe i can't correct my errors
Can anyone help me to have an OR operation on 22st byte of ip header (ip_header)?
struct iphdr *ip_header;
struct tcphdr *tcp_header;
// Get the ip header
ip_header = (struct iphdr *)skb_network_header(skb);
skb_set_transport_header(skb, ip_header->ihl * 4);
tcp_header = (struct tcphdr *)skb_transport_header(skb);
How can we point to a specific byte of ip_header?
Is it possible to perform OR bitwise operation on 22st or 21st bytes (option field) with no more variable declaration ?
At the end please suggest me a book for networking programming in kernel(if exists).
any help would be greatly appreciated.
Best Regards.
|
I don't know any network programming books that are good, offhand.
As for the operation...w/o declaring any more variables you have to use a few parenthesis..some of them aren't necessary, but I like to be very clear w/ my intentions:
(Note: For the offsets I treated values as 0 based)
Code:
struct iphdr *ip_header;
struct tcphdr *tcp_header;
// Get the ip header
ip_header = (struct iphdr *)skb_network_header(skb);
skb_set_transport_header(skb, ip_header->ihl * 4);
tcp_header = (struct tcphdr *)skb_transport_header(skb);
// Set 21st byte, bit 1 to 1
*(((uint8_t*)ip_header) + 21) |= 1;
// Set 22nd byte, bit 4 to 1
*(((uint8_t*)ip_header) + 22) |= 1 << 4;
// Clear 21st byte, bit 3
*(((uint8_t*)ip_header) + 21) &= ~(1 << 3);
Hope that explains it a little better..it should work
.
NOTE: "uint8_t" is guaranteed to be 8 bits, unlike a char.