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; |
|