5 // Created by Terrin Eager on 4/24/13.
6 // Copyright (c) 2013-2014 Apple Inc. All rights reserved.
13 #include "BonjourTop.h"
18 #include <sys/types.h>
21 #define BJ_VERSION_MAJOR 0
22 #define BJ_VERSION_MINOR 23
28 printf("bonjourtop usage: bonjourTop (Version: %d.%d)\n",BJ_VERSION_MAJOR,BJ_VERSION_MINOR);
29 printf("\t\t\t [-t tcptrace_filename ]\n");
30 printf("\t\t\t [-i interfaceName]\n");
31 printf("\t\t\t [-m ipaddress/subnetmask] ie 17.255.45.12/17\n");
32 printf("\t\t\t [-e export_filename] \n");
33 printf("\t\t\t [-x seconds] 'Snapshot export every x seconds'\n");
34 printf("\t\t\t [-s] 'service information'\n");
35 printf("\t\t\t [-v] 'report the version number' \n");
36 printf("\t\t\t [-d] filename 'export device map. Adds timestamp and csv extension to the filename' \n");
37 printf("\t\t\t [-f application] 'filter application for device map (only available with -t -d options)' \n");
38 printf("While running the follow keys may be used:\n");
39 printf("\t b - sort by Bytes\n");
40 printf("\t p - sort by Packets (default)\n");
41 printf("\t n - sort by Name\n");
42 printf("\t a - Display Application Names (default) \n");
43 printf("\t s - Display Services Names \n");
44 printf("\t t - Display 24 hour packet per min \n");
46 printf("\t o - flip sort order\n");
47 printf("\t e - export to BonjourTop.csv\n");
48 printf("\t q - quit\n\n");
52 handle_window_change(int signal) {
55 BjTop.WindowSizeChanged();
62 int main(int argc, char * const *argv)
65 sigset_t sset, oldsset;
68 static struct option longopts[] = {
69 { "trace", required_argument, NULL, 't' },
70 { "interface", required_argument, NULL, 'i' },
71 { "ipaddr_subnet", required_argument, NULL, 'm' },
72 { "export", required_argument, NULL, 'e' },
73 { "snapshot", required_argument, NULL, 'x' },
74 { "service", no_argument, NULL, 's' },
75 { "version", no_argument, NULL, 'v' },
76 { "devicemap", required_argument, NULL, 'd' },
77 { "filter", required_argument, NULL, 'f' },
83 /* Block SIGWINCH signals while we are in a relayout. */
84 if(-1 == sigprocmask(SIG_BLOCK, &sset, &oldsset)) {
85 perror("sigprocmask");
89 BJ_COLLECTBY_TYPE TypeList[] = {CBT_SERVICE,CBT_REQUEST_RESPONDS,CBT_SAME_DIFF_SUBNET,CBT_IP_ADDRESS_TYPE,CBT_PACKET};
92 bool bLiveCapture = true;
95 while ((c = getopt_long(argc, argv, "t:i:m:e:x:svd:f:phb", longopts, NULL)) != -1) {
98 BjTop.m_pTcpDumpFileName = optarg; // TCP Dump Filename
100 BjTop.m_bCursers = false;
103 BjTop.m_bCursers = false;
107 BjTop.m_pExportFileName = optarg; // Export filename
110 BjTop.interfaceName = optarg; // Interface name
113 BjTop.SetIPAddr(optarg); // TODO: verify that the argument is an ip address
116 sTemp = optarg; // time in seconds for snapshots
117 BjTop.m_SnapshotSeconds = sTemp.GetUINT32();
120 BjTop.m_bImportExportDeviceMap = true;
121 BjTop.m_DeviceFileName = optarg;
124 BjTop.filterApplicationName = optarg;
127 BjTop.m_CurrentDisplay = CBonjourTop::BJ_DISPLAY_SERVICE;
130 printf("\nbonjourtop Version: %d.%d\n\n",BJ_VERSION_MAJOR,BJ_VERSION_MINOR);
134 BjTop.m_Collection.Init(TypeList);
147 if (BjTop.m_bCursers)
149 signal(SIGWINCH, handle_window_change);
152 BjTop.PrintResults(1,false);
163 BjTop.ExportResults();
167 if (BjTop.m_bCursers)
170 if (BjTop.m_bImportExportDeviceMap)
172 BjTop.WriteDeviceFile();
173 BjTop.WriteVendorFile();