5 // Created by Terrin Eager on 9/26/12.
12 #include <sys/socket.h>
13 #include <sys/types.h>
14 #include <netinet/in.h>
17 #include <arpa/inet.h>
20 #include "BonjourTop.h"
22 #include "CaptureFile.h"
26 #include <sys/sysctl.h>
27 #include <mach/mach.h>
29 #define SERVICE_IPV4 0
30 #define SERVICE_IPV6 1
34 #define TRACE_PLATFORM_UNKNOWN 0
35 #define TRACE_PLATFORM_OSX 1
36 #define TRACE_PLATFORM_iOS 2
37 #define TRACE_PLATFORM_APPLE_TV 3
38 #define TRACE_PLATFORM_NON_APPLE_PLATFORM 4
39 #define DISCOVERYD_TRACE_PLATFORM_OSX (1 | 0x80)
40 #define DISCOVERYD_TRACE_PLATFORM_iOS (2 | 0x80)
41 #define DISCOVERYD_TRACE_PLATFORM_APPLE_TV (3 | 0x80)
42 #define DISCOVERYD_TRACE_PLATFORM_NON_APPLE_PLATFORM (4 | 0x80)
44 int CDeviceNode::nCreateCount
= 0;
45 static integer_t
Usage(void);
47 char CVSFileNameExample
[] ="BonjourTop";
48 char DeviceNameExample
[] ="BonjourTopDevice.csv";
50 char Service2App
[][50] = {
51 // Service_Name, Application_Name, Browse_OS_Type, Register_OS_Type
52 "_device-info._tcp.local.", "Device-Info", "?" , "?",
53 "_rfb._tcp.local.", "Finder", "X" , "?",
54 "_afpovertcp._tcp.local.", "Finder", "?" , "X",
55 "_adisk._tcp.local.", "Finder", "?" , "X",
56 "_odisk._tcp.local.", "Finder", "?" , "X",
57 "_smb._tcp.local.", "Finder", "X" , "X",
58 "_smb2._tcp.local.", "Finder", "X" , "X",
59 "_workstation._tcp.local.", "Finder", "X" , "X",
60 "_kerberos.", "Finder", "X" , "X",
61 "_nfs._tcp.local.", "Finder", "X" , "X",
62 "_ftp._tcp.local.", "Finder", "X" , "X",
64 "_appletv._tcp.local.", "AppleTV", "?" , "t",
65 "_appletv-v2._tcp.local.", "AppleTV", "?" , "?",
66 "_appletv-pair._tcp.local.", "AppleTV", "?" , "?",
68 "A", "LinkLocal", "?" , "?",
69 "AAAA", "LinkLocal", "?" , "?",
70 "*.ip6.arpa.", "LinkLocal", "?" , "?",
71 "*.arpa.", "LinkLocal", "?" , "?",
73 "_airplay._tcp.local.", "AirPlay", "?" , "t",
74 "_airplayTXT", "AirPlay","?" , "t",
75 "_raop._tcp.local.", "AirPlay","?" , "?",
77 "_ubd._tcp.local.", "Ubiquity", "?" , "?",
78 "_ubiquity._tcp.local.", "Ubiquity", "?" , "?",
79 "_ubiquityV1._tcp.local.", "Ubiquity", "?" , "?",
80 "_ubiquityV2._tcp.local.", "Ubiquity", "?" , "?",
82 " _ipps._tcp.local.", "Printing", "?" , "?",
83 "_ipp._tcp.local.", "Printing", "?" , "?",
84 "_ipps._tcp.local.", "Printing", "?" , "?",
85 "_ipp-tls._tcp.local.", "Printing", "?" , "?",
86 "_printer._tcp.local.", "Printing", "?" , "?",
87 "_scanner._tcp.local.", "Printing", "?" , "?",
88 "_pdl-datastream._tcp.local.", "Printing", "?" , "?",
89 "_fax-ipp._tcp.local.", "Printing", "?" , "?",
91 "_apple-mobdev._tcp.local.", "iTunes-WiFiSync","?" , "i",
92 "_daap._tcp.local.", "iTunes", "?" , "?",
94 "_sftp-ssh._tcp.local.", "Terminal", "?" , "X",
95 "_ssh._tcp.local.", "Terminal", "?" , "X",
97 "_sleep-proxy._udp.local.", "Sleep Proxy", "?" , "?",
98 "_keepalive._dns-sd._udp.local.","Sleep Proxy", "X" , "?",
99 "_services._dns-sd._udp.local.", "Services", "?" , "?",
100 "ANY *.ip6.arpa.", "Sleep Proxy", "?" , "?",
101 "ANY *.arpa.", "Sleep Proxy", "?" , "?",
103 "AirPort_presence._tcp.local.", "AirPort", "?" , "?",
104 "_airport._tcp.local.", "AirPort", "?" , "?",
105 "_presence._tcp.local.", "iChat", "X" , "X",
106 "_home-sharing._tcp.local.", "HomeSharing", "?" , "X",
108 "_ptp._tcp.local.", "iPhoto", "?" , "X",
109 "_ica-networking2._tcp.local.", "iPhoto", "X" , "X",
110 "_mobileiphoto._udp.local.", "iPhoto", "?" , "?",
111 "_mobileiphoto2._udp.local.", "iPhoto", "?" , "?",
112 "_dpap._tcp.local.", "iPhoto", "?" , "X",
113 "_airdrop._tcp.local.", "AirDrop", "?" , "?",
114 "_http._tcp.local.", "Safari", "X" , "X",
115 "_net-assistant._udp.local.","Apple Remote Desktop","X" , "X",
116 "_servermgr._tcp.local.", "OSX Server", "X" , "X",
120 char DeviceInfo2DeviceOS
[][50] = {
121 // deviceModel, deviceType
161 char Name2DeviceOS
[][50] = {
162 // Name contains, osType
178 BJ_UINT64
Hash(const char* pStr
);
179 BJ_UINT64
Hash2(char* pStr
);
182 CSocketStats::CSocketStats()
187 void CSocketStats::Init()
191 m_nQuestionOnlyFrames
= 0;
192 m_nAnswerOnlyFrames
= 0;
198 void CSocketStats::Clear()
203 CBonjourTop::CBonjourTop()
207 m_pTcpDumpFileName
= NULL
;
208 m_pExportFileName
= CVSFileNameExample
;
209 m_DeviceFileName
= DeviceNameExample
;
214 m_StartTime
= m_EndTime
= time(NULL
);
216 m_SnapshotSeconds
= 0;
218 m_MinAnswerCountForTruncatedFrames
= 0;
219 m_AvgAnswerCountForTruncatedFrames
= 0;
220 m_MaxAnswerCountForTruncatedFrames
= 0;
222 window_size_changed
= false;
223 m_bImportExportDeviceMap
= false;
225 // loadup application mapping
226 for(int i
=0; Service2App
[i
][0] != 0;)
228 BJString
a(Service2App
[i
++]);
230 m_Service2AppMap
.FindwithAddRecord(&a
)->value
= Service2App
[i
++];
231 m_Service2osBrowseMap
.FindwithAddRecord(&a
)->value
= Service2App
[i
++];
232 m_Service2osRegisterMap
.FindwithAddRecord(&a
)->value
= Service2App
[i
++];
237 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_APP
;
238 // m_CurrentDisplay = CBonjourTop::BJ_DISPLAY_SERVICE;
244 static int CbClearDataDevice(const void* pNode
, const void*)
246 CDeviceNode
* pDeviceRecord
= (CDeviceNode
*)pNode
;
248 pDeviceRecord
->ClearData();
252 void CBonjourTop::Reset()
257 m_MinAnswerCountForTruncatedFrames
= 0;
258 m_AvgAnswerCountForTruncatedFrames
= 0;
259 m_MaxAnswerCountForTruncatedFrames
= 0;
261 m_StartTime
= m_EndTime
= time(NULL
);
263 m_ServicePtrCache
.ClearAll();
264 m_ApplPtrCache
.ClearAll();
266 m_ServicePtrCacheIPv6
.ClearAll();
267 m_ApplPtrCacheIPv6
.ClearAll();
269 // Clear all data in the map
270 m_AppBreakdownIPv4OSX
.clear();
271 m_AppBreakdownIPv4iOS
.clear();
272 m_AppBreakdownIPv6OSX
.clear();
273 m_AppBreakdownIPv6iOS
.clear();
275 m_ServiceBreakdownIPv4OSX
.clear();
276 m_ServiceBreakdownIPv4iOS
.clear();
277 m_ServiceBreakdownIPv6OSX
.clear();
278 m_ServiceBreakdownIPv6iOS
.clear();
280 // Clear Socket Status
281 for (int i
= 0; i
< NUM_SOCKET_STATUS
; i
++)
283 m_SocketStatus
[i
].Clear();
286 for (int i
= 0; i
< HOURS_IN_DAY
; i
++)
288 for (int j
= 0; j
< MINUTES_IN_HOUR
; j
++)
290 m_MinSnapshot
[i
][j
].Clear();
294 CDeviceNode
* pDeviceNode
= m_DeviceMap
.GetRoot();
297 pDeviceNode
->CallBack(&CbClearDataDevice
,NULL
);
302 void CBonjourTop::SetIPAddr(const char* pStr
)
304 m_IPv4Addr
.Set(pStr
);
308 void CBonjourTop::UpdateRecord(CStringTree
& Cache
,CDNSRecord
* pDNSRecord
,BJString
& RecordName
,BJString
& ServiceName
,BJ_UINT32 nBytes
,bool bGoodbye
)
310 BJ_UINT64 nHashValue
= 0;
313 nHashValue
= Hash(RecordName
.GetBuffer());
314 CStringNode
* pRecord
= Cache
.Find(&nHashValue
);
317 pRecord
= (CStringNode
*) Cache
.FindwithAddRecord(&nHashValue
);
318 strcpy(pRecord
->m_Value
, RecordName
.GetBuffer());
323 CDeviceNode dummyDevice
;
324 CDeviceNode
*device
= &dummyDevice
;
325 CIPDeviceNode
*pipNode
= m_IPtoNameMap
.Find(&m_Frame
.m_SourceIPAddress
);
327 device
= (pipNode
)? pipNode
->pDeviceNode
: &dummyDevice
;
328 pRecord
->m_nBytes
+= 10 + nBytes
;
329 deviceOS
= device
->GetDeviceOS();
330 device
->frameTotal
.Increment(m_nFrameCount
);
332 if (pRecord
->m_nLastFrameIndex
!= m_nFrameCount
)
334 pRecord
->m_nLastFrameIndex
= m_nFrameCount
;
336 pRecord
->m_nFrames
++;
337 if (deviceOS
== 't' || deviceOS
== 'i')
339 pRecord
->m_nFramesiOS
++;
341 else if (deviceOS
== 'X')
343 pRecord
->m_nFramesOSX
++;
347 // Update Total Device Count
348 if (pRecord
->m_DeviceTotalTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
350 pRecord
->m_nDeviceTotalCount
++;
351 pRecord
->m_DeviceTotalTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
354 if (m_Frame
.IsQueryFrame())
356 GetOSTypeFromQuery(pDNSRecord
, ServiceName
);
357 device
->questionFrame
.Increment(m_nFrameCount
);
358 if (pRecord
->m_nLastQueryFrameIndex
!= m_nFrameCount
)
360 pRecord
->m_nLastQueryFrameIndex
= m_nFrameCount
;
362 pRecord
->m_nQuestionFrames
++;
364 if (deviceOS
== 't' || deviceOS
== 'i')
366 pRecord
->m_nQuestionFramesiOS
++;
368 else if (deviceOS
== 'X')
370 pRecord
->m_nQuestionFramesOSX
++;
373 if (pRecord
->m_DeviceAskingTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
375 pRecord
->m_nDeviceAskingCount
++;
376 pRecord
->m_DeviceAskingTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
382 GetOSTypeFromRegistration(pDNSRecord
,ServiceName
);
384 device
->answerFrame
.Increment(m_nFrameCount
);
385 if (pRecord
->m_nLastRespondsFrameIndex
!= m_nFrameCount
)
387 pRecord
->m_nLastRespondsFrameIndex
= m_nFrameCount
;
389 pRecord
->m_nAnswerFrames
++;
390 if (deviceOS
== 't' || deviceOS
== 'i')
392 pRecord
->m_nAnswerFramesiOS
++;
394 else if (deviceOS
== 'X')
396 pRecord
->m_nAnswerFramesOSX
++;
401 pRecord
->m_nGoodbyeFrames
++;
404 if (pRecord
->m_DeviceAnsweringTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
406 pRecord
->m_nDeviceAnsweringCount
++;
407 pRecord
->m_DeviceAnsweringTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
412 if (m_Frame
.IsWakeFrame())
414 if (pRecord
->m_nLastWakeFrameIndex
!= m_nFrameCount
)
416 pRecord
->m_nLastWakeFrameIndex
= m_nFrameCount
;
417 if (pRecord
->m_lastQUFrameTime
+1000000ll < m_Frame
.GetTime() || pRecord
->m_lastQUFrameTime
== 0) // last qu frame has been over 1 sec
419 pRecord
->m_nWakeFrames
++;
420 pRecord
->m_lastQUFrameTime
= m_Frame
.GetTime();
421 device
->QUFrame
.Increment(m_nFrameCount
);
423 pRecord
->m_lastQUFrameTime
= m_Frame
.GetTime();
430 void CBonjourTop::UpdateShortRecordHelper(BJ_UINT32 cacheType
, BJ_UINT32 tracePlatform
, BJ_UINT32 traceVersion
, char deviceOS
, CDNSRecord
* pDNSRecord
,BJString
& RecordName
,BJString
& ServiceName
,BJ_UINT32 nBytes
,bool bGoodbye
)
433 BJString versionNumber
= "mDNSResponder-";
434 const int version_max_length
= 11; // largest number is 0xffffffff = 4294967295
435 char versionChar
[version_max_length
];
437 CStringShortTree
*cache
;
438 map
<BJString
, CStringShortTree
*>* myMap
;
440 if ((tracePlatform
| 0x80) == tracePlatform
)
442 versionNumber
= "Discoveryd-";
445 snprintf(versionChar
, sizeof(versionChar
), "%u", 0); // Set versionChar to "0" by default
446 if (tracePlatform
== TRACE_PLATFORM_UNKNOWN
) // Pre iOS 7 or Pre OSX 10.9
448 if (deviceOS
== 'i' || deviceOS
== 't') // Pre iOS 7
452 else if (deviceOS
== 'X') // Pre OSX 10.9
457 else if ((tracePlatform
== TRACE_PLATFORM_OSX
) || (tracePlatform
== DISCOVERYD_TRACE_PLATFORM_OSX
)) // >= OSX 10.9
460 snprintf(versionChar
, sizeof(versionChar
), "%u", traceVersion
);
462 else if ((tracePlatform
== TRACE_PLATFORM_iOS
) || (tracePlatform
== DISCOVERYD_TRACE_PLATFORM_iOS
)) // >= iOS 7.x
465 snprintf(versionChar
, sizeof(versionChar
), "%u", traceVersion
);
467 else if ((tracePlatform
== TRACE_PLATFORM_APPLE_TV
) || (tracePlatform
== DISCOVERYD_TRACE_PLATFORM_APPLE_TV
))
469 snprintf(versionChar
, sizeof(versionChar
), "%u", traceVersion
);
472 versionNumber
+= (const char*)versionChar
;
478 myMap
= &m_ServiceBreakdownIPv4OSX
;
482 myMap
= &m_ServiceBreakdownIPv4iOS
;
488 myMap
= &m_ServiceBreakdownIPv6OSX
;
492 myMap
= &m_ServiceBreakdownIPv6iOS
;
498 myMap
= &m_AppBreakdownIPv4OSX
;
502 myMap
= &m_AppBreakdownIPv4iOS
;
508 myMap
= &m_AppBreakdownIPv6OSX
;
512 myMap
= &m_AppBreakdownIPv6iOS
;
521 if (myMap
->find(versionNumber
) == myMap
->end()) // Version number not found. Create new record
523 myMap
->insert(std::pair
<BJString
, CStringShortTree
*>(versionNumber
, new CStringShortTree()));
525 cache
= (*myMap
)[versionNumber
];
526 UpdateShortRecord(cache
, pDNSRecord
, RecordName
, ServiceName
, nBytes
, bGoodbye
);
529 void CBonjourTop::UpdateShortRecord(CStringShortTree
* Cache
,CDNSRecord
* pDNSRecord
,BJString
& RecordName
,BJString
& ServiceName
,BJ_UINT32 nBytes
,bool bGoodbye
)
536 BJ_UINT64 nHashValue
= 0;
539 nHashValue
= Hash(RecordName
.GetBuffer());
540 CStringShortNode
* pRecord
= Cache
->Find(&nHashValue
);
543 pRecord
= (CStringShortNode
*) Cache
->FindwithAddRecord(&nHashValue
);
544 strcpy(pRecord
->m_Value
, RecordName
.GetBuffer());
552 CDeviceNode dummyDevice
;
553 CDeviceNode
*device
= &dummyDevice
;
554 CIPDeviceNode
*pipNode
= m_IPtoNameMap
.Find(&m_Frame
.m_SourceIPAddress
);
556 device
= (pipNode
)? pipNode
->pDeviceNode
: &dummyDevice
;
557 pRecord
->m_nBytes
+= 10 + nBytes
;
558 deviceOS
= device
->GetDeviceOS();
559 device
->frameTotal
.Increment(m_nFrameCount
);
561 if (pRecord
->m_nLastFrameIndex
!= m_nFrameCount
)
563 pRecord
->m_nLastFrameIndex
= m_nFrameCount
;
564 pRecord
->m_nFrames
++;
567 // Update Total Device Count
568 if (pRecord
->m_DeviceTotalTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
570 pRecord
->m_nDeviceTotalCount
++;
571 pRecord
->m_DeviceTotalTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
574 if (m_Frame
.IsQueryFrame())
576 GetOSTypeFromQuery(pDNSRecord
, ServiceName
);
577 device
->questionFrame
.Increment(m_nFrameCount
);
578 if (pRecord
->m_nLastQueryFrameIndex
!= m_nFrameCount
)
580 pRecord
->m_nLastQueryFrameIndex
= m_nFrameCount
;
582 pRecord
->m_nQuestionFrames
++;
584 if (pRecord
->m_DeviceAskingTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
586 pRecord
->m_nDeviceAskingCount
++;
587 pRecord
->m_DeviceAskingTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
594 GetOSTypeFromRegistration(pDNSRecord
,ServiceName
);
596 device
->answerFrame
.Increment(m_nFrameCount
);
597 if (pRecord
->m_nLastRespondsFrameIndex
!= m_nFrameCount
)
599 pRecord
->m_nLastRespondsFrameIndex
= m_nFrameCount
;
601 pRecord
->m_nAnswerFrames
++;
605 pRecord
->m_nGoodbyeFrames
++;
608 if (pRecord
->m_DeviceAnsweringTree
.Find(&m_Frame
.m_SourceIPAddress
) == NULL
)
610 pRecord
->m_nDeviceAnsweringCount
++;
611 pRecord
->m_DeviceAnsweringTree
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
616 if (m_Frame
.IsWakeFrame())
618 if (pRecord
->m_nLastWakeFrameIndex
!= m_nFrameCount
)
620 pRecord
->m_nLastWakeFrameIndex
= m_nFrameCount
;
621 if (pRecord
->m_lastQUFrameTime
+1000000ll < m_Frame
.GetTime() || pRecord
->m_lastQUFrameTime
== 0) // last qu frame has been over 1 sec
623 pRecord
->m_nWakeFrames
++;
624 pRecord
->m_lastQUFrameTime
= m_Frame
.GetTime();
625 device
->QUFrame
.Increment(m_nFrameCount
);
627 pRecord
->m_lastQUFrameTime
= m_Frame
.GetTime();
634 void CBonjourTop::GetOSTypeFromQuery(CDNSRecord
*pDNSRecord
,BJString
& ServiceName
)
636 if (pDNSRecord
->m_RecType
== DNS_TYPE_PTR
)
638 StringMapNode
* pStringNode
= m_Service2osBrowseMap
.Find(&ServiceName
);
639 if (pStringNode
&& *pStringNode
->value
.GetBuffer() != '?')
641 CIPDeviceNode
*ipNode
= m_IPtoNameMap
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
642 if (ipNode
->pDeviceNode
)
644 StringMapNode
* pStringNode_temp
= m_Service2osBrowseMap
.Find(&ServiceName
);
645 ipNode
->pDeviceNode
->SetDeviceOS(*pStringNode_temp
->value
.GetBuffer(),ServiceName
.GetBuffer());
651 void CBonjourTop::GetOSTypeFromRegistration(CDNSRecord
*pDNSRecord
,BJString
& ServiceName
)
653 CDeviceNode
* deviceNode
= NULL
;
654 BJString sDeviceName
;
656 if (pDNSRecord
->m_RecType
== DNS_TYPE_PTR
)
658 BJString sInstanceName
;
659 pDNSRecord
->GetRdata(sInstanceName
,0,99);
660 CDNSRecord
* pSRVRecord
= m_Frame
.FindAdditionRecord(sInstanceName
, DNS_TYPE_SRV
);
663 pSRVRecord
->GetRdata(sDeviceName
,0,1);
667 sDeviceName
= sInstanceName
;
669 deviceNode
= m_DeviceMap
.Find(&sDeviceName
);
673 if (Name2OSType(sDeviceName
,deviceNode
))
676 StringMapNode
* pStringNode
= m_Service2osRegisterMap
.Find(&ServiceName
);
678 if (pStringNode
== NULL
|| *pStringNode
->value
.GetBuffer() == '?')
683 if (sDeviceName
.GetLength() > 0)
685 // update global device table with os type
688 deviceNode
->SetDeviceOS(*pStringNode
->value
.GetBuffer(),ServiceName
.GetBuffer());
692 bool CBonjourTop::Name2OSType(BJString name
,CDeviceNode
* device
)
696 // try to set device type from common names
697 for (int i
=0; Name2DeviceOS
[i
][0] != 0; i
+=2)
699 if (name
.Contains(Name2DeviceOS
[i
]))
701 device
->SetDeviceOS(Name2DeviceOS
[i
+1][0], "Name Mapping");
707 void CBonjourTop::ProcessFrame(BJ_UINT8
* pBuffer
,BJ_INT32 nLength
,BJ_UINT64 nFrameTime
)
710 m_Frame
.ParseDNSFrame(pBuffer
, nLength
, nFrameTime
);
712 if (m_Collection
.IsValid())
714 // setup static collectby
715 CollectByPacketCount::nFrameIndex
= m_nFrameCount
;
716 CollectBySameSubnetDiffSubnet::bSameSubnet
= m_Frame
.m_SourceIPAddress
.IsIPv6()? true: m_IPv4Addr
.IsSameSubNet(&m_Frame
.m_SourceIPAddress
);
717 m_Collection
.ProcessFrame(&m_Frame
);
721 if (m_Frame
.IsTruncatedFrame())
723 if (m_Frame
.GetAnswerCount() > 0)
725 if (m_AvgAnswerCountForTruncatedFrames
)
727 m_AvgAnswerCountForTruncatedFrames
+= m_Frame
.GetAnswerCount();
728 m_AvgAnswerCountForTruncatedFrames
/=2;
731 m_AvgAnswerCountForTruncatedFrames
+= m_Frame
.GetAnswerCount();
733 if (m_MinAnswerCountForTruncatedFrames
> m_Frame
.GetAnswerCount() || m_MinAnswerCountForTruncatedFrames
== 0)
734 m_MinAnswerCountForTruncatedFrames
= m_Frame
.GetAnswerCount();
735 if (m_MaxAnswerCountForTruncatedFrames
< m_Frame
.GetAnswerCount())
736 m_MaxAnswerCountForTruncatedFrames
= m_Frame
.GetAnswerCount();
741 // find min snapshot bucket
742 time_t now
= time(NULL
);
743 struct tm
* timeStruct
= localtime(&now
);
744 if (m_MinSnapshot
[timeStruct
->tm_hour
][timeStruct
->tm_min
].m_SampleDay
!= timeStruct
->tm_mday
)
746 //Reset Snapshot 24 hour wrap around
747 m_MinSnapshot
[timeStruct
->tm_hour
][timeStruct
->tm_min
].Init();
748 m_MinSnapshot
[timeStruct
->tm_hour
][timeStruct
->tm_min
].m_SampleDay
= timeStruct
->tm_mday
;
751 m_MinSnapshot
[timeStruct
->tm_hour
][timeStruct
->tm_min
].m_nFrameCount
++;
753 if (m_Frame
.GetQuestionCount() == 0 && m_Frame
.GetAnswerCount() > 0)
754 m_SocketStatus
[0].m_nAnswerOnlyFrames
++;
755 else if (m_Frame
.GetQuestionCount() > 0 && m_Frame
.GetAnswerCount() == 0)
756 m_SocketStatus
[0].m_nQuestionOnlyFrames
++;
758 m_SocketStatus
[0].m_nQandAFrames
++;
760 BJString InstanceName
;
762 BJString ApplRecordName
;
764 /// first get the name to address
765 for (int dnsItemsIndex
=m_Frame
.GetQuestionCount(); dnsItemsIndex
< m_Frame
.GetMaxRecords();dnsItemsIndex
++)
767 CDNSRecord
* pDNSRecord
= m_Frame
.GetDnsRecord(dnsItemsIndex
);
768 if (pDNSRecord
== NULL
)
771 if (pDNSRecord
->m_RecType
== DNS_TYPE_A
)
774 pDNSRecord
->GetDnsRecordName(sName
, 0, 1);
776 ip
.Setv4Raw(pDNSRecord
->GetStartofRdata());
778 CDeviceNode
* device
= m_DeviceMap
.FindwithAddRecord(&sName
);
779 device
->ipAddressv4
= ip
;
781 // create ip to name mapping
782 CIPDeviceNode
* pipNode
= m_IPtoNameMap
.FindwithAddRecord(&ip
);
784 if (pipNode
->pDeviceNode
&& pipNode
->pDeviceNode
->bIPName
&& pipNode
->pDeviceNode
->m_Key
!= device
->m_Key
)
786 pipNode
->pDeviceNode
->bDuplicate
= true;
787 device
->MergeData(pipNode
->pDeviceNode
);
788 pipNode
->pDeviceNode
->ClearData();
790 if (!pipNode
->pDeviceNode
->ipAddressv6
.IsEmpty())
792 CIPDeviceNode
* ipv6Node
= m_IPtoNameMap
.Find(&pipNode
->pDeviceNode
->ipAddressv6
);
794 ipv6Node
->pDeviceNode
= device
;
798 pipNode
->pDeviceNode
= device
;
799 Name2OSType(sName
,device
);
802 if (pDNSRecord
->m_RecType
== DNS_TYPE_AAAA
)
805 pDNSRecord
->GetDnsRecordName(sName
, 0, 1);
807 ip
.Setv6Raw(pDNSRecord
->GetStartofRdata());
809 if (ip
.IsIPv6LinkLocal())
811 CDeviceNode
* device
= m_DeviceMap
.FindwithAddRecord(&sName
);
812 device
->ipAddressv6
= ip
;
814 // create ip to name mapping
815 CIPDeviceNode
* pipNode
= m_IPtoNameMap
.FindwithAddRecord(&ip
);
817 if (pipNode
->pDeviceNode
&& pipNode
->pDeviceNode
->bIPName
&& pipNode
->pDeviceNode
->m_Key
!= device
->m_Key
)
819 pipNode
->pDeviceNode
->bDuplicate
= true;
820 device
->MergeData(pipNode
->pDeviceNode
);
821 pipNode
->pDeviceNode
->ClearData();
823 if (!pipNode
->pDeviceNode
->ipAddressv4
.IsEmpty())
825 CIPDeviceNode
* ipv4Node
= m_IPtoNameMap
.Find(&pipNode
->pDeviceNode
->ipAddressv4
);
827 ipv4Node
->pDeviceNode
= device
;
831 pipNode
->pDeviceNode
= device
;
832 Name2OSType(sName
,device
);
835 if (pDNSRecord
->m_RecType
== DNS_TYPE_SRV
)
836 { // Save SVR to Target
838 pDNSRecord
->GetDnsRecordName(sName
, 0, 1);
839 StringMapNode
*node
= SVRtoDeviceName
.FindwithAddRecord(&sName
);
840 pDNSRecord
->GetRdata(node
->value
, 0, 1);
844 CIPDeviceNode
* pipNode
= m_IPtoNameMap
.FindwithAddRecord(&m_Frame
.m_SourceIPAddress
);
845 CDeviceNode
* device
= pipNode
->pDeviceNode
;
848 // find the device by mac address
849 CMACAddrDeviceNode
*macDevice
= m_MACtoDevice
.FindwithAddRecord(&m_Frame
.m_SourceMACAddress
);
850 device
= macDevice
->device
;
853 // auto create a device record
854 BJString name
= m_Frame
.m_SourceIPAddress
.GetString();
855 device
= m_DeviceMap
.FindwithAddRecord(&name
);
856 device
->bIPName
= true;
857 macDevice
->device
= device
;
860 if (m_Frame
.m_SourceIPAddress
.IsIPv4())
861 device
->ipAddressv4
= m_Frame
.m_SourceIPAddress
;
863 device
->ipAddressv6
= m_Frame
.m_SourceIPAddress
;
864 if (device
->macAddress
.IsEmpty())
865 device
->macAddress
= m_Frame
.m_SourceMACAddress
;
867 pipNode
->pDeviceNode
= device
;
869 device
->bHasFrames
= true;
870 // update mac address
871 if (m_Frame
.IsQueryFrame() || device
->GetDeviceOS() == 'i' ) // iOS don't use BSP so we can use SourceIP
873 if (m_Frame
.m_SourceIPAddress
.IsIPv4())
874 device
->ipAddressv4
= m_Frame
.m_SourceIPAddress
;
875 if (m_Frame
.m_SourceIPAddress
.IsIPv6())
876 device
->ipAddressv6
=m_Frame
.m_SourceIPAddress
;
877 device
->macAddress
= m_Frame
.m_SourceMACAddress
;
880 BJ_UINT8 traceplatform
= TRACE_PLATFORM_UNKNOWN
;
881 BJ_UINT32 traceversion
= 0;
883 if (device
/*&& device->GetDeviceOS() == '?' */&& m_Frame
.GetTracingInfo(traceplatform
, traceversion
, traceMac
))
885 // printf("Tracing Data found platform=%d traceversion=%d\n",traceplatform,traceversion);
886 char platformMap
[]= "?Xitw";
887 device
->SetDeviceOS((traceplatform
< 5) ? platformMap
[traceplatform
] : '?', "EDNS0 Trace");
888 if ((traceplatform
== TRACE_PLATFORM_OSX
) || (traceplatform
== DISCOVERYD_TRACE_PLATFORM_OSX
))
890 device
->bOSXWithEDNSField
= true;
892 else if ((traceplatform
== TRACE_PLATFORM_iOS
) || (traceplatform
== DISCOVERYD_TRACE_PLATFORM_iOS
))
894 device
->biOSWithEDNSField
= true;
898 for (int dnsItemsIndex
=0; dnsItemsIndex
< m_Frame
.GetQuestionCount()+m_Frame
.GetAnswerCount();dnsItemsIndex
++)
903 // printf("Name = %s\n", GetDnsRecordName(&Frame,dnsItemsIndex,tempBuffer,sizeof(tempBuffer),0));
905 CDNSRecord
* pDNSRecord
= m_Frame
.GetDnsRecord(dnsItemsIndex
);
906 if (pDNSRecord
== NULL
)
909 pDNSRecord
->GetDnsRecordName(RecordName
,0,99);
910 InstanceName
= RecordName
;
912 if (RecordName
.Contains("_kerberos."))
914 RecordName
= "_kerberos.";
917 pDNSRecord
->GetDnsRecordName(RecordName
, (pDNSRecord
->m_RecType
== DNS_TYPE_PTR
)?0:1,99);
919 if (pDNSRecord
->m_RecType
== DNS_TYPE_PTR
)
921 if (RecordName
.Contains(".ip6.arpa."))
922 RecordName
= "*.ip6.arpa.";
923 else if (RecordName
.Contains(".arpa."))
924 RecordName
= "*.arpa.";
926 if (pDNSRecord
->m_RecType
== DNS_TYPE_A
)
928 if (pDNSRecord
->m_RecType
== DNS_TYPE_AAAA
)
930 if (pDNSRecord
->m_RecType
== 255)
932 if (RecordName
.Contains(".ip6.arpa."))
933 RecordName
= "ANY *.ip6.arpa.";
934 else if (RecordName
.Contains(".arpa."))
935 RecordName
= "ANY *.arpa.";
939 if (RecordName
.Contains("_sub."))
941 pDNSRecord
->GetDnsRecordName(RecordName
,2,99); /// skip first label and _sub. label
944 BJ_UINT32 nBytes
= pDNSRecord
->m_nNameLength
+ pDNSRecord
->m_nRdataLen
;
946 m_nTotalBytes
+= 10 + nBytes
;
948 if (m_Frame
.m_SourceIPAddress
.IsIPv4())
950 UpdateRecord(m_ServicePtrCache
,pDNSRecord
,RecordName
,RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
951 UpdateShortRecordHelper(SERVICE_IPV4
, traceplatform
, traceversion
, device
->GetDeviceOS(), pDNSRecord
, RecordName
, RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
955 UpdateRecord(m_ServicePtrCacheIPv6
,pDNSRecord
,RecordName
,RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
956 UpdateShortRecordHelper(SERVICE_IPV6
, traceplatform
, traceversion
, device
->GetDeviceOS(), pDNSRecord
, RecordName
, RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
959 // Add application to cache
960 if (RecordName
.GetLength() != 0)
963 ApplRecordName
= RecordName
;
964 StringMapNode
* pNode
;
965 pNode
= m_Service2AppMap
.Find(&ApplRecordName
);
966 if (pNode
&& ApplRecordName
.GetBuffer() != NULL
)
968 ApplRecordName
= pNode
->value
.GetBuffer();
969 if ( ApplRecordName
== "Device-Info")
971 // find device record
973 pDNSRecord
->GetDnsRecordName(svrName
, 0, 1);
974 StringMapNode
*nodeName
= SVRtoDeviceName
.Find(&svrName
);
976 CDeviceNode
* pDeviceNode
= nodeName
? m_DeviceMap
.Find(&nodeName
->value
) : NULL
;
981 DeviceInfo
.Set((char*)pDNSRecord
->GetStartofRdata(),MIN(pDNSRecord
->m_nRdataLen
,50));
984 for (int i
=0; DeviceInfo2DeviceOS
[i
][0] != 0; i
+=2)
986 if (DeviceInfo
.Contains(DeviceInfo2DeviceOS
[i
]))
988 osType
= *DeviceInfo2DeviceOS
[i
+1];
989 if (pDeviceNode
->GetDeviceOS() != *DeviceInfo2DeviceOS
[i
])
991 pDeviceNode
->SetDeviceOS(osType
,"_device-info._tcp.local.");
992 pDeviceNode
->SetModel(DeviceInfo2DeviceOS
[i
]);
999 if (osType
== 'X' || (pDeviceNode
&& pDeviceNode
->GetDeviceOS() == 'X'))
1000 ApplRecordName
= "Finder";
1001 if (osType
== 't' || (pDeviceNode
&& pDeviceNode
->GetDeviceOS() == 't'))
1002 ApplRecordName
= "AirPlay";
1004 if (pDeviceNode
&& pDeviceNode
->GetDeviceOS() == '?' && pDNSRecord
->m_nRdataLen
> 0)
1006 BJString DeviceInfo_temp
;
1007 DeviceInfo_temp
.Set((char*)pDNSRecord
->GetStartofRdata(),MIN(pDNSRecord
->m_nRdataLen
,25));
1014 ApplRecordName
= "Other";
1017 if (m_Frame
.m_SourceIPAddress
.IsIPv4())
1019 UpdateRecord(m_ApplPtrCache
,pDNSRecord
,ApplRecordName
,RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
1020 UpdateShortRecordHelper(APP_IPV4
, traceplatform
, traceversion
, device
->GetDeviceOS(), pDNSRecord
, ApplRecordName
, RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
1025 UpdateRecord(m_ApplPtrCacheIPv6
,pDNSRecord
,ApplRecordName
,RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
1026 UpdateShortRecordHelper(APP_IPV6
, traceplatform
, traceversion
, device
->GetDeviceOS(), pDNSRecord
, ApplRecordName
, RecordName
, nBytes
, (pDNSRecord
->m_nTTL
== 0));
1039 CStringTree m_SortedCache
;
1043 static int CbPrintResults(const void* pNode
, const void* pParam
)
1045 CStringNode
* pRecord
= (CStringNode
*)pNode
;
1046 CSortOptions
* pSortedOption
= (CSortOptions
*)pParam
;
1048 CStringNode
* pNewRecord
;
1050 BJ_UINT64 SortKey
=0;
1051 switch (pSortedOption
->m_nSortCol
) {
1053 SortKey
= Hash2(pRecord
->m_Value
); // cheat the sort to the first 8 char
1056 SortKey
= pRecord
->m_nBytes
;
1059 SortKey
= pRecord
->m_nFrames
;
1062 SortKey
= pRecord
->m_nQuestionFrames
;
1065 SortKey
= pRecord
->m_nAnswerFrames
;
1072 pNewRecord
= pSortedOption
->m_SortedCache
.AddRecord(&SortKey
);
1076 pNewRecord
->CopyNode(pRecord
);
1084 static int CbPrintUnknownDevice(const void* pNode
, const void*)
1086 CDeviceNode
* pDeviceRecord
= (CDeviceNode
*)pNode
;
1088 if (pDeviceRecord
->GetDeviceOS() != '?')
1091 // printf("%s %s\n",pDeviceRecord->m_Key.GetBuffer(), pDeviceRecord->macAddress.GetString());
1097 static int CbBuildMacMap(const void* pNode
, const void* pParam
)
1099 CDeviceNode
* pDeviceNode
= (CDeviceNode
*)pNode
;
1100 CMACAddrTree
* pMacMap
= (CMACAddrTree
*)pParam
;
1103 BJMACAddr vendorMac
;
1104 vendorMac
.CopyVendor(pDeviceNode
->macAddress
);
1105 if (vendorMac
.IsEmpty())
1110 if (pDeviceNode
->GetDeviceOS() == '?')
1112 // try to set device type from MAC address
1113 CMACAddrNode
* pMacRecord
= pMacMap
->Find(&vendorMac
);
1114 if (pMacRecord
!= NULL
&& pDeviceNode
->GetDeviceOS() == '?')
1116 pDeviceNode
->SetDeviceOS(pMacRecord
->deviceOS
, "MAC Mapping");
1117 // printf("update device %s %c\n",vendorMac.GetStringVendor(),pMacRecord->deviceOS);
1120 if (pDeviceNode
->GetDeviceOS() == '?')
1125 CMACAddrNode
* pMacRecord
= pMacMap
->Find(&vendorMac
);
1126 if (pMacRecord
== NULL
)
1128 pMacRecord
= pMacMap
->FindwithAddRecord(&vendorMac
);
1129 pMacRecord
->deviceOS
= pDeviceNode
->GetDeviceOS();
1130 pMacRecord
->model
= pDeviceNode
->model
;
1131 pMacRecord
->method
= pDeviceNode
->settingService
;
1136 /// if (pMacRecord && pMacRecord->deviceOS != pDeviceNode->GetDeviceOS())
1137 // printf("Mac Mapping Bad deviceOS %c != %c %s %s %s\n", pMacRecord->deviceOS, pDeviceNode->GetDeviceOS(),pMacRecord->method.GetBuffer(), pDeviceNode->settingService.GetBuffer(),vendorMac.GetStringVendor());
1138 // if (pMacRecord && !(pMacRecord->model == pDeviceNode->model) && pMacRecord->model.GetLength() > 0 && pDeviceNode->model.GetLength() > 0)
1139 // printf("Mac Mapping Bad model %s != %s\n", pMacRecord->model.GetBuffer(), pDeviceNode->model.GetBuffer());
1146 CStringNode
* CBonjourTop::GetCurrentDisplayRoot(BJString
&sTitle
)
1148 CStringNode
* pRecord
= NULL
;
1150 switch(m_CurrentDisplay
)
1152 case BJ_DISPLAY_APP
:
1153 pRecord
= m_ApplPtrCache
.GetRoot();
1154 sTitle
= "Application (IPv4)";
1156 case BJ_DISPLAY_APPv6
:
1157 pRecord
= m_ApplPtrCacheIPv6
.GetRoot();
1158 sTitle
= "Application (IPv6)";
1160 case BJ_DISPLAY_SERVICE
:
1161 pRecord
= m_ServicePtrCache
.GetRoot();
1162 sTitle
= "Services (IPv4)";
1164 case BJ_DISPLAY_SERVICEv6
:
1165 pRecord
= m_ServicePtrCacheIPv6
.GetRoot();
1166 sTitle
= "Services (IPv6)";
1168 case BJ_DISPLAY_24_MIN
:
1174 void CBonjourTop::UpdateOSCounts()
1178 CDeviceNode
* pDeviceNode
= m_DeviceMap
.GetRoot();
1181 pDeviceNode
->CallBack(&CbBuildMacMap
,&m_MacMap
);
1182 // pDeviceNode->CallBack(&CbPrintUnknownDevice,NULL);
1186 // Update Application Caches
1187 CStringNode
* pCacheRoot
= m_ApplPtrCache
.GetRoot();
1191 pCacheRoot
->UpdateOSTypeCounts(&m_DeviceMap
,&m_IPtoNameMap
);
1193 pCacheRoot
= m_ApplPtrCacheIPv6
.GetRoot();
1197 pCacheRoot
->UpdateOSTypeCounts(&m_DeviceMap
,&m_IPtoNameMap
);
1200 // Update Service caches
1201 pCacheRoot
= m_ServicePtrCache
.GetRoot();
1205 pCacheRoot
->UpdateOSTypeCounts(&m_DeviceMap
,&m_IPtoNameMap
);
1207 pCacheRoot
= m_ServicePtrCacheIPv6
.GetRoot();
1211 pCacheRoot
->UpdateOSTypeCounts(&m_DeviceMap
,&m_IPtoNameMap
);
1216 void CBonjourTop::PrintResults(int nSortCol
, bool bSortAsc
)
1220 GetCurrentDisplayRoot(sTitle
);
1221 device_count devCount
;
1222 BJString sTableTitle
;
1227 BJ_UINT64 nRate
= 0;
1228 BJ_UINT64 nElapsedTime
= m_EndTime
-m_StartTime
;
1229 if (nElapsedTime
> 0)
1231 nRate
= (m_nFrameCount
*3600) /nElapsedTime
;
1238 printw("While running the follow keys may be used:\n");
1239 printw("[p = sort by Packets (default)], [b = sort by Bytes], [n = sort by Name]\n");
1240 printw("[a = Display Application Names (default)], [s = Display Services Names], [t = Display 24 hour packet per min]\n");
1241 printw("[o = flip sort order], [e = export to BonjourTop.csv], [q = quit]\n\n");
1243 printw("Total Packets: %llu, Total Bytes: %llu, Elapse Time: %lld sec, Rate: %llu packet/hr\n",m_nFrameCount
,m_nTotalBytes
,nElapsedTime
,nRate
);
1244 printw("IPv4 multicast: %llu, IPv6 multicast: %llu, IPv4 Unicast: %lld, IPv6 Unicast: %llu\n",m_SocketStatus
[0].m_nFrameCount
,m_SocketStatus
[1].m_nFrameCount
,m_SocketStatus
[2].m_nFrameCount
,m_SocketStatus
[3].m_nFrameCount
);
1245 printw("IPv4 Wrong subnet: %llu, IPv6 Wrong subnet: %llu\n",m_SocketStatus
[4].m_nFrameCount
,m_SocketStatus
[5].m_nFrameCount
);
1246 printw("QuestionOnly Packets: %llu, AnswerOnly Packets: %llu, Q&A Packets %llu\n",m_SocketStatus
[0].m_nQuestionOnlyFrames
,m_SocketStatus
[0].m_nAnswerOnlyFrames
,m_SocketStatus
[0].m_nQandAFrames
);
1247 printw("AnswerCount for truncated frames(min,avg,max): %llu,%llu,%llu\n\n",m_MinAnswerCountForTruncatedFrames
,m_AvgAnswerCountForTruncatedFrames
,m_MaxAnswerCountForTruncatedFrames
);
1249 bzero(&devCount
, sizeof(devCount
));
1250 m_DeviceMap
.GetDeviceOSTypes(m_DeviceMap
.GetRoot(),NULL
, devCount
);
1251 printw("Total Devices: %llu, iOS Devices: %llu(>= iOS7: %llu), OSX Devices %llu(>= OSX 10.9: %llu)\n",devCount
.iOS
+devCount
.OSX
+devCount
.unknownOS
,devCount
.iOS
, devCount
.iOSWithEDNSField
, devCount
.OSX
,devCount
.OSXWithEDNSField
);
1255 printf("\nTotal Packets: %llu, Total Bytes: %llu, Elapse Time: %lld sec, Rate: %llu packet/hr\n",m_nFrameCount
,m_nTotalBytes
,nElapsedTime
,nRate
);
1256 printf("IPv4 multicast: %llu, IPv6 multicast: %llu, IPv4 Unicast: %lld, IPv6 Unicast: %llu\n",m_SocketStatus
[0].m_nFrameCount
,m_SocketStatus
[1].m_nFrameCount
,m_SocketStatus
[2].m_nFrameCount
,m_SocketStatus
[3].m_nFrameCount
);
1257 printf("IPv4 Wrong subnet: %llu, IPv6 Wrong subnet: %llu\n",m_SocketStatus
[4].m_nFrameCount
,m_SocketStatus
[5].m_nFrameCount
);
1258 printf("QuestionOnly Packets: %llu, AnswerOnly Packets: %llu, Q&A Packets %llu\n",m_SocketStatus
[0].m_nQuestionOnlyFrames
,m_SocketStatus
[0].m_nAnswerOnlyFrames
,m_SocketStatus
[0].m_nQandAFrames
);
1260 bzero(&devCount
, sizeof(devCount
));
1261 m_DeviceMap
.GetDeviceOSTypes(m_DeviceMap
.GetRoot(),NULL
, devCount
);
1263 printf("Total Devices: %llu, iOS Devices: %llu(>= iOS7: %llu), OSX Devices %llu(>= OSX 10.9: %llu), unknown Devices %llu\n",devCount
.iOS
+devCount
.OSX
+devCount
.unknownOS
,devCount
.iOS
, devCount
.iOSWithEDNSField
,devCount
.OSX
,devCount
.OSXWithEDNSField
,devCount
.unknownOS
);
1264 printf("AnswerCount for truncated frames(min,avg,max): %llu,%llu,%llu\n\n",m_MinAnswerCountForTruncatedFrames
,m_AvgAnswerCountForTruncatedFrames
,m_MaxAnswerCountForTruncatedFrames
);
1266 PrintDetailResults(nSortCol
, bSortAsc
);
1270 void CBonjourTop::PrintDetailResults(int nSortCol
, bool bSortAsc
)
1273 CStringNode
* pCacheRoot
= GetCurrentDisplayRoot(sTitle
);
1277 if(m_CurrentDisplay
== CBonjourTop::BJ_DISPLAY_24_MIN
)
1280 for(int i
=0;i
<24;i
++)
1286 printw("\n%s\n",sTitle
.GetBuffer());
1287 printw(" %- 30s %10s %10s%24s%24s%24s%24s%24s\n","","","Total","Question","Answer","Asking","Answering", "Total");
1288 printw(" %- 30s %10s%24s%24s%24s %23s%24s%24s %11s %10s\n","Name","Bytes","Packets( iOS/ OSX)","Packets( iOS/ OSX)","Packets( iOS/ OSX)","Devices( iOS/ OSX)","Devices( iOS/ OSX)","Devices( iOS/ OSX)", "QU Bit","Goodbye");
1293 if(m_CurrentDisplay
== CBonjourTop::BJ_DISPLAY_24_MIN
)
1299 printf("\n%s\n",sTitle
.GetBuffer());
1300 printf(" %-30s %10s %10s%24s%24s%24s%24s%24s\n","","","Total","Question","Answer","Asking","Answering", "Total");
1301 printf(" %-30s %10s%24s%24s%24s %23s%24s%24s %11s %10s\n","Name","Bytes","Packets( iOS/ OSX)","Packets( iOS/ OSX)","Packets( iOS/ OSX)","Devices( iOS/ OSX)","Devices( iOS/ OSX)","Devices( iOS/ OSX)", "QU Bit","Goodbye");
1304 if (m_CurrentDisplay
== CBonjourTop::BJ_DISPLAY_24_MIN
)
1307 for(int m
=0;m
<60;m
++)
1310 for (int h
=0;h
<24;h
++)
1311 printw("%5d ",m_MinSnapshot
[h
][m
].m_nFrameCount
);
1318 CSortOptions SortOptions
;
1319 SortOptions
.m_nSortCol
= nSortCol
;
1322 pCacheRoot
->UpdateOSTypeCounts(&m_DeviceMap
,&m_IPtoNameMap
);
1325 pCacheRoot
->CallBack(&CbPrintResults
,&SortOptions
);
1329 CStringNode
* pRecord
= SortOptions
.m_SortedCache
.GetRoot();
1330 BJ_UINT32 nIndex
= 1;
1333 pRecord
->Print(m_bCursers
,bSortAsc
, nIndex
,0,40);
1339 void CBonjourTop::LiveCapture()
1342 const BJ_UINT16 BonjourPort
= 5353;
1345 BJSelect SockSelect
;
1347 Sockv4
.CreateListenerIPv4(interfaceName
);
1348 Sockv6
.CreateListenerIPv6(interfaceName
);
1350 SockSelect
.Add(Sockv4
);
1351 SockSelect
.Add(Sockv6
);
1354 m_StartTime
= time(NULL
);
1356 bool bSortAsc
= false;
1361 SockSelect
.Add(Sockv4
);
1362 SockSelect
.Add(Sockv6
);
1364 int result
= SockSelect
.Wait(1);
1367 // if SockSelect.Wait failed due to an interrupt, then we want to continue processing the packets
1372 printf("Error in Select\n");
1376 if (SockSelect
.IsReady(Sockv4
))
1379 int recvsize
= Sockv4
.Read();
1381 if ((recvsize
!= 0) &&
1382 (Sockv4
.GetSrcAddr()->GetPortNumber() == BonjourPort
))
1385 m_SocketStatus
[Sockv4
.IsMulticastPacket()? 0:2].m_nFrameCount
++;
1387 if (!m_IPv4Addr
.IsSameSubNet(Sockv4
.GetSrcAddr()))
1389 m_SocketStatus
[4].m_nFrameCount
++;
1391 m_Frame
.m_SourceIPAddress
= *Sockv4
.GetSrcAddr();
1392 ProcessFrame(Sockv4
.GetBuffer(),recvsize
,Sockv4
.m_CurrentFrame
.GetTime());
1396 if (SockSelect
.IsReady(Sockv6
))
1398 int recvsize
= Sockv6
.Read();
1399 if ((recvsize
!= 0) &&
1400 (Sockv6
.GetSrcAddr()->GetPortNumber() == BonjourPort
))
1403 m_SocketStatus
[Sockv6
.IsMulticastPacket()? 1:3].m_nFrameCount
++;
1404 m_Frame
.m_SourceIPAddress
= *Sockv6
.GetSrcAddr();
1406 ProcessFrame(Sockv6
.GetBuffer(),recvsize
,Sockv6
.m_CurrentFrame
.GetTime());
1416 bSortAsc
= !bSortAsc
;
1417 result
= 0; // force an update
1421 result
= 0; // force an update
1425 result
= 0; // force an update
1430 else if (nSortCol
== 3)
1434 result
= 0; // force an update
1438 if (m_CurrentDisplay
== CBonjourTop::BJ_DISPLAY_APP
)
1439 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_APPv6
;
1441 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_APP
;
1447 if (m_CurrentDisplay
== CBonjourTop::BJ_DISPLAY_SERVICE
)
1448 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_SERVICEv6
;
1450 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_SERVICE
;
1455 m_CurrentDisplay
= CBonjourTop::BJ_DISPLAY_24_MIN
;
1467 result
= 0; // force an update
1470 result
= 0; // force an update
1473 if (window_size_changed
)
1477 window_size_changed
= false;
1480 if (m_EndTime
!= time(NULL
) || result
== 0)
1482 m_EndTime
= time(NULL
);
1483 PrintResults(nSortCol
,bSortAsc
);
1484 if (m_SnapshotSeconds
&& (time(NULL
) - m_StartTime
) > m_SnapshotSeconds
)
1487 if (m_bImportExportDeviceMap
)
1500 void CBonjourTop::CaptureFile()
1502 CCaptureFile CaptureFile
;
1503 BJIPAddr
* pIPSrcAddr
;
1504 BJIPAddr
* pIPDestAddr
;
1506 CIPAddrMap LocalSubnetIPv6
;
1509 CaptureFile
.Open(m_pTcpDumpFileName
);
1512 int nFrameIndex
= 0;
1514 while (CaptureFile
.NextFrame())
1518 BJ_UINT8
* pBonjourBuffer
= (BJ_UINT8
*)CaptureFile
.m_CurrentFrame
.GetBonjourStart();
1519 if (!pBonjourBuffer
)
1523 m_nTotalBytes
+= CaptureFile
.GetWiredLength();
1525 pIPSrcAddr
= CaptureFile
.m_CurrentFrame
.GetSrcIPAddr();
1526 pIPDestAddr
= CaptureFile
.m_CurrentFrame
.GetDestIPAddr();
1527 m_Frame
.m_SourceIPAddress
= *CaptureFile
.m_CurrentFrame
.GetSrcIPAddr();;
1528 m_Frame
.m_SourceMACAddress
= *CaptureFile
.m_CurrentFrame
.GetSrcMACAddr();
1530 if (pIPSrcAddr
->IsIPv4())
1532 // check fragment flag
1533 BJ_UINT8
* pIP
= CaptureFile
.m_CurrentFrame
.GetIPStart();
1534 BJ_UINT16 flags
= * ((BJ_UINT16
*)(pIP
+6));
1538 if (!m_IPv4Addr
.IsEmptySubnet())
1540 if (m_IPv4Addr
.IsSameSubNet(pIPSrcAddr
))
1542 BJ_UINT8
* pSourceMac
= CaptureFile
.m_CurrentFrame
.GetEthernetStart()+6;
1544 IPv6Addr
.CreateLinkLocalIPv6(pSourceMac
);
1545 LocalSubnetIPv6
.FindwithAddRecord(&IPv6Addr
);
1550 m_SocketStatus
[4].m_nFrameCount
++;
1552 if (!m_Collection
.IsValid())
1556 m_SocketStatus
[(pIPDestAddr
->IsBonjourMulticast())?0:2].m_nFrameCount
++;
1558 if (pIPSrcAddr
->IsIPv6())
1560 if (!LocalSubnetIPv6
.Find(pIPSrcAddr
) && !m_IPv4Addr
.IsEmptySubnet())
1562 m_SocketStatus
[5].m_nFrameCount
++;
1563 if (!m_Collection
.IsValid())
1566 m_SocketStatus
[(pIPDestAddr
->IsBonjourMulticast())?1:3].m_nFrameCount
++;
1569 ProcessFrame(pBonjourBuffer
,CaptureFile
.GetBufferLen((pBonjourBuffer
)),CaptureFile
.m_CurrentFrame
.GetTime());
1572 m_EndTime
= CaptureFile
.GetDeltaTime();
1574 PrintResults(2,false);
1575 if ( m_CurrentDisplay
== BJ_DISPLAY_APP
)
1576 m_CurrentDisplay
= BJ_DISPLAY_APPv6
;
1578 m_CurrentDisplay
= BJ_DISPLAY_SERVICEv6
;
1580 PrintDetailResults(2,false);
1584 void CBonjourTop::ExportPtrCache(FILE* hFile
, BJString sTitle
,CStringNode
* pRoot
)
1586 fprintf(hFile
,"%s\n",sTitle
.GetBuffer());
1587 fprintf(hFile
,"Name,Bytes,Total Packets,Total Packets iOS,Total Packets OSX,Question Packets,Question Packets iOS,Question Packets OSX,Answer Packets,Answer Packets iOS,Answer Packets OSX,Asking Devices, Asking Devices iOS,Asking Devices OSX,Answering Devices,Answering Devices iOS,Answering Devices OSX,Total Devices,Total Devices iOS, Total Devices OSX,QU Bit,Goodbye\n");
1590 pRoot
->Export(hFile
);
1593 void CBonjourTop::ExportShortCacheHelper(FILE* hFile
, BJString sTitle
, CStringShortNode
* pRoot
)
1595 fprintf(hFile
,"%s\n",sTitle
.GetBuffer());
1596 fprintf(hFile
,"Name,Bytes,Total Packets,Question Packets,Answer Packets,Asking Devices,Answering Devices,Total Devices,QU Bit,Goodbye\n");
1600 pRoot
->Export(hFile
);
1605 void CBonjourTop::ExportShortCache(FILE* hFile
, BJString sTitle
, map
<BJString
, CStringShortTree
*>* myMap
)
1607 CStringShortTree
* cache
;
1608 BJString versionNumber
;
1610 fprintf(hFile
,"%s\n",sTitle
.GetBuffer());
1612 for (map
<BJString
, CStringShortTree
*>::iterator it
= myMap
->begin(); it
!= myMap
->end(); ++it
)
1614 versionNumber
= (*it
).first
;
1615 cache
= (*it
).second
;
1617 ExportShortCacheHelper(hFile
, versionNumber
, cache
->GetRoot());
1621 void CBonjourTop::ExportResults()
1624 BJString sTempFileName
;
1625 device_count devCount
;
1626 sTempFileName
= m_pExportFileName
;
1628 if (m_SnapshotSeconds
)
1630 BJString sTimeStamp
;
1631 sTimeStamp
.Format(time(NULL
), BJString::BJSS_TIME
);
1632 sTempFileName
+= "_";
1633 sTempFileName
+= sTimeStamp
;
1635 sTempFileName
+= ".csv";
1637 if (m_Collection
.IsValid())
1639 m_Collection
.ExportCollection(sTempFileName
);
1643 FILE* hFile
= fopen(sTempFileName
.GetBuffer(),"w");
1647 printf("file open failed %s\n",m_pExportFileName
);
1651 fprintf(hFile
,"Total Number of Frames, %llu\n",m_nFrameCount
);
1652 fprintf(hFile
,"Total Number of Bytes, %llu\n",m_nTotalBytes
);
1653 fprintf(hFile
,"Total Number of Sec, %llu\n",m_EndTime
-m_StartTime
);
1655 bzero(&devCount
, sizeof(devCount
));
1656 m_DeviceMap
.GetDeviceOSTypes(m_DeviceMap
.GetRoot(),NULL
, devCount
);
1657 fprintf(hFile
,"Total Number of Devices, %llu\n\n",devCount
.iOS
+devCount
.OSX
+devCount
.unknownOS
);
1658 fprintf(hFile
,"Total Number of iOS Devices, %llu\n",devCount
.iOS
);
1659 fprintf(hFile
,"Total Number of iOS Devices (>= iOS7), %llu\n", devCount
.iOSWithEDNSField
);
1660 fprintf(hFile
,"Total Number of OSX Devices, %llu\n",devCount
.OSX
);
1661 fprintf(hFile
,"Total Number of OSX Devices (>= OSX 10.9), %llu\n",devCount
.OSXWithEDNSField
);
1663 fprintf(hFile
,"IPv4 multicast, %llu\n",m_SocketStatus
[0].m_nFrameCount
);
1664 fprintf(hFile
,"IPv6 multicast, %llu\n",m_SocketStatus
[1].m_nFrameCount
);
1665 fprintf(hFile
,"IPv4 Unicast, %llu\n",m_SocketStatus
[2].m_nFrameCount
);
1666 fprintf(hFile
,"IPv6 Unicast, %llu\n",m_SocketStatus
[3].m_nFrameCount
);
1667 fprintf(hFile
,"IPv4 Wrong subnet, %llu\n",m_SocketStatus
[4].m_nFrameCount
);
1668 fprintf(hFile
,"IPv6 Wrong subnet, %llu\n\n",m_SocketStatus
[5].m_nFrameCount
);
1670 fprintf(hFile
,"QuestionOnly Packets, %llu\n", m_SocketStatus
[0].m_nQuestionOnlyFrames
);
1671 fprintf(hFile
,"AnswerOnly Packets, %llu\n", m_SocketStatus
[0].m_nAnswerOnlyFrames
);
1672 fprintf(hFile
,"Q&A Packets, %llu\n\n", m_SocketStatus
[0].m_nQandAFrames
);
1674 fprintf(hFile
,"AnswerCount for truncated frames min, %llu\n", m_MinAnswerCountForTruncatedFrames
);
1675 fprintf(hFile
,"AnswerCount for truncated frames avg, %llu\n", m_AvgAnswerCountForTruncatedFrames
);
1676 fprintf(hFile
,"AnswerCount for truncated frames max, %llu\n\n", m_MaxAnswerCountForTruncatedFrames
);
1680 ExportPtrCache(hFile
,"Application IPv4 Cache",m_ApplPtrCache
.GetRoot());
1681 ExportShortCache(hFile
, "OSX", &m_AppBreakdownIPv4OSX
);
1682 ExportShortCache(hFile
, "iOS", &m_AppBreakdownIPv4iOS
);
1684 ExportPtrCache(hFile
,"Application IPv6 Cache",m_ApplPtrCacheIPv6
.GetRoot());
1685 ExportShortCache(hFile
, "OSX", &m_AppBreakdownIPv6OSX
);
1686 ExportShortCache(hFile
, "iOS", &m_AppBreakdownIPv6iOS
);
1688 ExportPtrCache(hFile
,"Service IPv4 Cache",m_ServicePtrCache
.GetRoot());
1689 ExportShortCache(hFile
, "OSX", &m_ServiceBreakdownIPv4OSX
);
1690 ExportShortCache(hFile
, "iOS", &m_ServiceBreakdownIPv4iOS
);
1692 ExportPtrCache(hFile
,"Service IPv6 Cache",m_ServicePtrCacheIPv6
.GetRoot());
1693 ExportShortCache(hFile
, "OSX", &m_ServiceBreakdownIPv6OSX
);
1694 ExportShortCache(hFile
, "iOS", &m_ServiceBreakdownIPv6iOS
);
1696 /// min snapshot table
1698 fprintf(hFile
,"Min Snapshot table\n");
1700 for (int h
=0;h
<24;h
++)
1702 for(int m
=0;m
<60;m
++)
1704 if (m_MinSnapshot
[h
][m
].m_nFrameCount
)
1706 fprintf(hFile
,"%02d:%02d,%llu\n",h
,m
,m_MinSnapshot
[h
][m
].m_nFrameCount
);
1716 void CBonjourTop::WriteDeviceFile()
1718 BJString sTempFileName
;
1719 BJString sTimeStamp
;
1721 sTempFileName
= m_DeviceFileName
;
1722 sTimeStamp
.Format(time(NULL
), BJString::BJSS_TIME
);
1723 sTempFileName
+= "_";
1724 sTempFileName
+= sTimeStamp
;
1725 sTempFileName
+= ".csv";
1727 FILE* hFile
= fopen(sTempFileName
.GetBuffer(),"w");
1731 printf("file open failed %s\n",sTempFileName
.GetBuffer());
1735 fprintf(hFile
,"\"Name\",\"IPv4Address\",\"IPv6Address\",\"MACAddress\",O,\"Model\",\"Method\",\"total frames\",\"question frames\",\"QU frames\",\"answer frames\"\n");
1737 CDeviceNode
*pDeviceNode
= m_DeviceMap
.GetRoot();
1740 pDeviceNode
->Export(hFile
);
1744 printf("devicemap count %llu %d\n",m_DeviceMap
.GetCount(),CDeviceNode::nCreateCount
);
1748 void CBonjourTop::WriteVendorFile()
1750 BJString sTempFileName
= "BonjourTopVendor";
1751 BJString sTimeStamp
;
1753 sTimeStamp
.Format(time(NULL
), BJString::BJSS_TIME
);
1754 sTempFileName
+= "_";
1755 sTempFileName
+= sTimeStamp
;
1756 sTempFileName
+= ".csv";
1758 FILE* hFile
= fopen(sTempFileName
.GetBuffer(),"w");
1762 printf("file open failed %s\n",sTempFileName
.GetBuffer());
1765 fprintf(hFile
,"\"MACAddress\",O,\"Model\",\"Method\"\n");
1767 CMACAddrNode
*node
= m_MacMap
.GetRoot();
1770 node
->Export(hFile
);
1775 void CBonjourTop::WindowSizeChanged()
1777 window_size_changed
= true;
1780 BJ_UINT64
Hash(const char* pStr
)
1786 while ((c
= *pStr
++))
1794 BJ_UINT64
Hash2(char* pStr
)
1801 while ((c
= *pStr
++) && i
++ < 8)
1812 static integer_t
Usage(void)
1814 task_t targetTask
= mach_task_self();
1815 struct task_basic_info ti
;
1816 mach_msg_type_number_t count
= TASK_BASIC_INFO_64_COUNT
;
1818 kern_return_t kr
= task_info(targetTask
, TASK_BASIC_INFO_64
,
1819 (task_info_t
) &ti
, &count
);
1820 if (kr
!= KERN_SUCCESS
)
1822 printf("Kernel returned error during memory usage query");
1826 // On Mac OS X, the resident_size is in bytes, not pages!
1827 // (This differs from the GNU Mach kernel)
1828 // return ti.resident_size;
1829 return ti
.user_time
.seconds
;
1837 void CStringNode::UpdateOSTypeCounts(CDeviceMap
* pGlobalDeviceMap
,CIPAddrMap
*pIp2NameMap
)
1840 ((CStringNode
*)m_rbLeft
)->UpdateOSTypeCounts(pGlobalDeviceMap
,pIp2NameMap
);
1842 ((CStringNode
*)m_rbRight
)->UpdateOSTypeCounts(pGlobalDeviceMap
,pIp2NameMap
);
1844 BJ_UINT64 nDeviceUnknown
= 0;
1845 m_nDeviceAskingiOSCount
= 0;
1846 m_nDeviceAskingOSXCount
= 0;
1847 m_nDeviceAnsweringiOSCount
= 0;
1848 m_nDeviceAnsweringOSXCount
= 0;
1849 m_nDeviceTotaliOSCount
= 0;
1850 m_nDeviceTotalOSXCount
= 0;
1851 m_DeviceAskingTree
.GetDeviceOSTypes(m_DeviceAskingTree
.GetRoot(),pIp2NameMap
,m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
,nDeviceUnknown
);
1852 if (m_DeviceAskingTree
.GetCount() != m_nDeviceAskingiOSCount
+ m_nDeviceAskingOSXCount
+nDeviceUnknown
)
1857 m_DeviceAnsweringTree
.GetDeviceOSTypes(m_DeviceAnsweringTree
.GetRoot(),pIp2NameMap
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
,nDeviceUnknown
);
1858 if (m_DeviceAnsweringTree
.GetCount() != m_nDeviceAnsweringiOSCount
+ m_nDeviceAnsweringOSXCount
+nDeviceUnknown
)
1863 m_DeviceTotalTree
.GetDeviceOSTypes(m_DeviceTotalTree
.GetRoot(), pIp2NameMap
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
, nDeviceUnknown
);
1864 if (m_DeviceTotalTree
.GetCount() != m_nDeviceTotaliOSCount
+ m_nDeviceTotalOSXCount
+ nDeviceUnknown
)
1870 void CStringNode::Print(bool bCursers
,bool bDescendingSort
,BJ_UINT32
&nIndex
, BJ_UINT32 nStartIndex
,BJ_UINT32 nEndIndex
)
1872 if (bDescendingSort
)
1875 ((CStringNode
*)m_rbLeft
)->Print(bCursers
,bDescendingSort
,nIndex
,nStartIndex
,nEndIndex
);
1877 if (nIndex
>= nStartIndex
&& nIndex
<= nEndIndex
)
1881 printw("%3d. %-30s %10llu %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu %10llu\n",nIndex
,(char*)&(m_Value
),m_nBytes
,m_nFrames
, m_nFramesiOS
, m_nFramesOSX
, m_nQuestionFrames
, m_nQuestionFramesiOS
, m_nQuestionFramesOSX
, m_nAnswerFrames
,m_nAnswerFramesiOS
, m_nAnswerFramesOSX
, m_nDeviceAskingCount
,m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
, m_nDeviceAnsweringCount
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
, m_nDeviceTotalCount
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
, m_nWakeFrames
,m_nGoodbyeFrames
);
1886 printf("%3d. %-30s %10llu %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu %10llu\n",nIndex
,(char*)&(m_Value
),m_nBytes
,m_nFrames
, m_nFramesiOS
, m_nFramesOSX
, m_nQuestionFrames
, m_nQuestionFramesiOS
, m_nQuestionFramesOSX
, m_nAnswerFrames
,m_nAnswerFramesiOS
, m_nAnswerFramesOSX
, m_nDeviceAskingCount
,m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
, m_nDeviceAnsweringCount
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
, m_nDeviceTotalCount
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
, m_nWakeFrames
,m_nGoodbyeFrames
);
1892 ((CStringNode
*)m_rbRight
)->Print(bCursers
,bDescendingSort
,nIndex
,nStartIndex
,nEndIndex
);
1897 ((CStringNode
*)m_rbRight
)->Print(bCursers
,bDescendingSort
,nIndex
,nStartIndex
,nEndIndex
);
1899 if (nIndex
>= nStartIndex
&& nIndex
<= nEndIndex
)
1903 printw("%3d. %-30s %10llu %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu %10llu\n",nIndex
,(char*)&(m_Value
),m_nBytes
,m_nFrames
, m_nFramesiOS
, m_nFramesOSX
, m_nQuestionFrames
, m_nQuestionFramesiOS
, m_nQuestionFramesOSX
, m_nAnswerFrames
,m_nAnswerFramesiOS
, m_nAnswerFramesOSX
, m_nDeviceAskingCount
,m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
, m_nDeviceAnsweringCount
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
, m_nDeviceTotalCount
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
, m_nWakeFrames
,m_nGoodbyeFrames
);
1907 printf("%3d. %-30s %10llu %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu(%5llu/%5llu) %10llu %10llu\n",nIndex
,(char*)&(m_Value
),m_nBytes
,m_nFrames
, m_nFramesiOS
, m_nFramesOSX
, m_nQuestionFrames
, m_nQuestionFramesiOS
, m_nQuestionFramesOSX
, m_nAnswerFrames
,m_nAnswerFramesiOS
, m_nAnswerFramesOSX
, m_nDeviceAskingCount
,m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
, m_nDeviceAnsweringCount
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
, m_nDeviceTotalCount
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
, m_nWakeFrames
,m_nGoodbyeFrames
);
1912 ((CStringNode
*)m_rbLeft
)->Print(bCursers
,bDescendingSort
,nIndex
,nStartIndex
,nEndIndex
);
1916 void CStringNode::Export(FILE* hFile
)
1918 fprintf(hFile
, "%s,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n",
1919 (char*)&(m_Value
),m_nBytes
,
1920 m_nFrames
, m_nFramesiOS
, m_nFramesOSX
,
1921 m_nQuestionFrames
, m_nQuestionFramesiOS
, m_nQuestionFramesOSX
,
1922 m_nAnswerFrames
, m_nAnswerFramesiOS
, m_nAnswerFramesOSX
,
1923 m_nDeviceAskingCount
, m_nDeviceAskingiOSCount
,m_nDeviceAskingOSXCount
,
1924 m_nDeviceAnsweringCount
,m_nDeviceAnsweringiOSCount
,m_nDeviceAnsweringOSXCount
,
1925 m_nDeviceTotalCount
, m_nDeviceTotaliOSCount
, m_nDeviceTotalOSXCount
,
1926 m_nWakeFrames
,m_nGoodbyeFrames
);
1929 ((CStringNode
*)m_rbLeft
)->Export(hFile
);
1931 ((CStringNode
*)m_rbRight
)->Export(hFile
);
1935 /* CStringShortNode */
1937 void CStringShortNode::Export(FILE *hFile
)
1939 fprintf(hFile
, "%s,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n",
1940 (char*)&(m_Value
),m_nBytes
,
1941 m_nFrames
, m_nQuestionFrames
, m_nAnswerFrames
,
1942 m_nDeviceAskingCount
, m_nDeviceAnsweringCount
, m_nDeviceTotalCount
,
1943 m_nWakeFrames
,m_nGoodbyeFrames
);
1948 ((CStringShortNode
*)m_rbLeft
)->Export(hFile
);
1952 ((CStringShortNode
*)m_rbRight
)->Export(hFile
);
1958 void CDeviceMap::GetDeviceOSTypes(CDeviceNode
*node
, CDeviceMap
*pGlobalDeviceMap
, device_count
& dev_cnt
)
1963 GetDeviceOSTypes(dynamic_cast<CDeviceNode
*>(node
->m_rbLeft
),pGlobalDeviceMap
, dev_cnt
);
1964 GetDeviceOSTypes(dynamic_cast<CDeviceNode
*>(node
->m_rbRight
),pGlobalDeviceMap
, dev_cnt
);
1966 if (node
->bDuplicate
|| !node
->bHasFrames
)
1969 char deviceType
= '?';
1970 if (pGlobalDeviceMap
)
1972 CDeviceNode
* globalDevice
= pGlobalDeviceMap
->Find(&node
->m_Key
);
1975 deviceType
= globalDevice
->GetDeviceOS();
1977 if (globalDevice
->bOSXWithEDNSField
&& deviceType
== 'X')
1979 dev_cnt
.OSXWithEDNSField
++;
1981 else if (globalDevice
->biOSWithEDNSField
&& (deviceType
== 't' || deviceType
== 'i'))
1983 dev_cnt
.iOSWithEDNSField
++;
1989 deviceType
= node
->GetDeviceOS();
1990 if (node
->bOSXWithEDNSField
&& deviceType
== 'X')
1992 dev_cnt
.OSXWithEDNSField
++;
1994 else if (node
->biOSWithEDNSField
&& (deviceType
== 't' || deviceType
== 'i'))
1996 dev_cnt
.iOSWithEDNSField
++;
2009 dev_cnt
.unknownOS
++;
2014 void CIPAddrMap::GetDeviceOSTypes(CIPDeviceNode
* node
, CIPAddrMap
* pGobalMap
, BJ_UINT64
& iOS
,BJ_UINT64
& OSX
,BJ_UINT64
& unknowOS
)
2019 GetDeviceOSTypes(dynamic_cast<CIPDeviceNode
*>(node
->m_rbLeft
),pGobalMap
, iOS
, OSX
, unknowOS
);
2020 GetDeviceOSTypes(dynamic_cast<CIPDeviceNode
*>(node
->m_rbRight
),pGobalMap
,iOS
, OSX
, unknowOS
);
2022 char deviceType
= '?';
2025 CIPDeviceNode
*ipDevice
= pGobalMap
->Find(&node
->m_Key
);
2027 if (ipDevice
&& ipDevice
->pDeviceNode
)
2028 deviceType
= ipDevice
->pDeviceNode
->GetDeviceOS();