我从互联网上学习编码,并尝试理解我从互联网上获得的代码。我从代码中复制了一个片段,因为我迷失了它。请帮帮我。
private byte[] get(string request, IPAddress ipAddress, string community, string mibstring)
{
byte[] buffer = new byte[1024];
byte[] numArray1 = new byte[1024];
int length1 = community.Length;
string[] strArray = mibstring.Split('.');
int length2 = strArray.Length;
int index1 = 0;
int num1 = length2;
int num2 = 0;
for (int index2 = 0; index2 < num1; ++index2)
{
int num3 = (int) Convert.ToInt16(strArray[index2]);
if (num3 > (int) sbyte.MaxValue)
{
numArray1[index1] = Convert.ToByte(128 + num3 / 128);
numArray1[index1 + 1] = Convert.ToByte(num3 - num3 / 128 * 128);
index1 += 2;
++length2;
}
else
{
numArray1[index1] = Convert.ToByte(num3);
++index1;
}
}
int size = 29 + length1 + length2 - 1;
byte[] numArray2 = buffer;
我遇到这个缓冲的问题。如果我没错,这个缓冲区是一个1024 0元素的数组。
这个代码的作用是什么?:
byte[] numArray2 = buffer;
名称没有索引。复制整个数组?
byte[] numArray2 = buffer;
int index3 = num2;
int num4 = 1;
int num5 = index3 + num4;
int num6 = 48;
numArray2[index3] = (byte) num6;
byte[] numArray3 = buffer;
int index4 = num5;
int num7 = 1;
int num8 = index4 + num7;
int num9 = (int) Convert.ToByte(size - 2);
numArray3[index4] = (byte) num9;
byte[] numArray4 = buffer;
int index5 = num8;
int num10 = 1;
int num11 = index5 + num10;
int num12 = 2;
numArray4[index5] = (byte) num12;
byte[] numArray5 = buffer;
int index6 = num11;
int num13 = 1;
int num14 = index6 + num13;
int num15 = 1;
numArray5[index6] = (byte) num15;
byte[] numArray6 = buffer;
int index7 = num14;
int num16 = 1;
int num17 = index7 + num16;
int num18 = 0;
numArray6[index7] = (byte) num18;
byte[] numArray7 = buffer;
int index8 = num17;
int num19 = 1;
int num20 = index8 + num19;
int num21 = 4;
numArray7[index8] = (byte) num21;
byte[] numArray8 = buffer;
int index9 = num20;
int num22 = 1;
int num23 = index9 + num22;
int num24 = (int) Convert.ToByte(length1);
numArray8[index9] = (byte) num24;
foreach (byte @byte in Encoding.ASCII.GetBytes(community))
buffer[num23++] = @byte;
int num25;
if (request == "get")
{
byte[] numArray9 = buffer;
int index2 = num23;
int num3 = 1;
num25 = index2 + num3;
int num26 = 160;
numArray9[index2] = (byte) num26;
}
else
{
byte[] numArray9 = buffer;
int index2 = num23;
int num3 = 1;
num25 = index2 + num3;
int num26 = 161;
numArray9[index2] = (byte) num26;
}
byte[] numArray10 = buffer;
int index10 = num25;
int num27 = 1;
int num28 = index10 + num27;
int num29 = (int) Convert.ToByte(20 + length2 - 1);
numArray10[index10] = (byte) num29;
byte[] numArray11 = buffer;
int index11 = num28;
int num30 = 1;
int num31 = index11 + num30;
int num32 = 2;
numArray11[index11] = (byte) num32;
byte[] numArray12 = buffer;
int index12 = num31;
int num33 = 1;
int num34 = index12 + num33;
int num35 = 4;
numArray12[index12] = (byte) num35;
byte[] numArray13 = buffer;
int index13 = num34;
int num36 = 1;
int num37 = index13 + num36;
int num38 = 0;
numArray13[index13] = (byte) num38;
byte[] numArray14 = buffer;
int index14 = num37;
int num39 = 1;
int num40 = index14 + num39;
int num41 = 0;
numArray14[index14] = (byte) num41;
byte[] numArray15 = buffer;
int index15 = num40;
int num42 = 1;
int num43 = index15 + num42;
int num44 = 0;
numArray15[index15] = (byte) num44;
byte[] numArray16 = buffer;
int index16 = num43;
int num45 = 1;
int num46 = index16 + num45;
int num47 = 1;
numArray16[index16] = (byte) num47;
byte[] numArray17 = buffer;
int index17 = num46;
int num48 = 1;
int num49 = index17 + num48;
int num50 = 2;
numArray17[index17] = (byte) num50;
byte[] numArray18 = buffer;
int index18 = num49;
int num51 = 1;
int num52 = index18 + num51;
int num53 = 1;
numArray18[index18] = (byte) num53;
byte[] numArray19 = buffer;
int index19 = num52;
int num54 = 1;
int num55 = index19 + num54;
int num56 = 0;
numArray19[index19] = (byte) num56;
byte[] numArray20 = buffer;
int index20 = num55;
int num57 = 1;
int num58 = index20 + num57;
int num59 = 2;
numArray20[index20] = (byte) num59;
byte[] numArray21 = buffer;
int index21 = num58;
int num60 = 1;
int num61 = index21 + num60;
int num62 = 1;
numArray21[index21] = (byte) num62;
byte[] numArray22 = buffer;
int index22 = num61;
int num63 = 1;
int num64 = index22 + num63;
int num65 = 0;
numArray22[index22] = (byte) num65;
byte[] numArray23 = buffer;
int index23 = num64;
int num66 = 1;
int num67 = index23 + num66;
int num68 = 48;
numArray23[index23] = (byte) num68;
byte[] numArray24 = buffer;
int index24 = num67;
int num69 = 1;
int num70 = index24 + num69;
int num71 = (int) Convert.ToByte(6 + length2 - 1);
numArray24[index24] = (byte) num71;
byte[] numArray25 = buffer;
int index25 = num70;
int num72 = 1;
int num73 = index25 + num72;
int num74 = 48;
numArray25[index25] = (byte) num74;
byte[] numArray26 = buffer;
int index26 = num73;
int num75 = 1;
int num76 = index26 + num75;
int num77 = (int) Convert.ToByte(6 + length2 - 1 - 2);
numArray26[index26] = (byte) num77;
byte[] numArray27 = buffer;
int index27 = num76;
int num78 = 1;
int num79 = index27 + num78;
int num80 = 6;
numArray27[index27] = (byte) num80;
byte[] numArray28 = buffer;
int index28 = num79;
int num81 = 1;
int num82 = index28 + num81;
int num83 = (int) Convert.ToByte(length2 - 1);
numArray28[index28] = (byte) num83;
byte[] numArray29 = buffer;
int index29 = num82;
int num84 = 1;
int num85 = index29 + num84;
int num86 = 43;
numArray29[index29] = (byte) num86;
for (int index2 = 2; index2 < length2; ++index2)
buffer[num85++] = Convert.ToByte(numArray1[index2]);
byte[] numArray30 = buffer;
int index30 = num85;
int num87 = 1;
int num88 = index30 + num87;
int num89 = 5;
numArray30[index30] = (byte) num89;
byte[] numArray31 = buffer;
int index31 = num88;
int num90 = 1;
int num91 = index31 + num90;
int num92 = 0;
numArray31[index31] = (byte) num92;
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3500);
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 161);
EndPoint remoteEP = (EndPoint) ipEndPoint;
socket.SendTo(buffer, size, SocketFlags.None, (EndPoint) ipEndPoint);
try
{
socket.ReceiveFrom(buffer, ref remoteEP);
}
catch (SocketException ex)
{
buffer[0] = byte.MaxValue;
}
return buffer;
}
我在这段代码中完全丢失了。此代码逐个获取网络打印机计数器。我不知道它是怎么做的。
这是调用方法:
byte[] numArray2 = this.get("get", machineIPAddress, "public", "1.3.6.1.2.1.43.10.2.1.4.1.1");
答案 0 :(得分:1)
打破这一行:
byte[] numArray2 = buffer;
byte[]
numArray2
附加到该引用buffer
的值复制到引用numArray2
。 现在两个变量都指向同一个对象。