Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...with companys cutting back on training, lack of true support by makers of software, the forums are a great tool in your cyber-toolbox...."

Geography

Where in the world do Tek-Tips members come from?
lars2001 (Programmer)
14 Mar 01 2:02
Hello Every1

Iam programming under w2k, and its seems that i cant make my own tcp header, the ip header is no problem. only when i set the 0x06 in the protocol on the ip header.

UPD and ICMP works fine. But not TCP.

So, the question are that does w2k support the following code, og is there another way to handle this issue?

Thanks for u help so fare.

Best Regards
Lars2001


//CODE START HER.
//a snip from my sourcecode writen in Delphi 5, without error control.
var
  i, sd, bwrote, packet_size, ttl, protocol : integer;
  optlen, optval : integer;
  Myname, send_buf : PChar;
  MyHostEnt : PHostEnt;
  destSock : SockAddr_in;
  sourceSock : SockAddr_in;
  Home : In_Addr;
  TCPhdr : TTCP;
begin
  randomize;
  packet_size := SizeOf(TCPhdr);
  //init send_buf and fill it with 0
  GetMem (send_buf, Packet_size);
  FillChar (send_buf^, packet_size, $41);

  //init my raw socket. and make my IP header to an TCP/IP packet.
  sd := socket(AF_INET, SOCK_RAW, IPPROTO_TCP);


  //init max send size;
  optlen := sizeof(optval);
  optval := 4096; //i doubt that i need that much space.
  setsockopt(sd, SOL_SOCKET, SO_SNDBUF, @optval, optlen);

  GetMem (Myname, 64);
  if GetHostName(Myname, 64) = 0 then
    MyHostEnt := GetHostByName(MyName);
    if MyHostEnt = nil then
      ShowMessage ('Unknown host...');

  for i := 0 to 3 do
    PChar (@Home.S_addr) := PChar (MyHostEnt^.h_addr^);

  //init destination
  DestSock.sin_family := AF_INET;
  DestSock.sin_port := htons (0);
  DestSock.sin_addr.S_addr := Home.S_addr;
  if bind (sd, DestSock, SizeOf(DestSock));

  //init source
  sourceSock.sin_family := AF_INET;
  sourceSock.sin_port := htons (0);
  sourceSock.sin_addr.S_addr := inet_addr( PCHar('INSERT IP HERE'));

  //init tcp header
  TCPhdr.TCP_SPORT := htons(21);
  TCPhdr.TCP_DPORT := htons(21);
  TCPhdr.TCP_SEQ := htonl(random($ffffffff));
  TCPhdr.TCP_ACK := $00000000;
  TCPhdr.TCP_OFL := htons ($5003);
  TCPhdr.TCP_W := htons($0000);
  TCPhdr.TCP_CH := $0000; //i dont think this is important at this point.
  TCPhdr.TCP_UGP := $0000;

  //copy ip header to send_buf
  for i := 0 to SizeOf(TCPhdr)-1 do
    PChar (Send_buf) := PChar (@TCPhdr);
  HexDump (Send_buf, packet_size);

  //send message.
  bwrote := sendto(sd, PChar (send_buf), packet_size , 0, sourceSock, sizeof(sourceSock));

//I get error message 10040(message too long)

  closeSocket (sd);
  FreeMem (send_buf);
end;

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close