c++, raw sockets, stopping kernel write in header?


 
Thread Tools Search this Thread
Top Forums Programming c++, raw sockets, stopping kernel write in header?
# 1  
Old 02-13-2011
c++, raw sockets, stopping kernel write in header?

Hi, im trying to lern about raw sockets with my debian and c++. Tried to make a icmp and tcp packet and send it with sendto. Checked on wireshark and recognized that kernel changed my headers. So searched about stopping the kernel change the header and tried it with setsockopt, like said in at this mixter,void,ru/rawip,html tutorial, that didnt helped.
Is there any way to send a raw socket without letting the kernel overwrite the headers on the 3 layer and upper? Or do you need knowledges in kernel programming for this?
# 2  
Old 02-14-2011
If you're using raw sockets, theoretically you should be able to send things unaltered... Since my crystal ball is still out-of-order you'll have to post your code for us to see what's going wrong with it.
# 3  
Old 02-14-2011
Right, the kernel didn't change anything. It was a pointer mistake. This line from the tutorial didn't work:
Code:
struct tcphdr *tcph = (struct tcphdr *) datagram + sizeof(struct ip);

and it worked with :
Code:
struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof(struct ip));

Don't really get why, looks equal to meSmilie
# 4  
Old 02-14-2011
Quote:
Originally Posted by sandcastle
Right, the kernel didn't change anything. It was a pointer mistake. This line from the tutorial didn't work:
Code:
struct tcphdr *tcph = (struct tcphdr *) datagram + sizeof(struct ip);

and it worked with :
Code:
struct tcphdr *tcph = (struct tcphdr *) (datagram + sizeof(struct ip));

This is pointer arithmetic, which always adds in multiples of the base type. So "ptr + 3" amounts to "position_in_bytes + sizeof(type_of_pointer)*3"

So it's the difference between adding "sizeof(struct ip)*sizeof(whatever_type_datagram_iis)" bytes and adding "sizeof(struct ip)*sizeof(struct tcphdr)" bytes.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 02-14-2011
Thats why my tcpheader started at position 400 in the packet, instead of position 20 Smilie. Thanks
This User Gave Thanks to sandcastle For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How many packets can be written into Kernel sockets per second?

Hi, Its been a long time since i programmed a multithreaded application that can do Tx and Rx of datagrams over unix sockets. I well remember that though the threads were efficiently designed to be independent of each other, and was writing to different sockets, there was a limitation ,... (0 Replies)
Discussion started by: binnyjeshan
0 Replies

2. UNIX for Dummies Questions & Answers

Kernel Header Files

I'm trying to lookup the definition of the ext4 superblock schedule in the kernel header files, but I can't seem to locate the files. I'm running the most recent Raspian Debian Wheezy OS with kernel version 3.18. Any help is greatly appreciated. Thank you!! (1 Reply)
Discussion started by: ksmarine1980
1 Replies

3. Ubuntu

Kernel panics : trying to write / read on tiny tty driver

I'm a beginner to the Linux programming and trying my hands on some device driver examples while practising. The below code (a trimmed down version of tiny_tty.c from ldd3 book) loads perfectly using insmod and I'm able to see it in /proc/tty/drivers , /proc/modules and device nodes are getting... (1 Reply)
Discussion started by: diwsdiwa
1 Replies

4. Programming

help: problem with sockets write/read

I am trying to make a server and client, the client will choose between some options and the server will react accordingly. After a some reads and writes that work the server needs to read from client an INT i use this: read(newSd,&k,sizeof(int));But even if all the other times there was no... (1 Reply)
Discussion started by: theSling
1 Replies

5. UNIX for Dummies Questions & Answers

Partial Write for sockets in LINUX

We have a server-client communication in our application. Sockets are used for the communication. We are using AF_INET sockets with SOCK_STREAM(TCP/IP). Also these sockets are in Non Blocking mode (O_NONBLOCK). Application is written in C++ on UNIX. In our system the Server will write to a... (4 Replies)
Discussion started by: sanushchacko
4 Replies

6. Programming

Understanding read/write and kernel interaction

Ok, so I'm trying to finalize my understanding of read/write and kernel interaction. read(): You have a library function that has as it's first parameter (what the open file to read from is), second parameter( a pointer to a buffer (is this the location of a buffer in the user area or the... (7 Replies)
Discussion started by: Krothos
7 Replies

7. UNIX for Dummies Questions & Answers

Understanding read/write and kernel interaction

Ok, so I'm trying to finalize my understanding of read/write and kernel interaction. read(): You have a library function that has as it's first parameter (what the open file to read from is), second parameter( a pointer to a buffer (is this the location of a buffer in the user area or the... (1 Reply)
Discussion started by: Krothos
1 Replies

8. IP Networking

Raw Sockets Programming

Hi everybody!! I'm studding at the university raw sockets, but i can't find a good place to read about them... Does anybody now where i can find some information??? I've been goggling a lot but couldn't find nothing useful, just man pages... by the way, I'm programming under Linux... Bye! (4 Replies)
Discussion started by: Sandia_man
4 Replies
Login or Register to Ask a Question