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 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353
|
/* main.c
*
* $Id: main.c 44410 2012-08-10 00:08:03Z gerald $
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* Richard Sharpe, 13-Feb-1999, added support for initializing structures
* needed by dissect routines
* Jeff Foster, 2001/03/12, added support tabbed hex display windowss
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#if GTK_CHECK_VERSION(3,0,0)
# include <gdk/gdkkeysyms-compat.h>
#endif
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifndef HAVE_GETOPT
#include "wsutil/wsgetopt.h"
#endif
#ifdef _WIN32 /* Needed for console I/O */
#if _MSC_VER < 1500
/* AttachConsole() needs this #define! */
#define _WIN32_WINNT 0x0501
#endif
#include <fcntl.h>
#include <conio.h>
#endif
#ifdef HAVE_LIBPORTAUDIO
#include <portaudio.h>
#endif /* HAVE_LIBPORTAUDIO */
#include <epan/epan.h>
#include <epan/filesystem.h>
#include <wsutil/privileges.h>
#include <epan/epan_dissect.h>
#include <epan/timestamp.h>
#include <epan/packet.h>
#include <epan/plugins.h>
#include <epan/dfilter/dfilter.h>
#include <epan/strutil.h>
#include <epan/addr_resolv.h>
#include <epan/emem.h>
#include <epan/ex-opt.h>
#include <epan/funnel.h>
#include <epan/expert.h>
#include <epan/frequency-utils.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/tap.h>
#include <epan/stat_cmd_args.h>
#include <epan/uat.h>
#include <epan/column.h>
/* general (not GTK specific) */
#include "../file.h"
#include "../summary.h"
#include "../filters.h"
#include "../disabled_protos.h"
#include "../color.h"
#include "../color_filters.h"
#include "../print.h"
#include "../register.h"
#include "../ringbuffer.h"
#include "ui/util.h"
#include "../clopts_common.h"
#include "../console_io.h"
#include "../cmdarg_err.h"
#include "../version_info.h"
#include "../merge.h"
#include "../log.h"
#include "../u3.h"
#include "ui/alert_box.h"
#include "ui/main_statusbar.h"
#include "ui/recent.h"
#include "ui/recent_utils.h"
#include "ui/simple_dialog.h"
#include "ui/ui_util.h"
#include <wsutil/file_util.h>
#ifdef HAVE_LIBPCAP
#include "../capture_ui_utils.h"
#include "../capture-pcap-util.h"
#include "../capture_ifinfo.h"
#include "../capture.h"
#include "../capture_sync.h"
extern gint if_list_comparator_alph (const void *first_arg, const void *second_arg);
#endif
#ifdef _WIN32
#include "../capture-wpcap.h"
#include "../capture_wpcap_packet.h"
#include <tchar.h> /* Needed for Unicode */
#include <wsutil/unicode-utils.h>
#include <commctrl.h>
#include <shellapi.h>
#endif /* _WIN32 */
/* GTK related */
#include "ui/gtk/file_dlg.h"
#include "ui/gtk/gtkglobals.h"
#include "ui/gtk/color_utils.h"
#include "ui/gtk/gui_utils.h"
#include "ui/gtk/color_dlg.h"
#include "ui/gtk/filter_dlg.h"
#include "ui/gtk/uat_gui.h"
#include "ui/gtk/main.h"
#include "ui/gtk/main_airpcap_toolbar.h"
#include "ui/gtk/main_filter_toolbar.h"
#include "ui/gtk/main_titlebar.h"
#include "ui/gtk/menus.h"
#include "ui/gtk/main_menubar_private.h"
#include "ui/gtk/macros_dlg.h"
#include "ui/gtk/main_statusbar_private.h"
#include "ui/gtk/main_toolbar.h"
#include "ui/gtk/main_toolbar_private.h"
#include "ui/gtk/main_welcome.h"
#include "ui/gtk/drag_and_drop.h"
#include "ui/gtk/capture_file_dlg.h"
#include "ui/gtk/main_proto_draw.h"
#include "ui/gtk/keys.h"
#include "ui/gtk/packet_win.h"
#include "ui/gtk/stock_icons.h"
#include "ui/gtk/find_dlg.h"
#include "ui/gtk/follow_tcp.h"
#include "ui/gtk/font_utils.h"
#include "ui/gtk/about_dlg.h"
#include "ui/gtk/help_dlg.h"
#include "ui/gtk/decode_as_dlg.h"
#include "ui/gtk/webbrowser.h"
#include "ui/gtk/capture_dlg.h"
#include "ui/gtk/capture_if_dlg.h"
#include "ui/gtk/tap_param_dlg.h"
#include "ui/gtk/prefs_column.h"
#include "ui/gtk/prefs_dlg.h"
#include "ui/gtk/proto_help.h"
#include "ui/gtk/new_packet_list.h"
#include "ui/gtk/filter_expression_save_dlg.h"
#include "ui/gtk/old-gtk-compat.h"
#ifdef HAVE_LIBPCAP
#include "../../image/wsicon16.xpm"
#include "../../image/wsicon32.xpm"
#include "../../image/wsicon48.xpm"
#include "../../image/wsicon64.xpm"
#include "../../image/wsiconcap16.xpm"
#include "../../image/wsiconcap32.xpm"
#include "../../image/wsiconcap48.xpm"
#endif
#ifdef HAVE_AIRPCAP
#include <airpcap.h>
#include "airpcap_loader.h"
#include "airpcap_dlg.h"
#include "airpcap_gui_utils.h"
#endif
#include <epan/crypt/airpdcap_ws.h>
#ifdef HAVE_GTKOSXAPPLICATION
#include <igemacintegration/gtkosxapplication.h>
#endif
/*
* Files under personal and global preferences directories in which
* GTK settings for Wireshark are stored.
*/
#define RC_FILE "gtkrc"
capture_file cfile;
static gboolean capture_stopping;
/* "exported" main widgets */
GtkWidget *top_level = NULL, *pkt_scrollw, *tree_view_gbl, *byte_nb_ptr_gbl;
/* placement widgets (can be a bit confusing, because of the many layout possibilities */
static GtkWidget *main_vbox, *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2;
static GtkWidget *main_first_pane, *main_second_pane;
/* internally used widgets */
static GtkWidget *menubar, *main_tb, *filter_tb, *tv_scrollw, *statusbar, *welcome_pane;
#ifdef HAVE_AIRPCAP
GtkWidget *airpcap_tb;
int airpcap_dll_ret_val = -1;
#endif
GString *comp_info_str, *runtime_info_str;
static gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */
static guint tap_update_timer_id;
#ifdef _WIN32
static gboolean has_console; /* TRUE if app has console */
static gboolean console_wait; /* "Press any key..." */
static void destroy_console(void);
static gboolean stdin_capture = FALSE; /* Don't grab stdin & stdout if TRUE */
#endif
static void console_log_handler(const char *log_domain,
GLogLevelFlags log_level, const char *message, gpointer user_data);
#ifdef HAVE_LIBPCAP
capture_options global_capture_opts;
#endif
static void create_main_window(gint, gint, gint, e_prefs*);
static void show_main_window(gboolean);
static void main_save_window_geometry(GtkWidget *widget);
/* Match selected byte pattern */
static void
match_selected_cb_do(GtkWidget *filter_te, gpointer data, int action, gchar *text)
{
char *cur_filter, *new_filter;
if ((!text) || (0 == strlen(text))) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to build a filter!\nTry expanding or choosing another item.");
return;
}
g_assert(data);
g_assert(filter_te);
cur_filter = gtk_editable_get_chars(GTK_EDITABLE(filter_te), 0, -1);
switch (action&MATCH_SELECTED_MASK) {
case MATCH_SELECTED_REPLACE:
new_filter = g_strdup(text);
break;
case MATCH_SELECTED_AND:
if ((!cur_filter) || (0 == strlen(cur_filter)))
new_filter = g_strdup(text);
else
new_filter = g_strconcat("(", cur_filter, ") && (", text, ")", NULL);
break;
case MATCH_SELECTED_OR:
if ((!cur_filter) || (0 == strlen(cur_filter)))
new_filter = g_strdup(text);
else
new_filter = g_strconcat("(", cur_filter, ") || (", text, ")", NULL);
break;
case MATCH_SELECTED_NOT:
new_filter = g_strconcat("!(", text, ")", NULL);
break;
case MATCH_SELECTED_AND_NOT:
if ((!cur_filter) || (0 == strlen(cur_filter)))
new_filter = g_strconcat("!(", text, ")", NULL);
else
new_filter = g_strconcat("(", cur_filter, ") && !(", text, ")", NULL);
break;
case MATCH_SELECTED_OR_NOT:
if ((!cur_filter) || (0 == strlen(cur_filter)))
new_filter = g_strconcat("!(", text, ")", NULL);
else
new_filter = g_strconcat("(", cur_filter, ") || !(", text, ")", NULL);
break;
default:
g_assert_not_reached();
new_filter = NULL;
break;
}
/* Free up the copy we got of the old filter text. */
g_free(cur_filter);
/* Don't change the current display filter if we only want to copy the filter */
if (action&MATCH_SELECTED_COPY_ONLY) {
GString *gtk_text_str = g_string_new("");
g_string_append(gtk_text_str, new_filter);
copy_to_clipboard(gtk_text_str);
g_string_free(gtk_text_str, TRUE);
} else {
/* create a new one and set the display filter entry accordingly */
gtk_entry_set_text(GTK_ENTRY(filter_te), new_filter);
/* Run the display filter so it goes in effect. */
if (action&MATCH_SELECTED_APPLY_NOW)
main_filter_packets(&cfile, new_filter, FALSE);
}
/* Free up the new filter text. */
g_free(new_filter);
}
void
match_selected_ptree_cb(gpointer data, MATCH_SELECTED_E action)
{
char *filter = NULL;
if (cfile.finfo_selected) {
filter = proto_construct_match_selected_string(cfile.finfo_selected,
cfile.edt);
match_selected_cb_do(g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY),data, action, filter);
}
}
void
colorize_selected_ptree_cb(GtkWidget *w _U_, gpointer data _U_, guint8 filt_nr)
{
char *filter = NULL;
if (cfile.finfo_selected) {
filter = proto_construct_match_selected_string(cfile.finfo_selected,
cfile.edt);
if ((!filter) || (0 == strlen(filter))) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Could not acquire information to build a filter!\n"
"Try expanding or choosing another item.");
return;
}
if (filt_nr==0) {
color_display_with_filter(filter);
} else {
if (filt_nr==255) {
color_filters_reset_tmp();
} else {
color_filters_set_tmp(filt_nr,filter, FALSE);
}
new_packet_list_colorize_packets();
}
}
}
static void selected_ptree_info_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
{
gchar *selected_proto_url;
gchar *proto_abbrev = data;
switch(btn) {
case(ESD_BTN_OK):
if (cfile.finfo_selected) {
/* open wiki page using the protocol abbreviation */
selected_proto_url = g_strdup_printf("http://wiki.wireshark.org/Protocols/%s", proto_abbrev);
browser_open_url(selected_proto_url);
g_free(selected_proto_url);
}
break;
case(ESD_BTN_CANCEL):
break;
default:
g_assert_not_reached();
}
}
void
selected_ptree_info_cb(GtkWidget *widget _U_, gpointer data _U_)
{
int field_id;
const gchar *proto_abbrev;
gpointer dialog;
if (cfile.finfo_selected) {
/* convert selected field to protocol abbreviation */
/* XXX - could this conversion be simplified? */
field_id = cfile.finfo_selected->hfinfo->id;
/* if the selected field isn't a protocol, get it's parent */
if(!proto_registrar_is_protocol(field_id)) {
field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
}
proto_abbrev = proto_registrar_get_abbrev(field_id);
if (!proto_is_private(field_id)) {
/* ask the user if the wiki page really should be opened */
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
"%sOpen Wireshark Wiki page of protocol \"%s\"?%s\n"
"\n"
"This will open the \"%s\" related Wireshark Wiki page in your Web browser.\n"
"\n"
"The Wireshark Wiki is a collaborative approach to provide information "
"about Wireshark in several ways (not limited to protocol specifics).\n"
"\n"
"This Wiki is new, so the page of the selected protocol "
"may not exist and/or may not contain valuable information.\n"
"\n"
"As everyone can edit the Wiki and add new content (or extend existing), "
"you are encouraged to add information if you can.\n"
"\n"
"Hint 1: If you are new to wiki editing, try out editing the Sandbox first!\n"
"\n"
"Hint 2: If you want to add a new protocol page, you should use the ProtocolTemplate, "
"which will save you a lot of editing and will give a consistent look over the pages.",
simple_dialog_primary_start(), proto_abbrev, simple_dialog_primary_end(), proto_abbrev);
simple_dialog_set_cb(dialog, selected_ptree_info_answered_cb, (gpointer)proto_abbrev);
} else {
/* appologize to the user that the wiki page cannot be opened */
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"%sCan't open Wireshark Wiki page of protocol \"%s\"%s\n"
"\n"
"This would open the \"%s\" related Wireshark Wiki page in your Web browser.\n"
"\n"
"Since this is a private protocol, such information is not available in "
"a public wiki. Therefore this wiki entry is blocked.\n"
"\n"
"Sorry for the inconvenience.\n",
simple_dialog_primary_start(), proto_abbrev, simple_dialog_primary_end(), proto_abbrev);
}
}
}
static void selected_ptree_ref_answered_cb(gpointer dialog _U_, gint btn, gpointer data)
{
gchar *selected_proto_url;
gchar *proto_abbrev = data;
switch(btn) {
case(ESD_BTN_OK):
if (cfile.finfo_selected) {
/* open reference page using the protocol abbreviation */
selected_proto_url = g_strdup_printf("http://www.wireshark.org/docs/dfref/%c/%s", proto_abbrev[0], proto_abbrev);
browser_open_url(selected_proto_url);
g_free(selected_proto_url);
}
break;
case(ESD_BTN_CANCEL):
break;
default:
g_assert_not_reached();
}
}
void
selected_ptree_ref_cb(GtkWidget *widget _U_, gpointer data _U_)
{
int field_id;
const gchar *proto_abbrev;
gpointer dialog;
if (cfile.finfo_selected) {
/* convert selected field to protocol abbreviation */
/* XXX - could this conversion be simplified? */
field_id = cfile.finfo_selected->hfinfo->id;
/* if the selected field isn't a protocol, get it's parent */
if(!proto_registrar_is_protocol(field_id)) {
field_id = proto_registrar_get_parent(cfile.finfo_selected->hfinfo->id);
}
proto_abbrev = proto_registrar_get_abbrev(field_id);
if (!proto_is_private(field_id)) {
/* ask the user if the wiki page really should be opened */
dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_OK_CANCEL,
"%sOpen Wireshark filter reference page of protocol \"%s\"?%s\n"
"\n"
"This will open the \"%s\" related Wireshark filter reference page in your Web browser.\n"
"\n",
simple_dialog_primary_start(), proto_abbrev, simple_dialog_primary_end(), proto_abbrev);
simple_dialog_set_cb(dialog, selected_ptree_ref_answered_cb, (gpointer)proto_abbrev);
} else {
/* appologize to the user that the wiki page cannot be opened */
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"%sCan't open Wireshark filter reference page of protocol \"%s\"%s\n"
"\n"
"This would open the \"%s\" related Wireshark filter reference page in your Web browser.\n"
"\n"
"Since this is a private protocol, such information is not available on "
"a public website. Therefore this filter entry is blocked.\n"
"\n"
"Sorry for the inconvenience.\n",
simple_dialog_primary_start(), proto_abbrev, simple_dialog_primary_end(), proto_abbrev);
}
}
}
static gboolean
is_address_column (gint column)
{
if (((cfile.cinfo.col_fmt[column] == COL_DEF_SRC) ||
(cfile.cinfo.col_fmt[column] == COL_RES_SRC) ||
(cfile.cinfo.col_fmt[column] == COL_DEF_DST) ||
(cfile.cinfo.col_fmt[column] == COL_RES_DST)) &&
strlen(cfile.cinfo.col_expr.col_expr_val[column]))
{
return TRUE;
}
return FALSE;
}
GList *
get_ip_address_list_from_packet_list_row(gpointer data)
{
gint row = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_ROW_KEY));
gint column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
gint col;
frame_data *fdata;
GList *addr_list = NULL;
fdata = (frame_data *) new_packet_list_get_row_data(row);
if (fdata != NULL) {
epan_dissect_t edt;
if (!cf_read_frame (&cfile, fdata))
return NULL; /* error reading the frame */
epan_dissect_init(&edt, FALSE, FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.pseudo_header, cfile.pd, fdata, &cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
/* First check selected column */
if (is_address_column (column)) {
addr_list = g_list_append (addr_list, se_strdup_printf("%s", cfile.cinfo.col_expr.col_expr_val[column]));
}
for (col = 0; col < cfile.cinfo.num_cols; col++) {
/* Then check all columns except the selected */
if ((col != column) && (is_address_column (col))) {
addr_list = g_list_append (addr_list, se_strdup_printf("%s", cfile.cinfo.col_expr.col_expr_val[col]));
}
}
epan_dissect_cleanup(&edt);
}
return addr_list;
}
static gchar *
get_filter_from_packet_list_row_and_column(gpointer data)
{
gint row = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_ROW_KEY));
gint column = new_packet_list_get_column_id (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(data), E_MPACKET_LIST_COL_KEY)));
frame_data *fdata;
gchar *buf=NULL;
fdata = (frame_data *) new_packet_list_get_row_data(row);
if (fdata != NULL) {
epan_dissect_t edt;
if (!cf_read_frame(&cfile, fdata))
return NULL; /* error reading the frame */
/* proto tree, visible. We need a proto tree if there's custom columns */
epan_dissect_init(&edt, have_custom_cols(&cfile.cinfo), FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.pseudo_header, cfile.pd, fdata,
&cfile.cinfo);
epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
if ((cfile.cinfo.col_custom_occurrence[column]) ||
(strchr (cfile.cinfo.col_expr.col_expr_val[column], ',') == NULL))
{
/* Only construct the filter when a single occurrence is displayed
* otherwise we might end up with a filter like "ip.proto==1,6".
*
* Or do we want to be able to filter on multiple occurrences so that
* the filter might be calculated as "ip.proto==1 && ip.proto==6"
* instead?
*/
if (strlen(cfile.cinfo.col_expr.col_expr[column]) != 0 &&
strlen(cfile.cinfo.col_expr.col_expr_val[column]) != 0) {
/* leak a little but safer than ep_ here */
if (cfile.cinfo.col_fmt[column] == COL_CUSTOM) {
header_field_info *hfi = proto_registrar_get_byname(cfile.cinfo.col_custom_field[column]);
if (hfi->parent == -1) {
/* Protocol only */
buf = se_strdup(cfile.cinfo.col_expr.col_expr[column]);
} else if (hfi->type == FT_STRING) {
/* Custom string, add quotes */
buf = se_strdup_printf("%s == \"%s\"", cfile.cinfo.col_expr.col_expr[column],
cfile.cinfo.col_expr.col_expr_val[column]);
}
}
if (buf == NULL) {
buf = se_strdup_printf("%s == %s", cfile.cinfo.col_expr.col_expr[column],
cfile.cinfo.col_expr.col_expr_val[column]);
}
}
}
epan_dissect_cleanup(&edt);
}
return buf;
}
void
match_selected_plist_cb(gpointer data, MATCH_SELECTED_E action)
{
match_selected_cb_do(g_object_get_data(G_OBJECT(data), E_DFILTER_TE_KEY),
data,
action,
get_filter_from_packet_list_row_and_column(data));
}
/* This function allows users to right click in the details window and copy the text
* information to the operating systems clipboard.
*
* We first check to see if a string representation is setup in the tree and then
* read the string. If not available then we try to grab the value. If all else
* fails we display a message to the user to indicate the copy could not be completed.
*/
void
copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_, COPY_SELECTED_E action)
{
GString *gtk_text_str = g_string_new("");
char labelstring[256];
char *stringpointer = labelstring;
switch(action)
{
case COPY_SELECTED_DESCRIPTION:
if (cfile.finfo_selected->rep &&
strlen (cfile.finfo_selected->rep->representation) > 0) {
g_string_append(gtk_text_str, cfile.finfo_selected->rep->representation);
}
break;
case COPY_SELECTED_FIELDNAME:
if (cfile.finfo_selected->hfinfo->abbrev != 0) {
g_string_append(gtk_text_str, cfile.finfo_selected->hfinfo->abbrev);
}
break;
case COPY_SELECTED_VALUE:
if (cfile.edt !=0 ) {
g_string_append(gtk_text_str,
get_node_field_value(cfile.finfo_selected, cfile.edt));
}
break;
default:
break;
}
if (gtk_text_str->len == 0) {
/* If no representation then... Try to read the value */
proto_item_fill_label(cfile.finfo_selected, stringpointer);
g_string_append(gtk_text_str, stringpointer);
}
if (gtk_text_str->len == 0) {
/* Could not get item so display error msg */
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to copy, try expanding or choosing another item");
} else {
/* Copy string to clipboard */
copy_to_clipboard(gtk_text_str);
}
g_string_free(gtk_text_str, TRUE); /* Free the memory */
}
/* mark as reference time frame */
void
set_frame_reftime(gboolean set, frame_data *frame, gint row) {
if (row == -1)
return;
if (set) {
frame->flags.ref_time=1;
cfile.ref_time_count++;
} else {
frame->flags.ref_time=0;
cfile.ref_time_count--;
}
cf_reftime_packets(&cfile);
if (!frame->flags.ref_time && !frame->flags.passed_dfilter) {
new_packet_list_freeze();
cfile.displayed_count--;
new_packet_list_recreate_visible_rows();
new_packet_list_thaw();
}
new_packet_list_queue_draw();
}
static void reftime_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_)
{
switch(btn) {
case(ESD_BTN_YES):
timestamp_set_type(TS_RELATIVE);
recent.gui_time_format = TS_RELATIVE;
cf_timestamp_auto_precision(&cfile);
new_packet_list_queue_draw();
break;
case(ESD_BTN_NO):
break;
default:
g_assert_not_reached();
}
if (cfile.current_frame) {
set_frame_reftime(!cfile.current_frame->flags.ref_time,
cfile.current_frame, cfile.current_row);
}
}
void
reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action)
{
static GtkWidget *reftime_dialog = NULL;
switch(action){
case REFTIME_TOGGLE:
if (cfile.current_frame) {
if(recent.gui_time_format != TS_RELATIVE && cfile.current_frame->flags.ref_time==0) {
reftime_dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_YES_NO,
"%sSwitch to the appropriate Time Display Format?%s\n\n"
"Time References don't work well with the currently selected Time Display Format.\n\n"
"Do you want to switch to \"Seconds Since Beginning of Capture\" now?",
simple_dialog_primary_start(), simple_dialog_primary_end());
simple_dialog_set_cb(reftime_dialog, reftime_answered_cb, NULL);
} else {
set_frame_reftime(!cfile.current_frame->flags.ref_time,
cfile.current_frame, cfile.current_row);
}
}
break;
case REFTIME_FIND_NEXT:
cf_find_packet_time_reference(&cfile, SD_FORWARD);
break;
case REFTIME_FIND_PREV:
cf_find_packet_time_reference(&cfile, SD_BACKWARD);
break;
}
}
void
find_next_mark_cb(GtkWidget *w _U_, gpointer data _U_, int action _U_)
{
cf_find_packet_marked(&cfile, SD_FORWARD);
}
void
find_prev_mark_cb(GtkWidget *w _U_, gpointer data _U_, int action _U_)
{
cf_find_packet_marked(&cfile, SD_BACKWARD);
}
static void
tree_view_selection_changed_cb(GtkTreeSelection *sel, gpointer user_data _U_)
{
field_info *finfo;
gchar len_str[2+10+1+5+1]; /* ", {N} bytes\0",
N < 4294967296 */
gboolean has_blurb = FALSE;
guint length = 0, byte_len;
GtkWidget *byte_view;
const guint8 *byte_data;
gint finfo_length;
GtkTreeModel *model;
GtkTreeIter iter;
/* if nothing is selected */
if (!gtk_tree_selection_get_selected(sel, &model, &iter))
{
/*
* Which byte view is displaying the current protocol tree
* row's data?
*/
byte_view = get_notebook_bv_ptr(byte_nb_ptr_gbl);
if (byte_view == NULL)
return; /* none */
byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
if (byte_data == NULL)
return; /* none */
cf_unselect_field(&cfile);
packet_hex_print(byte_view, byte_data,
cfile.current_frame, NULL, byte_len);
proto_help_menu_modify(sel, &cfile);
return;
}
gtk_tree_model_get(model, &iter, 1, &finfo, -1);
if (!finfo) return;
set_notebook_page(byte_nb_ptr_gbl, finfo->ds_tvb);
byte_view = get_notebook_bv_ptr(byte_nb_ptr_gbl);
byte_data = get_byte_view_data_and_length(byte_view, &byte_len);
g_assert(byte_data != NULL);
cfile.finfo_selected = finfo;
set_menus_for_selected_tree_row(&cfile);
if (finfo->hfinfo) {
if (finfo->hfinfo->blurb != NULL &&
finfo->hfinfo->blurb[0] != '\0') {
has_blurb = TRUE;
length = (guint) strlen(finfo->hfinfo->blurb);
} else {
length = (guint) strlen(finfo->hfinfo->name);
}
finfo_length = finfo->length + finfo->appendix_length;
if (finfo_length == 0) {
len_str[0] = '\0';
} else if (finfo_length == 1) {
g_strlcpy (len_str, ", 1 byte", sizeof len_str);
} else {
g_snprintf (len_str, sizeof len_str, ", %d bytes", finfo_length);
}
statusbar_pop_field_msg(); /* get rid of current help msg */
if (length) {
statusbar_push_field_msg(" %s (%s)%s",
(has_blurb) ? finfo->hfinfo->blurb : finfo->hfinfo->name,
finfo->hfinfo->abbrev, len_str);
} else {
/*
* Don't show anything if the field name is zero-length;
* the pseudo-field for "proto_tree_add_text()" is such
* a field, and we don't want "Text (text)" showing up
* on the status line if you've selected such a field.
*
* XXX - there are zero-length fields for which we *do*
* want to show the field name.
*
* XXX - perhaps the name and abbrev field should be null
* pointers rather than null strings for that pseudo-field,
* but we'd have to add checks for null pointers in some
* places if we did that.
*
* Or perhaps protocol tree items added with
* "proto_tree_add_text()" should have -1 as the field index,
* with no pseudo-field being used, but that might also
* require special checks for -1 to be added.
*/
statusbar_push_field_msg("%s", "");
}
}
packet_hex_print(byte_view, byte_data, cfile.current_frame, finfo,
byte_len);
proto_help_menu_modify(sel, &cfile);
}
void collapse_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
if (cfile.edt->tree)
collapse_all_tree(cfile.edt->tree, tree_view_gbl);
}
void expand_all_cb(GtkWidget *widget _U_, gpointer data _U_) {
if (cfile.edt->tree)
expand_all_tree(cfile.edt->tree, tree_view_gbl);
}
void apply_as_custom_column_cb (GtkWidget *widget _U_, gpointer data _U_)
{
if (cfile.finfo_selected) {
column_prefs_add_custom(COL_CUSTOM, cfile.finfo_selected->hfinfo->name,
cfile.finfo_selected->hfinfo->abbrev,0);
/* Recreate the packet list according to new preferences */
new_packet_list_recreate ();
if (!prefs.gui_use_pref_save) {
prefs_main_write();
}
cfile.cinfo.columns_changed = FALSE; /* Reset value */
}
}
void expand_tree_cb(GtkWidget *widget _U_, gpointer data _U_) {
GtkTreePath *path;
path = tree_find_by_field_info(GTK_TREE_VIEW(tree_view_gbl), cfile.finfo_selected);
if(path) {
/* the mouse position is at an entry, expand that one */
gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_view_gbl), path, TRUE);
gtk_tree_path_free(path);
}
}
void resolve_name_cb(GtkWidget *widget _U_, gpointer data _U_) {
if (cfile.edt->tree) {
guint32 tmp = gbl_resolv_flags;
gbl_resolv_flags = RESOLV_ALL;
proto_tree_draw(cfile.edt->tree, tree_view_gbl);
gbl_resolv_flags = tmp;
}
}
static void
main_set_for_capture_file(gboolean have_capture_file_in)
{
have_capture_file = have_capture_file_in;
main_widgets_show_or_hide();
}
gboolean
main_do_quit(void)
{
/* get the current geometry, before writing it to disk */
main_save_window_geometry(top_level);
/* write user's recent file to disk
* It is no problem to write this file, even if we do not quit */
write_profile_recent();
write_recent();
/* XXX - should we check whether the capture file is an
unsaved temporary file for a live capture and, if so,
pop up a "do you want to exit without saving the capture
file?" dialog, and then just return, leaving said dialog
box to forcibly quit if the user clicks "OK"?
If so, note that this should be done in a subroutine that
returns TRUE if we do so, and FALSE otherwise, and if it
returns TRUE we should return TRUE without nuking anything.
Note that, if we do that, we might also want to check if
an "Update list of packets in real time" capture is in
progress and, if so, ask whether they want to terminate
the capture and discard it, and return TRUE, before nuking
any child capture, if they say they don't want to do so. */
#ifdef HAVE_LIBPCAP
/* Nuke any child capture in progress. */
capture_kill_child(&global_capture_opts);
#endif
/* Are we in the middle of reading a capture? */
if (cfile.state == FILE_READ_IN_PROGRESS) {
/* Yes, so we can't just close the file and quit, as
that may yank the rug out from under the read in
progress; instead, just set the state to
"FILE_READ_ABORTED" and return - the code doing the read
will check for that and, if it sees that, will clean
up and quit. */
cfile.state = FILE_READ_ABORTED;
/* Say that the window should *not* be deleted;
that'll be done by the code that cleans up. */
return TRUE;
} else {
/* Close any capture file we have open; on some OSes, you
can't unlink a temporary capture file if you have it
open.
"cf_close()" will unlink it after closing it if
it's a temporary file.
We do this here, rather than after the main loop returns,
as, after the main loop returns, the main window may have
been destroyed (if this is called due to a "destroy"
even on the main window rather than due to the user
selecting a menu item), and there may be a crash
or other problem when "cf_close()" tries to
clean up stuff in the main window.
XXX - is there a better place to put this?
Or should we have a routine that *just* closes the
capture file, and doesn't do anything with the UI,
which we'd call here, and another routine that
calls that routine and also cleans up the UI, which
we'd call elsewhere? */
cf_close(&cfile);
/* Exit by leaving the main loop, so that any quit functions
we registered get called. */
gtk_main_quit();
/* Say that the window should be deleted. */
return FALSE;
}
}
static gboolean
main_window_delete_event_cb(GtkWidget *widget _U_, GdkEvent *event _U_, gpointer data _U_)
{
/* If we're in the middle of stopping a capture, don't do anything;
the user can try deleting the window after the capture stops. */
if (capture_stopping)
return TRUE;
/* If there's unsaved data, let the user save it first.
If they cancel out of it, don't quit. */
if (do_file_close(&cfile, TRUE, " before quitting"))
return main_do_quit();
else
return TRUE; /* will this keep the window from being deleted? */
}
static void
main_pane_load_window_geometry(void)
{
if (recent.has_gui_geometry_main_upper_pane && recent.gui_geometry_main_upper_pane)
gtk_paned_set_position(GTK_PANED(main_first_pane), recent.gui_geometry_main_upper_pane);
if (recent.has_gui_geometry_main_lower_pane && recent.gui_geometry_main_lower_pane) {
gtk_paned_set_position(GTK_PANED(main_second_pane), recent.gui_geometry_main_lower_pane);
}
}
static void
main_load_window_geometry(GtkWidget *widget)
{
window_geometry_t geom;
geom.set_pos = prefs.gui_geometry_save_position;
geom.x = recent.gui_geometry_main_x;
geom.y = recent.gui_geometry_main_y;
geom.set_size = prefs.gui_geometry_save_size;
if (recent.gui_geometry_main_width > 0 &&
recent.gui_geometry_main_height > 0) {
geom.width = recent.gui_geometry_main_width;
geom.height = recent.gui_geometry_main_height;
geom.set_maximized = prefs.gui_geometry_save_maximized;
} else {
/* We assume this means the width and height weren't set in
the "recent" file (or that there is no "recent" file),
and weren't set to a default value, so we don't set the
size. (The "recent" file code rejects non-positive width
and height values.) */
geom.set_size = FALSE;
}
geom.maximized = recent.gui_geometry_main_maximized;
window_set_geometry(widget, &geom);
main_pane_load_window_geometry();
statusbar_load_window_geometry();
}
static void
main_save_window_geometry(GtkWidget *widget)
{
window_geometry_t geom;
window_get_geometry(widget, &geom);
if (prefs.gui_geometry_save_position) {
recent.gui_geometry_main_x = geom.x;
recent.gui_geometry_main_y = geom.y;
}
if (prefs.gui_geometry_save_size) {
recent.gui_geometry_main_width = geom.width;
recent.gui_geometry_main_height = geom.height;
}
if(prefs.gui_geometry_save_maximized) {
recent.gui_geometry_main_maximized = geom.maximized;
}
recent.gui_geometry_main_upper_pane = gtk_paned_get_position(GTK_PANED(main_first_pane));
recent.gui_geometry_main_lower_pane = gtk_paned_get_position(GTK_PANED(main_second_pane));
statusbar_save_window_geometry();
}
void
file_quit_cmd_cb(GtkWidget *widget _U_, gpointer data _U_)
{
/* If there's unsaved data, let the user save it first. */
if (do_file_close(&cfile, TRUE, " before quitting"))
main_do_quit();
}
static void
print_usage(gboolean print_ver) {
FILE *output;
#ifdef _WIN32
create_console();
#endif
if (print_ver) {
output = stdout;
fprintf(output, "Wireshark " VERSION "%s\n"
"Interactively dump and analyze network traffic.\n"
"See http://www.wireshark.org for more information.\n"
"\n"
"%s",
wireshark_svnversion, get_copyright_info());
} else {
output = stderr;
}
fprintf(output, "\n");
fprintf(output, "Usage: wireshark [options] ... [ <infile> ]\n");
fprintf(output, "\n");
#ifdef HAVE_LIBPCAP
fprintf(output, "Capture interface:\n");
fprintf(output, " -i <interface> name or idx of interface (def: first non-loopback)\n");
fprintf(output, " -f <capture filter> packet filter in libpcap filter syntax\n");
fprintf(output, " -s <snaplen> packet snapshot length (def: 65535)\n");
fprintf(output, " -p don't capture in promiscuous mode\n");
fprintf(output, " -k start capturing immediately (def: do nothing)\n");
fprintf(output, " -S update packet display when new packets are captured\n");
fprintf(output, " -l turn on automatic scrolling while -S is in use\n");
#ifdef HAVE_PCAP_CREATE
fprintf(output, " -I capture in monitor mode, if available\n");
#endif
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
fprintf(output, " -B <buffer size> size of kernel buffer (def: 1MB)\n");
#endif
fprintf(output, " -y <link type> link layer type (def: first appropriate)\n");
fprintf(output, " -D print list of interfaces and exit\n");
fprintf(output, " -L print list of link-layer types of iface and exit\n");
fprintf(output, "\n");
fprintf(output, "Capture stop conditions:\n");
fprintf(output, " -c <packet count> stop after n packets (def: infinite)\n");
fprintf(output, " -a <autostop cond.> ... duration:NUM - stop after NUM seconds\n");
fprintf(output, " filesize:NUM - stop this file after NUM KB\n");
fprintf(output, " files:NUM - stop after NUM files\n");
/*fprintf(output, "\n");*/
fprintf(output, "Capture output:\n");
fprintf(output, " -b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs\n");
fprintf(output, " filesize:NUM - switch to next file after NUM KB\n");
fprintf(output, " files:NUM - ringbuffer: replace after NUM files\n");
#endif /* HAVE_LIBPCAP */
/*fprintf(output, "\n");*/
fprintf(output, "Input file:\n");
fprintf(output, " -r <infile> set the filename to read from (no pipes or stdin!)\n");
fprintf(output, "\n");
fprintf(output, "Processing:\n");
fprintf(output, " -R <read filter> packet filter in Wireshark display filter syntax\n");
fprintf(output, " -n disable all name resolutions (def: all enabled)\n");
fprintf(output, " -N <name resolve flags> enable specific name resolution(s): \"mntC\"\n");
fprintf(output, "\n");
fprintf(output, "User interface:\n");
fprintf(output, " -C <config profile> start with specified configuration profile\n");
fprintf(output, " -d <display filter> start with the given display filter\n");
fprintf(output, " -g <packet number> go to specified packet number after \"-r\"\n");
fprintf(output, " -J <jump filter> jump to the first packet matching the (display)\n");
fprintf(output, " filter\n");
fprintf(output, " -j search backwards for a matching packet after \"-J\"\n");
fprintf(output, " -m <font> set the font name used for most text\n");
fprintf(output, " -t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)\n");
fprintf(output, " -u s|hms output format of seconds (def: s: seconds)\n");
fprintf(output, " -X <key>:<value> eXtension options, see man page for details\n");
fprintf(output, " -z <statistics> show various statistics, see man page for details\n");
fprintf(output, "\n");
fprintf(output, "Output:\n");
fprintf(output, " -w <outfile|-> set the output filename (or '-' for stdout)\n");
fprintf(output, "\n");
fprintf(output, "Miscellaneous:\n");
fprintf(output, " -h display this help and exit\n");
fprintf(output, " -v display version info and exit\n");
fprintf(output, " -P <key>:<path> persconf:path - personal configuration files\n");
fprintf(output, " persdata:path - personal data files\n");
fprintf(output, " -o <name>:<value> ... override preference or recent setting\n");
fprintf(output, " -K <keytab> keytab file to use for kerberos decryption\n");
#ifndef _WIN32
fprintf(output, " --display=DISPLAY X display to use\n");
#endif
#ifdef _WIN32
destroy_console();
#endif
}
static void
show_version(void)
{
#ifdef _WIN32
create_console();
#endif
printf(PACKAGE " " VERSION "%s\n"
"\n"
"%s"
"\n"
"%s"
"\n"
"%s",
wireshark_svnversion, get_copyright_info(), comp_info_str->str,
runtime_info_str->str);
#ifdef _WIN32
destroy_console();
#endif
}
/*
* Print to the standard error. On Windows, create a console for the
* standard error to show up on, if necessary.
* XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
* terminal isn't the standard error?
*/
void
vfprintf_stderr(const char *fmt, va_list ap)
{
#ifdef _WIN32
create_console();
#endif
vfprintf(stderr, fmt, ap);
}
void
fprintf_stderr(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf_stderr(fmt, ap);
va_end(ap);
}
/*
* Report an error in command-line arguments.
* Creates a console on Windows.
*/
void
cmdarg_err(const char *fmt, ...)
{
va_list ap;
fprintf_stderr("wireshark: ");
va_start(ap, fmt);
vfprintf_stderr(fmt, ap);
va_end(ap);
fprintf_stderr("\n");
}
/*
* Report additional information for an error in command-line arguments.
* Creates a console on Windows.
* XXX - pop this up in a window of some sort on UNIX+X11 if the controlling
* terminal isn't the standard error?
*/
void
cmdarg_err_cont(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf_stderr(fmt, ap);
fprintf_stderr("\n");
va_end(ap);
}
/*
Once every 3 seconds we get a callback here which we use to update
the tap extensions.
*/
static gboolean
tap_update_cb(gpointer data _U_)
{
draw_tap_listeners(FALSE);
return TRUE;
}
/* Restart the tap update display timer with new configured interval */
void reset_tap_update_timer(void)
{
g_source_remove(tap_update_timer_id);
tap_update_timer_id = g_timeout_add(prefs.tap_update_interval, tap_update_cb, NULL);
}
void
protect_thread_critical_region(void)
{
/* Threading support for TAP:s removed
* http://www.wireshark.org/lists/wireshark-dev/200611/msg00199.html
* See the commit for removed code:
* http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
*/
}
void
unprotect_thread_critical_region(void)
{
/* Threading support for TAP:s removed
* http://www.wireshark.org/lists/wireshark-dev/200611/msg00199.html
*/
}
/*
* Periodically process outstanding hostname lookups. If we have new items,
* redraw the packet list and tree view.
*/
static gboolean
resolv_update_cb(gpointer data _U_)
{
/* Anything new show up? */
if (host_name_lookup_process(NULL)) {
if (gtk_widget_get_window(pkt_scrollw))
gdk_window_invalidate_rect(gtk_widget_get_window(pkt_scrollw), NULL, TRUE);
if (gtk_widget_get_window(tv_scrollw))
gdk_window_invalidate_rect(gtk_widget_get_window(tv_scrollw), NULL, TRUE);
}
/* Always check. Even if we don't do async lookups we could still get
passive updates, e.g. from DNS packets. */
return TRUE;
}
/* Set main_window_name and it's icon title to the capture filename */
static void
set_display_filename(capture_file *cf)
{
gchar *display_name;
gchar *window_name;
if (cf->filename) {
display_name = cf_get_display_name(cf);
window_name = g_strdup_printf("%s%s", cf->unsaved_changes ? "*" : "",
display_name);
g_free(display_name);
main_set_window_name(window_name);
g_free(window_name);
} else {
main_set_window_name("The Wireshark Network Analyzer");
}
}
/* Update various parts of the main window for a capture file "unsaved
changes" change - update the title to reflect whether there are
unsaved changes or not, and update the menus and toolbar to
enable or disable the "Save" operation. */
void
main_update_for_unsaved_changes(capture_file *cf)
{
set_display_filename(cf);
set_menus_for_capture_file(cf);
set_toolbar_for_capture_file(cf);
}
#ifdef HAVE_LIBPCAP
void
main_auto_scroll_live_changed(gboolean auto_scroll_live_in)
{
/* Update menubar and toolbar */
menu_auto_scroll_live_changed(auto_scroll_live_in);
toolbar_auto_scroll_live_changed(auto_scroll_live_in);
/* change auto scroll state */
auto_scroll_live = auto_scroll_live_in;
}
#endif
void
main_colorize_changed(gboolean packet_list_colorize)
{
/* Update menubar and toolbar */
menu_colorize_changed(packet_list_colorize);
toolbar_colorize_changed(packet_list_colorize);
/* change colorization */
if(packet_list_colorize != recent.packet_list_colorize) {
recent.packet_list_colorize = packet_list_colorize;
color_filters_enable(packet_list_colorize);
new_packet_list_colorize_packets();
}
}
static GtkWidget *close_dlg = NULL;
static void
priv_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)
{
recent.privs_warn_if_elevated = !simple_dialog_check_get(dialog);
}
#ifdef _WIN32
static void
npf_warning_dialog_cb(gpointer dialog, gint btn _U_, gpointer data _U_)
{
recent.privs_warn_if_no_npf = !simple_dialog_check_get(dialog);
}
#endif
static void
main_cf_cb_file_closing(capture_file *cf)
{
/* if we have more than 10000 packets, show a splash screen while closing */
/* XXX - don't know a better way to decide whether to show or not,
* as most of the time is spend in a single eth_clist_clear function,
* so we can't use a progress bar here! */
if(cf->count > 10000) {
close_dlg = simple_dialog(ESD_TYPE_STOP, ESD_BTN_NONE,
"%sClosing file!%s\n\nPlease wait ...",
simple_dialog_primary_start(),
simple_dialog_primary_end());
gtk_window_set_position(GTK_WINDOW(close_dlg), GTK_WIN_POS_CENTER_ON_PARENT);
}
/* Destroy all windows that refer to the
capture file we're closing. */
destroy_packet_wins();
/* Restore the standard title bar message. */
main_set_window_name("The Wireshark Network Analyzer");
/* Disable all menu items that make sense only if you have a capture. */
set_menus_for_capture_file(NULL);
set_toolbar_for_capture_file(NULL);
set_menus_for_captured_packets(FALSE);
set_menus_for_selected_packet(cf);
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
set_menus_for_selected_tree_row(cf);
/* Set up main window for no capture file. */
main_set_for_capture_file(FALSE);
main_window_update();
}
static void
main_cf_cb_file_closed(capture_file *cf _U_)
{
if(close_dlg != NULL) {
splash_destroy(close_dlg);
close_dlg = NULL;
}
}
static void
main_cf_cb_file_read_started(capture_file *cf _U_)
{
tap_param_dlg_update();
/* Set up main window for a capture file. */
main_set_for_capture_file(TRUE);
}
static void
main_cf_cb_file_read_finished(capture_file *cf)
{
gchar *dir_path;
if (!cf->is_tempfile && cf->filename) {
/* Add this filename to the list of recent files in the "Recent Files" submenu */
add_menu_recent_capture_file(cf->filename);
/* Remember folder for next Open dialog and save it in recent */
dir_path = get_dirname(g_strdup(cf->filename));
set_last_open_dir(dir_path);
g_free(dir_path);
}
/* Update the appropriate parts of the main window. */
main_update_for_unsaved_changes(cf);
/* Enable menu items that make sense if you have some captured packets. */
set_menus_for_captured_packets(TRUE);
}
static void
main_cf_cb_file_rescan_finished(capture_file *cf)
{
gchar *dir_path;
if (!cf->is_tempfile && cf->filename) {
/* Add this filename to the list of recent files in the "Recent Files" submenu */
add_menu_recent_capture_file(cf->filename);
/* Remember folder for next Open dialog and save it in recent */
dir_path = get_dirname(g_strdup(cf->filename));
set_last_open_dir(dir_path);
g_free(dir_path);
}
/* Update the appropriate parts of the main window. */
main_update_for_unsaved_changes(cf);
}
#ifdef HAVE_LIBPCAP
static GList *icon_list_create(
const char **icon16_xpm,
const char **icon32_xpm,
const char **icon48_xpm,
const char **icon64_xpm)
{
GList *icon_list = NULL;
GdkPixbuf * pixbuf16;
GdkPixbuf * pixbuf32;
GdkPixbuf * pixbuf48;
GdkPixbuf * pixbuf64;
if(icon16_xpm != NULL) {
pixbuf16 = gdk_pixbuf_new_from_xpm_data(icon16_xpm);
g_assert(pixbuf16);
icon_list = g_list_append(icon_list, pixbuf16);
}
if(icon32_xpm != NULL) {
pixbuf32 = gdk_pixbuf_new_from_xpm_data(icon32_xpm);
g_assert(pixbuf32);
icon_list = g_list_append(icon_list, pixbuf32);
}
if(icon48_xpm != NULL) {
pixbuf48 = gdk_pixbuf_new_from_xpm_data(icon48_xpm);
g_assert(pixbuf48);
icon_list = g_list_append(icon_list, pixbuf48);
}
if(icon64_xpm != NULL) {
pixbuf64 = gdk_pixbuf_new_from_xpm_data(icon64_xpm);
g_assert(pixbuf64);
icon_list = g_list_append(icon_list, pixbuf64);
}
return icon_list;
}
static void
main_capture_set_main_window_title(capture_options *capture_opts)
{
GString *title = g_string_new("");
g_string_append(title, "Capturing ");
g_string_append_printf(title, "from %s ", cf_get_tempfile_source(capture_opts->cf));
main_set_window_name(title->str);
g_string_free(title, TRUE);
}
static void
main_capture_cb_capture_prepared(capture_options *capture_opts)
{
static GList *icon_list = NULL;
main_capture_set_main_window_title(capture_opts);
if(icon_list == NULL) {
icon_list = icon_list_create(wsiconcap16_xpm, wsiconcap32_xpm, wsiconcap48_xpm, NULL);
}
gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
/* Disable menu items that make no sense if you're currently running
a capture. */
set_menus_for_capture_in_progress(TRUE);
set_capture_if_dialog_for_capture_in_progress(TRUE);
/* Don't set up main window for a capture file. */
main_set_for_capture_file(FALSE);
}
static void
main_capture_cb_capture_update_started(capture_options *capture_opts)
{
/* We've done this in "prepared" above, but it will be cleared while
switching to the next multiple file. */
main_capture_set_main_window_title(capture_opts);
set_menus_for_capture_in_progress(TRUE);
set_capture_if_dialog_for_capture_in_progress(TRUE);
/* Enable menu items that make sense if you have some captured
packets (yes, I know, we don't have any *yet*). */
set_menus_for_captured_packets(TRUE);
/* Set up main window for a capture file. */
main_set_for_capture_file(TRUE);
}
static void
main_capture_cb_capture_update_finished(capture_options *capture_opts)
{
capture_file *cf = capture_opts->cf;
static GList *icon_list = NULL;
/* The capture isn't stopping any more - it's stopped. */
capture_stopping = FALSE;
if (!cf->is_tempfile && cf->filename) {
/* Add this filename to the list of recent files in the "Recent Files" submenu */
add_menu_recent_capture_file(cf->filename);
}
/* Update the main window as appropriate */
main_update_for_unsaved_changes(cf);
/* Enable menu items that make sense if you're not currently running
a capture. */
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
/* Set up main window for a capture file. */
main_set_for_capture_file(TRUE);
if(icon_list == NULL) {
icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
}
gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
if(global_capture_opts.quit_after_cap) {
/* command line asked us to quit after the capture */
/* don't pop up a dialog to ask for unsaved files etc. */
main_do_quit();
}
}
static void
main_capture_cb_capture_fixed_started(capture_options *capture_opts _U_)
{
/* Don't set up main window for a capture file. */
main_set_for_capture_file(FALSE);
}
static void
main_capture_cb_capture_fixed_finished(capture_options *capture_opts _U_)
{
#if 0
capture_file *cf = capture_opts->cf;
#endif
static GList *icon_list = NULL;
/* The capture isn't stopping any more - it's stopped. */
capture_stopping = FALSE;
/*set_display_filename(cf);*/
/* Enable menu items that make sense if you're not currently running
a capture. */
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
/* Restore the standard title bar message */
/* (just in case we have trouble opening the capture file). */
main_set_window_name("The Wireshark Network Analyzer");
if(icon_list == NULL) {
icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
}
gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
/* We don't have loaded the capture file, this will be done later.
* For now we still have simply a blank screen. */
if(global_capture_opts.quit_after_cap) {
/* command line asked us to quit after the capture */
/* don't pop up a dialog to ask for unsaved files etc. */
main_do_quit();
}
}
static void
main_capture_cb_capture_stopping(capture_options *capture_opts _U_)
{
capture_stopping = TRUE;
set_menus_for_capture_stopping();
}
static void
main_capture_cb_capture_failed(capture_options *capture_opts _U_)
{
static GList *icon_list = NULL;
/* Capture isn't stopping any more. */
capture_stopping = FALSE;
/* the capture failed before the first packet was captured
reset title, menus and icon */
main_set_window_name("The Wireshark Network Analyzer");
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
main_set_for_capture_file(FALSE);
if(icon_list == NULL) {
icon_list = icon_list_create(wsicon16_xpm, wsicon32_xpm, wsicon48_xpm, wsicon64_xpm);
}
gtk_window_set_icon_list(GTK_WINDOW(top_level), icon_list);
if(global_capture_opts.quit_after_cap) {
/* command line asked us to quit after the capture */
/* don't pop up a dialog to ask for unsaved files etc. */
main_do_quit();
}
}
#endif /* HAVE_LIBPCAP */
static void
main_cf_cb_packet_selected(gpointer data)
{
capture_file *cf = data;
/* Display the GUI protocol tree and packet bytes.
XXX - why do we dump core if we call "proto_tree_draw()"
before calling "add_byte_views()"? */
add_main_byte_views(cf->edt);
main_proto_tree_draw(cf->edt->tree);
/* Note: Both string and hex value searches in the packet data produce a non-zero
search_pos if successful */
if(cf->search_in_progress &&
(cf->search_pos != 0 || (cf->string && cf->decode_data))) {
highlight_field(cf->edt->tvb, cf->search_pos,
(GtkTreeView *)tree_view_gbl, cf->edt->tree);
}
/* A packet is selected. */
set_menus_for_selected_packet(cf);
}
static void
main_cf_cb_packet_unselected(capture_file *cf)
{
/* Clear out the display of that packet. */
clear_tree_and_hex_views();
/* No packet is selected. */
set_menus_for_selected_packet(cf);
}
static void
main_cf_cb_field_unselected(capture_file *cf)
{
set_menus_for_selected_tree_row(cf);
}
static void
main_cf_callback(gint event, gpointer data, gpointer user_data _U_)
{
switch(event) {
case(cf_cb_file_closing):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closing");
main_cf_cb_file_closing(data);
break;
case(cf_cb_file_closed):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Closed");
main_cf_cb_file_closed(data);
break;
case(cf_cb_file_read_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read started");
main_cf_cb_file_read_started(data);
break;
case(cf_cb_file_read_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Read finished");
main_cf_cb_file_read_finished(data);
break;
case(cf_cb_file_reload_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload started");
main_cf_cb_file_read_started(data);
break;
case(cf_cb_file_reload_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Reload finished");
main_cf_cb_file_read_finished(data);
break;
case(cf_cb_file_rescan_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Rescan started");
break;
case(cf_cb_file_rescan_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Rescan finished");
main_cf_cb_file_rescan_finished(data);
break;
case(cf_cb_file_fast_save_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Fast save finished");
main_cf_cb_file_rescan_finished(data);
break;
case(cf_cb_packet_selected):
main_cf_cb_packet_selected(data);
break;
case(cf_cb_packet_unselected):
main_cf_cb_packet_unselected(data);
break;
case(cf_cb_field_unselected):
main_cf_cb_field_unselected(data);
break;
case(cf_cb_file_save_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save started");
break;
case(cf_cb_file_save_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save finished");
break;
case(cf_cb_file_save_failed):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save failed");
break;
case(cf_cb_file_save_stopped):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Save stopped");
break;
case(cf_cb_file_export_specified_packets_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Export specified packets started");
break;
case(cf_cb_file_export_specified_packets_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Export specified packets finished");
break;
case(cf_cb_file_export_specified_packets_failed):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Export specified packets failed");
break;
case(cf_cb_file_export_specified_packets_stopped):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: Export specified packets stopped");
break;
default:
g_warning("main_cf_callback: event %u unknown", event);
g_assert_not_reached();
}
}
#ifdef HAVE_LIBPCAP
static void
main_capture_callback(gint event, capture_options *capture_opts, gpointer user_data _U_)
{
#ifdef HAVE_GTKOSXAPPLICATION
GtkOSXApplication *theApp;
#endif
switch(event) {
case(capture_cb_capture_prepared):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture prepared");
main_capture_cb_capture_prepared(capture_opts);
break;
case(capture_cb_capture_update_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update started");
main_capture_cb_capture_update_started(capture_opts);
#ifdef HAVE_GTKOSXAPPLICATION
theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsiconcap48_xpm));
#endif
break;
case(capture_cb_capture_update_continue):
/*g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update continue");*/
break;
case(capture_cb_capture_update_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture update finished");
main_capture_cb_capture_update_finished(capture_opts);
break;
case(capture_cb_capture_fixed_started):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed started");
main_capture_cb_capture_fixed_started(capture_opts);
break;
case(capture_cb_capture_fixed_continue):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed continue");
break;
case(capture_cb_capture_fixed_finished):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture fixed finished");
main_capture_cb_capture_fixed_finished(capture_opts);
break;
case(capture_cb_capture_stopping):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture stopping");
/* Beware: this state won't be called, if the capture child
* closes the capturing on it's own! */
#ifdef HAVE_GTKOSXAPPLICATION
theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsicon64_xpm));
#endif
main_capture_cb_capture_stopping(capture_opts);
break;
case(capture_cb_capture_failed):
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "Callback: capture failed");
main_capture_cb_capture_failed(capture_opts);
break;
default:
g_warning("main_capture_callback: event %u unknown", event);
g_assert_not_reached();
}
}
#endif
static void
get_gtk_compiled_info(GString *str)
{
g_string_append(str, "with ");
g_string_append_printf(str,
#ifdef GTK_MAJOR_VERSION
"GTK+ %d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION,
GTK_MICRO_VERSION);
#else
"GTK+ (version unknown)");
#endif
g_string_append(str, ", ");
/* Cairo */
g_string_append(str, "with Cairo ");
g_string_append(str, CAIRO_VERSION_STRING);
g_string_append(str, ", ");
/* Pango */
g_string_append(str, "with Pango ");
g_string_append(str, PANGO_VERSION_STRING);
g_string_append(str, ", ");
}
static void
get_gui_compiled_info(GString *str)
{
epan_get_compiled_version_info(str);
g_string_append(str, ", ");
#ifdef HAVE_LIBPORTAUDIO
#ifdef PORTAUDIO_API_1
g_string_append(str, "with PortAudio <= V18");
#else /* PORTAUDIO_API_1 */
g_string_append(str, "with ");
g_string_append(str, Pa_GetVersionText());
#endif /* PORTAUDIO_API_1 */
#else /* HAVE_LIBPORTAUDIO */
g_string_append(str, "without PortAudio");
#endif /* HAVE_LIBPORTAUDIO */
g_string_append(str, ", ");
#ifdef HAVE_AIRPCAP
get_compiled_airpcap_version(str);
#else
g_string_append(str, "without AirPcap");
#endif
}
static void
get_gui_runtime_info(GString *str)
{
epan_get_runtime_version_info(str);
#ifdef HAVE_AIRPCAP
g_string_append(str, ", ");
get_runtime_airpcap_version(str);
#endif
if(u3_active()) {
g_string_append(str, ", ");
u3_runtime_info(str);
}
}
static e_prefs *
read_configuration_files(char **gdp_path, char **dp_path)
{
int gpf_open_errno, gpf_read_errno;
int cf_open_errno, df_open_errno;
int gdp_open_errno, gdp_read_errno;
int dp_open_errno, dp_read_errno;
char *gpf_path, *pf_path;
char *cf_path, *df_path;
int pf_open_errno, pf_read_errno;
e_prefs *prefs_p;
/* load the decode as entries of this profile */
load_decode_as_entries();
/* Read the preference files. */
prefs_p = read_prefs(&gpf_open_errno, &gpf_read_errno, &gpf_path,
&pf_open_errno, &pf_read_errno, &pf_path);
if (gpf_path != NULL) {
if (gpf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open global preferences file\n\"%s\": %s.", gpf_path,
g_strerror(gpf_open_errno));
}
if (gpf_read_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"I/O error reading global preferences file\n\"%s\": %s.", gpf_path,
g_strerror(gpf_read_errno));
}
}
if (pf_path != NULL) {
if (pf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open your preferences file\n\"%s\": %s.", pf_path,
g_strerror(pf_open_errno));
}
if (pf_read_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"I/O error reading your preferences file\n\"%s\": %s.", pf_path,
g_strerror(pf_read_errno));
}
g_free(pf_path);
pf_path = NULL;
}
#ifdef _WIN32
/* if the user wants a console to be always there, well, we should open one for him */
if (prefs_p->gui_console_open == console_open_always) {
create_console();
}
#endif
/* Read the capture filter file. */
read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
if (cf_path != NULL) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open your capture filter file\n\"%s\": %s.", cf_path,
g_strerror(cf_open_errno));
g_free(cf_path);
}
/* Read the display filter file. */
read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
if (df_path != NULL) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open your display filter file\n\"%s\": %s.", df_path,
g_strerror(df_open_errno));
g_free(df_path);
}
/* Read the disabled protocols file. */
read_disabled_protos_list(gdp_path, &gdp_open_errno, &gdp_read_errno,
dp_path, &dp_open_errno, &dp_read_errno);
if (*gdp_path != NULL) {
if (gdp_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open global disabled protocols file\n\"%s\": %s.",
*gdp_path, g_strerror(gdp_open_errno));
}
if (gdp_read_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"I/O error reading global disabled protocols file\n\"%s\": %s.",
*gdp_path, g_strerror(gdp_read_errno));
}
g_free(*gdp_path);
*gdp_path = NULL;
}
if (*dp_path != NULL) {
if (dp_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open your disabled protocols file\n\"%s\": %s.", *dp_path,
g_strerror(dp_open_errno));
}
if (dp_read_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"I/O error reading your disabled protocols file\n\"%s\": %s.", *dp_path,
g_strerror(dp_read_errno));
}
g_free(*dp_path);
*dp_path = NULL;
}
return prefs_p;
}
/* Check if there's something important to tell the user during startup.
* We want to do this *after* showing the main window so that any windows
* we pop up will be above the main window.
*/
static void
#ifdef _WIN32
check_and_warn_user_startup(gchar *cf_name)
#else
check_and_warn_user_startup(gchar *cf_name _U_)
#endif
{
gchar *cur_user, *cur_group;
gpointer priv_warning_dialog;
/* Tell the user not to run as root. */
if (running_with_special_privs() && recent.privs_warn_if_elevated) {
cur_user = get_cur_username();
cur_group = get_cur_groupname();
priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Running as user \"%s\" and group \"%s\".\n"
"This could be dangerous.\n\n"
"If you're running Wireshark this way in order to perform live capture, "
"you may want to be aware that there is a better way documented at\n"
"/usr/share/doc/wireshark-common/README.Debian", cur_user, cur_group);
g_free(cur_user);
g_free(cur_group);
simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
simple_dialog_set_cb(priv_warning_dialog, priv_warning_dialog_cb, NULL);
}
#ifdef _WIN32
/* Warn the user if npf.sys isn't loaded. */
if (!stdin_capture && !cf_name && !npf_sys_is_running() && recent.privs_warn_if_no_npf && get_os_major_version() >= 6) {
priv_warning_dialog = simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"The NPF driver isn't running. You may have trouble\n"
"capturing or listing interfaces.");
simple_dialog_check_set(priv_warning_dialog, "Don't show this message again.");
simple_dialog_set_cb(priv_warning_dialog, npf_warning_dialog_cb, NULL);
}
#endif
}
/* And now our feature presentation... [ fade to music ] */
int
main(int argc, char *argv[])
{
char *init_progfile_dir_error;
char *s;
int opt;
gboolean arg_error = FALSE;
extern int info_update_freq; /* Found in about_dlg.c. */
const gchar *filter;
#ifdef _WIN32
WSADATA wsaData;
#endif /* _WIN32 */
char *rf_path;
int rf_open_errno;
char *gdp_path, *dp_path;
int err;
#ifdef HAVE_LIBPCAP
gboolean start_capture = FALSE;
gboolean list_link_layer_types = FALSE;
GList *if_list;
gchar *err_str;
#else
gboolean capture_option_specified = FALSE;
#ifdef _WIN32
#ifdef HAVE_AIRPCAP
gchar *err_str;
#endif
#endif
#endif
gint pl_size = 280, tv_size = 95, bv_size = 75;
gchar *rc_file, *cf_name = NULL, *rfilter = NULL, *dfilter = NULL, *jfilter = NULL;
dfilter_t *rfcode = NULL;
gboolean rfilter_parse_failed = FALSE;
e_prefs *prefs_p;
char badopt;
GtkWidget *splash_win = NULL;
GLogLevelFlags log_flags;
guint go_to_packet = 0;
gboolean jump_backwards = FALSE;
dfilter_t *jump_to_filter = NULL;
int optind_initial;
int status;
#ifdef HAVE_GTKOSXAPPLICATION
GtkOSXApplication *theApp;
#endif
#ifdef HAVE_LIBPCAP
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
#define OPTSTRING_B "B:"
#else
#define OPTSTRING_B ""
#endif /* _WIN32 or HAVE_PCAP_CREATE */
#else /* HAVE_LIBPCAP */
#define OPTSTRING_B ""
#endif /* HAVE_LIBPCAP */
#ifdef HAVE_PCAP_CREATE
#define OPTSTRING_I "I"
#else
#define OPTSTRING_I ""
#endif
#define OPTSTRING "a:b:" OPTSTRING_B "c:C:d:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pr:R:Ss:t:u:vw:X:y:z:"
static const char optstring[] = OPTSTRING;
/* Set the C-language locale to the native environment. */
setlocale(LC_ALL, "");
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
#endif /* _WIN32 */
/*
* Get credential information for later use, and drop privileges
* before doing anything else.
* Let the user know if anything happened.
*/
init_process_policies();
relinquish_special_privs_perm();
/*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0], main);
/* initialize the funnel mini-api */
initialize_funnel_ops();
AirPDcapInitContext(&airpdcap_ctx);
#ifdef _WIN32
/* Load wpcap if possible. Do this before collecting the run-time version information */
load_wpcap();
/* ... and also load the packet.dll from wpcap */
wpcap_packet_load();
#ifdef HAVE_AIRPCAP
/* Load the airpcap.dll. This must also be done before collecting
* run-time version information. */
airpcap_dll_ret_val = load_airpcap();
switch (airpcap_dll_ret_val) {
case AIRPCAP_DLL_OK:
/* load the airpcap interfaces */
airpcap_if_list = get_airpcap_interface_list(&err, &err_str);
if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){
if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!");
g_free(err_str);
}
airpcap_if_active = NULL;
} else {
/* select the first ad default (THIS SHOULD BE CHANGED) */
airpcap_if_active = airpcap_get_default_if(airpcap_if_list);
}
break;
#if 0
/*
* XXX - Maybe we need to warn the user if one of the following happens???
*/
case AIRPCAP_DLL_OLD:
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_OLD\n");
break;
case AIRPCAP_DLL_ERROR:
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DLL_ERROR\n");
break;
case AIRPCAP_DLL_NOT_FOUND:
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s","AIRPCAP_DDL_NOT_FOUND\n");
break;
#endif
}
#endif /* HAVE_AIRPCAP */
/* Start windows sockets */
WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
#endif /* _WIN32 */
profile_store_persconffiles (TRUE);
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, get_gtk_compiled_info, get_gui_compiled_info);
/* Assemble the run-time version information string */
runtime_info_str = g_string_new("Running ");
get_runtime_version_info(runtime_info_str, get_gui_runtime_info);
/* Read the profile independent recent file. We have to do this here so we can */
/* set the profile before it can be set from the command line parameterts */
recent_read_static(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open common recent file\n\"%s\": %s.",
rf_path, g_strerror(rf_open_errno));
}
/* "pre-scan" the command line parameters, if we have "console only"
parameters. We do this so we don't start GTK+ if we're only showing
command-line help or version information.
XXX - this pre-scan is done before we start GTK+, so we haven't
run gtk_init() on the arguments. That means that GTK+ arguments
have not been removed from the argument list; those arguments
begin with "--", and will be treated as an error by getopt().
We thus ignore errors - *and* set "opterr" to 0 to suppress the
error messages. */
opterr = 0;
optind_initial = optind;
while ((opt = getopt(argc, argv, optstring)) != -1) {
switch (opt) {
case 'C': /* Configuration Profile */
if (profile_exists (optarg, FALSE)) {
set_profile_name (optarg);
} else {
cmdarg_err("Configuration Profile \"%s\" does not exist", optarg);
exit(1);
}
break;
case 'D': /* Print a list of capture devices and exit */
#ifdef HAVE_LIBPCAP
if_list = capture_interface_list(&err, &err_str);
if (if_list == NULL) {
switch (err) {
case CANT_GET_INTERFACE_LIST:
case DONT_HAVE_PCAP:
cmdarg_err("%s", err_str);
g_free(err_str);
break;
case NO_INTERFACES_FOUND:
cmdarg_err("There are no interfaces on which a capture can be done");
break;
}
exit(2);
}
capture_opts_print_interfaces(if_list);
free_interface_list(if_list);
exit(0);
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#endif
break;
case 'h': /* Print help and exit */
print_usage(TRUE);
exit(0);
break;
#ifdef _WIN32
case 'i':
if (strcmp(optarg, "-") == 0)
stdin_capture = TRUE;
break;
#endif
case 'P': /* Path settings - change these before the Preferences and alike are processed */
status = filesystem_opt(opt, optarg);
if(status != 0) {
cmdarg_err("-P flag \"%s\" failed (hint: is it quoted and existing?)", optarg);
exit(status);
}
break;
case 'v': /* Show version and exit */
show_version();
exit(0);
break;
case 'X':
/*
* Extension command line options have to be processed before
* we call epan_init() as they are supposed to be used by dissectors
* or taps very early in the registration process.
*/
ex_opt_add(optarg);
break;
case '?': /* Ignore errors - the "real" scan will catch them. */
break;
}
}
/* Init the "Open file" dialog directory */
/* (do this after the path settings are processed) */
/* Read the profile dependent (static part) of the recent file. */
/* Only the static part of it will be read, as we don't have the gui now to fill the */
/* recent lists which is done in the dynamic part. */
/* We have to do this already here, so command line parameters can overwrite these values. */
recent_read_profile_static(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open recent file\n\"%s\": %s.",
rf_path, g_strerror(rf_open_errno));
}
if (recent.gui_fileopen_remembered_dir &&
test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
set_last_open_dir(recent.gui_fileopen_remembered_dir);
} else {
set_last_open_dir(get_persdatafile_dir());
}
/* Set getopt index back to initial value, so it will start with the
first command line parameter again. Also reset opterr to 1, so that
error messages are printed by getopt().
XXX - this seems to work on most platforms, but time will tell.
The Single UNIX Specification says "The getopt() function need
not be reentrant", so this isn't guaranteed to work. The Mac
OS X 10.4[.x] getopt() man page says
In order to use getopt() to evaluate multiple sets of arguments, or to
evaluate a single set of arguments multiple times, the variable optreset
must be set to 1 before the second and each additional set of calls to
getopt(), and the variable optind must be reinitialized.
...
The optreset variable was added to make it possible to call the getopt()
function multiple times. This is an extension to the IEEE Std 1003.2
(``POSIX.2'') specification.
which I think comes from one of the other BSDs.
XXX - if we want to control all the command-line option errors, so
that we can display them where we choose (e.g., in a window), we'd
want to leave opterr as 0, and produce our own messages using optopt.
We'd have to check the value of optopt to see if it's a valid option
letter, in which case *presumably* the error is "this option requires
an argument but none was specified", or not a valid option letter,
in which case *presumably* the error is "this option isn't valid".
Some versions of getopt() let you supply a option string beginning
with ':', which means that getopt() will return ':' rather than '?'
for "this option requires an argument but none was specified", but
not all do. */
optind = optind_initial;
opterr = 1;
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
/* Set the current locale according to the program environment.
* We haven't localized anything, but some GTK widgets are localized
* (the file selection dialogue, for example).
* This also sets the C-language locale to the native environment. */
setlocale (LC_ALL, "");
/* Let GTK get its args (will need an X server, so do this after command line only commands handled) */
gtk_init (&argc, &argv);
cf_callback_add(main_cf_callback, NULL);
#ifdef HAVE_LIBPCAP
capture_callback_add(main_capture_callback, NULL);
#endif
cf_callback_add(statusbar_cf_callback, NULL);
#ifdef HAVE_LIBPCAP
capture_callback_add(statusbar_capture_callback, NULL);
#endif
/* Arrange that if we have no console window, and a GLib message logging
routine is called to log a message, we pop up a console window.
We do that by inserting our own handler for all messages logged
to the default domain; that handler pops up a console if necessary,
and then calls the default handler. */
/* We might want to have component specific log levels later ... */
log_flags =
G_LOG_LEVEL_ERROR|
G_LOG_LEVEL_CRITICAL|
G_LOG_LEVEL_WARNING|
G_LOG_LEVEL_MESSAGE|
G_LOG_LEVEL_INFO|
G_LOG_LEVEL_DEBUG|
G_LOG_FLAG_FATAL|G_LOG_FLAG_RECURSION;
g_log_set_handler(NULL,
log_flags,
console_log_handler, NULL /* user_data */);
g_log_set_handler(LOG_DOMAIN_MAIN,
log_flags,
console_log_handler, NULL /* user_data */);
#ifdef HAVE_LIBPCAP
g_log_set_handler(LOG_DOMAIN_CAPTURE,
log_flags,
console_log_handler, NULL /* user_data */);
g_log_set_handler(LOG_DOMAIN_CAPTURE_CHILD,
log_flags,
console_log_handler, NULL /* user_data */);
/* Set the initial values in the capture options. This might be overwritten
by preference settings and then again by the command line parameters. */
capture_opts_init(&global_capture_opts, &cfile);
#endif
/* Initialize whatever we need to allocate colors for GTK+ */
colors_init();
/* Non-blank filter means we're remote. Throttle splash screen and resolution updates. */
filter = get_conn_cfilter();
if ( *filter != '\0' ) {
info_update_freq = 1000; /* Milliseconds */
}
/* We won't come till here, if we had a "console only" command line parameter. */
splash_win = splash_new("Loading Wireshark ...");
if (init_progfile_dir_error != NULL) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Can't get pathname of Wireshark: %s.\n"
"It won't be possible to capture traffic.\n"
"Report this to the Wireshark developers.",
init_progfile_dir_error);
g_free(init_progfile_dir_error);
}
splash_update(RA_DISSECTORS, NULL, (gpointer)splash_win);
/* Register all dissectors; we must do this before checking for the
"-G" flag, as the "-G" flag dumps information registered by the
dissectors, and we must do it before we read the preferences, in
case any dissectors register preferences. */
epan_init(register_all_protocols,register_all_protocol_handoffs,
splash_update, (gpointer) splash_win,
failure_alert_box,open_failure_alert_box,read_failure_alert_box,
write_failure_alert_box);
splash_update(RA_LISTENERS, NULL, (gpointer)splash_win);
/* Register all tap listeners; we do this before we parse the arguments,
as the "-z" argument can specify a registered tap. */
/* we register the plugin taps before the other taps because
stats_tree taps plugins will be registered as tap listeners
by stats_tree_stat.c and need to registered before that */
#ifdef HAVE_PLUGINS
register_all_plugin_tap_listeners();
#endif
register_all_tap_listeners();
splash_update(RA_PREFERENCES, NULL, (gpointer)splash_win);
/* Now register the preferences for any non-dissector modules.
We must do that before we read the preferences as well. */
prefs_register_modules();
prefs_p = read_configuration_files (&gdp_path, &dp_path);
/* Removed thread code:
* http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
*/
/* this is to keep tap extensions updating once every 3 seconds */
tap_update_timer_id = g_timeout_add(prefs_p->tap_update_interval, tap_update_cb, NULL);
splash_update(RA_CONFIGURATION, NULL, (gpointer)splash_win);
proto_help_init();
cap_file_init(&cfile);
/* Fill in capture options with values from the preferences */
prefs_to_capture_opts();
/*#ifdef HAVE_LIBPCAP
if (global_capture_opts.all_ifaces->len == 0) {
scan_local_interfaces(&global_capture_opts);
}
#endif*/
/* Now get our args */
while ((opt = getopt(argc, argv, optstring)) != -1) {
switch (opt) {
/*** capture option specific ***/
case 'a': /* autostop criteria */
case 'b': /* Ringbuffer option */
case 'c': /* Capture xxx packets */
case 'f': /* capture filter */
case 'k': /* Start capture immediately */
case 'H': /* Hide capture info dialog box */
case 'p': /* Don't capture in promiscuous mode */
case 'i': /* Use interface x */
#ifdef HAVE_PCAP_CREATE
case 'I': /* Capture in monitor mode, if available */
#endif
case 's': /* Set the snapshot (capture) length */
case 'S': /* "Sync" mode: used for following file ala tail -f */
case 'w': /* Write to capture file xxx */
case 'y': /* Set the pcap data link type */
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
case 'B': /* Buffer size */
#endif /* _WIN32 or HAVE_PCAP_CREATE */
#ifdef HAVE_LIBPCAP
status = capture_opts_add_opt(&global_capture_opts, opt, optarg,
&start_capture);
if(status != 0) {
exit(status);
}
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#endif
break;
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
case 'K': /* Kerberos keytab file */
read_keytab_file(optarg);
break;
#endif
/*** all non capture option specific ***/
case 'C':
/* Configuration profile settings were already processed just ignore them this time*/
break;
case 'd':
dfilter = optarg;
break;
case 'j': /* Search backwards for a matching packet from filter in option J */
jump_backwards = TRUE;
break;
case 'g': /* Go to packet with the given packet number */
go_to_packet = get_positive_int(optarg, "go to packet");
break;
case 'J': /* Jump to the first packet which matches the filter criteria */
jfilter = optarg;
break;
case 'l': /* Automatic scrolling in live capture mode */
#ifdef HAVE_LIBPCAP
auto_scroll_live = TRUE;
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#endif
break;
case 'L': /* Print list of link-layer types and exit */
#ifdef HAVE_LIBPCAP
list_link_layer_types = TRUE;
#else
capture_option_specified = TRUE;
arg_error = TRUE;
#endif
break;
case 'm': /* Fixed-width font for the display */
g_free(prefs_p->gui_font_name);
prefs_p->gui_font_name = g_strdup(optarg);
break;
case 'n': /* No name resolution */
gbl_resolv_flags = RESOLV_NONE;
break;
case 'N': /* Select what types of addresses/port #s to resolve */
if (gbl_resolv_flags == RESOLV_ALL)
gbl_resolv_flags = RESOLV_NONE;
badopt = string_to_name_resolve(optarg, &gbl_resolv_flags);
if (badopt != '\0') {
cmdarg_err("-N specifies unknown resolving option '%c'; valid options are 'm', 'n', and 't'",
badopt);
exit(1);
}
break;
case 'o': /* Override preference from command line */
switch (prefs_set_pref(optarg)) {
case PREFS_SET_OK:
break;
case PREFS_SET_SYNTAX_ERR:
cmdarg_err("Invalid -o flag \"%s\"", optarg);
exit(1);
break;
case PREFS_SET_NO_SUCH_PREF:
/* not a preference, might be a recent setting */
switch (recent_set_arg(optarg)) {
case PREFS_SET_OK:
break;
case PREFS_SET_SYNTAX_ERR:
/* shouldn't happen, checked already above */
cmdarg_err("Invalid -o flag \"%s\"", optarg);
exit(1);
break;
case PREFS_SET_NO_SUCH_PREF:
case PREFS_SET_OBSOLETE:
cmdarg_err("-o flag \"%s\" specifies unknown preference/recent value",
optarg);
exit(1);
break;
default:
g_assert_not_reached();
}
break;
case PREFS_SET_OBSOLETE:
cmdarg_err("-o flag \"%s\" specifies obsolete preference",
optarg);
exit(1);
break;
default:
g_assert_not_reached();
}
break;
case 'P':
/* Path settings were already processed just ignore them this time*/
break;
case 'r': /* Read capture file xxx */
/* We may set "last_open_dir" to "cf_name", and if we change
"last_open_dir" later, we free the old value, so we have to
set "cf_name" to something that's been allocated. */
cf_name = g_strdup(optarg);
break;
case 'R': /* Read file filter */
rfilter = optarg;
break;
case 't': /* Time stamp type */
if (strcmp(optarg, "r") == 0)
timestamp_set_type(TS_RELATIVE);
else if (strcmp(optarg, "a") == 0)
timestamp_set_type(TS_ABSOLUTE);
else if (strcmp(optarg, "ad") == 0)
timestamp_set_type(TS_ABSOLUTE_WITH_DATE);
else if (strcmp(optarg, "d") == 0)
timestamp_set_type(TS_DELTA);
else if (strcmp(optarg, "dd") == 0)
timestamp_set_type(TS_DELTA_DIS);
else if (strcmp(optarg, "e") == 0)
timestamp_set_type(TS_EPOCH);
else if (strcmp(optarg, "u") == 0)
timestamp_set_type(TS_UTC);
else if (strcmp(optarg, "ud") == 0)
timestamp_set_type(TS_UTC_WITH_DATE);
else {
cmdarg_err("Invalid time stamp type \"%s\"", optarg);
cmdarg_err_cont("It must be \"r\" for relative, \"a\" for absolute,");
cmdarg_err_cont("\"ad\" for absolute with date, or \"d\" for delta.");
exit(1);
}
break;
case 'u': /* Seconds type */
if (strcmp(optarg, "s") == 0)
timestamp_set_seconds_type(TS_SECONDS_DEFAULT);
else if (strcmp(optarg, "hms") == 0)
timestamp_set_seconds_type(TS_SECONDS_HOUR_MIN_SEC);
else {
cmdarg_err("Invalid seconds type \"%s\"", optarg);
cmdarg_err_cont("It must be \"s\" for seconds or \"hms\" for hours, minutes and seconds.");
exit(1);
}
break;
case 'X':
/* ext ops were already processed just ignore them this time*/
break;
case 'z':
/* We won't call the init function for the stat this soon
as it would disallow MATE's fields (which are registered
by the preferences set callback) from being used as
part of a tap filter. Instead, we just add the argument
to a list of stat arguments. */
if (!process_stat_cmd_arg(optarg)) {
cmdarg_err("Invalid -z argument.");
cmdarg_err_cont(" -z argument must be one of :");
list_stat_cmd_args();
exit(1);
}
break;
default:
case '?': /* Bad flag - print usage message */
arg_error = TRUE;
break;
}
}
if (!arg_error) {
argc -= optind;
argv += optind;
if (argc >= 1) {
if (cf_name != NULL) {
/*
* Input file name specified with "-r" *and* specified as a regular
* command-line argument.
*/
cmdarg_err("File name specified both with -r and regular argument");
arg_error = TRUE;
} else {
/*
* Input file name not specified with "-r", and a command-line argument
* was specified; treat it as the input file name.
*
* Yes, this is different from tshark, where non-flag command-line
* arguments are a filter, but this works better on GUI desktops
* where a command can be specified to be run to open a particular
* file - yes, you could have "-r" as the last part of the command,
* but that's a bit ugly.
*/
cf_name = g_strdup(argv[0]);
}
argc--;
argv++;
}
if (argc != 0) {
/*
* Extra command line arguments were specified; complain.
*/
cmdarg_err("Invalid argument: %s", argv[0]);
arg_error = TRUE;
}
}
if (arg_error) {
#ifndef HAVE_LIBPCAP
if (capture_option_specified) {
cmdarg_err("This version of Wireshark was not built with support for capturing packets.");
}
#endif
print_usage(FALSE);
exit(1);
}
#ifdef HAVE_LIBPCAP
if (global_capture_opts.all_ifaces->len == 0) {
scan_local_interfaces(&global_capture_opts);
}
#endif
#ifdef HAVE_LIBPCAP
if (start_capture && list_link_layer_types) {
/* Specifying *both* is bogus. */
cmdarg_err("You can't specify both -L and a live capture.");
exit(1);
}
if (list_link_layer_types) {
/* We're supposed to list the link-layer types for an interface;
did the user also specify a capture file to be read? */
if (cf_name) {
/* Yes - that's bogus. */
cmdarg_err("You can't specify -L and a capture file to be read.");
exit(1);
}
/* No - did they specify a ring buffer option? */
if (global_capture_opts.multi_files_on) {
cmdarg_err("Ring buffer requested, but a capture isn't being done.");
exit(1);
}
} else {
/* We're supposed to do a live capture; did the user also specify
a capture file to be read? */
if (start_capture && cf_name) {
/* Yes - that's bogus. */
cmdarg_err("You can't specify both a live capture and a capture file to be read.");
exit(1);
}
/* No - was the ring buffer option specified and, if so, does it make
sense? */
if (global_capture_opts.multi_files_on) {
/* Ring buffer works only under certain conditions:
a) ring buffer does not work with temporary files;
b) real_time_mode and multi_files_on are mutually exclusive -
real_time_mode takes precedence;
c) it makes no sense to enable the ring buffer if the maximum
file size is set to "infinite". */
if (global_capture_opts.save_file == NULL) {
cmdarg_err("Ring buffer requested, but capture isn't being saved to a permanent file.");
global_capture_opts.multi_files_on = FALSE;
}
if (!global_capture_opts.has_autostop_filesize && !global_capture_opts.has_file_duration) {
cmdarg_err("Ring buffer requested, but no maximum capture file size or duration were specified.");
/* XXX - this must be redesigned as the conditions changed */
}
}
}
if (start_capture || list_link_layer_types) {
/* Did the user specify an interface to use? */
if (!capture_opts_trim_iface(&global_capture_opts,
(prefs_p->capture_device) ? get_if_name(prefs_p->capture_device) : NULL)) {
exit(2);
}
}
if (list_link_layer_types) {
/* Get the list of link-layer types for the capture devices. */
if_capabilities_t *caps;
guint i;
interface_t device;
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device.selected) {
#if defined(HAVE_PCAP_CREATE)
caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, &err_str);
#else
caps = capture_get_if_capabilities(device.name, FALSE, &err_str);
#endif
if (caps == NULL) {
cmdarg_err("%s", err_str);
g_free(err_str);
exit(2);
}
if (caps->data_link_types == NULL) {
cmdarg_err("The capture device \"%s\" has no data link types.", device.name);
exit(2);
}
#if defined(HAVE_PCAP_CREATE)
capture_opts_print_if_capabilities(caps, device.name, device.monitor_mode_supported);
#else
capture_opts_print_if_capabilities(caps, device.name, FALSE);
#endif
free_if_capabilities(caps);
}
}
exit(0);
}
capture_opts_trim_snaplen(&global_capture_opts, MIN_PACKET_SIZE);
capture_opts_trim_ring_num_files(&global_capture_opts);
#endif /* HAVE_LIBPCAP */
/* Notify all registered modules that have had any of their preferences
changed either from one of the preferences file or from the command
line that their preferences have changed. */
prefs_apply_all();
#ifdef HAVE_LIBPCAP
if ((global_capture_opts.num_selected == 0) &&
(prefs.capture_device != NULL)) {
guint i;
interface_t device;
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (!device.hidden && strcmp(device.display_name, prefs.capture_device) == 0) {
device.selected = TRUE;
global_capture_opts.num_selected++;
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
break;
}
}
}
#endif
/* disabled protocols as per configuration file */
if (gdp_path == NULL && dp_path == NULL) {
set_disabled_protos_list();
}
build_column_format_array(&cfile.cinfo, prefs_p->num_cols, TRUE);
/* read in rc file from global and personal configuration paths. */
rc_file = get_datafile_path(RC_FILE);
#if GTK_CHECK_VERSION(3,0,0)
/* XXX resolve later */
#else
gtk_rc_parse(rc_file);
g_free(rc_file);
rc_file = get_persconffile_path(RC_FILE, FALSE, FALSE);
gtk_rc_parse(rc_file);
#endif
g_free(rc_file);
font_init();
macros_init();
stock_icons_init();
/* close the splash screen, as we are going to open the main window now */
splash_destroy(splash_win);
/************************************************************************/
/* Everything is prepared now, preferences and command line was read in */
/* Pop up the main window. */
create_main_window(pl_size, tv_size, bv_size, prefs_p);
/* Read the dynamic part of the recent file, as we have the gui now ready for it. */
recent_read_dynamic(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open recent file\n\"%s\": %s.",
rf_path, g_strerror(rf_open_errno));
}
color_filters_enable(recent.packet_list_colorize);
/* rearrange all the widgets as we now have all recent settings ready for this */
main_widgets_rearrange();
/* Fill in column titles. This must be done after the top level window
is displayed.
XXX - is that still true, with fixed-width columns? */
menu_recent_read_finished();
#ifdef HAVE_LIBPCAP
main_auto_scroll_live_changed(auto_scroll_live);
#endif
switch (user_font_apply()) {
case FA_SUCCESS:
break;
case FA_FONT_NOT_RESIZEABLE:
/* "user_font_apply()" popped up an alert box. */
/* turn off zooming - font can't be resized */
case FA_FONT_NOT_AVAILABLE:
/* XXX - did we successfully load the un-zoomed version earlier?
If so, this *probably* means the font is available, but not at
this particular zoom level, but perhaps some other failure
occurred; I'm not sure you can determine which is the case,
however. */
/* turn off zooming - zoom level is unavailable */
default:
/* in any other case than FA_SUCCESS, turn off zooming */
recent.gui_zoom_level = 0;
/* XXX: would it be a good idea to disable zooming (insensitive GUI)? */
}
dnd_init(top_level);
color_filters_init();
decode_as_init();
#ifdef HAVE_LIBPCAP
capture_filter_init();
#endif
/* the window can be sized only, if it's not already shown, so do it now! */
main_load_window_geometry(top_level);
g_timeout_add(info_update_freq, resolv_update_cb, NULL);
if (dfilter) {
GtkWidget *filter_te;
filter_te = gtk_bin_get_child(GTK_BIN(g_object_get_data(G_OBJECT(top_level), E_DFILTER_CM_KEY)));
gtk_entry_set_text(GTK_ENTRY(filter_te), dfilter);
/* Run the display filter so it goes in effect. */
main_filter_packets(&cfile, dfilter, FALSE);
}
/* If we were given the name of a capture file, read it in now;
we defer it until now, so that, if we can't open it, and pop
up an alert box, the alert box is more likely to come up on
top of the main window - but before the preference-file-error
alert box, so, if we get one of those, it's more likely to come
up on top of us. */
if (cf_name) {
show_main_window(TRUE);
check_and_warn_user_startup(cf_name);
if (rfilter != NULL) {
if (!dfilter_compile(rfilter, &rfcode)) {
bad_dfilter_alert_box(top_level, rfilter);
rfilter_parse_failed = TRUE;
}
}
if (!rfilter_parse_failed) {
if (cf_open(&cfile, cf_name, FALSE, &err) == CF_OK) {
/* "cf_open()" succeeded, so it closed the previous
capture file, and thus destroyed any previous read filter
attached to "cf". */
cfile.rfcode = rfcode;
/* Open stat windows; we do so after creating the main window,
to avoid GTK warnings, and after successfully opening the
capture file, so we know we have something to compute stats
on, and after registering all dissectors, so that MATE will
have registered its field array and we can have a tap filter
with one of MATE's late-registered fields as part of the
filter. */
start_requested_stats();
/* Read the capture file. */
switch (cf_read(&cfile, FALSE)) {
case CF_READ_OK:
case CF_READ_ERROR:
/* Just because we got an error, that doesn't mean we were unable
to read any of the file; we handle what we could get from the
file. */
/* if the user told us to jump to a specific packet, do it now */
if(go_to_packet != 0) {
/* Jump to the specified frame number, kept for backward
compatibility. */
cf_goto_frame(&cfile, go_to_packet);
} else if (jfilter != NULL) {
/* try to compile given filter */
if (!dfilter_compile(jfilter, &jump_to_filter)) {
bad_dfilter_alert_box(top_level, jfilter);
} else {
/* Filter ok, jump to the first packet matching the filter
conditions. Default search direction is forward, but if
option d was given, search backwards */
cf_find_packet_dfilter(&cfile, jump_to_filter, jump_backwards);
}
}
break;
case CF_READ_ABORTED:
/* Exit now. */
exit(0);
break;
}
/* If the filename is not the absolute path, prepend the current dir. This happens
when wireshark is invoked from a cmd shell (e.g.,'wireshark -r file.pcap'). */
if (!g_path_is_absolute(cf_name)) {
char *old_cf_name = cf_name;
char *pwd = g_get_current_dir();
cf_name = g_strdup_printf("%s%s%s", pwd, G_DIR_SEPARATOR_S, cf_name);
g_free(old_cf_name);
g_free(pwd);
}
/* Save the name of the containing directory specified in the
path name, if any; we can write over cf_name, which is a
good thing, given that "get_dirname()" does write over its
argument. */
s = get_dirname(cf_name);
set_last_open_dir(s);
g_free(cf_name);
cf_name = NULL;
} else {
if (rfcode != NULL)
dfilter_free(rfcode);
cfile.rfcode = NULL;
show_main_window(FALSE);
/* Don't call check_and_warn_user_startup(): we did it above */
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
}
}
} else {
#ifdef HAVE_LIBPCAP
if (start_capture) {
if (global_capture_opts.save_file != NULL) {
/* Save the directory name for future file dialogs. */
/* (get_dirname overwrites filename) */
s = get_dirname(g_strdup(global_capture_opts.save_file));
set_last_open_dir(s);
g_free(s);
}
/* "-k" was specified; start a capture. */
show_main_window(FALSE);
check_and_warn_user_startup(cf_name);
/* If no user interfaces were specified on the command line,
copy the list of selected interfaces to the set of interfaces
to use for this capture. */
if (global_capture_opts.ifaces->len == 0)
collect_ifaces(&global_capture_opts);
if (capture_start(&global_capture_opts)) {
/* The capture started. Open stat windows; we do so after creating
the main window, to avoid GTK warnings, and after successfully
opening the capture file, so we know we have something to compute
stats on, and after registering all dissectors, so that MATE will
have registered its field array and we can have a tap filter with
one of MATE's late-registered fields as part of the filter. */
start_requested_stats();
}
} else {
show_main_window(FALSE);
check_and_warn_user_startup(cf_name);
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
}
/* if the user didn't supply a capture filter, use the one to filter out remote connections like SSH */
if (!start_capture && !global_capture_opts.default_options.cfilter) {
global_capture_opts.default_options.cfilter = g_strdup(get_conn_cfilter());
}
#else /* HAVE_LIBPCAP */
show_main_window(FALSE);
check_and_warn_user_startup(cf_name);
set_menus_for_capture_in_progress(FALSE);
set_capture_if_dialog_for_capture_in_progress(FALSE);
#endif /* HAVE_LIBPCAP */
}
/* register our pid if we are being run from a U3 device */
u3_register_pid();
profile_store_persconffiles (FALSE);
#ifdef HAVE_GTKOSXAPPLICATION
theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);
gtk_osxapplication_set_dock_icon_pixbuf(theApp,gdk_pixbuf_new_from_xpm_data(wsicon64_xpm));
gtk_osxapplication_ready(theApp);
#endif
g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_INFO, "Wireshark is up and ready to go");
/* we'll enter the GTK loop now and hand the control over to GTK ... */
gtk_main();
/* ... back from GTK, we're going down now! */
/* deregister our pid */
u3_deregister_pid();
epan_cleanup();
AirPDcapDestroyContext(&airpdcap_ctx);
#ifdef _WIN32
/* hide the (unresponsive) main window, while asking the user to close the console window */
gtk_widget_hide(top_level);
#ifdef HAVE_GTKOSXAPPLICATION
g_object_unref(theApp);
#endif
/* Shutdown windows sockets */
WSACleanup();
/* For some unknown reason, the "atexit()" call in "create_console()"
doesn't arrange that "destroy_console()" be called when we exit,
so we call it here if a console was created. */
destroy_console();
#endif
exit(0);
}
#ifdef _WIN32
/* We build this as a GUI subsystem application on Win32, so
"WinMain()", not "main()", gets called.
Hack shamelessly stolen from the Win32 port of the GIMP. */
#ifdef __GNUC__
#define _stdcall __attribute__((stdcall))
#endif
int _stdcall
WinMain (struct HINSTANCE__ *hInstance,
struct HINSTANCE__ *hPrevInstance,
char *lpszCmdLine,
int nCmdShow)
{
INITCOMMONCONTROLSEX comm_ctrl;
/*
* Initialize our DLL search path. MUST be called before LoadLibrary
* or g_module_open.
*/
ws_init_dll_search_path();
/* Initialize our controls. Required for native Windows file dialogs. */
memset (&comm_ctrl, 0, sizeof(comm_ctrl));
comm_ctrl.dwSize = sizeof(comm_ctrl);
/* Includes the animate, header, hot key, list view, progress bar,
* status bar, tab, tooltip, toolbar, trackbar, tree view, and
* up-down controls
*/
comm_ctrl.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&comm_ctrl);
/* RichEd20.DLL is needed for filter entries. */
ws_load_library("riched20.dll");
has_console = FALSE;
console_wait = FALSE;
return main (__argc, __argv);
}
/* The code to create and desstroy console windows should not be necessary,
at least as I read the GLib source code, as it looks as if GLib is, on
Win32, *supposed* to create a console window into which to display its
output.
That doesn't happen, however. I suspect there's something completely
broken about that code in GLib-for-Win32, and that it may be related
to the breakage that forces us to just call "printf()" on the message
rather than passing the message on to "g_log_default_handler()"
(which is the routine that does the aforementioned non-functional
console window creation). */
/*
* If this application has no console window to which its standard output
* would go, create one.
*/
void
create_console(void)
{
if (stdin_capture) {
/* We've been handed "-i -". Don't mess with stdio. */
return;
}
if (!has_console) {
/* We have no console to which to print the version string, so
create one and make it the standard input, output, and error. */
/*
* See if we have an existing console (i.e. we were run from a
* command prompt)
*/
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
if (AllocConsole()) {
console_wait = TRUE;
SetConsoleTitle(_T("Wireshark Debug Console"));
} else {
return; /* couldn't create console */
}
}
ws_freopen("CONIN$", "r", stdin);
ws_freopen("CONOUT$", "w", stdout);
ws_freopen("CONOUT$", "w", stderr);
fprintf(stdout, "\n");
fprintf(stderr, "\n");
/* Now register "destroy_console()" as a routine to be called just
before the application exits, so that we can destroy the console
after the user has typed a key (so that the console doesn't just
disappear out from under them, giving the user no chance to see
the message(s) we put in there). */
atexit(destroy_console);
/* Well, we have a console now. */
has_console = TRUE;
}
}
static void
destroy_console(void)
{
if (console_wait) {
printf("\n\nPress any key to exit\n");
_getch();
}
FreeConsole();
}
#endif /* _WIN32 */
static void
console_log_handler(const char *log_domain, GLogLevelFlags log_level,
const char *message, gpointer user_data _U_)
{
time_t curr;
struct tm *today;
const char *level;
/* ignore log message, if log_level isn't interesting based
upon the console log preferences.
If the preferences haven't been loaded loaded yet, display the
message anyway.
The default console_log_level preference value is such that only
ERROR, CRITICAL and WARNING level messages are processed;
MESSAGE, INFO and DEBUG level messages are ignored. */
if((log_level & G_LOG_LEVEL_MASK & prefs.console_log_level) == 0 &&
prefs.console_log_level != 0) {
return;
}
#ifdef _WIN32
if (prefs.gui_console_open != console_open_never || log_level & G_LOG_LEVEL_ERROR) {
/* the user wants a console or the application will terminate immediately */
create_console();
}
if (has_console) {
/* For some unknown reason, the above doesn't appear to actually cause
anything to be sent to the standard output, so we'll just splat the
message out directly, just to make sure it gets out. */
#endif
switch(log_level & G_LOG_LEVEL_MASK) {
case G_LOG_LEVEL_ERROR:
level = "Err ";
break;
case G_LOG_LEVEL_CRITICAL:
level = "Crit";
break;
case G_LOG_LEVEL_WARNING:
level = "Warn";
break;
case G_LOG_LEVEL_MESSAGE:
level = "Msg ";
break;
case G_LOG_LEVEL_INFO:
level = "Info";
break;
case G_LOG_LEVEL_DEBUG:
level = "Dbg ";
break;
default:
fprintf(stderr, "unknown log_level %u\n", log_level);
level = NULL;
g_assert_not_reached();
}
/* create a "timestamp" */
time(&curr);
today = localtime(&curr);
fprintf(stderr, "%02u:%02u:%02u %8s %s %s\n",
today->tm_hour, today->tm_min, today->tm_sec,
log_domain != NULL ? log_domain : "",
level, message);
#ifdef _WIN32
if(log_level & G_LOG_LEVEL_ERROR) {
/* wait for a key press before the following error handler will terminate the program
this way the user at least can read the error message */
printf("\n\nPress any key to exit\n");
_getch();
}
} else {
/* XXX - on UN*X, should we just use g_log_default_handler()?
We want the error messages to go to the standard output;
on Mac OS X, that will cause them to show up in various
per-user logs accessible through Console (details depend
on whether you're running 10.0 through 10.4 or running
10.5 and later), and, on other UN*X desktop environments,
if they don't show up in some form of console log, that's
a deficiency in that desktop environment. (Too bad
Windows doesn't set the standard output and error for
GUI apps to something that shows up in such a log.) */
g_log_default_handler(log_domain, log_level, message, user_data);
}
#endif
}
/*
* Helper for main_widgets_rearrange()
*/
static void foreach_remove_a_child(GtkWidget *widget, gpointer data) {
gtk_container_remove(GTK_CONTAINER(data), widget);
}
static GtkWidget *main_widget_layout(gint layout_content)
{
switch(layout_content) {
case(layout_pane_content_none):
return NULL;
case(layout_pane_content_plist):
return pkt_scrollw;
case(layout_pane_content_pdetails):
return tv_scrollw;
case(layout_pane_content_pbytes):
return byte_nb_ptr_gbl;
default:
g_assert_not_reached();
return NULL;
}
}
/*
* Rearrange the main window widgets
*/
void main_widgets_rearrange(void) {
GtkWidget *first_pane_widget1, *first_pane_widget2;
GtkWidget *second_pane_widget1, *second_pane_widget2;
gboolean split_top_left = FALSE;
/* be a bit faster */
gtk_widget_hide(main_vbox);
/* be sure we don't lose a widget while rearranging */
g_object_ref(G_OBJECT(menubar));
g_object_ref(G_OBJECT(main_tb));
g_object_ref(G_OBJECT(filter_tb));
#ifdef HAVE_AIRPCAP
g_object_ref(G_OBJECT(airpcap_tb));
#endif
g_object_ref(G_OBJECT(pkt_scrollw));
g_object_ref(G_OBJECT(tv_scrollw));
g_object_ref(G_OBJECT(byte_nb_ptr_gbl));
g_object_ref(G_OBJECT(statusbar));
g_object_ref(G_OBJECT(main_pane_v1));
g_object_ref(G_OBJECT(main_pane_v2));
g_object_ref(G_OBJECT(main_pane_h1));
g_object_ref(G_OBJECT(main_pane_h2));
g_object_ref(G_OBJECT(welcome_pane));
/* empty all containers participating */
gtk_container_foreach(GTK_CONTAINER(main_vbox), foreach_remove_a_child, main_vbox);
gtk_container_foreach(GTK_CONTAINER(main_pane_v1), foreach_remove_a_child, main_pane_v1);
gtk_container_foreach(GTK_CONTAINER(main_pane_v2), foreach_remove_a_child, main_pane_v2);
gtk_container_foreach(GTK_CONTAINER(main_pane_h1), foreach_remove_a_child, main_pane_h1);
gtk_container_foreach(GTK_CONTAINER(main_pane_h2), foreach_remove_a_child, main_pane_h2);
statusbar_widgets_emptying(statusbar);
/* add the menubar always at the top */
gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0);
/* main toolbar */
gtk_box_pack_start(GTK_BOX(main_vbox), main_tb, FALSE, TRUE, 0);
/* filter toolbar in toolbar area */
if (!prefs.filter_toolbar_show_in_statusbar) {
gtk_box_pack_start(GTK_BOX(main_vbox), filter_tb, FALSE, TRUE, 1);
}
#ifdef HAVE_AIRPCAP
/* airpcap toolbar */
gtk_box_pack_start(GTK_BOX(main_vbox), airpcap_tb, FALSE, TRUE, 1);
#endif
/* fill the main layout panes */
switch(prefs.gui_layout_type) {
case(layout_type_5):
main_first_pane = main_pane_v1;
main_second_pane = main_pane_v2;
split_top_left = FALSE;
break;
case(layout_type_2):
main_first_pane = main_pane_v1;
main_second_pane = main_pane_h1;
split_top_left = FALSE;
break;
case(layout_type_1):
main_first_pane = main_pane_v1;
main_second_pane = main_pane_h1;
split_top_left = TRUE;
break;
case(layout_type_4):
main_first_pane = main_pane_h1;
main_second_pane = main_pane_v1;
split_top_left = FALSE;
break;
case(layout_type_3):
main_first_pane = main_pane_h1;
main_second_pane = main_pane_v1;
split_top_left = TRUE;
break;
case(layout_type_6):
main_first_pane = main_pane_h1;
main_second_pane = main_pane_h2;
split_top_left = FALSE;
break;
default:
main_first_pane = NULL;
main_second_pane = NULL;
g_assert_not_reached();
}
if (split_top_left) {
first_pane_widget1 = main_second_pane;
second_pane_widget1 = main_widget_layout(prefs.gui_layout_content_1);
second_pane_widget2 = main_widget_layout(prefs.gui_layout_content_2);
first_pane_widget2 = main_widget_layout(prefs.gui_layout_content_3);
} else {
first_pane_widget1 = main_widget_layout(prefs.gui_layout_content_1);
first_pane_widget2 = main_second_pane;
second_pane_widget1 = main_widget_layout(prefs.gui_layout_content_2);
second_pane_widget2 = main_widget_layout(prefs.gui_layout_content_3);
}
if (first_pane_widget1 != NULL)
gtk_paned_add1(GTK_PANED(main_first_pane), first_pane_widget1);
if (first_pane_widget2 != NULL)
gtk_paned_add2(GTK_PANED(main_first_pane), first_pane_widget2);
if (second_pane_widget1 != NULL)
gtk_paned_pack1(GTK_PANED(main_second_pane), second_pane_widget1, TRUE, TRUE);
if (second_pane_widget2 != NULL)
gtk_paned_pack2(GTK_PANED(main_second_pane), second_pane_widget2, FALSE, FALSE);
gtk_box_pack_start(GTK_BOX(main_vbox), main_first_pane, TRUE, TRUE, 0);
/* welcome pane */
gtk_box_pack_start(GTK_BOX(main_vbox), welcome_pane, TRUE, TRUE, 0);
/* statusbar */
gtk_box_pack_start(GTK_BOX(main_vbox), statusbar, FALSE, TRUE, 0);
/* filter toolbar in statusbar hbox */
if (prefs.filter_toolbar_show_in_statusbar) {
gtk_box_pack_start(GTK_BOX(statusbar), filter_tb, FALSE, TRUE, 1);
}
/* statusbar widgets */
statusbar_widgets_pack(statusbar);
/* hide widgets on users recent settings */
main_widgets_show_or_hide();
gtk_widget_show(main_vbox);
}
static void
is_widget_visible(GtkWidget *widget, gpointer data)
{
gboolean *is_visible = data;
if (!*is_visible) {
if (gtk_widget_get_visible(widget))
*is_visible = TRUE;
}
}
void
main_widgets_show_or_hide(void)
{
gboolean main_second_pane_show;
if (recent.main_toolbar_show) {
gtk_widget_show(main_tb);
} else {
gtk_widget_hide(main_tb);
}
statusbar_widgets_show_or_hide(statusbar);
if (recent.filter_toolbar_show) {
gtk_widget_show(filter_tb);
} else {
gtk_widget_hide(filter_tb);
}
#ifdef HAVE_AIRPCAP
if (recent.airpcap_toolbar_show) {
gtk_widget_show(airpcap_tb);
} else {
gtk_widget_hide(airpcap_tb);
}
#endif
if (recent.packet_list_show && have_capture_file) {
gtk_widget_show(pkt_scrollw);
} else {
gtk_widget_hide(pkt_scrollw);
}
if (recent.tree_view_show && have_capture_file) {
gtk_widget_show(tv_scrollw);
} else {
gtk_widget_hide(tv_scrollw);
}
if (recent.byte_view_show && have_capture_file) {
gtk_widget_show(byte_nb_ptr_gbl);
} else {
gtk_widget_hide(byte_nb_ptr_gbl);
}
if (have_capture_file) {
gtk_widget_show(main_first_pane);
} else {
gtk_widget_hide(main_first_pane);
}
/*
* Is anything in "main_second_pane" visible?
* If so, show it, otherwise hide it.
*/
main_second_pane_show = FALSE;
gtk_container_foreach(GTK_CONTAINER(main_second_pane), is_widget_visible,
&main_second_pane_show);
if (main_second_pane_show) {
gtk_widget_show(main_second_pane);
} else {
gtk_widget_hide(main_second_pane);
}
if (!have_capture_file) {
if(welcome_pane) {
gtk_widget_show(welcome_pane);
}
} else {
gtk_widget_hide(welcome_pane);
}
}
/* called, when the window state changes (minimized, maximized, ...) */
static gboolean
window_state_event_cb (GtkWidget *widget _U_,
GdkEvent *event,
gpointer data _U_)
{
GdkWindowState new_window_state = ((GdkEventWindowState*)event)->new_window_state;
if( (event->type) == (GDK_WINDOW_STATE)) {
if(!(new_window_state & GDK_WINDOW_STATE_ICONIFIED)) {
/* we might have dialogs popped up while we where iconified,
show em now */
display_queued_messages();
}
}
return FALSE;
}
#define NO_SHIFT_MOD_MASK (GDK_MODIFIER_MASK & ~(GDK_SHIFT_MASK|GDK_MOD2_MASK|GDK_LOCK_MASK))
static gboolean
top_level_key_pressed_cb(GtkWidget *w _U_, GdkEventKey *event, gpointer user_data _U_)
{
if (event->keyval == GDK_F8) {
new_packet_list_next();
return TRUE;
} else if (event->keyval == GDK_F7) {
new_packet_list_prev();
return TRUE;
} else if (event->state & NO_SHIFT_MOD_MASK) {
return FALSE; /* Skip control, alt, and other modifiers */
/*
* A comment in gdkkeysyms.h says that it's autogenerated from
* freedesktop.org/x.org's keysymdef.h. Although the GDK docs
* don't explicitly say so, isprint() should work as expected
* for values < 127.
*/
} else if (isascii(event->keyval) && isprint(event->keyval)) {
/* Forward the keypress on to the display filter entry */
if (main_display_filter_widget && !gtk_widget_is_focus(main_display_filter_widget)) {
gtk_window_set_focus(GTK_WINDOW(top_level), main_display_filter_widget);
gtk_editable_set_position(GTK_EDITABLE(main_display_filter_widget), -1);
}
return FALSE;
}
return FALSE;
}
static void
create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs_p)
{
GtkAccelGroup *accel;
/* Main window */
top_level = window_new(GTK_WINDOW_TOPLEVEL, "");
main_set_window_name("The Wireshark Network Analyzer");
gtk_widget_set_name(top_level, "main window");
g_signal_connect(top_level, "delete_event", G_CALLBACK(main_window_delete_event_cb),
NULL);
g_signal_connect(G_OBJECT(top_level), "window_state_event",
G_CALLBACK(window_state_event_cb), NULL);
g_signal_connect(G_OBJECT(top_level), "key-press-event",
G_CALLBACK(top_level_key_pressed_cb), NULL );
/* Vertical container for menu bar, toolbar(s), paned windows and progress/info box */
main_vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
gtk_container_add(GTK_CONTAINER(top_level), main_vbox);
gtk_widget_show(main_vbox);
/* Menu bar */
menubar = main_menu_new(&accel);
#if defined(HAVE_IGE_MAC_INTEGRATION) || defined (HAVE_GTKOSXAPPLICATION)
/* Mac OS X native menus are created and displayed by main_menu_new() */
if(!prefs_p->gui_macosx_style) {
#endif
gtk_window_add_accel_group(GTK_WINDOW(top_level), accel);
gtk_widget_show(menubar);
#if defined(HAVE_IGE_MAC_INTEGRATION) || defined(HAVE_GTKOSXAPPLICATION)
}
#endif
/* Main Toolbar */
main_tb = toolbar_new();
gtk_widget_show (main_tb);
/* Filter toolbar */
filter_tb = filter_toolbar_new();
/* Packet list */
pkt_scrollw = new_packet_list_create();
gtk_widget_set_size_request(pkt_scrollw, -1, pl_size);
gtk_widget_show_all(pkt_scrollw);
/* Tree view */
tv_scrollw = main_tree_view_new(prefs_p, &tree_view_gbl);
gtk_widget_set_size_request(tv_scrollw, -1, tv_size);
gtk_widget_show(tv_scrollw);
g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_gbl)),
"changed", G_CALLBACK(tree_view_selection_changed_cb), NULL);
g_signal_connect(tree_view_gbl, "button_press_event", G_CALLBACK(popup_menu_handler),
g_object_get_data(G_OBJECT(popup_menu_object), PM_TREE_VIEW_KEY));
gtk_widget_show(tree_view_gbl);
/* Byte view. */
byte_nb_ptr_gbl = byte_view_new();
gtk_widget_set_size_request(byte_nb_ptr_gbl, -1, bv_size);
gtk_widget_show(byte_nb_ptr_gbl);
g_signal_connect(byte_nb_ptr_gbl, "button_press_event", G_CALLBACK(popup_menu_handler),
g_object_get_data(G_OBJECT(popup_menu_object), PM_BYTES_VIEW_KEY));
/* Panes for the packet list, tree, and byte view */
main_pane_v1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
gtk_widget_show(main_pane_v1);
main_pane_v2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
gtk_widget_show(main_pane_v2);
main_pane_h1 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show(main_pane_h1);
main_pane_h2 = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_widget_show(main_pane_h2);
#ifdef HAVE_AIRPCAP
airpcap_tb = airpcap_toolbar_new();
gtk_widget_show(airpcap_tb);
#endif
/* status bar */
statusbar = statusbar_new();
gtk_widget_show(statusbar);
/* Pane for the welcome screen */
welcome_pane = welcome_new();
gtk_widget_show(welcome_pane);
}
static void
show_main_window(gboolean doing_work)
{
main_set_for_capture_file(doing_work);
/*** we have finished all init things, show the main window ***/
gtk_widget_show(top_level);
/* the window can be maximized only, if it's visible, so do it after show! */
main_load_window_geometry(top_level);
/* process all pending GUI events before continue */
while (gtk_events_pending()) gtk_main_iteration();
/* Pop up any queued-up alert boxes. */
display_queued_messages();
/* Move the main window to the front, in case it isn't already there */
gdk_window_raise(gtk_widget_get_window(top_level));
#ifdef HAVE_AIRPCAP
airpcap_toolbar_show(airpcap_tb);
#endif /* HAVE_AIRPCAP */
}
/* Fill in capture options with values from the preferences */
void
prefs_to_capture_opts(void)
{
#ifdef HAVE_LIBPCAP
/* Set promiscuous mode from the preferences setting. */
/* the same applies to other preferences settings as well. */
global_capture_opts.default_options.promisc_mode = prefs.capture_prom_mode;
global_capture_opts.use_pcapng = prefs.capture_pcap_ng;
global_capture_opts.show_info = prefs.capture_show_info;
global_capture_opts.real_time_mode = prefs.capture_real_time;
auto_scroll_live = prefs.capture_auto_scroll;
#endif /* HAVE_LIBPCAP */
/* Set the name resolution code's flags from the preferences. */
gbl_resolv_flags = prefs.name_resolve;
}
static void copy_global_profile (const gchar *profile_name)
{
char *pf_dir_path, *pf_dir_path2, *pf_filename;
if (create_persconffile_profile(profile_name, &pf_dir_path) == -1) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't create directory\n\"%s\":\n%s.",
pf_dir_path, g_strerror(errno));
g_free(pf_dir_path);
}
if (copy_persconffile_profile(profile_name, profile_name, TRUE, &pf_filename,
&pf_dir_path, &pf_dir_path2) == -1) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno));
g_free(pf_filename);
g_free(pf_dir_path);
g_free(pf_dir_path2);
}
}
/* Change configuration profile */
void change_configuration_profile (const gchar *profile_name)
{
char *gdp_path, *dp_path;
char *rf_path;
int rf_open_errno;
/* First check if profile exists */
if (!profile_exists(profile_name, FALSE)) {
if (profile_exists(profile_name, TRUE)) {
/* Copy from global profile */
copy_global_profile (profile_name);
} else {
/* No personal and no global profile exists */
return;
}
}
/* Then check if changing to another profile */
if (profile_name && strcmp (profile_name, get_profile_name()) == 0) {
return;
}
/* Get the current geometry, before writing it to disk */
main_save_window_geometry(top_level);
if (profile_exists(get_profile_name(), FALSE)) {
/* Write recent file for profile we are leaving, if it still exists */
write_profile_recent();
}
/* Set profile name and update the status bar */
set_profile_name (profile_name);
profile_bar_update ();
filter_expression_reinit(FILTER_EXPRESSION_REINIT_DESTROY);
/* Reset current preferences and apply the new */
prefs_reset();
menu_prefs_reset();
(void) read_configuration_files (&gdp_path, &dp_path);
recent_read_profile_static(&rf_path, &rf_open_errno);
if (rf_path != NULL && rf_open_errno != 0) {
simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
"Could not open common recent file\n\"%s\": %s.",
rf_path, g_strerror(rf_open_errno));
}
if (recent.gui_fileopen_remembered_dir &&
test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
set_last_open_dir(recent.gui_fileopen_remembered_dir);
}
timestamp_set_type (recent.gui_time_format);
timestamp_set_seconds_type (recent.gui_seconds_format);
color_filters_enable(recent.packet_list_colorize);
prefs_to_capture_opts();
prefs_apply_all();
macros_post_update();
/* Update window view and redraw the toolbar */
main_titlebar_update();
filter_expression_reinit(FILTER_EXPRESSION_REINIT_CREATE);
toolbar_redraw_all();
/* Enable all protocols and disable from the disabled list */
proto_enable_all();
if (gdp_path == NULL && dp_path == NULL) {
set_disabled_protos_list();
}
/* Reload color filters */
color_filters_reload();
/* Reload list of interfaces on welcome page */
welcome_if_panel_reload();
/* Recreate the packet list according to new preferences */
new_packet_list_recreate ();
cfile.cinfo.columns_changed = FALSE; /* Reset value */
user_font_apply();
/* Update menus with new recent values */
menu_recent_read_finished();
/* Reload pane geometry, must be done after recreating the list */
main_pane_load_window_geometry();
}
/** redissect packets and update UI */
void redissect_packets(void)
{
cf_redissect_packets(&cfile);
status_expert_update();
}
#ifdef HAVE_LIBPCAP
guint get_interface_type(gchar *name, gchar *description)
{
#if defined(__linux__)
ws_statb64 statb;
char *wireless_path;
#endif
#if defined(_WIN32)
/*
* Much digging failed to reveal any obvious way to get something such
* as the SNMP MIB-II ifType value for an interface:
*
* http://www.iana.org/assignments/ianaiftype-mib
*
* by making some NDIS request.
*/
if (description && (strstr(description,"generic dialup") != NULL ||
strstr(description,"PPP/SLIP") != NULL )) {
return IF_DIALUP;
} else if (description && (strstr(description,"Wireless") != NULL ||
strstr(description,"802.11") != NULL)) {
return IF_WIRELESS;
} else if (description && strstr(description,"AirPcap") != NULL ||
strstr(name,"airpcap")) {
return IF_AIRPCAP;
} else if (description && strstr(description, "Bluetooth") != NULL ) {
return IF_BLUETOOTH;
}
#elif defined(__APPLE__)
/*
* XXX - yes, fetching all the network addresses for an interface
* gets you an AF_LINK address, of type "struct sockaddr_dl", and,
* yes, that includes an SNMP MIB-II ifType value.
*
* However, it's IFT_ETHER, i.e. Ethernet, for AirPort interfaces,
* not IFT_IEEE80211 (which isn't defined in OS X in any case).
*
* Perhaps some other BSD-flavored OSes won't make this mistake;
* however, FreeBSD 7.0 and OpenBSD 4.2, at least, appear to have
* made the same mistake, at least for my Belkin ZyDAS stick.
*
* XXX - this is wrong on a MacBook Air, as en0 is the AirPort
* interface, and it's also wrong on a Mac that has no AirPort
* interfaces and has multiple Ethernet interfaces.
*
* The SystemConfiguration framework is your friend here.
* SCNetworkInterfaceGetInterfaceType() will get the interface
* type. SCNetworkInterfaceCopyAll() gets all network-capable
* interfaces on the system; SCNetworkInterfaceGetBSDName()
* gets the "BSD name" of the interface, so we look for
* an interface with the specified "BSD name" and get its
* interface type. The interface type is a CFString, and:
*
* kSCNetworkInterfaceTypeIEEE80211 means IF_WIRELESS;
* kSCNetworkInterfaceTypeBluetooth means IF_BLUETOOTH;
* kSCNetworkInterfaceTypeModem or
* kSCNetworkInterfaceTypePPP or
* maybe kSCNetworkInterfaceTypeWWAN means IF_DIALUP
*/
if (strcmp(name, "en1") == 0) {
return IF_WIRELESS;
}
/*
* XXX - PPP devices have names beginning with "ppp" and an IFT_ of
* IFT_PPP, but they could be dial-up, or PPPoE, or mobile phone modem,
* or VPN, or... devices. One might have to dive into the bowels of
* IOKit to find out.
*/
/*
* XXX - there's currently no support for raw Bluetooth capture,
* and IP-over-Bluetooth devices just look like fake Ethernet
* devices. There's also Bluetooth modem support, but that'll
* probably just give you a device that looks like a PPP device.
*/
#elif defined(__linux__)
/*
* Look for /sys/class/net/{device}/wireless.
*/
wireless_path = g_strdup_printf("/sys/class/net/%s/wireless", name);
if (wireless_path != NULL) {
if (ws_stat64(wireless_path, &statb) == 0) {
g_free(wireless_path);
return IF_WIRELESS;
}
}
/*
* Bluetooth devices.
*
* XXX - this is for raw Bluetooth capture; what about IP-over-Bluetooth
* devices?
*/
if ( strstr(name,"bluetooth") != NULL) {
return IF_BLUETOOTH;
}
/*
* USB devices.
*/
if ( strstr(name,"usbmon") != NULL ) {
return IF_USB;
}
#endif
/*
* Bridge, NAT, or host-only interfaces on VMWare hosts have the name
* vmnet[0-9]+ or VMnet[0-9+ on Windows. Guests might use a native
* (LANCE or E1000) driver or the vmxnet driver. These devices have an
* IFT_ of IFT_ETHER, so we have to check the name.
*/
if ( g_ascii_strncasecmp(name, "vmnet", 5) == 0) {
return IF_VIRTUAL;
}
if ( g_ascii_strncasecmp(name, "vmxnet", 6) == 0) {
return IF_VIRTUAL;
}
if (description && strstr(description, "VMware") != NULL ) {
return IF_VIRTUAL;
}
return IF_WIRED;
}
/*
* Fetch the list of local interfaces with capture_interface_list()
* and set the list of "all interfaces" in *capture_opts to include
* those interfaces.
*/
void
scan_local_interfaces(capture_options* capture_opts)
{
GList *if_entry, *lt_entry, *if_list;
if_info_t *if_info, *temp;
char *if_string;
gchar *descr;
if_capabilities_t *caps=NULL;
gint linktype_count;
cap_settings_t cap_settings;
GSList *curr_addr;
int ips = 0, i, err;
guint count = 0, j;
if_addr_t *addr, *temp_addr;
link_row *link = NULL;
data_link_info_t *data_link_info;
interface_t device;
GString *ip_str;
interface_options interface_opts;
gboolean found = FALSE;
if (capture_opts->all_ifaces->len > 0) {
for (i = (int)capture_opts->all_ifaces->len-1; i >= 0; i--) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i);
if (device.local) {
capture_opts->all_ifaces = g_array_remove_index(capture_opts->all_ifaces, i);
}
}
}
/* Scan through the list and build a list of strings to display. */
if_list = capture_interface_list(&err, NULL);
count = 0;
for (if_entry = if_list; if_entry != NULL; if_entry = g_list_next(if_entry)) {
if_info = if_entry->data;
ip_str = g_string_new("");
ips = 0;
if (strstr(if_info->name, "rpcap:")) {
continue;
}
device.name = g_strdup(if_info->name);
device.hidden = FALSE;
device.locked = FALSE;
temp = g_malloc0(sizeof(if_info_t));
temp->name = g_strdup(if_info->name);
temp->description = g_strdup(if_info->description);
temp->loopback = if_info->loopback;
/* Is this interface hidden and, if so, should we include it anyway? */
/* Do we have a user-supplied description? */
descr = capture_dev_user_descr_find(if_info->name);
if (descr != NULL) {
/* Yes, we have a user-supplied description; use it. */
if_string = g_strdup_printf("%s: %s", descr, if_info->name);
g_free(descr);
} else {
/* No, we don't have a user-supplied description; did we get
one from the OS or libpcap? */
if (if_info->description != NULL) {
/* Yes - use it. */
if_string = g_strdup_printf("%s: %s", if_info->description, if_info->name);
} else {
/* No. */
if_string = g_strdup(if_info->name);
}
}
if (if_info->loopback) {
device.display_name = g_strdup_printf("%s (loopback)", if_string);
} else {
device.display_name = g_strdup(if_string);
}
g_free(if_string);
device.selected = FALSE;
if (prefs_is_capture_device_hidden(if_info->name)) {
device.hidden = TRUE;
}
device.type = get_interface_type(if_info->name, if_info->description);
cap_settings = capture_get_cap_settings(if_info->name);
caps = capture_get_if_capabilities(if_info->name, cap_settings.monitor_mode, NULL);
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
temp_addr = g_malloc0(sizeof(if_addr_t));
if (ips != 0) {
g_string_append(ip_str, "\n");
}
addr = (if_addr_t *)curr_addr->data;
if (addr) {
temp_addr->ifat_type = addr->ifat_type;
switch (addr->ifat_type) {
case IF_AT_IPv4:
temp_addr->addr.ip4_addr = addr->addr.ip4_addr;
g_string_append(ip_str, ip_to_str((guint8 *)&addr->addr.ip4_addr));
break;
case IF_AT_IPv6:
memcpy(temp_addr->addr.ip6_addr, addr->addr.ip6_addr, sizeof(addr->addr));
g_string_append(ip_str, ip6_to_str((struct e_in6_addr *)&addr->addr.ip6_addr));
break;
default:
/* In case we add non-IP addresses */
break;
}
} else {
g_free(temp_addr);
temp_addr = NULL;
}
if (temp_addr) {
temp->addrs = g_slist_append(temp->addrs, temp_addr);
}
}
#ifdef HAVE_PCAP_REMOTE
device.local = TRUE;
device.remote_opts.src_type = CAPTURE_IFLOCAL;
device.remote_opts.remote_host_opts.remote_host = g_strdup(capture_opts->default_options.remote_host);
device.remote_opts.remote_host_opts.remote_port = g_strdup(capture_opts->default_options.remote_port);
device.remote_opts.remote_host_opts.auth_type = capture_opts->default_options.auth_type;
device.remote_opts.remote_host_opts.auth_username = g_strdup(capture_opts->default_options.auth_username);
device.remote_opts.remote_host_opts.auth_password = g_strdup(capture_opts->default_options.auth_password);
device.remote_opts.remote_host_opts.datatx_udp = capture_opts->default_options.datatx_udp;
device.remote_opts.remote_host_opts.nocap_rpcap = capture_opts->default_options.nocap_rpcap;
device.remote_opts.remote_host_opts.nocap_local = capture_opts->default_options.nocap_local;
#endif
#ifdef HAVE_PCAP_SETSAMPLING
device.remote_opts.sampling_method = capture_opts->default_options.sampling_method;
device.remote_opts.sampling_param = capture_opts->default_options.sampling_param;
#endif
linktype_count = 0;
device.links = NULL;
if (caps != NULL) {
#if defined(HAVE_PCAP_CREATE)
device.monitor_mode_enabled = cap_settings.monitor_mode;
device.monitor_mode_supported = caps->can_set_rfmon;
#endif
for (lt_entry = caps->data_link_types; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) {
data_link_info = lt_entry->data;
if (linktype_count == 0) {
device.active_dlt = data_link_info->dlt;
}
link = (link_row *)g_malloc(sizeof(link_row));
if (data_link_info->description != NULL) {
link->dlt = data_link_info->dlt;
link->name = g_strdup_printf("%s", data_link_info->description);
} else {
link->dlt = -1;
link->name = g_strdup_printf("%s (not supported)", data_link_info->name);
}
device.links = g_list_append(device.links, link);
linktype_count++;
}
} else {
cap_settings.monitor_mode = FALSE;
#if defined(HAVE_PCAP_CREATE)
device.monitor_mode_enabled = FALSE;
device.monitor_mode_supported = FALSE;
#endif
device.active_dlt = -1;
}
device.addresses = g_strdup(ip_str->str);
device.no_addresses = ips;
device.local = TRUE;
device.if_info = *temp;
device.last_packets = 0;
device.pmode = capture_opts->default_options.promisc_mode;
device.has_snaplen = capture_opts->default_options.has_snaplen;
device.snaplen = capture_opts->default_options.snaplen;
device.cfilter = g_strdup(capture_opts->default_options.cfilter);
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
device.buffer = 1;
#endif
if (capture_opts->ifaces->len > 0) {
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
if (strcmp(interface_opts.name, device.name) == 0) {
#if defined(HAVE_PCAP_CREATE)
device.buffer = interface_opts.buffer_size;
device.monitor_mode_enabled = interface_opts.monitor_mode;
#endif
device.pmode = interface_opts.promisc_mode;
device.has_snaplen = interface_opts.has_snaplen;
device.snaplen = interface_opts.snaplen;
device.cfilter = g_strdup(interface_opts.cfilter);
device.active_dlt = interface_opts.linktype;
device.selected = TRUE;
capture_opts->num_selected++;
break;
}
}
}
if (capture_opts->all_ifaces->len <= count) {
g_array_append_val(capture_opts->all_ifaces, device);
count = capture_opts->all_ifaces->len;
} else {
g_array_insert_val(capture_opts->all_ifaces, count, device);
}
if (caps != NULL) {
free_if_capabilities(caps);
}
g_string_free(ip_str, TRUE);
count++;
}
free_interface_list(if_list);
/* see whether there are additional interfaces in ifaces */
for (j = 0; j < capture_opts->ifaces->len; j++) {
interface_opts = g_array_index(capture_opts->ifaces, interface_options, j);
found = FALSE;
for (i = 0; i < (int)capture_opts->all_ifaces->len; i++) {
device = g_array_index(capture_opts->all_ifaces, interface_t, i);
if (strcmp(device.name, interface_opts.name) == 0) {
found = TRUE;
break;
}
}
if (!found) { /* new interface, maybe a pipe */
device.name = g_strdup(interface_opts.name);
device.display_name = g_strdup_printf("%s", device.name);
device.hidden = FALSE;
device.selected = TRUE;
device.type = IF_PIPE;
#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
device.buffer = interface_opts.buffer_size;
#endif
#if defined(HAVE_PCAP_CREATE)
device.monitor_mode_enabled = interface_opts.monitor_mode;
device.monitor_mode_supported = FALSE;
#endif
device.pmode = interface_opts.promisc_mode;
device.has_snaplen = interface_opts.has_snaplen;
device.snaplen = interface_opts.snaplen;
device.cfilter = g_strdup(interface_opts.cfilter);
device.active_dlt = interface_opts.linktype;
device.addresses = NULL;
device.no_addresses = 0;
device.last_packets = 0;
device.links = NULL;
device.local = TRUE;
device.locked = FALSE;
device.if_info.name = g_strdup(interface_opts.name);
device.if_info.description = g_strdup(interface_opts.descr);
device.if_info.addrs = NULL;
device.if_info.loopback = FALSE;
g_array_append_val(capture_opts->all_ifaces, device);
capture_opts->num_selected++;
}
}
}
void hide_interface(gchar* new_hide)
{
gchar *tok;
guint i;
interface_t device;
gboolean found = FALSE;
GList *hidden_devices = NULL, *entry;
if (new_hide != NULL) {
for (tok = strtok (new_hide, ","); tok; tok = strtok(NULL, ",")) {
hidden_devices = g_list_append(hidden_devices, tok);
}
}
for (i = 0; i < global_capture_opts.all_ifaces->len; i++) {
device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
found = FALSE;
for (entry = hidden_devices; entry != NULL; entry = g_list_next(entry)) {
if (strcmp(entry->data, device.name)==0) {
device.hidden = TRUE;
if (device.selected) {
device.selected = FALSE;
global_capture_opts.num_selected--;
}
found = TRUE;
break;
}
}
if (!found) {
device.hidden = FALSE;
}
global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, i);
g_array_insert_val(global_capture_opts.all_ifaces, i, device);
}
}
#endif
|