本文整理汇总了C#中MemBlock.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# MemBlock.CopyTo方法的具体用法?C# MemBlock.CopyTo怎么用?C# MemBlock.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemBlock
的用法示例。
在下文中一共展示了MemBlock.CopyTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleData
public void HandleData(MemBlock packet, ISender from, object node)
{
_message_count++;
long stop_time, rt_ticks = -10000;
if ( !from.Equals(node)) {
if (packet[0] == 0) {
//log.Debug("Echo Response:");
stop_time = System.DateTime.Now.Ticks;
int received_uid = NumberSerializer.ReadInt(packet, 1);
if(uid_starttime.ContainsKey(received_uid)){
rt_ticks = stop_time - (long)EchoTester.uid_starttime[received_uid];
}
double rt_ms = (double) rt_ticks/10000.0;
uid_brunetpingtime.Add(received_uid, rt_ms);
Console.WriteLine("Packet ID = {0}, Round-trip = {1}", received_uid, rt_ms);
}
else {
//log.Debug("Echo Request:");
}
//log.Debug(packet.ToString());
//System.Console.WriteLine("{0}", packet.ToString());
if (packet[0] > 0) {
//Send a reply back, this is a request
byte[] new_payload = new byte[ packet.Length ];
packet.CopyTo(new_payload, 0);
new_payload[0] = (byte) 0;
from.Send(new CopyList(PType.Protocol.Echo, MemBlock.Reference(new_payload)));
}
}
}
示例2: GetManagedDhcpServer
public static ManagedDhcpServer GetManagedDhcpServer(MemBlock ip, MemBlock netmask) {
DHCPConfig config = new DHCPConfig();
config.LeaseTime = 3200;
config.Netmask = Utils.MemBlockToString(netmask, '.');
config.IPBase = Utils.MemBlockToString(ip, '.');
config.ReservedIPs = new DHCPConfig.ReservedIP[1];
config.ReservedIPs[0] = new DHCPConfig.ReservedIP();
byte[] local_ip = new byte[4];
ip.CopyTo(local_ip, 0);
local_ip[3] = 2;
config.ReservedIPs[0].IPBase = Utils.BytesToString(local_ip, '.');
config.ReservedIPs[0].Mask = "255.255.255.255";
return new ManagedDhcpServer(config);
}
示例3: GenToken
protected byte[] GenToken(MemBlock key) {
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
byte[] token = new byte[20];
provider.GetBytes(token);
byte[] res = new byte[40];
key.CopyTo(res, 0);
token.CopyTo(res, 20);
return res;
}
示例4: DhcpPacket
public DhcpPacket(byte op, MemBlock xid, MemBlock ciaddr, MemBlock yiaddr,
MemBlock siaddr, MemBlock chaddr, Dictionary<OptionTypes, MemBlock> Options)
{
this.op = op;
this.xid = xid;
this.ciaddr = ciaddr;
this.yiaddr = yiaddr;
this.siaddr = siaddr;
this.chaddr = chaddr;
this.Options = Options;
byte[] header = new byte[240];
header[0] = op;
header[1] = 1;
header[2] = (byte) chaddr.Length;
header[3] = 0;
xid.CopyTo(header, 4);
for(int i = 8; i < 12; i++) {
header[i] = 0;
}
ciaddr.CopyTo(header, 12);
yiaddr.CopyTo(header, 16);
siaddr.CopyTo(header, 20);
for(int i = 24; i < 28; i++) {
header[i] = 0;
}
chaddr.CopyTo(header, 28);
for(int i = 34; i < 236; i++) {
header[i] = 0;
}
magic_key.CopyTo(header, 236);
_icpacket = new CopyList(MemBlock.Reference(header));
foreach(KeyValuePair<OptionTypes, MemBlock> kvp in Options) {
MemBlock value = kvp.Value;
byte[] tmp = new byte[2];
tmp[0] = (byte) kvp.Key;
tmp[1] = (byte) value.Length;
_icpacket = new CopyList(_icpacket, MemBlock.Reference(tmp), value);
}
byte []end = new byte[1]{255}; /* End of Options */
_icpacket = new CopyList(_icpacket, MemBlock.Reference(end));
}
示例5: MakePseudoHeader
public static MemBlock MakePseudoHeader(MemBlock source_address,
MemBlock destination_address, byte protocol, ushort length)
{
byte[] pseudoheader = new byte[source_address.Length + destination_address.Length + 4];
int pos = 0;
source_address.CopyTo(pseudoheader, pos);
pos += source_address.Length;
destination_address.CopyTo(pseudoheader, pos);
pos += destination_address.Length;
pseudoheader[++pos] = protocol;
NumberSerializer.WriteUShort(length, pseudoheader, ++pos);
return MemBlock.Reference(pseudoheader);
}
示例6: well
/**
<summary>If we're not creating a packet from scratch, this will keep its
integrity and transform UDP and TCP headers as well (due to their checksums
being dependent on source and destination ip addresses.</summary>
<param name="Packet">The packet to translate.</param>
<param name="SourceIP">The new source ip.</param>
<param name="DestinationIP">The new destination ip.</param>
*/
public static MemBlock Translate(MemBlock Packet, MemBlock SourceIP,
MemBlock DestinationIP) {
byte[] new_packet = new byte[Packet.Length];
Packet.CopyTo(new_packet, 0);
int length = (Packet[0] & 0xF) * 4;
SourceIP.CopyTo(new_packet, 12);
// Do not copy over multicast addresses!
if(new_packet[16] < 224 || new_packet[16] > 239) {
DestinationIP.CopyTo(new_packet, 16);
}
// Zero out the checksum so we don't use it in our future calculations
new_packet[10] = 0;
new_packet[11] = 0;
MemBlock header = MemBlock.Reference(new_packet, 0, length);
int checksum = GenerateChecksum(header);
new_packet[10] = (byte) ((checksum >> 8) & 0xFF);
new_packet[11] = (byte) (checksum & 0xFF);
Protocols p = (Protocols) Packet[9];
bool fragment = ((Packet[6] & 0x1F) | Packet[7]) != 0;
if(p == Protocols.Udp && !fragment) {
// Zero out the checksum to disable it
new_packet[length + 6] = 0;
new_packet[length + 7] = 0;
}
else if(p == Protocols.Tcp && !fragment) {
// Zero out the checksum so we don't use it in our future calculations
new_packet[length + 16] = 0;
new_packet[length + 17] = 0;
MemBlock payload = MemBlock.Reference(new_packet).Slice(length);
MemBlock pseudoheader = IPPacket.MakePseudoHeader(SourceIP,
DestinationIP, (byte) Protocols.Tcp, (ushort) (Packet.Length - 20));
checksum = IPPacket.GenerateChecksum(payload, pseudoheader);
new_packet[length + 16] = (byte) ((checksum >> 8) & 0xFF);
new_packet[length + 17] = (byte) (checksum & 0xFF);
}
return MemBlock.Reference(new_packet);
}