Click here to Skip to main content
15,913,685 members
Home / Discussions / C#
   

C#

 
GeneralSearch files.. Pin
nc3b13-Aug-05 11:14
nc3b13-Aug-05 11:14 
GeneralRe: Search files.. Pin
Vasudevan Deepak Kumar14-Aug-05 1:54
Vasudevan Deepak Kumar14-Aug-05 1:54 
GeneralRe: Search files.. Pin
nc3b14-Aug-05 5:52
nc3b14-Aug-05 5:52 
GeneralNumericUpDown Control Pin
Yigal Agam13-Aug-05 9:51
Yigal Agam13-Aug-05 9:51 
GeneralRe: NumericUpDown Control Pin
Daniel Grunwald13-Aug-05 10:48
Daniel Grunwald13-Aug-05 10:48 
GeneralXML Deserialisation and Default Values Pin
MrEyes13-Aug-05 9:48
MrEyes13-Aug-05 9:48 
Generaliphlpapi.dll and sendarp Pin
Genbox13-Aug-05 8:24
Genbox13-Aug-05 8:24 
GeneralRe: iphlpapi.dll and sendarp Pin
Bojan Rajkovic13-Aug-05 19:07
Bojan Rajkovic13-Aug-05 19:07 
Mmm, no, that won't work.. You can't create integer IP's from just using Convert.ToDecimal(). That would be too simple.

Also, you can't pass in a 0 for the 3rd parameter, it's a byte[] that's returned out as your data that you receive from the ARP I think (I haven't done any research, I'm just letting you know basic things that are wrong.)

What this all means is that you need to:

a) Declare a byte[] to use for the 3rd parameter. I'd reccomend using one that's got a decent length, like 256...declared as so: byte[] buffer = new byte[256]; (Note: You might not even need to declare a length, since you have that ref integer parameter that seems to tell you how much data you got out of the function - I'd try both ways)

b) for the 4th parameter, you need to declare an integer before calling the function, then pass that integer in as a ref parameter...that variable will hold the length of the actual output from the function (how much data it filled in the buffer)

c) you need IP's as integers...fortunately for you, I've written code that does that. Smile | :)

public static int StringIPToInt(string IPString) 
		{
			string[] _splitString = IPString.Split(new char[]{'.'});
			int _retVal = 0;
			if (_splitString.Length < 4)
				throw new ArgumentException("Please pass in a valid IP in dotted-quad notation!","IPString");
			else 
			{
				_retVal += (int)(int.Parse(_splitString[3]) * Math.Pow(256,0));
				_retVal += (int)(int.Parse(_splitString[2]) * Math.Pow(256,1));
				_retVal += (int)(int.Parse(_splitString[1]) * Math.Pow(256,2));
				_retVal += (int)(int.Parse(_splitString[0]) * Math.Pow(256,3));
			}
			_retVal = (int) (((_retVal & 0x000000ff) << 24) +
				((_retVal & 0x0000ff00) << 8) +
				((_retVal & 0x00ff0000) >> 8) +
				((_retVal & 0xff000000) >> 24));
			return _retVal;
		}


I won't go into detail except that all the compound addition you see is parsing the dotted-quad notation and creating an integer value to represent it (dotted-quad just stores the 32 bits of an IP address as four octets, so it's easy to go back to a 32bit integer). The last bit of code with all the bitshifting and binary AND's flips the endianness of the output integer so that you have the correct value.

So, a call like this may be appropriate:

byte[] outputData;
int dataLength = 0;
SendARP(StringIPToLong("192.168.1.101"),StringIPToLong("127.0.0.1"),outputData,ref dataLength);


I would then use BitConverter.ToString() or something similar to get human-readable data out of that buffer byte[].
GeneralRe: iphlpapi.dll and sendarp Pin
Genbox13-Aug-05 23:58
Genbox13-Aug-05 23:58 
GeneralRe: iphlpapi.dll and sendarp Pin
Rob Graham14-Aug-05 1:27
Rob Graham14-Aug-05 1:27 
GeneralRe: iphlpapi.dll and sendarp Pin
Anonymous14-Aug-05 2:38
Anonymous14-Aug-05 2:38 
GeneralRe: iphlpapi.dll and sendarp Pin
Bojan Rajkovic14-Aug-05 11:49
Bojan Rajkovic14-Aug-05 11:49 
GeneralRe: iphlpapi.dll and sendarp Pin
mohsenbz12-Feb-12 20:05
mohsenbz12-Feb-12 20:05 
GeneralZoming problem in c# Pin
wasife13-Aug-05 7:30
wasife13-Aug-05 7:30 
GeneralRe: Zoming problem in c# Pin
Guffa13-Aug-05 7:35
Guffa13-Aug-05 7:35 
GeneralDistribute my software to other computers Pin
Ming Luo13-Aug-05 1:00
Ming Luo13-Aug-05 1:00 
GeneralRe: Distribute my software to other computers Pin
User 665813-Aug-05 1:39
User 665813-Aug-05 1:39 
GeneralRe: Distribute my software to other computers Pin
Ming Luo13-Aug-05 5:22
Ming Luo13-Aug-05 5:22 
GeneralRe: Distribute my software to other computers Pin
User 665813-Aug-05 7:50
User 665813-Aug-05 7:50 
Generalproblem with asynchronous server Pin
bahith13-Aug-05 0:40
bahith13-Aug-05 0:40 
GeneralRe: problem with asynchronous server Pin
Vasudevan Deepak Kumar14-Aug-05 1:55
Vasudevan Deepak Kumar14-Aug-05 1:55 
GeneralRe: problem with asynchronous server Pin
S. Senthil Kumar14-Aug-05 3:31
S. Senthil Kumar14-Aug-05 3:31 
GeneralDatetimePicker in a datagrid Pin
deep712-Aug-05 21:36
deep712-Aug-05 21:36 
GeneralUnmanaged dll access from c# passing paramaters by reference Pin
steveski7412-Aug-05 21:13
steveski7412-Aug-05 21:13 
Generalwrapping Dlls into .exe Pin
allenmpcx12-Aug-05 19:08
allenmpcx12-Aug-05 19:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.