LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-13-2005, 09:22 AM   #1
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Rep: Reputation: 30
problem in TCP packet


Hi Guys,

I'm trying to send a TCP segment .When I try and send the segemtn and print out the values on the client side evrything seems ot be properly filled but when I start EThereal and have a look at the packet it shows "Malformed Packet" and stops immediately after looking at TCP sport and TCP dest port . EVen the values it takes for the source and est port are wrong . AFter a bit of work I found otu that the values its taking is the hex equivalent of the entire segment which is wrong .Heres what I'm talking about:-

Code:
memcpy(segment, h.conn->seg->ttcp_hdr, 20);
        memcpy(segment+20, h.conn->seg->options, strlen((char *)h.conn->seg->options)
);
        memcpy(segment+20+strlen((char *)h.conn->seg->options), h.conn->seg->buff, st
rlen((char *)h.conn->seg->buff));

        int n = sendto(sockfd, &segment, strlen((char *)segment), 0, toAddr, toAddrle
n);
        //cout<<"N is    "<<n<<"and segment is "<<segment<<endl;
	printf("Segment is %x",segment);    //THE OUTPUT HERE IS Segment is 8058e68 which is what is getting displayed in ethereal.....
        for(int i=0; i < 43; i++)
        {

                unsigned char *name = new unsigned char;
                memcpy(name, segment+i, i);
                printf("\nbuffer in cli is %c, %x, %s", *(segment+i), *(segment+i), n
ame);
                delete name;
        }
Otherwise the segment prints perfectly...any ideas.....I can give anyone whois intrstd the whole code...
Thnx
Arvind
 
Old 05-14-2005, 09:22 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: At home: Arch, OpenBSD, Solaris. At work: CentOS, Debian, Ubuntu
Posts: 3,625

Rep: Reputation: 101Reputation: 101
I suppose it could be a byte ordering problem. IIRC network byte ordering is big endian and if you're on an x86 processor the native byte ordering is little endian. Do the values look "backwards" (i.e. the bytes in the value are reversed?)? If so, it's byte ordering.

You should look to htonl, ntohl, and friends for byte order conversion.
 
Old 05-15-2005, 12:18 PM   #3
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 30
Your code also has a problem with heap corruption.
unsigned char *name = new unsigned char;
memcpy(name, segment+i, i);
You are allocating space for only 1 char, but copying 'i' chars into it. Which is a number from 0-42.
 
Old 05-16-2005, 06:00 AM   #4
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Original Poster
Rep: Reputation: 30
hey thnx guys will check ur suggestions out and let you know....
thnx
arvind
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TCP Packet Size ajkannan83 General 3 11-03-2005 06:46 AM
TCP Packet Collisions artematalento Linux - Networking 5 11-11-2004 08:48 PM
tcp packet size dellcom1800 Linux - Networking 2 07-28-2004 07:49 AM
Linux tcp/ip packet optimizer wildtiger23 Linux - Networking 1 06-09-2004 05:00 PM
./snort -dvr packet.log tcp psyklops Linux - Security 1 04-26-2002 07:33 PM


All times are GMT -5. The time now is 02:48 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration