|
Hi,
I'm trying to use raw sockets, but I have some problems with the 3-way handshake.
The problem is that the server doesn't answer me when I send the SYN packet.
Maybe, it's a class problem. This is the class for the TCP header:
public enum TcpHeaderFlags : byte
{
CWR = 128,
ECE = 64,
URG = 32,
ACK = 16,
PSH = 8,
RST = 4,
SYN = 2,
FIN = 1,
None = 0
}
public class TcpHeader : ProtocolHeader
{
public UInt16 SourcePort = 80;
public UInt16 DestinationPort = 80;
public UInt32 SequenceNumber = 0;
public UInt32 AcknowledgmentNumber = 0;
private byte DataOffsetAndReserved = 0;
public TcpHeaderFlags Flags = TcpHeaderFlags.None;
public UInt16 WindowSize = UInt16.MaxValue;
public UInt16 Checksum = 0;
public UInt16 UrgentPointer = 0;
public override byte[] GetProtocolPacketBytes(byte[] payLoad)
{
MemoryStream memStream = new MemoryStream();
byte[] buffer = null;
buffer = BitConverter.GetBytes(SourcePort);
memStream.Write(buffer, 0, buffer.Length);
buffer = BitConverter.GetBytes(DestinationPort);
memStream.Write(buffer, 0, buffer.Length);
buffer = BitConverter.GetBytes(SequenceNumber);
memStream.Write(buffer, 0, buffer.Length);
buffer = BitConverter.GetBytes(AcknowledgmentNumber);
memStream.Write(buffer, 0, buffer.Length);
memStream.Write(new byte[] { DataOffsetAndReserved }, 0, 1);
memStream.Write(new byte[] { (byte)Flags }, 0, 1);
buffer = BitConverter.GetBytes(WindowSize);
memStream.Write(buffer, 0, buffer.Length);
buffer = BitConverter.GetBytes(Checksum);
memStream.Write(buffer, 0, buffer.Length);
buffer = BitConverter.GetBytes(UrgentPointer);
memStream.Write(buffer, 0, buffer.Length);
return memStream.ToArray().Concat(payLoad).ToArray();
}
}
So, my question is:
please, can you give me a working class for the tcp header??
PS:
I've taken the IP header class from this site:
http://www.winsocketdotnetworkprogramming.com/clientserversocketnetworkcommunication8chap.html[^]
|
|
|
|
|
You may first want to read a small section in this article[^] on Raw Sockets.
Reads:
Limitations on Raw Sockets
On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:
•TCP data cannot be sent over raw sockets.
•UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
•A call to the bind function with a raw socket is not allowed.
These above restrictions do not apply to Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.
Note The Microsoft implementation of TCP/IP on Windows is capable of opening a raw UDP or TCP socket based on the above restrictions. But other Winsock providers may not support the use of raw sockets.
There are further limitations for applications that use a socket of type SOCK_RAW. For example, all applications listening for a specific protocol will receive all packets received for this protocol. This may not be what is desired for multiple applications using a protocol. This is also not suitable for high-performance applications. To get around these issues, it may be required to write a Windows network protocol driver (device driver) for the specific network protocol. This requires a Transport Driver Interface (TDI) provider and a Winsock helper DLL be written to support the network protocol. The network protocol would then be added to the Winsock catalog as a supported protocol. This allows multiple applications to open sockets for this specific protocol and the device driver can keep track of which socket receives specific packets and errors. For information on writing a network protocol provider, see the sections on TDI in the Microsoft Windows Driver Kit (WDK).
Applications also need to be aware of the impact that firewall settings may have on sending and receiving packets using raw sockets.
|
|
|
|
|
So... I cannot use the RawSockets...
I decided to use the RawSockets because I needed to change the source IP of the packet, because I'm writing a crawler.
The problem is that after some requests, I get 403 errors, so I thought it was because the server has a sort of protection against DDoS attacks, and I decided to change my source IP.
If you have any other solutions for the problem of the 403 errors,
please, save my life!
|
|
|
|
|
First, changing the source IP is what everyone looks for in a spoofed packet, so that's out. Besides, if you don't have a server listening at that IP address, the return data just went to never-never land.
Second, you didn't read the line I posted that started with "The above restrictions do not apply to...", did you?
|
|
|
|
|
How does .NET handles a winapi that doesn't exsist on current OS, for example: If it was proggramed on Windows 7 64bit and then attempted to use on Windows XP 32 bit?
API IsWow64Process does exsist in 64 bit OS, but does it exsist in 32bit version?
edit: Re-edited question
|
|
|
|
|
P/Invoke problems are signaled through exceptions, see here[^] for some details.
So you may choose to use some try-catch construct.
|
|
|
|
|
Thank you, as other question does IsWow64Process exsist in 32 bit Windows?
|
|
|
|
|
I don't know.
Read the documentation.
Google.
Try it.
|
|
|
|
|
I have some pictureBox (simple winform) that i change the image every 3 seconds.
When i stop changing the images - and i move the mouse on the picture i get an exception about 'arguments are not valid'.
In debug i see that all the arguments are fine - and the image that appear on the pictureBox is valid.
The Bitmap b is also valid and is not null - and i see in debug the bitmap information.
The exception appear on line 5
1 private Color OnMouseMove_PictureBox( object sender, MouseEventArgs e )
{
2 Color c = null;
3 if( pictureBox.Image != null )
{
4 Bitmap b = ( Bitmap )pictureBox.Image;
5 c = b.GetPixel( e.X, e.Y );
}
return c;
}
|
|
|
|
|
what are the values of e.X and e.Y? These are probably not valid, could you post the entire text of the exception message?
|
|
|
|
|
The value of e.X and e.Y are valid and i see the values on debug.
The entire text on the exception does not give anything => just 'argument are not valid'.
|
|
|
|
|
Is the ArgumentOutOfRangeException thrown?
I can not see the other exception to be thrown.
try adding to prevent e.X and e.Y to be higher than image width and height, or if you do not care use try catch to supress error. I do recomend the first solution
|
|
|
|
|
What might have happened is that the picture box was set to stretch the image to fit it's size.
Then when you tried to get the pixel at e.x, e.y these values might well be larger than the true
picture size. In that case a transformation of picture box x,y to image x,y would need to be done.
Something along the lines of:
x' = e.x * image.width / picturebox.width
y' = e.y * image.height / picturebox.height
|
|
|
|
|
|
Hi,
I am suspecting that my VS2010 is improperly building the .RDLC file to use with SQL Server 2008 R2, as I am getting an error that I can't explain or figure out. The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition' which cannot be upgraded. If I rename the file to an .RDL it works, however I have to manually add the Data Source, DataSet and the SQL Query. Looking at the .RDLC file it doesn't look right as it has no data connections.
Anyone have an example from VS2008 that works and you can send me via email, or paste into this link? Something simple like printing one field from the Northwind database.
Much appreciated...
Glenn
Sr. Software Specialist
|
|
|
|
|
I'm guessing here as I do not have the definitive answer. I believe the 'C' stands for client, that is the RDL will not be published via reporting services. Therefore in the 'C' version of the RDL it expects the 'C'lient to supply the data, whereas the published format retains the data connections.
Client format is for embedding in your application and your app should supply the dataset/table to service the report.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to change the look of Up and Down buttons in NumericUpDown control with some images, I know one way is to override OnPaint event but I could not find any example. Does anyone know good example of this?
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
Hoo Hoo! That's not an easy one. NumericUpDown is a composite control, it contains a text box and a button box - but it doesn't make either public. You can get at the contents (I believe, I've never tried) with reflection, but to be honest, you would be relying on class internals that you have no guarantee will remain the same. I.e. your code may work today, but tomorrow...
A better solution would be to create your own custom control that looks the way you need, including your own up/down logic and text box. Would be more reliable, and probably quicker to develop, too.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Yes, after more investigation, I came into same result. Thanks for reply.
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
Welcome - good luck!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
I want to define the ConcurrentQueue size -
I mean that if the ConcurrentQueue_.count is bigger then X then the last item in the queue need to be out.
Is it possible ?
Thanks.
|
|
|
|
|
hi guys
how to copy control with relative code?
such as a button with click and double click ,mouse move and etc
thanks a lot
|
|
|
|
|
behzadcp wrote: how to copy control with relative code?
Are you asking how to create a custom control based on other controls with the little code as possible?
|
|
|
|
|
I seen a struct on a pInvoke.Net
[StructLayout(LayoutKind.Sequential)]
public struct PROCESSENTRY32
{
public uint dwSize;
public uint cntUsage;
public uint th32ProcessID;
public IntPtr th32DefaultHeapID;
public uint th32ModuleID;
public uint cntThreads;
public uint th32ParentProcessID;
public int pcPriClassBase;
public uint dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)] public string szExeFile;
};
PROCESSENTRY32 pe = new PROCESSENTRY32();
pe.dwSize = (uint)Marshal.SizeOf(pe);
I know i have read somewhere here that strut should be intalized inside constructior or it will couse problems. Does that applay to WinAPI too?
Edit: Forgot code tags
|
|
|
|
|
Inside what constructor? The only thing you have to worry about is establishing the size of the struct so that the WinAPI knows how big the object is. The only concern about initializing it is what scope the resulting object has.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|