singularity /verify/src/Checked/Libraries/NetStack2/ARP.cs

Language C# Lines 708
MD5 Hash a719b2f10267126708972747d3d3daed Estimated Cost $13,323 (why?)
Repository https://singularity.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
///////////////////////////////////////////////////////////////////////////////
//
//  Microsoft Research Singularity
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//
//  File: ARP.sg
//
//  Note: are fun
//

//#define DEBUG_ARP

using System;
using System.Diagnostics;
using System.Collections;
using System.Text;
//using System.SchedulerTime;
using System.Threading;

using System.Net.IP;
using Drivers.Net;
using Microsoft.Singularity.NetStack.Protocols;

using Microsoft.Singularity.Channels;
using Microsoft.Singularity;
using Microsoft.Singularity.V1.Services;
using Microsoft.SingSharp;

//using Allocation = SharedHeapService.Allocation;
using SchedulerTime = System.DateTime;

namespace Microsoft.Singularity.NetStack.Protocols{}
namespace Microsoft.Singularity.NetStack2
{

    public class ArpHeader
    {
        public ushort htype;
        public ushort pad0;
        public ushort ptype;
        public byte   hlen;
        public byte   plen;
        public ushort op;
        public ushort pad1;
        public EthernetAddress senderEthernetAddr;
        public IPv4            senderIPAddr;
        public EthernetAddress destEthernetAddr;
        public IPv4            destIPAddr;

        public static int Size = 28;
        public static ushort ARP_REQUEST = 1;
        public static ushort ARP_REPLY   = 2;

        public ArpHeader(Bytes packet, ushort index)
        {
            //since this is already known to be an arp request
            //we skip the sanity checks...

            VTable.Assert(packet.Length - index >= 96);

            // check hardware type == 0x0001 (Ethernet)
            htype = NetworkBitConverter.ToUInt16(packet, index);
            DebugStub.Assert(htype == 0x001);
            index +=2;

            // check protocol type == 0x0800 (IP)
            ptype =  NetworkBitConverter.ToUInt16(packet, index);
            DebugStub.Assert(ptype == 0x0800);
            index += 2;

            // check hardware address len is 6 bytes
            hlen = packet[index++];
            DebugStub.Assert(hlen == 6);


            // check IP address len is 4 bytes
            plen = packet[index++];
            DebugStub.Assert(plen == 4);

            op =  NetworkBitConverter.ToUInt16(packet, index);
            index += 2;

            senderEthernetAddr = EthernetAddress.ParseBytes(packet.Array, packet.Start + index);
            index += EthernetAddress.Length;

            uint addr = NetworkBitConverter.ToUInt32(packet, index);
            index += 4;
            senderIPAddr = new IPv4(addr);


            destEthernetAddr = EthernetAddress.ParseBytes(packet.Array, packet.Start + index);
            index += EthernetAddress.Length;

            addr = NetworkBitConverter.ToUInt32(packet, index);
            index += 4;
            destIPAddr = new IPv4(addr);
            //sgc complains
            pad0 = 0;
            pad1 = 0;
        }

        public static int Write(Bytes pkt,
                                EthernetAddress    srchw,
                                IPv4               srcip,
                                ushort             operation,
                                EthernetAddress    targethw,
                                IPv4               targetip)
        {
            int o = 0;

            pkt[o++] = 0x00; pkt[o++] = 0x01;  // hardware type = 0x0001
            pkt[o++] = 0x08; pkt[o++] = 0x00;  // protocol type = 0x0800
            pkt[o++] = 0x06; // hardware addr len (bytes)
            pkt[o++] = 0x04; // protocol address len (bytes)
            pkt[o++] = (byte) (operation >> 8);
            pkt[o++] = (byte) (operation & 0xff);

            srchw.CopyOut(pkt.Array, pkt.Start + o);
            o += EthernetAddress.Length;

            srcip.CopyOut(pkt.Array, pkt.Start + o);
            o += IPv4.Length;

            targethw.CopyOut(pkt.Array, pkt.Start + o);
            o += EthernetAddress.Length;

            targetip.CopyOut(pkt.Array, pkt.Start + o);
            o += IPv4.Length;

            return o;
        }
    }


    public class ARP: IThreadStart
    {
        // ARP variables
        private ArpTable arpTable = null;

        public static int ARP_REQUEST = 1;
        public static int ARP_REPLY = 2;

        //this is a soft limit
        private const int DefaultMaxPendingArpRequests = 256;
        private AutoResetEvent arpHandle;
        private Queue pendingRequestsFreelist;
        private Queue pendingRequests;
        private MonitorLock pendingRequestsLock = new MonitorLock();


        // Pending request polling period
        private static readonly TimeSpan PollPeriod = TimeSpan.FromSeconds(1);

        [Conditional("DEBUG_ARP")]
        public static void DebugPrint(string           format,
                                        params object [] arguments)
        {
            DebugStub.Print("ARP: {0}",
                            DebugStub.ArgList(
                                string.Format(format, arguments))
                            );
        }

        private class PendingArpRequest
        {
            public IPv4            address;
            public SchedulerTime   requestExpiration;
            public AutoResetEvent  requestEvent;
            public EthernetAddress localMac;
            public bool            active;
            public IAdapter               adapter;
            public TContainerVectorQueueByte txContainer;

            public PendingArpRequest()
            {
                this.requestEvent = new AutoResetEvent(false);
                this.active = false;

                txContainer = new TContainerVectorQueueByte(
                    new VectorQueueByte()
                );
            }
        }


        private void ARPManageThread()
        {
            DebugPrint("ARP managment thread spinning up\n");
            //the pending requests list is ordered by deadline...
            //finding a requests when we rceive a reply is in the worst case O(n)...
            //Hopefully we won't have many oustanding requests, and the first request out
            //will often return first...

            //track two different timeouts here...ARP requests and ARP table aging.
            SchedulerTime  ageTableTimeout;
            SchedulerTime  now;
            SchedulerTime  nextTimer;


            ageTableTimeout = SchedulerTime.Now;
            ageTableTimeout = ageTableTimeout.AddMinutes(5);
            while(true) {
                now = SchedulerTime.Now;
                if (now > ageTableTimeout) {
                    arpTable.AgeTable();
                    ageTableTimeout = SchedulerTime.Now;
                    ageTableTimeout = ageTableTimeout.AddMinutes(5);
                }
                using (pendingRequestsLock.Lock()) {
                    nextTimer = SchedulerTime.MaxValue;
                    bool done = false;
                    while (!done) {
                        if (pendingRequests.Count == 0) {
                            done = true;
                            continue;
                        }
                        PendingArpRequest pendingArpRequest = (PendingArpRequest) pendingRequests.Peek();
                        if (pendingArpRequest == null) {
                            done = true;
                            continue;
                        }
                        if (pendingArpRequest.requestExpiration > now) {
                            nextTimer = pendingArpRequest.requestExpiration;
                            done = true;
                            continue;
                        }
                        else {
                            pendingArpRequest = (PendingArpRequest) pendingRequests.Dequeue();
                            if (pendingArpRequest.active == true) {
                                //We need error propagation here...
                                pendingArpRequest.active = false;
                                DebugStub.Assert(false);
                            }
                            pendingRequestsFreelist.Enqueue(pendingArpRequest);
                        }
                    }
                }
                if (ageTableTimeout < nextTimer) {
                    DebugPrint("setting nextTimer ageTableTimeout\n");
                    nextTimer = ageTableTimeout;
                }
                bool rc;
                rc = arpHandle.WaitOne(nextTimer);
            }
        }

        [Microsoft.Contracts.NotDelayed]
        public ARP()
        {
            DebugPrint("Initializing ARP module\n");
            arpTable = new ArpTable(this);
            pendingRequests = new Queue();
            pendingRequestsFreelist = new Queue();

            //start the array list with 256 elements to
            for(int i = 0; i < DefaultMaxPendingArpRequests; i++) {
                PendingArpRequest pendingArpRequest =
                    new PendingArpRequest();
                pendingRequestsFreelist.Enqueue(pendingArpRequest);
            }
            arpHandle = new AutoResetEvent(false);

            Thread arpThread = new Thread(this);
            DebugStub.Assert(arpThread != null);
            arpThread.Start();

        }

        public void Run()
        {
            System.DebugStub.Print("ARP@" + Kernel.CurrentThread + ". ");
            ARPManageThread();
        }

        // Original note from Yaron:
        // ARP logic: see RFC 826 http://www.faqs.org/rfcs/rfc826.html
        //

        public void ProcessIncomingPacket(Bytes packet, IAdapter adapter)
        {
            //Get the ARP packet info located after the ethernet header
            ArpHeader arpHeader = new ArpHeader(packet, 14);

            DebugPrint("ARP: ProcessIncomingPacket\n");
            //do some checks to make sure the packet is copacetic
            if (arpHeader.htype != 0x1) {
                DebugPrint("ARP: ProcessIncomingPacket got wrong hardware type? 0x{0,8:x}\n",
                           arpHeader.htype);
                //delete packet;
                return;
            }

            if (arpHeader.ptype != 0x0800) {
                DebugPrint("ARP: ProcessIncomingPacket got wrong  protocol? 0x{0,8:x}\n",
                           arpHeader.ptype);
                //delete packet;
                return;
            }
            //ethernet address should be 6 bytes
            if (arpHeader.hlen != 6) {
                DebugPrint("ARP: ProcessIncomingPacket got wrong hw length? 0x{0,8:x}\n",
                           arpHeader.hlen);
                //delete packet;
                return;
            }

            if (arpHeader.plen != 4) {
                DebugPrint("ARP: ProcessIncomingPacket got wrong protocol address length? 0x{0,8:x}\n",
                           arpHeader.plen);
                //delete packet;
                return;
            }


            DebugPrint("Incoming packet\n");

            bool merged  = false;
            bool updated = false;
            ArpEntry target = arpTable.Lookup(arpHeader.senderIPAddr);
            if (target != null && target.Dynamic == true) {
                DebugPrint("ARP UPDATE\n");
                // we have it already - just update the details...
                target.MacAddress = arpHeader.senderEthernetAddr;
                target.EntryAge   = arpTable.Age;
                merged            = true;
                updated           = true;
            }

            if (merged == false) {
                DebugPrint("ARP ADDITION\n");
                arpTable.AddEntry(new ArpEntry(arpHeader.senderIPAddr,
                                               arpHeader.senderEthernetAddr, true));
                merged = true;
                UpdatePendingRequests(arpHeader.senderIPAddr, arpHeader.senderEthernetAddr);
            }

            //Is this a local address
            bool forSelf = IP.IsLocalAddress(arpHeader.destIPAddr);
            if (forSelf == false) {
                //delete packet;
                return;
            }

            // now figure out the opcode
            if (arpHeader.op == ARP_REQUEST) {
                DebugPrint("Handling request ({0},{1}) ---> ({2},{3} \npkt dest {4} {5})\n",
                           arpHeader.senderIPAddr, arpHeader.senderEthernetAddr,
                           arpHeader.destIPAddr, adapter.HardwareAddress,
                           arpHeader.destIPAddr, arpHeader.destEthernetAddr
                           );

                int dataLength = EthernetHeader.Size + ArpHeader.Size;
                VTable.Assert(packet.Length >= dataLength);

                Bytes data = Bitter.SplitOff(ref packet, EthernetHeader.Size);

                EthernetHeader.Write(packet,
                                     adapter.HardwareAddress,
                                     arpHeader.senderEthernetAddr,
                                     EthernetHeader.PROTOCOL_ARP);

                //use arp header to format reply
                ArpHeader.Write(data, adapter.HardwareAddress,
                                arpHeader.destIPAddr, ArpHeader.ARP_REPLY,
                                arpHeader.senderEthernetAddr, arpHeader.senderIPAddr);
                adapter.PopulateTxRing(packet, data);
            }
            else {
                // otherwise we are done
                DebugPrint(
                    "Handling reply ({2},{3}) <--- ({0},{1})\n",
                    arpHeader.senderIPAddr, arpHeader.senderEthernetAddr,
                    arpHeader.destIPAddr, arpHeader.destEthernetAddr
                    );
                //delete packet;
            }

            if (merged && !updated) {
                DebugPrint(arpTable.ToString());
            }
        }

        public void ArpRequest(IPv4               sourceIP,
                               IPv4               targetIP,
                               EthernetAddress    localMac,
                               Bytes header,
                               Bytes buffer,
                               IAdapter          adapter)
        {
            //            AutoResetEvent requestComplete =
            AddPendingRequest(targetIP, TimeSpan.FromSeconds(3), localMac, header, buffer, adapter);

            // initiate an arp request...
            DebugPrint("Initiating request " +
                       "({0},{1}) --> ({2},{3})\n",
                       sourceIP, localMac, targetIP, EthernetAddress.Zero);

            //eventially we'll want to follow Orion's conservation of
            //packets philosophy
            Bytes arpHeader = new Bytes(new byte [EthernetHeader.Size]);
            Bytes arpMsg = new Bytes(new byte [ArpHeader.Size]);
            //xxx I'd like to get rid of EthernetHeader eventually...

            EthernetHeader.Write(arpHeader,
                                 localMac,
                                 EthernetAddress.Broadcast,
                                 EthernetHeader.PROTOCOL_ARP);

            ArpHeader.Write(arpMsg, localMac, sourceIP,
                            ArpHeader.ARP_REQUEST, EthernetAddress.Zero,
                            targetIP);
            adapter.PopulateTxRing(arpHeader, arpMsg);
            //            DebugPrint("ArpRequest: waiting for reply\n");
            //requestComplete.WaitOne();
            //            DebugPrint("ArpRequest: reply received!\n");
        }

        public bool Lookup(IPv4 targetIP, out EthernetAddress macAddress)
        {
            return arpTable.Lookup(targetIP, out macAddress);
        }

        private AutoResetEvent AddPendingRequest(IPv4 address,
                                                  TimeSpan timeout,
                                                  EthernetAddress    localMac,
                                                  Bytes header,
                                                  Bytes buffer,
                                                  IAdapter          adapter
                                                  )
        {

            PendingArpRequest pendingRequest = (PendingArpRequest) pendingRequestsFreelist.Dequeue();
            VTable.Assert(pendingRequest != null);
            pendingRequest.address = address;
            pendingRequest.active  = true;
            pendingRequest.localMac = localMac;
            pendingRequest.adapter = adapter;
            VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire();
            txBuffer.AddTail(header);
            txBuffer.AddTail(buffer);
            pendingRequest.txContainer.Release(txBuffer);

            using (pendingRequestsLock.Lock()) {
                pendingRequests.Enqueue(pendingRequest);
            }

            SchedulerTime expiration = SchedulerTime.Now;
            expiration = expiration.Add(timeout);
            pendingRequest.requestExpiration = expiration;

            //poke the wait thread
            if (pendingRequests.Count == 1) {
                arpHandle.Set();
            }
            return pendingRequest.requestEvent;
        }

        private void UpdatePendingRequests(IPv4            ipAddress,
                                           EthernetAddress macAddress)
        {
            using (pendingRequestsLock.Lock()) {
                //Sigh...we're missing a linked list in the current Singularity C# runtime
                foreach (PendingArpRequest pendingRequest in pendingRequests) {
                    VTable.Assert(pendingRequest != null);
                    if (pendingRequest.address == ipAddress) {
                        pendingRequest.active = false;
                        DebugStub.WriteLine("found waiting arp request...sending on out");
                        VectorQueueByte txBuffer = pendingRequest.txContainer.Acquire();
                        Bytes header = txBuffer.ExtractHead();
                        Bytes buffer = txBuffer.ExtractHead();
                        VTable.Assert(header != null);
                        VTable.Assert(buffer != null);
                        pendingRequest.txContainer.Release(txBuffer);
                        //Format ethernet header
                        EthernetHeader.Write(header, pendingRequest.localMac, macAddress, EthernetHeader.PROTOCOL_IP);
                        //send it!
                        VTable.Assert(pendingRequest.adapter != null);
                        pendingRequest.adapter.PopulateTxRing(header, buffer);
                        continue;
                    }
                }
            }
        }
    }

    // an arp entry (we only deal with IPv4)
    public class ArpEntry
    {
        private IPv4            ipAddress;
        private EthernetAddress mac;
        private int             entryAge;
        private bool            dynamic;

        public int EntryAge
        {
            get { return entryAge; }
            set { entryAge = value; }
        }

        public EthernetAddress MacAddress
        {
            get { return mac; }
            set { mac = value; }
        }

        public IPv4 IPAddress
        {
            get { return ipAddress; }
        }

        public bool Dynamic
        {
            get { return dynamic; }
        }

        // create a new entry
        public ArpEntry(IPv4 ipAddress, EthernetAddress mac, bool dynamic)
        {
            this.ipAddress = ipAddress;
            this.mac       = mac;
            this.dynamic   = dynamic;
            this.entryAge  = ArpTable.MaxAge;
        }

        public override string ToString()
        {
            return String.Format("{0} {1} {2} {3}",
                                 ipAddress, mac, entryAge,
                                 dynamic ? "dynamic" : "static");
        }
    }

    // define the arp table
    internal class ArpTable
    {
        Hashtable arpEntries;   // <Key = IPv4 address, Value = ArpEntry>

        // max table size
        protected readonly int maxEntries;

        // default entry age
        protected int defaultAge;

        // get the default age
        public int Age { get { return defaultAge; } }

        // the default age
        public const int MaxAge = 50;

        public const int defaultSize = 128;

        // aging timeout [msec]
        public static readonly TimeSpan AgePeriod = TimeSpan.FromMinutes(5);

        // our parent
        protected ARP arp;

        [Conditional("DEBUG_ARP")]
        internal static void DebugPrint(string           format,
                                        params object [] arguments)
        {
            DebugStub.Print("ARP: {0}",
                            DebugStub.ArgList(
                                string.Format(format, arguments))
                            );
        }

        [Conditional("DEBUG_ARP")]
        internal static void DebugPrint(string format)
        {
            DebugStub.Print("ARP: {0}",
                            DebugStub.ArgList(format));
        }

        public ArpTable(int size, int age, ARP arp)
        {
            DebugPrint("creating ArpTable size={0}, age={1}\n",
                           size, age);

            arpEntries = new Hashtable(size);
            maxEntries = size;
            defaultAge = age;
            this.arp   = arp;
        }

        public ArpTable(ARP arp)
        {
            DebugPrint("creating ArpTable size={0}, age={1}\n",
                       defaultSize, MaxAge);

            arpEntries = new Hashtable(defaultSize);
            maxEntries = defaultSize;
            defaultAge = MaxAge;
            this.arp   = arp;
        }

        // add a new entry
        // return false if there is no more room
        public bool AddEntry(ArpEntry e)
        {
            // if no more room, make one
            if (arpEntries.Count >= maxEntries) {
                PurgeLRUEntry();
            }
            e.EntryAge = this.defaultAge;
            arpEntries.Add(e.IPAddress, e);
            DebugPrint("Added entry {0}\n", e);
            return true;
        }

        private void RemoveEntry(ArpEntry e)
        {
            arpEntries.Remove(e.IPAddress);
            DebugPrint("Removed entry for {0}\n", e);
        }

        public void RemoveEntry(IPv4 targetIP)
        {
            arpEntries.Remove(targetIP);
            DebugPrint("Removed entry for {0}\n");
        }

        // makes a room for a new entry, get rid of
        // the least recently used entry (LRU)
        public void PurgeLRUEntry()
        {
            if (arpEntries.Count == 0)
                return;

            // can use a LRU list to avoid O(n)
            // but this is a kind of a small table...
            IDictionaryEnumerator dicEnum = arpEntries.GetEnumerator();
            dicEnum.MoveNext();  // get the first entry

            ArpEntry lruElement = (ArpEntry)dicEnum.Value;

            while (dicEnum.MoveNext()) {
                ArpEntry current = (ArpEntry)dicEnum.Value;
                if (current.EntryAge < lruElement.EntryAge) {
                    lruElement = current;
                }
            }
            RemoveEntry(lruElement);
        }

        // age the dynamic table entries, if age drops to 0 purge entry
        internal bool AgeTable()
        {
            int startCount = arpEntries.Count;

            // Can't hold iterator and add or remove items so use
            // list to hold items to be deleted.
            ArrayList purgeItems = new ArrayList();

            foreach (ArpEntry e in arpEntries.Values) {
                if (e.Dynamic == true && --e.EntryAge == 0) {
                    purgeItems.Add(e);
                }
            }

            foreach (ArpEntry e in purgeItems) {
                RemoveEntry(e);
            }

            return startCount < arpEntries.Count;
        }

        public ArpEntry Lookup(IPv4 destination)
        {
            return arpEntries[destination] as ArpEntry;
        }

        // an upper layer interface to get the mac
        // to a target IP. The upper protocol must
        // provide the Mux for the target IP.
        // if we have it then we return true + macAddress
        // and refresh the age to create a LRU list
        public bool Lookup(IPv4 targetIP, out EthernetAddress macAddress)
        {
            ArpEntry e = arpEntries[targetIP] as ArpEntry;
            if (e != null) {
                e.EntryAge = Age;
                macAddress = e.MacAddress;
                return true;
            }
            macAddress = EthernetAddress.Zero;
            return false;
        }

        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("Internet Address      Physical Address    Type             \n");
            stringBuilder.Append("-----------------------------------------------------------\n");

            string [] types = { "static", "dynamic" };
            foreach (ArpEntry e in arpEntries.Values) {
                stringBuilder.Append(e.IPAddress + "       " + e.MacAddress +
                                     "   " + types[ e.Dynamic ? 1 : 0] +
                                     " [Age=" + e.EntryAge + "]\n");
            }
            return stringBuilder.ToString();
        }
    }
}
Back to Top