aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-vnc.c
blob: 8bfd03e1154da5c3e8fe1bbae79ced9fd72ec118 (plain)
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
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
/* packet-vnc.c
 * Routines for VNC dissection (Virtual Network Computing)
 * Copyright 2005, Ulf Lamping <ulf.lamping@web.de>
 * Copyright 2006-2007, Stephen Fisher (see AUTHORS file)
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/* Dissection of the VNC (Virtual Network Computing) network traffic.
 *
 * All versions of RealVNC and TightVNC are supported.
 * Note: The addition of TightVNC support is not yet complete.
 *
 * Several VNC implementations available, see:
 * http://www.realvnc.com/
 * http://www.tightvnc.com/
 * http://ultravnc.sourceforge.net/
 * [Fedora TigerVNC]
 * ...
 *
 * The protocol itself is known as RFB - Remote Frame Buffer Protocol.
 *
 * This code is based on the protocol specification:
 *   http://www.realvnc.com/docs/rfbproto.pdf
 *  and the RealVNC free edition & TightVNC source code
 *  Note: rfbproto.rst [ https://github.com/svn2github/tigervnc/blob/master/rfbproto/rfbproto.rst ]
 *        seems to have additional information over rfbproto.pdf.
 */

/* XXX:
 *  This dissector adds items to the protocol tree before completing re-assembly
 *   of a VNC PDU which extends over more than one TCP segment.
 *  This is not correct. As noted in Bug #5366 (and elsewhere), the correct method
 *  is that:
 *   "one must walk over all the message first, to determine its exact length
 *    (one of the characteristics of the protocol, hard to determine prior to
 *    going over the message what its final size would be)".
 *
 *  The original method of reassembly:
 *    When more data is needed to continue dissecting a PDU, repeatedly request
 *    a few additional bytes (for one or a few more fields of the PDU).
 *   This resulted in 'one-pass' tshark dissection redissecting
 *    the PDU repeatedly many, many times with each time dissecting
 *    the PDU with one or a few more additional fields.
 *    This generated *lots* of (repeated) output since a reassembled
 *    VNC PDU can contain many fields (each of short length).
 *    It also resulted in the fragment table containing many, many small fragments
 *     for VNC PDUS containing many small fields.
 *
 *  The current reassembly method:
 *    Use DESEGMENT_ONE_MORE_SEGMENT when requesting additional data for a PDU.
 *    This significantly reduces the amount of repeated data in a dissection,
 *    but will still result in "partial" repeated dissection output in some cases.
 */

/* (Somewhat random notes while reviewing the code):
   Check types, etc against IANA list
   Optimize: Do col_set(..., COL_INFO) once (after fetching message type & before dispatching ?)
   Dispatch via a message table (instead of using a switch(...)
   Worry about globals (vnc_bytes_per_pixel & nc_depth): "Global so they keep their value between packets"
   Msg type 150: client-server: enable/disable (1+9 bytes); server-client: endofContinousUpdates(1+0 bytes) ?
*/

#include "config.h"

#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/proto_data.h>
#include "packet-x11.h" /* This contains the extern for the X11 value_string_ext
			 * "x11_keysym_vals_source_ext" that VNC uses. */

void proto_register_vnc(void);

typedef enum {
	VNC_SECURITY_TYPE_INVALID       =  0,
	VNC_SECURITY_TYPE_NONE          =  1,
	VNC_SECURITY_TYPE_VNC           =  2,
	VNC_SECURITY_TYPE_RA2           =  5,
	VNC_SECURITY_TYPE_RA2ne         =  6,
	VNC_SECURITY_TYPE_TIGHT         = 16,
	VNC_SECURITY_TYPE_ULTRA         = 17,
	VNC_SECURITY_TYPE_TLS           = 18,
	VNC_SECURITY_TYPE_VENCRYPT      = 19,
	VNC_SECURITY_TYPE_GTK_VNC_SASL  = 20,
	VNC_SECURITY_TYPE_MD5_HASH_AUTH = 21,
	VNC_SECURITY_TYPE_XVP           = 22,
	VNC_SECURITY_TYPE_ARD           = 30,
	VNC_TIGHT_AUTH_TGHT_ULGNAUTH	= 119,
	VNC_TIGHT_AUTH_TGHT_XTRNAUTH	= 130
} vnc_security_types_e;

static const value_string vnc_security_types_vs[] = {
	{ VNC_SECURITY_TYPE_INVALID,      "Invalid"              },
	{ VNC_SECURITY_TYPE_NONE,         "None"                 },
	{ VNC_SECURITY_TYPE_VNC,          "VNC"                  },
	{ VNC_SECURITY_TYPE_RA2,          "RA2"                  },
	{ VNC_SECURITY_TYPE_RA2ne,        "RA2ne"                },
	{ VNC_SECURITY_TYPE_TIGHT,        "Tight"                },
	{ VNC_SECURITY_TYPE_ULTRA,        "Ultra"                },
	{ VNC_SECURITY_TYPE_TLS,          "TLS"                  },
	{ VNC_SECURITY_TYPE_VENCRYPT,     "VeNCrypt"             },
	{ VNC_SECURITY_TYPE_GTK_VNC_SASL, "GTK-VNC SASL"         },
	{ VNC_SECURITY_TYPE_ARD,          "Apple Remote Desktop" },
	{ 0,  NULL                     }
};

static const true_false_string auth_result_tfs = {
	"Failed",
	"OK"
};

static const value_string yes_no_vs[] = {
	{ 0, "No"  },
	{ 1, "Yes" },
	{ 0,  NULL }
};

typedef enum {
	/* Required */
	VNC_CLIENT_MESSAGE_TYPE_SET_PIXEL_FORMAT	  =   0,
	VNC_CLIENT_MESSAGE_TYPE_SET_ENCODINGS		  =   2,
	VNC_CLIENT_MESSAGE_TYPE_FRAMEBUF_UPDATE_REQ	  =   3,
	VNC_CLIENT_MESSAGE_TYPE_KEY_EVENT		  =   4,
	VNC_CLIENT_MESSAGE_TYPE_POINTER_EVENT		  =   5,
	VNC_CLIENT_MESSAGE_TYPE_CLIENT_CUT_TEXT		  =   6,
	/* Optional */
	VNC_CLIENT_MESSAGE_TYPE_MIRRORLINK		  = 128,
	VNC_CLIENT_MESSAGE_TYPE_ENABLE_CONTINUOUS_UPDATES = 150,  /* TightVNC */
	VNC_CLIENT_MESSAGE_TYPE_FENCE			  = 248,  /* TigerVNC */
	VNC_CLIENT_MESSAGE_TYPE_XVP			  = 250,
	VNC_CLIENT_MESSAGE_TYPE_SETR_DESKTOP_SIZE	  = 251,
	VNC_CLIENT_MESSAGE_TYPE_TIGHT			  = 252,
	VNC_CLIENT_MESSAGE_TYPE_GII			  = 253,
	VNC_CLIENT_MESSAGE_TYPE_QEMU			  = 255
} vnc_client_message_types_e;

static const value_string vnc_client_message_types_vs[] = {
	/* Required */
	{ VNC_CLIENT_MESSAGE_TYPE_SET_PIXEL_FORMAT,	     "Set Pixel Format"		  },
	{ VNC_CLIENT_MESSAGE_TYPE_SET_ENCODINGS,	     "Set Encodings"		  },
	{ VNC_CLIENT_MESSAGE_TYPE_FRAMEBUF_UPDATE_REQ,	     "Framebuffer Update Request" },
	{ VNC_CLIENT_MESSAGE_TYPE_KEY_EVENT,		     "Key Event"		  },
	{ VNC_CLIENT_MESSAGE_TYPE_POINTER_EVENT,	     "Pointer Event"         	  },
	{ VNC_CLIENT_MESSAGE_TYPE_CLIENT_CUT_TEXT,	     "Cut Text"                   },
	/* Optional */
	{ VNC_CLIENT_MESSAGE_TYPE_MIRRORLINK,		     "MirrorLink"		  },
	{ VNC_CLIENT_MESSAGE_TYPE_ENABLE_CONTINUOUS_UPDATES, "Enable Continuous Updates"  },
	{ VNC_CLIENT_MESSAGE_TYPE_FENCE,		     "Fence"			  },
	{ VNC_CLIENT_MESSAGE_TYPE_XVP,			     "Xvp"			  },
	{ VNC_CLIENT_MESSAGE_TYPE_SETR_DESKTOP_SIZE,	     "Setr Desktop Size"	  },
	{ VNC_CLIENT_MESSAGE_TYPE_TIGHT,		     "Tight"			  },
	{ VNC_CLIENT_MESSAGE_TYPE_GII,			     "Gii"			  },
	{ VNC_CLIENT_MESSAGE_TYPE_QEMU,			     "Qemu"			  },
	{ 0,  NULL                        						  }
};

typedef enum {
	VNC_SERVER_MESSAGE_TYPE_FRAMEBUFFER_UPDATE	  =   0,
	VNC_SERVER_MESSAGE_TYPE_SET_COLORMAP_ENTRIES	  =   1,
	VNC_SERVER_MESSAGE_TYPE_RING_BELL		  =   2,
	VNC_SERVER_MESSAGE_TYPE_CUT_TEXT		  =   3,
	VNC_SERVER_MESSAGE_TYPE_MIRRORLINK		  = 128,
	VNC_SERVER_MESSAGE_TYPE_END_CONTINUOUS_UPDATES    = 150,  /* TightVNC */
	VNC_SERVER_MESSAGE_TYPE_FENCE			  = 248,  /* TigerVNC */
	VNC_SERVER_MESSAGE_TYPE_XVP			  = 250,
	VNC_SERVER_MESSAGE_TYPE_TIGHT			  = 252,
	VNC_SERVER_MESSAGE_TYPE_GII			  = 253,
	VNC_SERVER_MESSAGE_TYPE_QEMU			  = 255
} vnc_server_message_types_e;

static const value_string vnc_server_message_types_vs[] = {
	{ VNC_SERVER_MESSAGE_TYPE_FRAMEBUFFER_UPDATE,	     "Framebuffer Update"	 },
	{ VNC_SERVER_MESSAGE_TYPE_SET_COLORMAP_ENTRIES,	     "Set Colormap Entries"	 },
	{ VNC_SERVER_MESSAGE_TYPE_RING_BELL,		     "Ring Bell"		 },
	{ VNC_SERVER_MESSAGE_TYPE_CUT_TEXT,		     "Cut Text"			 },
	{ VNC_SERVER_MESSAGE_TYPE_MIRRORLINK,		     "MirrorLink"		 },
	{ VNC_SERVER_MESSAGE_TYPE_END_CONTINUOUS_UPDATES,    "End Continuous Updates" },
	{ VNC_SERVER_MESSAGE_TYPE_FENCE,		     "Fence"			 },
	{ VNC_SERVER_MESSAGE_TYPE_XVP,			     "Xvp"			 },
	{ VNC_SERVER_MESSAGE_TYPE_TIGHT,		     "Tight"			 },
	{ VNC_SERVER_MESSAGE_TYPE_GII,			     "Gii"			 },
	{ VNC_SERVER_MESSAGE_TYPE_QEMU,			     "Qemu"			 },
	{ 0,  NULL									 }
};

static const true_false_string button_mask_tfs = {
	"Pressed",
	"Not pressed"
};

#define VNC_ENCODING_TYPE_DESKTOP_SIZE       0xFFFFFF21
#define VNC_ENCODING_TYPE_LAST_RECT          0xFFFFFF20
#define VNC_ENCODING_TYPE_POINTER_POS        0xFFFFFF18
#define VNC_ENCODING_TYPE_RICH_CURSOR        0xFFFFFF11
#define VNC_ENCODING_TYPE_X_CURSOR           0xFFFFFF10
#define VNC_ENCODING_TYPE_RAW                0
#define VNC_ENCODING_TYPE_COPY_RECT          1
#define VNC_ENCODING_TYPE_RRE                2
#define VNC_ENCODING_TYPE_CORRE              4
#define VNC_ENCODING_TYPE_HEXTILE            5
#define VNC_ENCODING_TYPE_ZLIB	             6
#define VNC_ENCODING_TYPE_TIGHT	             7
#define VNC_ENCODING_TYPE_ZLIBHEX            8
#define VNC_ENCODING_TYPE_ULTRA	             9
#define VNC_ENCODING_TYPE_TRLE	             15
#define VNC_ENCODING_TYPE_RLE	             16
#define VNC_ENCODING_TYPE_HITACHI_ZYWRLE     17
#define VNC_ENCODING_TYPE_JPEG_0             -32
#define VNC_ENCODING_TYPE_JPEG_1             -31
#define VNC_ENCODING_TYPE_JPEG_2             -30
#define VNC_ENCODING_TYPE_JPEG_3             -29
#define VNC_ENCODING_TYPE_JPEG_4             -28
#define VNC_ENCODING_TYPE_JPEG_5             -27
#define VNC_ENCODING_TYPE_JPEG_6             -26
#define VNC_ENCODING_TYPE_JPEG_7             -25
#define VNC_ENCODING_TYPE_JPEG_8             -24
#define VNC_ENCODING_TYPE_JPEG_9             -23
#define VNC_ENCODING_TYPE_COMPRESSION_0      0xFFFFFF00
#define VNC_ENCODING_TYPE_COMPRESSION_1      0xFFFFFF01
#define VNC_ENCODING_TYPE_COMPRESSION_2      0xFFFFFF02
#define VNC_ENCODING_TYPE_COMPRESSION_3      0xFFFFFF03
#define VNC_ENCODING_TYPE_COMPRESSION_4      0xFFFFFF04
#define VNC_ENCODING_TYPE_COMPRESSION_5      0xFFFFFF05
#define VNC_ENCODING_TYPE_COMPRESSION_6      0xFFFFFF06
#define VNC_ENCODING_TYPE_COMPRESSION_7      0xFFFFFF07
#define VNC_ENCODING_TYPE_COMPRESSION_8      0xFFFFFF08
#define VNC_ENCODING_TYPE_COMPRESSION_9      0xFFFFFF09
#define VNC_ENCODING_TYPE_WMVi               0x574D5669
#define VNC_ENCODING_TYPE_CACHE              0xFFFF0000
#define VNC_ENCODING_TYPE_CACHE_ENABLE       0xFFFF0001
#define VNC_ENCODING_TYPE_XOR_ZLIB           0xFFFF0002
#define VNC_ENCODING_TYPE_XOR_MONO_ZLIB      0xFFFF0003
#define VNC_ENCODING_TYPE_XOR_MULTI_ZLIB     0xFFFF0004
#define VNC_ENCODING_TYPE_SOLID_COLOR        0xFFFF0005
#define VNC_ENCODING_TYPE_XOR_ENABLE         0xFFFF0006
#define VNC_ENCODING_TYPE_CACHE_ZIP          0xFFFF0007
#define VNC_ENCODING_TYPE_SOL_MONO_ZIP       0xFFFF0008
#define VNC_ENCODING_TYPE_ULTRA_ZIP          0xFFFF0009
#define VNC_ENCODING_TYPE_SERVER_STATE       0xFFFF8000
#define VNC_ENCODING_TYPE_ENABLE_KEEP_ALIVE  0xFFFF8001
#define VNC_ENCODING_TYPE_FTP_PROTO_VER      0xFFFF8002
#define VNC_ENCODING_TYPE_POINTER_CHANGE     -257
#define VNC_ENCODING_TYPE_EXT_KEY_EVENT      -258
#define VNC_ENCODING_TYPE_AUDIO               259
#define VNC_ENCODING_TYPE_DESKTOP_NAME       -307
#define VNC_ENCODING_TYPE_EXTENDED_DESK_SIZE -308
#define VNC_ENCODING_TYPE_KEYBOARD_LED_STATE 0XFFFE0000
#define VNC_ENCODING_TYPE_SUPPORTED_MESSAGES 0XFFFE0001
#define VNC_ENCODING_TYPE_SUPPORTED_ENCODINGS 0XFFFE0002
#define VNC_ENCODING_TYPE_SERVER_IDENTITY    0XFFFE0003
#define VNC_ENCODING_TYPE_MIRRORLINK         0xFFFFFDF5
#define VNC_ENCODING_TYPE_CONTEXT_INFORMATION 0xFFFFFDF4
#define VNC_ENCODING_TYPE_SLRLE              0xFFFFFDF3
#define VNC_ENCODING_TYPE_TRANSFORM          0xFFFFFDF2
#define VNC_ENCODING_TYPE_HSML               0xFFFFFDF1
#define VNC_ENCODING_TYPE_H264               0X48323634

static const value_string encoding_types_vs[] = {
	{ VNC_ENCODING_TYPE_DESKTOP_SIZE,	"DesktopSize (pseudo)" },
	{ VNC_ENCODING_TYPE_LAST_RECT,		"LastRect (pseudo)"    },
	{ VNC_ENCODING_TYPE_POINTER_POS,	"Pointer pos (pseudo)" },
	{ VNC_ENCODING_TYPE_RICH_CURSOR,	"Rich Cursor (pseudo)" },
	{ VNC_ENCODING_TYPE_X_CURSOR,		"X Cursor (pseudo)"    },
	{ VNC_ENCODING_TYPE_RAW,		"Raw"                  },
	{ VNC_ENCODING_TYPE_COPY_RECT,		"CopyRect"             },
	{ VNC_ENCODING_TYPE_RRE,		"RRE"                  },
	{ VNC_ENCODING_TYPE_CORRE,		"CoRRE"                },
	{ VNC_ENCODING_TYPE_HEXTILE,		"Hextile"              },
	{ VNC_ENCODING_TYPE_ZLIB,		"Zlib"                 },
	{ VNC_ENCODING_TYPE_TIGHT,		"Tight"                },
	{ VNC_ENCODING_TYPE_ZLIBHEX,		"ZlibHex"              },
	{ VNC_ENCODING_TYPE_ULTRA,		"Ultra"		       },
	{ VNC_ENCODING_TYPE_RLE,		"ZRLE"                 },
	{ VNC_ENCODING_TYPE_HITACHI_ZYWRLE,	"Hitachi ZYWRLE"       },
	{ VNC_ENCODING_TYPE_JPEG_0,		"JPEG quality level 0" },
	{ VNC_ENCODING_TYPE_JPEG_1,		"JPEG quality level 1" },
	{ VNC_ENCODING_TYPE_JPEG_2,		"JPEG quality level 2" },
	{ VNC_ENCODING_TYPE_JPEG_3,		"JPEG quality level 3" },
	{ VNC_ENCODING_TYPE_JPEG_4,		"JPEG quality level 4" },
	{ VNC_ENCODING_TYPE_JPEG_5,		"JPEG quality level 5" },
	{ VNC_ENCODING_TYPE_JPEG_6,		"JPEG quality level 6" },
	{ VNC_ENCODING_TYPE_JPEG_7,		"JPEG quality level 7" },
	{ VNC_ENCODING_TYPE_JPEG_8,		"JPEG quality level 8" },
	{ VNC_ENCODING_TYPE_JPEG_9,		"JPEG quality level 9" },
	{ VNC_ENCODING_TYPE_COMPRESSION_0, 	"Compression level 0"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_1, 	"Compression level 1"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_2, 	"Compression level 2"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_3, 	"Compression level 3"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_4, 	"Compression level 4"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_5, 	"Compression level 5"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_6, 	"Compression level 6"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_7, 	"Compression level 7"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_8, 	"Compression level 8"  },
	{ VNC_ENCODING_TYPE_COMPRESSION_9, 	"Compression level 9"  },
	/* FIXME understand for real what the below mean. Taken from Ultra VNC source code */
/*	{ VNC_ENCODING_TYPE_CACHE,     */
	{ VNC_ENCODING_TYPE_CACHE_ENABLE, 	"Enable Caching"},
/*	{ VNC_ENCODING_TYPE_XOR_ZLIB,
	{ VNC_ENCODING_TYPE_XOR_MONO_ZLIB,
	{ VNC_ENCODING_TYPE_XOR_MULTI_ZLIB,
	{ VNC_ENCODING_TYPE_SOLID_COLOR,
	{ VNC_ENCODING_TYPE_XOR_ENABLE,
	{ VNC_ENCODING_TYPE_CACHE_ZIP,
	{ VNC_ENCODING_TYPE_SOL_MONO_ZIP,
	{ VNC_ENCODING_TYPE_ULTRA_ZIP,
*/	{ VNC_ENCODING_TYPE_SERVER_STATE, 	"Server State"	       },
	{ VNC_ENCODING_TYPE_ENABLE_KEEP_ALIVE, 	"Enable Keep Alive"    },
	{ VNC_ENCODING_TYPE_FTP_PROTO_VER, 	"FTP protocol version" },
	{ VNC_ENCODING_TYPE_EXTENDED_DESK_SIZE,	"Extended Desktop Size"},
	{ VNC_ENCODING_TYPE_DESKTOP_NAME,	"Desktop Name"         },
	{ VNC_ENCODING_TYPE_KEYBOARD_LED_STATE,	"Keyboard LED State"   },
	{ VNC_ENCODING_TYPE_SUPPORTED_MESSAGES,	"Supported Messages"   },
	{ VNC_ENCODING_TYPE_SUPPORTED_ENCODINGS, "Supported Encodings" },
	{ VNC_ENCODING_TYPE_SERVER_IDENTITY,	"Server Identity"      },
	{ VNC_ENCODING_TYPE_MIRRORLINK,		"MirrorLink"           },
	{ VNC_ENCODING_TYPE_CONTEXT_INFORMATION, "Context Information" },
	{ VNC_ENCODING_TYPE_SLRLE,		"SLRLE"                },
	{ VNC_ENCODING_TYPE_TRANSFORM,		"Transform"            },
	{ VNC_ENCODING_TYPE_HSML,		"HSML"                 },
	{ VNC_ENCODING_TYPE_H264,		"H264"                 },
	{ 0,				NULL                   }
};

/* Rectangle types for Tight encoding.  These come in the "control byte" at the
 * start of a rectangle's payload.  Note that these are with respect to the most
 * significant bits 4-7 of the control byte, so you must shift it to the right 4
 * bits before comparing against these values.
 */
#define TIGHT_RECT_FILL      0x08
#define TIGHT_RECT_JPEG      0x09
#define TIGHT_RECT_MAX_VALUE 0x09

#define TIGHT_RECT_EXPLICIT_FILTER_FLAG 0x04

/* Filter types for Basic encoding of Tight rectangles */
#define TIGHT_RECT_FILTER_COPY     0x00
#define TIGHT_RECT_FILTER_PALETTE  0x01
#define TIGHT_RECT_FILTER_GRADIENT 0x02

/* Minimum number of bytes to compress for Tight encoding */
#define TIGHT_MIN_BYTES_TO_COMPRESS 12

static const value_string tight_filter_ids_vs[] = {
	{ TIGHT_RECT_FILTER_COPY,     "Copy"     },
	{ TIGHT_RECT_FILTER_PALETTE,  "Palette"  },
	{ TIGHT_RECT_FILTER_GRADIENT, "Gradient" },
	{ 0, NULL }
};

/* MirrorLink messages */
typedef enum {
	VNC_ML_EXT_BYE_BYE                      = 0,
	VNC_ML_EXT_SERVER_DISPLAY_CONFIGURATION = 1,
	VNC_ML_EXT_CLIENT_DISPLAY_CONFIGURATION = 2,
	VNC_ML_EXT_SERVER_EVENT_CONFIGURATION   = 3,
	VNC_ML_EXT_CLIENT_EVENT_CONFIGURATION   = 4,
	VNC_ML_EXT_EVENT_MAPPING                = 5,
	VNC_ML_EXT_EVENT_MAPPING_REQUEST        = 6,
	VNC_ML_EXT_KEY_EVENT_LISTING            = 7,
	VNC_ML_EXT_KEY_EVENT_LISTING_REQUEST    = 8,
	VNC_ML_EXT_VIRTUAL_KEYBOARD             = 9,
	VNC_ML_EXT_VIRTUAL_KEYBOARD_REQUEST     = 10,
	VNC_ML_EXT_DEVICE_STATUS                = 11,
	VNC_ML_EXT_DEVICE_STATUS_REQUEST        = 12,
	VNC_ML_EXT_CONTENT_ATTESTATION          = 13,
	VNC_ML_EXT_CONTENT_ATTESTATION_REQUEST  = 14,
	VNC_ML_EXT_FB_BLOCKING_NOTIFICATION     = 16,
	VNC_ML_EXT_AUDIO_BLOCKING_NOTIFICATION  = 18,
	VNC_ML_EXT_TOUCH_EVENT                  = 20,
	VNC_ML_EXT_FB_ALTERNATIVE_TEXT          = 21,
	VNC_ML_EXT_FB_ALTERNATIVE_TEXT_REQUEST  = 22
} vnc_mirrorlink_ext_types_e;

static const value_string vnc_mirrorlink_types_vs[] = {
	{ VNC_ML_EXT_BYE_BYE,                      "ByeBye"                               },
	{ VNC_ML_EXT_SERVER_DISPLAY_CONFIGURATION, "Server Display Configuration"         },
	{ VNC_ML_EXT_CLIENT_DISPLAY_CONFIGURATION, "Client Display Configuration"         },
	{ VNC_ML_EXT_SERVER_EVENT_CONFIGURATION,   "Server Event Configuration"           },
	{ VNC_ML_EXT_CLIENT_EVENT_CONFIGURATION,   "Client Event Configuration"           },
	{ VNC_ML_EXT_EVENT_MAPPING,                "Event Mapping"                        },
	{ VNC_ML_EXT_EVENT_MAPPING_REQUEST,        "Event Mapping Request"                },
	{ VNC_ML_EXT_KEY_EVENT_LISTING,            "Key Event Listing"                    },
	{ VNC_ML_EXT_KEY_EVENT_LISTING_REQUEST,    "Key Event Listing Request"            },
	{ VNC_ML_EXT_VIRTUAL_KEYBOARD,             "Virtual Keyboard Trigger"             },
	{ VNC_ML_EXT_VIRTUAL_KEYBOARD_REQUEST,     "Virtual Keyboard Trigger Request"     },
	{ VNC_ML_EXT_DEVICE_STATUS,                "Device Status"                        },
	{ VNC_ML_EXT_DEVICE_STATUS_REQUEST,        "Device Status Request"                },
	{ VNC_ML_EXT_CONTENT_ATTESTATION,          "Content Attestation"                  },
	{ VNC_ML_EXT_CONTENT_ATTESTATION_REQUEST,  "Content Attestation Request"          },
	{ VNC_ML_EXT_FB_BLOCKING_NOTIFICATION,     "Framebuffer Blocking Notification"    },
	{ VNC_ML_EXT_AUDIO_BLOCKING_NOTIFICATION,  "Audio Blocking Notification"          },
	{ VNC_ML_EXT_TOUCH_EVENT,                  "Touch Event"                          },
	{ VNC_ML_EXT_FB_ALTERNATIVE_TEXT,          "Framebuffer Alternative Text"         },
	{ VNC_ML_EXT_FB_ALTERNATIVE_TEXT_REQUEST,  "Framebuffer Alternative Text Request" },
	{ 0,  NULL                                                                        }
};

/* Slice types for H.264 encoding */
typedef enum {
	VNC_H264_SLICE_TYPE_P = 0,
	VNC_H264_SLICE_TYPE_B = 1,
	VNC_H264_SLICE_TYPE_I = 2
} vnc_h264_slice_types_e;

static const value_string vnc_h264_slice_types_vs[] = {
	{ VNC_H264_SLICE_TYPE_P, "Predicted"    },
	{ VNC_H264_SLICE_TYPE_B, "Bi-predicted" },
	{ VNC_H264_SLICE_TYPE_I, "Intra coded"  },
	{ 0, NULL                               }
};


typedef enum {
	VNC_SESSION_STATE_SERVER_VERSION,
	VNC_SESSION_STATE_CLIENT_VERSION,

	VNC_SESSION_STATE_SECURITY,
	VNC_SESSION_STATE_SECURITY_TYPES,

	VNC_SESSION_STATE_TIGHT_TUNNELING_CAPABILITIES,
	VNC_SESSION_STATE_TIGHT_TUNNEL_TYPE_REPLY,
	VNC_SESSION_STATE_TIGHT_AUTH_CAPABILITIES,
	VNC_SESSION_STATE_TIGHT_AUTH_TYPE_REPLY,
	VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3,

	VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE,
	VNC_SESSION_STATE_VNC_AUTHENTICATION_RESPONSE,

	VNC_SESSION_STATE_ARD_AUTHENTICATION_CHALLENGE,
	VNC_SESSION_STATE_ARD_AUTHENTICATION_RESPONSE,

	VNC_SESSION_STATE_SECURITY_RESULT,

	VNC_SESSION_STATE_CLIENT_INIT,
	VNC_SESSION_STATE_SERVER_INIT,

	VNC_SESSION_STATE_TIGHT_INTERACTION_CAPS,

	VNC_SESSION_STATE_NORMAL_TRAFFIC
} vnc_session_state_e;

#define VNC_FENCE_BLOCK_BEFORE   0x00000001
#define VNC_FENCE_BLOCK_AFTER    0x00000002
#define VNC_FENCE_SYNC_NEXT      0x00000004
#define VNC_FENCE_REQUEST        0x80000000

/* This structure will be tied to each conversation. */
typedef struct {
	gdouble server_proto_ver, client_proto_ver;
	vnc_session_state_e vnc_next_state;
	guint32 server_port;
	/* These are specific to TightVNC */
	gint num_server_message_types;
	gint num_client_message_types;
	gint num_encoding_types;
	guint8 security_type_selected;
	gboolean tight_enabled;
	/* This is specific to Apple Remote Desktop */
	guint16 ard_key_length;
} vnc_conversation_t;

/* This structure will be tied to each packet */
typedef struct {
	vnc_session_state_e state;
	gint preferred_encoding;
	guint8 bytes_per_pixel;
	guint8 depth;
} vnc_packet_t;

void proto_reg_handoff_vnc(void);

static gboolean vnc_startup_messages(tvbuff_t *tvb, packet_info *pinfo,
				     gint offset, proto_tree *tree,
				     vnc_conversation_t *per_conversation_info);
static void vnc_client_to_server(tvbuff_t *tvb, packet_info *pinfo,
				 gint *offset, proto_tree *tree);
static void vnc_server_to_client(tvbuff_t *tvb, packet_info *pinfo,
				 gint *offset, proto_tree *tree);
static void vnc_client_set_pixel_format(tvbuff_t *tvb, packet_info *pinfo,
					gint *offset, proto_tree *tree);
static void vnc_client_set_encodings(tvbuff_t *tvb, packet_info *pinfo,
				     gint *offset, proto_tree *tree);
static void vnc_client_framebuffer_update_request(tvbuff_t *tvb,
						  packet_info *pinfo,
						  gint *offset,
						  proto_tree *tree);
static void vnc_client_key_event(tvbuff_t *tvb, packet_info *pinfo,
				 gint *offset, proto_tree *tree);
static void vnc_client_pointer_event(tvbuff_t *tvb, packet_info *pinfo,
				     gint *offset, proto_tree *tree);
static void vnc_client_cut_text(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
				proto_tree *tree);

static guint vnc_server_framebuffer_update(tvbuff_t *tvb, packet_info *pinfo,
					   gint *offset, proto_tree *tree);
static guint vnc_raw_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			      proto_tree *tree, const guint16 width, const guint16 height);
static guint vnc_copyrect_encoding(tvbuff_t *tvb, packet_info *pinfo,
				   gint *offset, proto_tree *tree,
				   const guint16 width, const guint16 height);
static guint vnc_rre_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			      proto_tree *tree, const guint16 width, const guint16 height);
static guint vnc_hextile_encoding(tvbuff_t *tvb, packet_info *pinfo,
				  gint *offset, proto_tree *tree,
				  const guint16 width, const guint16 height);
static guint vnc_zrle_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			       proto_tree *tree, const guint16 width, const guint16 height);
static guint vnc_tight_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
				proto_tree *tree, const guint16 width, const guint16 height);
static guint vnc_rich_cursor_encoding(tvbuff_t *tvb, packet_info *pinfo,
				      gint *offset, proto_tree *tree, const guint16 width,
				      const guint16 height);
static guint vnc_x_cursor_encoding(tvbuff_t *tvb, packet_info *pinfo,
				   gint *offset, proto_tree *tree, const guint16 width,
				   const guint16 height);
static guint vnc_server_set_colormap_entries(tvbuff_t *tvb, packet_info *pinfo,
					     gint *offset, proto_tree *tree);
static void vnc_server_ring_bell(tvbuff_t *tvb, packet_info *pinfo,
				 gint *offset, proto_tree *tree);
static guint vnc_server_cut_text(tvbuff_t *tvb, packet_info *pinfo,
				 gint *offset, proto_tree *tree);
static void vnc_set_bytes_per_pixel(packet_info *pinfo, const guint8 bytes_per_pixel);
static void vnc_set_depth(packet_info *pinfo, const guint8 depth);
static guint8 vnc_get_bytes_per_pixel(packet_info *pinfo);
static guint8 vnc_get_depth(packet_info *pinfo);
static guint32 vnc_extended_desktop_size(tvbuff_t *tvb, gint *offset, proto_tree *tree);

static guint vnc_supported_messages(tvbuff_t *tvb, gint *offset,
				    proto_tree *tree, const guint16 width);
static guint vnc_supported_encodings(tvbuff_t *tvb, gint *offset,
				     proto_tree *tree, const guint16 width,
				     const guint16 height);
static guint vnc_server_identity(tvbuff_t *tvb, gint *offset,
				 proto_tree *tree, const guint16 width);

static guint vnc_fence(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			    proto_tree *tree);
static guint vnc_mirrorlink(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			    proto_tree *tree);
static guint vnc_context_information(tvbuff_t *tvb, gint *offset,
				     proto_tree *tree);
static guint vnc_slrle_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
				proto_tree *tree, const guint16 height);

static guint vnc_h264_encoding(tvbuff_t *tvb, gint *offset, proto_tree *tree);

#define VNC_BYTES_NEEDED(a)					\
	if((a) > (guint)tvb_reported_length_remaining(tvb, *offset))	\
		return (a);

/* Initialize the protocol and registered fields */
static int proto_vnc = -1; /* Protocol subtree */
static int hf_vnc_padding = -1;
static int hf_vnc_server_proto_ver = -1;
static int hf_vnc_client_proto_ver = -1;
static int hf_vnc_num_security_types = -1;
static int hf_vnc_security_type = -1;
static int hf_vnc_server_security_type = -1;
static int hf_vnc_client_security_type = -1;
static int hf_vnc_auth_challenge = -1;
static int hf_vnc_auth_response = -1;
static int hf_vnc_auth_result = -1;
static int hf_vnc_auth_error = -1;
static int hf_vnc_auth_error_length = -1;

static int hf_vnc_ard_auth_generator = -1;
static int hf_vnc_ard_auth_key_len = -1;
static int hf_vnc_ard_auth_modulus = -1;
static int hf_vnc_ard_auth_server_key = -1;
static int hf_vnc_ard_auth_credentials = -1;
static int hf_vnc_ard_auth_client_key = -1;

static int hf_vnc_share_desktop_flag = -1;
static int hf_vnc_width = -1;
static int hf_vnc_height = -1;
static int hf_vnc_server_bits_per_pixel = -1;
static int hf_vnc_server_depth = -1;
static int hf_vnc_server_big_endian_flag = -1;
static int hf_vnc_server_true_color_flag = -1;
static int hf_vnc_server_red_max = -1;
static int hf_vnc_server_green_max = -1;
static int hf_vnc_server_blue_max = -1;
static int hf_vnc_server_red_shift = -1;
static int hf_vnc_server_green_shift = -1;
static int hf_vnc_server_blue_shift = -1;
static int hf_vnc_desktop_name = -1;
static int hf_vnc_desktop_name_len = -1;
static int hf_vnc_desktop_screen_num = -1;
static int hf_vnc_desktop_screen_id = -1;
static int hf_vnc_desktop_screen_x = -1;
static int hf_vnc_desktop_screen_y = -1;
static int hf_vnc_desktop_screen_width = -1;
static int hf_vnc_desktop_screen_height = -1;
static int hf_vnc_desktop_screen_flags = -1;
static int hf_vnc_num_server_message_types = -1;
static int hf_vnc_num_client_message_types = -1;
static int hf_vnc_num_encoding_types = -1;

/********** Client Message Types **********/

static int hf_vnc_client_message_type = -1; /* A subtree under VNC */
static int hf_vnc_client_bits_per_pixel = -1;
static int hf_vnc_client_depth = -1;
static int hf_vnc_client_big_endian_flag = -1;
static int hf_vnc_client_true_color_flag = -1;
static int hf_vnc_client_red_max = -1;
static int hf_vnc_client_green_max = -1;
static int hf_vnc_client_blue_max = -1;
static int hf_vnc_client_red_shift = -1;
static int hf_vnc_client_green_shift = -1;
static int hf_vnc_client_blue_shift = -1;

/* Client Key Event */
static int hf_vnc_key_down = -1;
static int hf_vnc_key = -1;

/* Client Pointer Event */
static int hf_vnc_button_1_pos = -1;
static int hf_vnc_button_2_pos = -1;
static int hf_vnc_button_3_pos = -1;
static int hf_vnc_button_4_pos = -1;
static int hf_vnc_button_5_pos = -1;
static int hf_vnc_button_6_pos = -1;
static int hf_vnc_button_7_pos = -1;
static int hf_vnc_button_8_pos = -1;
static int hf_vnc_pointer_x_pos = -1;
static int hf_vnc_pointer_y_pos = -1;

/* Client Framebuffer Update Request */
static int hf_vnc_update_req_incremental = -1;
static int hf_vnc_update_req_x_pos = -1;
static int hf_vnc_update_req_y_pos = -1;
static int hf_vnc_update_req_width = -1;
static int hf_vnc_update_req_height = -1;

/* Client Set Encodings */
static int hf_vnc_encoding_num = -1;
static int hf_vnc_client_set_encodings_encoding_type = -1;

/* Client Cut Text */
static int hf_vnc_client_cut_text_len = -1;
static int hf_vnc_client_cut_text = -1;

/********** Server Message Types **********/

static int hf_vnc_server_message_type = -1; /* Subtree */

/* Tunneling capabilities (TightVNC extension) */
static int hf_vnc_tight_num_tunnel_types = -1;
static int hf_vnc_tight_tunnel_type = -1;

/* Authentication capabilities (TightVNC extension) */
static int hf_vnc_tight_num_auth_types = -1;
static int hf_vnc_tight_auth_code = -1;
/* TightVNC capabilities */
static int hf_vnc_tight_server_message_type = -1;
static int hf_vnc_tight_server_vendor = -1;
static int hf_vnc_tight_signature = -1;
static int hf_vnc_tight_server_name = -1;

static int hf_vnc_tight_client_message_type = -1;
static int hf_vnc_tight_client_vendor = -1;
static int hf_vnc_tight_client_name = -1;

static int hf_vnc_tight_encoding_type = -1;
static int hf_vnc_tight_encoding_vendor = -1;
static int hf_vnc_tight_encoding_name = -1;

/* Tight compression parameters */
static int hf_vnc_tight_reset_stream0 = -1;
static int hf_vnc_tight_reset_stream1 = -1;
static int hf_vnc_tight_reset_stream2 = -1;
static int hf_vnc_tight_reset_stream3 = -1;

static int hf_vnc_tight_rect_type = -1;

static int hf_vnc_tight_image_len = -1;
static int hf_vnc_tight_image_data = -1;

static int hf_vnc_tight_fill_color = -1;

static int hf_vnc_tight_filter_flag = -1;
static int hf_vnc_tight_filter_id = -1;

static int hf_vnc_tight_palette_num_colors = -1;
static int hf_vnc_tight_palette_data = -1;

/* Server Framebuffer Update */
static int hf_vnc_rectangle_num = -1;
static int hf_vnc_fb_update_x_pos = -1;
static int hf_vnc_fb_update_y_pos = -1;
static int hf_vnc_fb_update_width = -1;
static int hf_vnc_fb_update_height = -1;
static int hf_vnc_fb_update_encoding_type = -1;

/* Raw Encoding */
static int hf_vnc_raw_pixel_data = -1;

/* CopyRect Encoding */
static int hf_vnc_copyrect_src_x_pos = -1;
static int hf_vnc_copyrect_src_y_pos = -1;

/* RRE Encoding */
static int hf_vnc_rre_num_subrects = -1;
static int hf_vnc_rre_bg_pixel = -1;

static int hf_vnc_rre_subrect_pixel = -1;
static int hf_vnc_rre_subrect_x_pos = -1;
static int hf_vnc_rre_subrect_y_pos = -1;
static int hf_vnc_rre_subrect_width = -1;
static int hf_vnc_rre_subrect_height = -1;

/* Hextile Encoding */
static int hf_vnc_hextile_subencoding_mask = -1;
static int hf_vnc_hextile_raw = -1;
static int hf_vnc_hextile_raw_value = -1;
static int hf_vnc_hextile_bg = -1;
static int hf_vnc_hextile_bg_value = -1;
static int hf_vnc_hextile_fg = -1;
static int hf_vnc_hextile_fg_value = -1;
static int hf_vnc_hextile_anysubrects = -1;
static int hf_vnc_hextile_num_subrects = -1;
static int hf_vnc_hextile_subrectscolored = -1;
static int hf_vnc_hextile_subrect_pixel_value = -1;
static int hf_vnc_hextile_subrect_x_pos = -1;
static int hf_vnc_hextile_subrect_y_pos = -1;
static int hf_vnc_hextile_subrect_width = -1;
static int hf_vnc_hextile_subrect_height = -1;

/* ZRLE Encoding */
static int hf_vnc_zrle_len = -1;
static int hf_vnc_zrle_subencoding = -1;
static int hf_vnc_zrle_rle = -1;
static int hf_vnc_zrle_palette_size = -1;
static int hf_vnc_zrle_data = -1;
static int hf_vnc_zrle_raw = -1;
static int hf_vnc_zrle_palette = -1;

/* Cursor Encoding */
static int hf_vnc_cursor_x_fore_back = -1;
static int hf_vnc_cursor_encoding_pixels = -1;
static int hf_vnc_cursor_encoding_bitmask = -1;

/* Server Set Colormap Entries */
static int hf_vnc_color_groups = -1;
static int hf_vnc_colormap_first_color = -1;
static int hf_vnc_colormap_num_colors = -1;
static int hf_vnc_colormap_red = -1;
static int hf_vnc_colormap_green = -1;
static int hf_vnc_colormap_blue = -1;

/* Server Cut Text */
static int hf_vnc_server_cut_text_len = -1;
static int hf_vnc_server_cut_text = -1;

/* LibVNCServer additions */
static int hf_vnc_supported_messages_client2server = -1;
static int hf_vnc_supported_messages_server2client = -1;
static int hf_vnc_num_supported_encodings = -1;
static int hf_vnc_supported_encodings = -1;
static int hf_vnc_server_identity = -1;

/* MirrorLink */
static int hf_vnc_mirrorlink_type = -1;
static int hf_vnc_mirrorlink_length = -1;
static int hf_vnc_mirrorlink_version_major = -1;
static int hf_vnc_mirrorlink_version_minor = -1;
static int hf_vnc_mirrorlink_framebuffer_configuration = -1;
static int hf_vnc_mirrorlink_pixel_width = -1;
static int hf_vnc_mirrorlink_pixel_height = -1;
static int hf_vnc_mirrorlink_pixel_format = -1;
static int hf_vnc_mirrorlink_display_width = -1;
static int hf_vnc_mirrorlink_display_height = -1;
static int hf_vnc_mirrorlink_display_distance = -1;
static int hf_vnc_mirrorlink_keyboard_language = -1;
static int hf_vnc_mirrorlink_keyboard_country = -1;
static int hf_vnc_mirrorlink_ui_language = -1;
static int hf_vnc_mirrorlink_ui_country = -1;
static int hf_vnc_mirrorlink_knob_keys = -1;
static int hf_vnc_mirrorlink_device_keys = -1;
static int hf_vnc_mirrorlink_multimedia_keys = -1;
static int hf_vnc_mirrorlink_key_related = -1;
static int hf_vnc_mirrorlink_pointer_related = -1;
static int hf_vnc_mirrorlink_key_symbol_value_client = -1;
static int hf_vnc_mirrorlink_key_symbol_value_server = -1;
static int hf_vnc_mirrorlink_key_configuration = -1;
static int hf_vnc_mirrorlink_key_num_events = -1;
static int hf_vnc_mirrorlink_key_event_counter = -1;
static int hf_vnc_mirrorlink_key_symbol_value = -1;
static int hf_vnc_mirrorlink_key_request_configuration = -1;
static int hf_vnc_mirrorlink_keyboard_configuration = -1;
static int hf_vnc_mirrorlink_cursor_x = -1;
static int hf_vnc_mirrorlink_cursor_y = -1;
static int hf_vnc_mirrorlink_text_x = -1;
static int hf_vnc_mirrorlink_text_y = -1;
static int hf_vnc_mirrorlink_text_width = -1;
static int hf_vnc_mirrorlink_text_height = -1;
static int hf_vnc_mirrorlink_keyboard_request_configuration = -1;
static int hf_vnc_mirrorlink_device_status = -1;
static int hf_vnc_mirrorlink_app_id = -1;
static int hf_vnc_mirrorlink_fb_block_x = -1;
static int hf_vnc_mirrorlink_fb_block_y = -1;
static int hf_vnc_mirrorlink_fb_block_width = -1;
static int hf_vnc_mirrorlink_fb_block_height = -1;
static int hf_vnc_mirrorlink_fb_block_reason = -1;
static int hf_vnc_mirrorlink_audio_block_reason = -1;
static int hf_vnc_mirrorlink_touch_num_events = -1;
static int hf_vnc_mirrorlink_touch_x = -1;
static int hf_vnc_mirrorlink_touch_y = -1;
static int hf_vnc_mirrorlink_touch_id = -1;
static int hf_vnc_mirrorlink_touch_pressure = -1;
static int hf_vnc_mirrorlink_text = -1;
static int hf_vnc_mirrorlink_text_length = -1;
static int hf_vnc_mirrorlink_text_max_length = -1;
static int hf_vnc_mirrorlink_unknown = -1;

/* Fence */
static int hf_vnc_fence_flags = -1;
static int hf_vnc_fence_request = -1;
static int hf_vnc_fence_sync_next = -1;
static int hf_vnc_fence_block_after = -1;
static int hf_vnc_fence_block_before = -1;
static int hf_vnc_fence_payload_length = -1;
static int hf_vnc_fence_payload = -1;

static const int *vnc_fence_flags[] = {
	&hf_vnc_fence_request,
	&hf_vnc_fence_sync_next,
	&hf_vnc_fence_block_after,
	&hf_vnc_fence_block_before,
	NULL
};

/* Context Information */
static int hf_vnc_context_information_app_id = -1;
static int hf_vnc_context_information_app_category = -1;
static int hf_vnc_context_information_app_trust_level = -1;
static int hf_vnc_context_information_content_category = -1;
static int hf_vnc_context_information_content_rules = -1;
static int hf_vnc_context_information_content_trust_level = -1;

/* Scan Line based Run-Length Encoding */
static int hf_vnc_slrle_run_num = -1;
static int hf_vnc_slrle_run_data = -1;

/* H.264 Encoding */
static int hf_vnc_h264_slice_type = -1;
static int hf_vnc_h264_nbytes = -1;
static int hf_vnc_h264_width = -1;
static int hf_vnc_h264_height = -1;
static int hf_vnc_h264_data = -1;

/********** End of Server Message Types **********/

static gboolean vnc_preference_desegment = TRUE;

/* Initialize the subtree pointers */
static gint ett_vnc = -1;
static gint ett_vnc_client_message_type = -1;
static gint ett_vnc_server_message_type = -1;
static gint ett_vnc_rect = -1;
static gint ett_vnc_encoding_type = -1;
static gint ett_vnc_rre_subrect = -1;
static gint ett_vnc_hextile_subencoding_mask = -1;
static gint ett_vnc_hextile_num_subrects = -1;
static gint ett_vnc_hextile_subrect = -1;
static gint ett_vnc_hextile_tile = -1;
static gint ett_vnc_zrle_subencoding = -1;
static gint ett_vnc_colormap_num_groups = -1;
static gint ett_vnc_colormap_color_group = -1;
static gint ett_vnc_desktop_screen = -1;
static gint ett_vnc_key_events = -1;
static gint ett_vnc_touch_events = -1;
static gint ett_vnc_slrle_subline = -1;
static gint ett_vnc_fence_flags = -1;

static expert_field ei_vnc_possible_gtk_vnc_bug = EI_INIT;
static expert_field ei_vnc_auth_code_mismatch = EI_INIT;
static expert_field ei_vnc_unknown_tight_vnc_auth = EI_INIT;
static expert_field ei_vnc_too_many_rectangles = EI_INIT;
static expert_field ei_vnc_too_many_sub_rectangles = EI_INIT;
static expert_field ei_vnc_invalid_encoding = EI_INIT;
static expert_field ei_vnc_too_many_colors = EI_INIT;
static expert_field ei_vnc_too_many_cut_text = EI_INIT;
static expert_field ei_vnc_zrle_failed = EI_INIT;
static expert_field ei_vnc_unknown_tight = EI_INIT;
static expert_field ei_vnc_reassemble = EI_INIT;

/* Global so they keep their value between packets */
guint8 vnc_bytes_per_pixel;
guint8 vnc_depth;

#define VNC_PORT_RANGE "5500-5501,5900-5901" /* Not IANA registered */

static range_t *vnc_tcp_range = NULL;
static dissector_handle_t vnc_handle;

/* Code to dissect the packets */
static int
dissect_vnc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	gboolean ret;
	gint     offset = 0;

	/* Set up structures needed to add the protocol subtree and manage it */
	proto_item	   *ti;
	proto_tree	   *vnc_tree;

	conversation_t     *conversation;
	vnc_conversation_t *per_conversation_info;

	conversation = find_or_create_conversation(pinfo);

	/* Retrieve information from conversation, or add it if it isn't
	 * there yet */
	per_conversation_info = (vnc_conversation_t *)conversation_get_proto_data(conversation, proto_vnc);
	if(!per_conversation_info) {
		per_conversation_info = wmem_new(wmem_file_scope(), vnc_conversation_t);

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SERVER_VERSION;
		per_conversation_info->security_type_selected = VNC_SECURITY_TYPE_INVALID;
		per_conversation_info->tight_enabled = FALSE;

		conversation_add_proto_data(conversation, proto_vnc, per_conversation_info);
	}


	/* Make entries in Protocol column and Info column on summary display */
	col_set_str(pinfo->cinfo, COL_PROTOCOL, "VNC");

	/* First, clear the info column */
	col_clear(pinfo->cinfo, COL_INFO);

	/* create display subtree for the protocol */
	ti = proto_tree_add_item(tree, proto_vnc, tvb, 0, -1, ENC_NA);
	vnc_tree = proto_item_add_subtree(ti, ett_vnc);

	/* Dissect any remaining session startup messages */
	ret = vnc_startup_messages(tvb, pinfo, offset, vnc_tree,
				   per_conversation_info);

	vnc_set_bytes_per_pixel(pinfo, vnc_bytes_per_pixel);
	vnc_set_depth(pinfo, vnc_depth);

	if (ret) {
		return tvb_captured_length(tvb);  /* We're in a "startup" state; Cannot yet do "normal" processing */
	}

	if(value_is_in_range(vnc_tcp_range, pinfo->destport) || per_conversation_info->server_port == pinfo->destport) {
		vnc_client_to_server(tvb, pinfo, &offset, vnc_tree);
	}
	else {
		vnc_server_to_client(tvb, pinfo, &offset, vnc_tree);
	}
	return tvb_captured_length(tvb);
}

/* Returns the new offset after processing the 4-byte vendor string */
static gint
process_vendor(proto_tree *tree, gint hfindex, tvbuff_t *tvb, gint offset)
{
	const guint8 *vendor;
	proto_item *ti;

	if (tree) {
		ti = proto_tree_add_item_ret_string(tree, hfindex, tvb, offset, 4, ENC_ASCII|ENC_NA, wmem_packet_scope(), &vendor);

		if(g_ascii_strcasecmp(vendor, "STDV") == 0)
			proto_item_append_text(ti, " (Standard VNC vendor)");
		else if(g_ascii_strcasecmp(vendor, "TRDV") == 0)
			proto_item_append_text(ti, " (Tridia VNC vendor)");
		else if(g_ascii_strcasecmp(vendor, "TGHT") == 0)
			proto_item_append_text(ti, " (Tight VNC vendor)");
	}

	offset += 4;
	return offset;
}

/* Returns the new offset after processing the specified number of capabilities */
static gint
process_tight_capabilities(proto_tree *tree,
			   gint type_index, gint vendor_index, gint name_index,
			   tvbuff_t *tvb, gint offset, const gint num_capabilities)
{
	gint i;
	/* See vnc_unixsrc/include/rfbproto.h:rfbCapabilityInfo */

	for (i = 0; i < num_capabilities; i++) {

		proto_tree_add_item(tree, type_index, tvb, offset, 4, ENC_BIG_ENDIAN);
		offset += 4;

		offset = process_vendor(tree, vendor_index, tvb, offset);

		proto_tree_add_item(tree, name_index, tvb, offset, 8, ENC_ASCII|ENC_NA);
		offset += 8;
	}

	return offset;
}

/* Returns true if this looks like a client or server version packet: 12 bytes, in the format "RFB xxx.yyy\n" .
* Will check for the 12 bytes exact length, the 'RFB ' string and that it ends with a '\n'.
* The exact 'xxx.yyy' is checked later, by trying to convert it to a double using g_ascii_strtod.
* pinfo and tree are NULL when using this function to check the heuristics for dissection.  If we're
* checking the heuristics, we don't need to add expert_info, we just reject that packet as not
* being a VNC packet.
*/
static gboolean
vnc_is_client_or_server_version_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	if(tvb_captured_length(tvb) != 12) {
		return FALSE;
	}

	if(tvb_strncaseeql(tvb, 0, "RFB ", 4) != 0) {
		return FALSE;
	}

	/* 0x2e = '.'   0xa = '\n' */
	if (tvb_get_guint8(tvb, 7) != 0x2e) {
		return FALSE;
	}

	if (tvb_get_guint8(tvb,11) != 0xa) {
		if (tvb_get_guint8(tvb,11) == 0) {
			/* Per bug 5469,  It appears that any VNC clients using gtk-vnc before [1] was
			* fixed will exhibit the described protocol violation that prevents wireshark
			* from dissecting the session.
			*
			* [1] http://git.gnome.org/browse/gtk-vnc/commit/?id=bc9e2b19167686dd381a0508af1a5113675d08a2
			*/
			if ((pinfo != NULL) && (tree != NULL)) {
				proto_tree_add_expert(tree, pinfo, &ei_vnc_possible_gtk_vnc_bug, tvb, -1, 0);
			}

			return TRUE;
		}

		return FALSE;
	}

	return TRUE;
}

static gboolean test_vnc_protocol(tvbuff_t *tvb, packet_info *pinfo,
				  proto_tree *tree, void *data _U_)
{
	conversation_t *conversation;

	if (vnc_is_client_or_server_version_message(tvb, NULL, NULL)) {
		conversation = conversation_new(pinfo->num, &pinfo->src,
						&pinfo->dst, pinfo->ptype,
						pinfo->srcport,
						pinfo->destport, 0);
		conversation_set_dissector(conversation, vnc_handle);
		dissect_vnc(tvb, pinfo, tree, data);
		return TRUE;
	}
	return FALSE;
}

/* Returns true if additional session startup messages follow */
static gboolean
vnc_startup_messages(tvbuff_t *tvb, packet_info *pinfo, gint offset,
		     proto_tree *tree, vnc_conversation_t
		     *per_conversation_info)
{
	guint8 num_security_types;
	guint32 desktop_name_len, auth_result, text_len, auth_code;
	vnc_packet_t *per_packet_info;
	gint num_tunnel_types;
	gint num_auth_types;
	proto_item* auth_item;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);

	if(!per_packet_info) {
		per_packet_info = wmem_new(wmem_file_scope(), vnc_packet_t);

		per_packet_info->state = per_conversation_info->vnc_next_state;
		per_packet_info->preferred_encoding = -1;

		p_add_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0, per_packet_info);
	}

	/* Packet dissection follows */
	switch(per_packet_info->state) {

	case VNC_SESSION_STATE_SERVER_VERSION :
		if (!vnc_is_client_or_server_version_message(tvb, pinfo, tree))
			return TRUE; /* we still hope to get a SERVER_VERSION message some day. Do not proceed yet */

		proto_tree_add_item(tree, hf_vnc_server_proto_ver, tvb, 4,
				    7, ENC_ASCII|ENC_NA);
		per_conversation_info->server_proto_ver =
			g_ascii_strtod((char *)tvb_get_string_enc(wmem_packet_scope(), tvb, 4, 7, ENC_ASCII), NULL);
		per_conversation_info->server_port = pinfo->srcport;

		col_add_fstr(pinfo->cinfo, COL_INFO,
				     "Server protocol version: %s",
				     tvb_format_text(tvb, 4, 7));

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_CLIENT_VERSION;
		break;

	case VNC_SESSION_STATE_CLIENT_VERSION :
		if (!vnc_is_client_or_server_version_message(tvb, pinfo, tree))
			return TRUE; /* we still hope to get a CLIENT_VERSION message some day. Do not proceed yet */

		proto_tree_add_item(tree, hf_vnc_client_proto_ver, tvb,
				    4, 7, ENC_ASCII|ENC_NA);
		per_conversation_info->client_proto_ver =
			g_ascii_strtod((char *)tvb_get_string_enc(wmem_packet_scope(), tvb, 4, 7, ENC_ASCII), NULL);

		col_add_fstr(pinfo->cinfo, COL_INFO,
				     "Client protocol version: %s",
				     tvb_format_text(tvb, 4, 7));

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SECURITY;
		break;

	case VNC_SESSION_STATE_SECURITY :
		col_set_str(pinfo->cinfo, COL_INFO, "Security types supported");

		/* We're checking against the client protocol version because
		 * the client is the final decider on which version to use
		 * after the server offers the highest version it supports. */

		if(per_conversation_info->client_proto_ver >= 3.007) {
			num_security_types = tvb_get_guint8(tvb, offset);
			if (tree) {
				proto_tree_add_item(tree,
						    hf_vnc_num_security_types,
						    tvb, offset, 1, ENC_BIG_ENDIAN);

				for(offset = 1; offset <= num_security_types; offset++){
					proto_tree_add_item(tree,
							    hf_vnc_security_type, tvb,
							    offset, 1, ENC_BIG_ENDIAN);
				}
			}
			per_conversation_info->vnc_next_state =	VNC_SESSION_STATE_SECURITY_TYPES;
		} else {
			/* Version < 3.007: The server decides the
			 * authentication type for us to use */
			proto_tree_add_item(tree, hf_vnc_server_security_type,
					    tvb, offset, 4, ENC_BIG_ENDIAN);
			/* The cast below is possible since in older versions of the protocol the only possible values are 0,1,2 */
			per_conversation_info->security_type_selected = (guint8)tvb_get_ntohl(tvb, offset);
			switch(per_conversation_info->security_type_selected) {

			case VNC_SECURITY_TYPE_INVALID:
				/* TODO: In this case (INVALID) the connection has failed */
				/* and there should be an error string describing the error */
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SECURITY_TYPES;
				break;

			case VNC_SECURITY_TYPE_NONE:
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_CLIENT_INIT;
				break;

			case VNC_SECURITY_TYPE_VNC:
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE;
				break;

			case VNC_SECURITY_TYPE_ARD:
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_ARD_AUTHENTICATION_CHALLENGE;
				break;

			default:
				/* Security type not supported by this dissector */
				break;
			}
		}

		break;

	case VNC_SESSION_STATE_SECURITY_TYPES :
		col_set_str(pinfo->cinfo, COL_INFO, "Authentication type selected by client");
		proto_tree_add_item(tree, hf_vnc_client_security_type, tvb, offset, 1, ENC_BIG_ENDIAN);
		per_conversation_info->security_type_selected =
			tvb_get_guint8(tvb, offset);

		switch(per_conversation_info->security_type_selected) {

		case VNC_SECURITY_TYPE_NONE :
			if(per_conversation_info->client_proto_ver >= 3.008)
				per_conversation_info->vnc_next_state =
					VNC_SESSION_STATE_SECURITY_RESULT;
			else
				per_conversation_info->vnc_next_state =
					VNC_SESSION_STATE_CLIENT_INIT;

			break;

		case VNC_SECURITY_TYPE_VNC :
			per_conversation_info->vnc_next_state =
				VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE;
			break;

		case VNC_SECURITY_TYPE_TIGHT :
			per_conversation_info->vnc_next_state =
				VNC_SESSION_STATE_TIGHT_TUNNELING_CAPABILITIES;
			per_conversation_info->tight_enabled = TRUE;
			break;

		case VNC_SECURITY_TYPE_ARD:
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_ARD_AUTHENTICATION_CHALLENGE;
			break;

		default :
			/* Security type not supported by this dissector */
			break;
		}

		break;

	case VNC_SESSION_STATE_TIGHT_TUNNELING_CAPABILITIES :
	{
		gint i;

		col_set_str(pinfo->cinfo, COL_INFO, "TightVNC tunneling capabilities supported");

		proto_tree_add_item(tree, hf_vnc_tight_num_tunnel_types, tvb, offset, 4, ENC_BIG_ENDIAN);
		num_tunnel_types = tvb_get_ntohl(tvb, offset);

		offset += 4;

		for(i = 0; i < num_tunnel_types; i++) {
			/* TightVNC and Xvnc don't support any tunnel capabilities yet, but each capability
			 * is 16 bytes, so skip them.
			 */

			proto_tree_add_item(tree, hf_vnc_tight_tunnel_type, tvb, offset, 16, ENC_BIG_ENDIAN);
			offset += 16;
		}

		if (num_tunnel_types == 0)
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_AUTH_CAPABILITIES;
		else
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_TUNNEL_TYPE_REPLY;
		break;
	}
	case VNC_SESSION_STATE_TIGHT_TUNNEL_TYPE_REPLY:
		/* Neither TightVNC nor Xvnc implement this; they just have a placeholder that emits an error
		 * message and closes the connection (xserver/hw/vnc/auth.c:rfbProcessClientTunnelingType).
		 * We should actually never get here...
		 */
		break;

	case VNC_SESSION_STATE_TIGHT_AUTH_CAPABILITIES:
		col_set_str(pinfo->cinfo, COL_INFO, "TightVNC authentication capabilities supported");

		proto_tree_add_item(tree, hf_vnc_tight_num_auth_types, tvb, offset, 4, ENC_BIG_ENDIAN);
		num_auth_types = tvb_get_ntohl(tvb, offset);
		offset += 4;

		{
			int i;
			const guint8 *vendor, *signature;
			for (i = 0; i < 1; i++) {
				auth_code = tvb_get_ntohl(tvb, offset);
				auth_item = proto_tree_add_item(tree, hf_vnc_tight_auth_code, tvb, offset, 4, ENC_BIG_ENDIAN);
				offset += 4;
				vendor = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII);
				process_vendor(tree, hf_vnc_tight_server_vendor, tvb, offset);
				offset += 4;
				proto_tree_add_item_ret_string(tree, hf_vnc_tight_signature, tvb, offset, 8, ENC_ASCII|ENC_NA, wmem_packet_scope(), &signature);
				offset += 8;

				switch(auth_code) {
					case VNC_SECURITY_TYPE_NONE:
						if ((g_ascii_strcasecmp(vendor, "STDV") != 0) || (g_ascii_strcasecmp(signature, "NOAUTH__") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					case VNC_SECURITY_TYPE_VNC:
						if ((g_ascii_strcasecmp(vendor, "STDV") != 0) || (g_ascii_strcasecmp(signature, "VNCAUTH_") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					case VNC_SECURITY_TYPE_VENCRYPT:
						if ((g_ascii_strcasecmp(vendor, "VENC") != 0) || (g_ascii_strcasecmp(signature, "VENCRYPT") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					case VNC_SECURITY_TYPE_GTK_VNC_SASL:
						if ((g_ascii_strcasecmp(vendor, "GTKV") != 0) || (g_ascii_strcasecmp(signature, "SASL____") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					case VNC_TIGHT_AUTH_TGHT_ULGNAUTH:
						if ((g_ascii_strcasecmp(vendor, "TGHT") != 0) || (g_ascii_strcasecmp(signature, "ULGNAUTH") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					case VNC_TIGHT_AUTH_TGHT_XTRNAUTH:
						if ((g_ascii_strcasecmp(vendor, "TGHT") != 0) || (g_ascii_strcasecmp(signature, "XTRNAUTH") != 0)) {
							expert_add_info(pinfo, auth_item, &ei_vnc_auth_code_mismatch);
						}
						break;
					default:
						expert_add_info(pinfo, auth_item, &ei_vnc_unknown_tight_vnc_auth);
						break;
				}
			}
		}

		if (num_auth_types == 0)
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_CLIENT_INIT;
		else
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_AUTH_TYPE_REPLY;
		break;

	case VNC_SESSION_STATE_TIGHT_AUTH_TYPE_REPLY:
		col_set_str(pinfo->cinfo, COL_INFO, "TightVNC authentication type selected by client");
		auth_code = tvb_get_ntohl(tvb, offset);
		auth_item = proto_tree_add_item(tree, hf_vnc_tight_auth_code, tvb, offset, 4, ENC_BIG_ENDIAN);

		switch(auth_code) {
			case VNC_SECURITY_TYPE_NONE:
				per_conversation_info->security_type_selected = VNC_SECURITY_TYPE_NONE;
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_CLIENT_INIT;
			break;
			case VNC_SECURITY_TYPE_VNC:
				per_conversation_info->security_type_selected = VNC_SECURITY_TYPE_VNC;
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE;
			break;
			case VNC_SECURITY_TYPE_GTK_VNC_SASL:
				per_conversation_info->security_type_selected = VNC_SECURITY_TYPE_GTK_VNC_SASL;
				/* TODO: dissection not implemented yet */
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3;
				break;
			case VNC_TIGHT_AUTH_TGHT_ULGNAUTH:
				per_conversation_info->security_type_selected = VNC_TIGHT_AUTH_TGHT_ULGNAUTH;
				/* TODO: dissection not implemented yet */
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3;
				break;
			case VNC_TIGHT_AUTH_TGHT_XTRNAUTH:
				per_conversation_info->security_type_selected = VNC_TIGHT_AUTH_TGHT_XTRNAUTH;
				/* TODO: dissection not implemented yet */
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3;
				break;
			default:
				expert_add_info(pinfo, auth_item, &ei_vnc_unknown_tight_vnc_auth);
				per_conversation_info->vnc_next_state = VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3;
				break;
		}

		break;

	case VNC_SESSION_STATE_TIGHT_UNKNOWN_PACKET3 :
		col_set_str(pinfo->cinfo, COL_INFO, "Unknown packet (TightVNC)");

		proto_tree_add_expert(tree, pinfo, &ei_vnc_unknown_tight, tvb, offset, -1);

		per_conversation_info->vnc_next_state =
			VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE;

		break;

	case VNC_SESSION_STATE_VNC_AUTHENTICATION_CHALLENGE :
		col_set_str(pinfo->cinfo, COL_INFO, "Authentication challenge from server");

		proto_tree_add_item(tree, hf_vnc_auth_challenge, tvb,
				    offset, 16, ENC_NA);

		per_conversation_info->vnc_next_state =
			VNC_SESSION_STATE_VNC_AUTHENTICATION_RESPONSE;
		break;

	case VNC_SESSION_STATE_VNC_AUTHENTICATION_RESPONSE :
		col_set_str(pinfo->cinfo, COL_INFO, "Authentication response from client");

		proto_tree_add_item(tree, hf_vnc_auth_response, tvb,
				    offset, 16, ENC_NA);

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SECURITY_RESULT;
		break;

	case VNC_SESSION_STATE_ARD_AUTHENTICATION_CHALLENGE :
		{
			gint key_len;

			col_set_str(pinfo->cinfo, COL_INFO, "ARD authentication challenge");

			proto_tree_add_item(tree, hf_vnc_ard_auth_generator, tvb,
						offset, 2, ENC_BIG_ENDIAN);
			proto_tree_add_item(tree, hf_vnc_ard_auth_key_len, tvb,
						offset + 2, 2, ENC_BIG_ENDIAN);

			key_len = tvb_get_ntohs(tvb, offset + 2);

			offset += 4;

			proto_tree_add_item(tree, hf_vnc_ard_auth_modulus, tvb,
						offset, key_len, ENC_NA);
			proto_tree_add_item(tree, hf_vnc_ard_auth_server_key, tvb,
						offset + key_len, key_len, ENC_NA);

			per_conversation_info->ard_key_length = key_len;
			per_conversation_info->vnc_next_state =
				VNC_SESSION_STATE_ARD_AUTHENTICATION_RESPONSE;
		}
		break;

	case VNC_SESSION_STATE_ARD_AUTHENTICATION_RESPONSE :
		col_set_str(pinfo->cinfo, COL_INFO, "ARD authentication response");

		proto_tree_add_item(tree, hf_vnc_ard_auth_credentials, tvb,
					offset, 128, ENC_NA);
		proto_tree_add_item(tree, hf_vnc_ard_auth_client_key, tvb,
					offset + 128, per_conversation_info->ard_key_length, ENC_NA);

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SECURITY_RESULT;
		break;

	case VNC_SESSION_STATE_SECURITY_RESULT :
		col_set_str(pinfo->cinfo, COL_INFO, "Authentication result");

		proto_tree_add_item(tree, hf_vnc_auth_result, tvb, offset,
				    4, ENC_BIG_ENDIAN);
		auth_result = tvb_get_ntohl(tvb, offset);
		offset += 4;

		switch(auth_result) {

		case 0 : /* OK */
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_CLIENT_INIT;
			break;

		case 1 : /* Failed */
			if(per_conversation_info->client_proto_ver >= 3.008) {
				text_len = tvb_get_ntohl(tvb, offset);
				proto_tree_add_item(tree, hf_vnc_auth_error_length, tvb, offset, 4, ENC_BIG_ENDIAN);
				offset += 4;

				proto_tree_add_item(tree, hf_vnc_auth_error, tvb,
						    offset, text_len, ENC_ASCII|ENC_NA);
			}

			return TRUE; /* All versions: Do not continue
					processing VNC packets as connection
					will be	closed after this packet. */

			break;
		}

		break;

	case VNC_SESSION_STATE_CLIENT_INIT :
		col_set_str(pinfo->cinfo, COL_INFO, "Share desktop flag");

		proto_tree_add_item(tree, hf_vnc_share_desktop_flag, tvb,
				    offset, 1, ENC_BIG_ENDIAN);

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_SERVER_INIT;

		break;

	case VNC_SESSION_STATE_SERVER_INIT :
		col_set_str(pinfo->cinfo, COL_INFO, "Server framebuffer parameters");

		proto_tree_add_item(tree, hf_vnc_width, tvb, offset, 2,
				    ENC_BIG_ENDIAN);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_height, tvb, offset, 2,
				    ENC_BIG_ENDIAN);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_server_bits_per_pixel,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		vnc_bytes_per_pixel = tvb_get_guint8(tvb, offset)/8;
		vnc_set_bytes_per_pixel(pinfo, vnc_bytes_per_pixel);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_depth, tvb, offset,
				    1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_big_endian_flag,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_true_color_flag,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_red_max,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_server_green_max,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_server_blue_max,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_server_red_shift,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_green_shift,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_server_blue_shift,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset += 1;

		proto_tree_add_item(tree, hf_vnc_padding,
				    tvb, offset, 3, ENC_NA);
		offset += 3; /* Skip over 3 bytes of padding */

		if(tvb_reported_length_remaining(tvb, offset) > 4) {
			/* Sometimes the desktop name & length is skipped */
			proto_tree_add_item(tree, hf_vnc_desktop_name_len,
					    tvb, offset, 4, ENC_BIG_ENDIAN);
			desktop_name_len = tvb_get_ntohl(tvb, offset);
			offset += 4;

			proto_tree_add_item(tree, hf_vnc_desktop_name,
					    tvb, offset, desktop_name_len,
					    ENC_ASCII|ENC_NA);
		}

		if(per_conversation_info->tight_enabled == TRUE)
			per_conversation_info->vnc_next_state =
				VNC_SESSION_STATE_TIGHT_INTERACTION_CAPS;
		else
			per_conversation_info->vnc_next_state = VNC_SESSION_STATE_NORMAL_TRAFFIC;
		break;

	case VNC_SESSION_STATE_TIGHT_INTERACTION_CAPS :
		col_set_str(pinfo->cinfo, COL_INFO, "TightVNC Interaction Capabilities");

		proto_tree_add_item(tree, hf_vnc_num_server_message_types,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		per_conversation_info->num_server_message_types = tvb_get_ntohs(tvb, offset);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_num_client_message_types,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		per_conversation_info->num_client_message_types = tvb_get_ntohs(tvb, offset);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_num_encoding_types,
				    tvb, offset, 2, ENC_BIG_ENDIAN);
		per_conversation_info->num_encoding_types = tvb_get_ntohs(tvb, offset);
		offset += 2;

		proto_tree_add_item(tree, hf_vnc_padding, tvb, offset, 2, ENC_NA);
		offset += 2;

		offset = process_tight_capabilities(tree,
						    hf_vnc_tight_server_message_type,
						    hf_vnc_tight_server_vendor,
						    hf_vnc_tight_server_name,
						    tvb, offset, per_conversation_info->num_server_message_types);
		offset = process_tight_capabilities(tree,
						    hf_vnc_tight_client_message_type,
						    hf_vnc_tight_client_vendor,
						    hf_vnc_tight_client_name,
						    tvb, offset, per_conversation_info->num_client_message_types);
		process_tight_capabilities(tree,
						    hf_vnc_tight_encoding_type,
						    hf_vnc_tight_encoding_vendor,
						    hf_vnc_tight_encoding_name,
						    tvb, offset, per_conversation_info->num_encoding_types);

		per_conversation_info->vnc_next_state = VNC_SESSION_STATE_NORMAL_TRAFFIC;
		break;

	case VNC_SESSION_STATE_NORMAL_TRAFFIC :
		return FALSE;
	}

	return TRUE;
}


static void
vnc_client_to_server(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		     proto_tree *tree)
{
	guint8 message_type;

	proto_item *ti;
	proto_tree *vnc_client_message_type_tree;

	message_type = tvb_get_guint8(tvb, *offset);

	ti = proto_tree_add_item(tree, hf_vnc_client_message_type, tvb,
				 *offset, 1, ENC_BIG_ENDIAN);

	vnc_client_message_type_tree =
		proto_item_add_subtree(ti, ett_vnc_client_message_type);

	*offset += 1;

	switch(message_type) {

	case VNC_CLIENT_MESSAGE_TYPE_SET_PIXEL_FORMAT :
		vnc_client_set_pixel_format(tvb, pinfo, offset,
					    vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_SET_ENCODINGS :
		vnc_client_set_encodings(tvb, pinfo, offset,
					 vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_FRAMEBUF_UPDATE_REQ :
		vnc_client_framebuffer_update_request(tvb, pinfo, offset,
						      vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_KEY_EVENT :
		vnc_client_key_event(tvb, pinfo, offset,
				     vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_POINTER_EVENT:
		vnc_client_pointer_event(tvb, pinfo, offset,
					 vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_CLIENT_CUT_TEXT :
		vnc_client_cut_text(tvb, pinfo, offset,
				    vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_MIRRORLINK :
		vnc_mirrorlink(tvb, pinfo, offset,
			       vnc_client_message_type_tree);
		break;

	case VNC_CLIENT_MESSAGE_TYPE_ENABLE_CONTINUOUS_UPDATES :
		col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Client Enable Continuous Updates");
		*offset += 9;
		break;

	case VNC_CLIENT_MESSAGE_TYPE_FENCE :
		vnc_fence(tvb, pinfo, offset,
			  vnc_client_message_type_tree);
		break;

	default :
		col_append_sep_fstr(pinfo->cinfo, COL_INFO, "; ",
				"Unknown client message type (%u)",
				message_type);
		break;
	}
}

static void
vnc_server_to_client(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		     proto_tree *tree)
{
	gint start_offset;
	guint8 message_type;
	gint bytes_needed = 0;

	proto_item *ti;
	proto_tree *vnc_server_message_type_tree;

again:
	start_offset = *offset;

	message_type = tvb_get_guint8(tvb, *offset);

	ti = proto_tree_add_item(tree, hf_vnc_server_message_type, tvb,
				 *offset, 1, ENC_BIG_ENDIAN);
	vnc_server_message_type_tree =
		proto_item_add_subtree(ti, ett_vnc_server_message_type);

	*offset += 1;

	switch(message_type) {

	case VNC_SERVER_MESSAGE_TYPE_FRAMEBUFFER_UPDATE :
		bytes_needed =
			vnc_server_framebuffer_update(tvb, pinfo, offset,
						      vnc_server_message_type_tree);
		break;

	case VNC_SERVER_MESSAGE_TYPE_SET_COLORMAP_ENTRIES :
		bytes_needed = vnc_server_set_colormap_entries(tvb, pinfo, offset, vnc_server_message_type_tree);
		break;

	case VNC_SERVER_MESSAGE_TYPE_RING_BELL :
		vnc_server_ring_bell(tvb, pinfo, offset,
				     vnc_server_message_type_tree);
		break;

	case VNC_SERVER_MESSAGE_TYPE_CUT_TEXT :
		bytes_needed = vnc_server_cut_text(tvb, pinfo, offset,
						   vnc_server_message_type_tree);
		break;

	case VNC_SERVER_MESSAGE_TYPE_MIRRORLINK :
		bytes_needed = vnc_mirrorlink(tvb, pinfo, offset,
					      vnc_server_message_type_tree);
		break;

	case VNC_SERVER_MESSAGE_TYPE_END_CONTINUOUS_UPDATES :
		col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Server End Continuous Updates");
		*offset += 1;
		break;

	case VNC_SERVER_MESSAGE_TYPE_FENCE :
		bytes_needed = vnc_fence(tvb, pinfo, offset,
			  vnc_server_message_type_tree);
		break;

	default :
		col_append_sep_str(pinfo->cinfo, COL_INFO, "; ",
				       "Unknown server message type");
		*offset = tvb_reported_length(tvb);  /* Swallow the rest of the segment */
		break;
	}

	if(bytes_needed > 0 && vnc_preference_desegment && pinfo->can_desegment) {
		proto_tree_add_expert(vnc_server_message_type_tree, pinfo, &ei_vnc_reassemble, tvb, start_offset, -1);
		pinfo->desegment_offset = start_offset;
		pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
		return;
	}

	if ((unsigned)*offset < tvb_reported_length(tvb)) {
		goto again;
	}
}


static void
vnc_client_set_pixel_format(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			    proto_tree *tree)
{
	col_set_str(pinfo->cinfo, COL_INFO, "Client set pixel format");

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 3, ENC_NA);
	*offset += 3; /* Skip over 3 bytes of padding */

	proto_tree_add_item(tree, hf_vnc_client_bits_per_pixel, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	vnc_bytes_per_pixel = tvb_get_guint8(tvb, *offset)/8;
	vnc_set_bytes_per_pixel(pinfo, vnc_bytes_per_pixel);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_depth, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	vnc_depth = tvb_get_guint8(tvb, *offset);
	vnc_set_depth(pinfo, vnc_depth);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_big_endian_flag, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_true_color_flag, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_red_max, tvb, *offset,
			    2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_client_green_max, tvb, *offset,
			    2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_client_blue_max, tvb, *offset,
			    2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_client_red_shift, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_green_shift, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_client_blue_shift, tvb, *offset,
			    1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 3, ENC_NA);
	*offset += 3; /* Skip over 3 bytes of padding */
}


static void
vnc_client_set_encodings(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			 proto_tree *tree)
{
	guint16       number_of_encodings;
	guint         counter;
	vnc_packet_t *per_packet_info;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	col_set_str(pinfo->cinfo, COL_INFO, "Client set encodings");

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 1, ENC_NA);
	*offset += 1; /* Skip over 1 byte of padding */

	number_of_encodings = tvb_get_ntohs(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_encoding_num, tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	per_packet_info->preferred_encoding = -1;

	for(counter = 0; counter < number_of_encodings; counter++) {
		proto_tree_add_item(tree,
				    hf_vnc_client_set_encodings_encoding_type,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);

		/* Remember the first real encoding as the preferred encoding,
		 * per xserver/hw/vnc/rfbserver.c:rfbProcessClientNormalMessage().
		 * Otherwise, use RAW as the preferred encoding.
		 */
		if (per_packet_info->preferred_encoding == -1) {
			int encoding;

			encoding = tvb_get_ntohl(tvb, *offset);

			switch(encoding) {
			case VNC_ENCODING_TYPE_RAW:
			case VNC_ENCODING_TYPE_RRE:
			case VNC_ENCODING_TYPE_CORRE:
			case VNC_ENCODING_TYPE_HEXTILE:
			case VNC_ENCODING_TYPE_ZLIB:
			case VNC_ENCODING_TYPE_TIGHT:
				per_packet_info->preferred_encoding = encoding;
				break;
			}
		}

		*offset += 4;
	}

	if (per_packet_info->preferred_encoding == -1)
		per_packet_info->preferred_encoding = VNC_ENCODING_TYPE_RAW;
}


static void
vnc_client_framebuffer_update_request(tvbuff_t *tvb, packet_info *pinfo,
				      gint *offset, proto_tree *tree)
{
	col_set_str(pinfo->cinfo, COL_INFO, "Client framebuffer update request");

	proto_tree_add_item(tree, hf_vnc_update_req_incremental,
			    tvb, *offset, 1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_update_req_x_pos,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_update_req_y_pos,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_update_req_width, tvb,
			    *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_update_req_height, tvb,
			    *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;
}


static void
vnc_client_key_event(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		     proto_tree *tree)
{
	col_set_str(pinfo->cinfo, COL_INFO, "Client key event");

	proto_tree_add_item(tree, hf_vnc_key_down, tvb, *offset, 1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 2, ENC_NA);
	*offset += 2; /* Skip over 2 bytes of padding */

	proto_tree_add_item(tree, hf_vnc_key, tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;
}


static void
vnc_client_pointer_event(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			 proto_tree *tree)
{
	col_set_str(pinfo->cinfo, COL_INFO, "Client pointer event");

	proto_tree_add_item(tree, hf_vnc_button_1_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_2_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_3_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_4_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_5_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_6_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_7_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_vnc_button_8_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);
	*offset += 1;

	proto_tree_add_item(tree, hf_vnc_pointer_x_pos, tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_pointer_y_pos, tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;
}


static void
vnc_client_cut_text(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		    proto_tree *tree)
{
	guint32 text_len;

	col_set_str(pinfo->cinfo, COL_INFO, "Client cut text");

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 3, ENC_NA);
	*offset += 3; /* Skip over 3 bytes of padding */

	text_len = tvb_get_ntohl(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_client_cut_text_len, tvb, *offset, 4,
			    ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_client_cut_text, tvb, *offset,
			    text_len, ENC_ASCII|ENC_NA);
	*offset += text_len;

}


static guint
vnc_server_framebuffer_update(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			      proto_tree *tree)
{
	guint       ii;
	guint       num_rects;
	guint16     width, height;
	guint       bytes_needed = 0;
	guint32     encoding_type;
	proto_item *ti, *ti_x, *ti_y, *ti_width, *ti_height;
	proto_tree *vnc_rect_tree, *vnc_encoding_type_tree;

	col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Server framebuffer update");

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 1, ENC_NA);
	*offset += 1;

	num_rects = tvb_get_ntohs(tvb, *offset);
	ti = proto_tree_add_item(tree, hf_vnc_rectangle_num, tvb, *offset, 2, ENC_BIG_ENDIAN);

	/* In some cases, TIGHT encoding ignores the "number of rectangles" field;	  */
	/* VNC_ENCODING_TYPE_LAST_RECT is used to indicate the end of the rectangle list. */
	/* (It appears that TIGHT encoding uses 0xFFFF for the num_rects field when the	  */
	/*  field is not being used). For now: we'll assume that a value 0f 0xFFFF means  */
	/*  that the field is not being used.						  */
	if (num_rects == 0xFFFF) {
		proto_item_append_text(ti, " [TIGHT encoding assumed (field is not used)]");
	}
	if ((num_rects != 0xFFFF) && (num_rects > 5000)) {
		expert_add_info_format(pinfo, ti, &ei_vnc_too_many_rectangles,
				"Too many rectangles (%d), aborting dissection", num_rects);
		return(0);
	}

	*offset += 2;

	for(ii = 0; ii < num_rects; ii++) {
		if (ii > 5000) {
			expert_add_info_format(pinfo, ti, &ei_vnc_too_many_rectangles,
					       "Too many rectangles (%d), aborting dissection", ii);
			return(0);
		}
		VNC_BYTES_NEEDED(12);

		vnc_rect_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 12,
					 ett_vnc_rect, NULL, "Rectangle #%d", ii+1);


		ti_x = proto_tree_add_item(vnc_rect_tree, hf_vnc_fb_update_x_pos,
					   tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		ti_y = proto_tree_add_item(vnc_rect_tree, hf_vnc_fb_update_y_pos,
					   tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		ti_width = proto_tree_add_item(vnc_rect_tree, hf_vnc_fb_update_width,
					       tvb, *offset, 2, ENC_BIG_ENDIAN);
		width = tvb_get_ntohs(tvb, *offset);
		*offset += 2;

		ti_height = proto_tree_add_item(vnc_rect_tree, hf_vnc_fb_update_height,
						tvb, *offset, 2, ENC_BIG_ENDIAN);
		height = tvb_get_ntohs(tvb, *offset);
		*offset += 2;

		ti = proto_tree_add_item(vnc_rect_tree,
					 hf_vnc_fb_update_encoding_type,
					 tvb, *offset, 4, ENC_BIG_ENDIAN);

		encoding_type = tvb_get_ntohl(tvb, *offset);
		*offset += 4;

		if (encoding_type == VNC_ENCODING_TYPE_LAST_RECT)
			break; /* exit the loop */

		vnc_encoding_type_tree =
			proto_item_add_subtree(ti, ett_vnc_encoding_type);

		switch(encoding_type) {

		case VNC_ENCODING_TYPE_RAW:
			bytes_needed = vnc_raw_encoding(tvb, pinfo, offset,
							vnc_encoding_type_tree,
							width, height);
			break;

		case VNC_ENCODING_TYPE_COPY_RECT:
			bytes_needed =
				vnc_copyrect_encoding(tvb, pinfo, offset,
						      vnc_encoding_type_tree,
						      width, height);
			break;

		case VNC_ENCODING_TYPE_RRE:
			bytes_needed =
				vnc_rre_encoding(tvb, pinfo, offset,
						 vnc_encoding_type_tree,
						 width, height);
			break;

		case VNC_ENCODING_TYPE_HEXTILE:
			bytes_needed =
				vnc_hextile_encoding(tvb, pinfo, offset,
						     vnc_encoding_type_tree,
						     width, height);
			break;

		case VNC_ENCODING_TYPE_RLE:
			bytes_needed =
				vnc_zrle_encoding(tvb, pinfo, offset,
						  vnc_encoding_type_tree,
						  width, height);
			break;

		case VNC_ENCODING_TYPE_TIGHT:
			bytes_needed =
				vnc_tight_encoding(tvb, pinfo, offset,
						   vnc_encoding_type_tree,
						   width, height);
			break;

		case VNC_ENCODING_TYPE_RICH_CURSOR:
		case VNC_ENCODING_TYPE_X_CURSOR:
			proto_item_append_text (ti_x,      " (hotspot X)");
			proto_item_append_text (ti_y,      " (hotspot Y)");
			proto_item_append_text (ti_width,  " (cursor width)");
			proto_item_append_text (ti_height, " (cursor height)");

			if (encoding_type == VNC_ENCODING_TYPE_RICH_CURSOR)
				bytes_needed = vnc_rich_cursor_encoding(tvb, pinfo, offset, vnc_encoding_type_tree, width, height);
			else
				bytes_needed = vnc_x_cursor_encoding(tvb, pinfo, offset, vnc_encoding_type_tree, width, height);

			break;

		case VNC_ENCODING_TYPE_POINTER_POS:
			proto_item_append_text (ti_x,      " (pointer X)");
			proto_item_append_text (ti_y,      " (pointer Y)");
			proto_item_append_text (ti_width,  " (unused)");
			proto_item_append_text (ti_height, " (unused)");
			bytes_needed = 0;
			break;

		case VNC_ENCODING_TYPE_DESKTOP_SIZE:

			/* There is no payload for this message type */

			bytes_needed = 0;
			break;

		case VNC_ENCODING_TYPE_EXTENDED_DESK_SIZE :
			bytes_needed = vnc_extended_desktop_size(tvb, offset, vnc_encoding_type_tree);
			break;

		case VNC_ENCODING_TYPE_KEYBOARD_LED_STATE :

			/* There is no payload for this message type */

			bytes_needed = 0;
			break;

		case VNC_ENCODING_TYPE_SUPPORTED_MESSAGES :
			bytes_needed = vnc_supported_messages(tvb, offset,
							      vnc_encoding_type_tree,
							      width);
			break;

		case VNC_ENCODING_TYPE_SUPPORTED_ENCODINGS :
			bytes_needed = vnc_supported_encodings(tvb, offset,
							       vnc_encoding_type_tree,
							       width, height);
			break;

		case VNC_ENCODING_TYPE_SERVER_IDENTITY :
			bytes_needed = vnc_server_identity(tvb, offset,
							   vnc_encoding_type_tree,
							   width);
			break;

		case VNC_ENCODING_TYPE_CONTEXT_INFORMATION :
			bytes_needed = vnc_context_information(tvb, offset,
							       vnc_encoding_type_tree);
			break;

		case VNC_ENCODING_TYPE_SLRLE :
			bytes_needed = vnc_slrle_encoding(tvb, pinfo, offset,
							  vnc_encoding_type_tree,
							  height);
			break;

		case VNC_ENCODING_TYPE_H264 :
			bytes_needed = vnc_h264_encoding(tvb, offset,
							 vnc_encoding_type_tree);
			break;

		}

		/* Check if the routines above requested more bytes to
		 * be desegmented. */
		if(bytes_needed > 0)
			return bytes_needed;
	}

	return 0;
}

static guint32
vnc_extended_desktop_size(tvbuff_t *tvb, gint *offset, proto_tree *tree)
{

	guint8      i, num_of_screens;
	proto_tree *screen_tree;

	num_of_screens = tvb_get_guint8(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_desktop_screen_num, tvb, *offset, 1, ENC_BIG_ENDIAN);
	*offset += 1;
	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 3, ENC_NA);

	VNC_BYTES_NEEDED((guint32)(3 + (num_of_screens * 16)));
	*offset += 3;
	for(i = 0; i < num_of_screens; i++) {
		screen_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 16, ett_vnc_desktop_screen, NULL, "Screen #%u", i+1);

		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_id, tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_x, tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_y, tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_width, tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_height, tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(screen_tree, hf_vnc_desktop_screen_flags, tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
	}

	return 0;
}

static guint
vnc_raw_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		 proto_tree *tree, const guint16 width, const guint16 height)
{
	guint8 bytes_per_pixel = vnc_get_bytes_per_pixel(pinfo);
	guint length;

	length = width * height * bytes_per_pixel;
	VNC_BYTES_NEEDED(length);

	proto_tree_add_item(tree, hf_vnc_raw_pixel_data, tvb, *offset,
			    length, ENC_NA);
	*offset += length;

	return 0; /* bytes_needed */
}


static guint
vnc_copyrect_encoding(tvbuff_t *tvb, packet_info *pinfo _U_, gint *offset,
		      proto_tree *tree, const guint16 width _U_, const guint16 height _U_)
{
	proto_tree_add_item(tree, hf_vnc_copyrect_src_x_pos, tvb, *offset,
			    2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_copyrect_src_y_pos, tvb, *offset,
			    2, ENC_BIG_ENDIAN);
	*offset += 2;

	return 0; /* bytes_needed */
}


static guint
vnc_rre_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		 proto_tree *tree, const guint16 width _U_, const guint16 height _U_)
{
	guint8      bytes_per_pixel = vnc_get_bytes_per_pixel(pinfo);
	guint32     num_subrects, i;
	guint       bytes_needed;
	proto_item *ti;
	proto_tree *subrect_tree;

	VNC_BYTES_NEEDED(4);
	ti = proto_tree_add_item(tree, hf_vnc_rre_num_subrects, tvb, *offset,
				 4, ENC_BIG_ENDIAN);
	num_subrects = tvb_get_ntohl(tvb, *offset);
	*offset += 4;

	if (num_subrects > 10000) {
		expert_add_info_format(pinfo, ti, &ei_vnc_too_many_sub_rectangles,
				"Too many sub-rectangles (%d), aborting dissection", num_subrects);
		return(0);
	}

	*offset += 2;
	VNC_BYTES_NEEDED(bytes_per_pixel);
	proto_tree_add_item(tree, hf_vnc_rre_bg_pixel, tvb, *offset,
			    bytes_per_pixel, ENC_NA);
	*offset += bytes_per_pixel;

	/*  We know we need (at least) all these bytes, so ask for them now
	 *  (instead of a few at a time...).
	 */
	bytes_needed = bytes_per_pixel + 8;
	VNC_BYTES_NEEDED(bytes_needed * num_subrects);
	for(i = 0; i < num_subrects; i++) {

		subrect_tree = proto_tree_add_subtree_format(tree, tvb, *offset, bytes_per_pixel +
					 8, ett_vnc_rre_subrect, NULL, "Subrectangle #%d", i+1);

		proto_tree_add_item(subrect_tree, hf_vnc_rre_subrect_pixel,
				    tvb, *offset, bytes_per_pixel, ENC_NA);
		*offset += bytes_per_pixel;

		proto_tree_add_item(subrect_tree, hf_vnc_rre_subrect_x_pos,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		proto_tree_add_item(subrect_tree, hf_vnc_rre_subrect_y_pos,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		proto_tree_add_item(subrect_tree, hf_vnc_rre_subrect_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		proto_tree_add_item(subrect_tree, hf_vnc_rre_subrect_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
	}

	return 0; /* bytes_needed */
}


static guint
vnc_hextile_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		     proto_tree *tree, const guint16 width, const guint16 height)
{
	guint8      bytes_per_pixel = vnc_get_bytes_per_pixel(pinfo);
	guint8      i, subencoding_mask, num_subrects, subrect_len, tile_height, tile_width;
	guint32     raw_length;
	proto_tree *tile_tree, *subencoding_mask_tree, *subrect_tree, *num_subrects_tree;
	proto_item *ti;
	guint16     current_height  = 0, current_width;

	while(current_height != height) {
		if (current_height + 16 > height)
			tile_height = height - current_height;
		else
			tile_height = 16;
		current_height += tile_height;
		current_width = 0;
		while(current_width != width) {
			if (current_width + 16 > width)
				tile_width = width - current_width;
			else
				tile_width = 16;

			current_width += tile_width;

			VNC_BYTES_NEEDED(1);
			subencoding_mask = tvb_get_guint8(tvb, *offset);

			tile_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 1, ett_vnc_hextile_tile, NULL,
							"Tile {%d:%d}, sub encoding mask %u", current_width, current_height, subencoding_mask);

			ti = proto_tree_add_item(tile_tree, hf_vnc_hextile_subencoding_mask, tvb,
						 *offset, 1, ENC_BIG_ENDIAN);

			subencoding_mask_tree =
				proto_item_add_subtree(ti, ett_vnc_hextile_subencoding_mask);

			proto_tree_add_item(subencoding_mask_tree,
					    hf_vnc_hextile_raw, tvb, *offset, 1,
					    ENC_BIG_ENDIAN);
			proto_tree_add_item(subencoding_mask_tree,
					    hf_vnc_hextile_bg, tvb, *offset, 1,
					    ENC_BIG_ENDIAN);
			proto_tree_add_item(subencoding_mask_tree,
					    hf_vnc_hextile_fg, tvb, *offset, 1,
					    ENC_BIG_ENDIAN);
			proto_tree_add_item(subencoding_mask_tree,
					    hf_vnc_hextile_anysubrects, tvb, *offset, 1,
					    ENC_BIG_ENDIAN);
			proto_tree_add_item(subencoding_mask_tree,
					    hf_vnc_hextile_subrectscolored, tvb, *offset, 1,
					    ENC_BIG_ENDIAN);
			*offset += 1;

			if(subencoding_mask & 0x1) { /* Raw */
				raw_length = tile_width * tile_height * bytes_per_pixel;

				proto_tree_add_item(tile_tree, hf_vnc_hextile_raw_value, tvb,
						    *offset, raw_length, ENC_NA);
				VNC_BYTES_NEEDED(raw_length);
				*offset += raw_length;
			} else {
				if(subencoding_mask & 0x2) { /* Background Specified */
					VNC_BYTES_NEEDED(bytes_per_pixel);
					proto_tree_add_item(tile_tree, hf_vnc_hextile_bg_value,
							    tvb, *offset, bytes_per_pixel,
							    ENC_NA);
					*offset += bytes_per_pixel;
				}

				if(subencoding_mask & 0x4) { /* Foreground Specified */
					VNC_BYTES_NEEDED(bytes_per_pixel);
					proto_tree_add_item(tile_tree, hf_vnc_hextile_fg_value,
							    tvb, *offset, bytes_per_pixel,
							    ENC_NA);
					*offset += bytes_per_pixel;
				}

				if(subencoding_mask & 0x8) { /* Any Subrects */
					VNC_BYTES_NEEDED(3); /* 1 byte for number of subrects field, +2 at least for 1 subrect */
					ti = proto_tree_add_item(tile_tree,
								 hf_vnc_hextile_num_subrects,
								 tvb, *offset, 1,
								 ENC_BIG_ENDIAN);
					num_subrects = tvb_get_guint8(tvb, *offset);
					*offset += 1;

					if(subencoding_mask & 0x10)
						subrect_len = bytes_per_pixel + 2;
					else
						subrect_len = 2;
					VNC_BYTES_NEEDED((guint)(subrect_len * num_subrects));

					num_subrects_tree =
						proto_item_add_subtree(ti, ett_vnc_hextile_num_subrects);

					for(i = 0; i < num_subrects; i++) {
						subrect_tree = proto_tree_add_subtree_format(num_subrects_tree, tvb,
									 *offset, subrect_len, ett_vnc_hextile_subrect, NULL,
									 "Subrectangle #%d", i+1);

						if(subencoding_mask & 0x10) {
							/* Subrects Colored */
							proto_tree_add_item(subrect_tree, hf_vnc_hextile_subrect_pixel_value, tvb, *offset, bytes_per_pixel, ENC_NA);

							*offset += bytes_per_pixel;
						}

						proto_tree_add_item(subrect_tree,
								    hf_vnc_hextile_subrect_x_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);

						proto_tree_add_item(subrect_tree, hf_vnc_hextile_subrect_y_pos, tvb, *offset, 1, ENC_BIG_ENDIAN);

						*offset += 1;

						proto_tree_add_item(subrect_tree, hf_vnc_hextile_subrect_width, tvb, *offset, 1, ENC_BIG_ENDIAN);

						proto_tree_add_item(subrect_tree, hf_vnc_hextile_subrect_height, tvb, *offset, 1, ENC_BIG_ENDIAN);

						*offset += 1;
					}
				}
			}
		}
	}
	return 0; /* bytes_needed */
}

static guint
vnc_supported_messages(tvbuff_t *tvb, gint *offset, proto_tree *tree,
		       const guint16 width)
{
	VNC_BYTES_NEEDED(width);
	if (width >= 64) {
		proto_tree_add_item(tree,
				    hf_vnc_supported_messages_client2server,
				    tvb, *offset, 32, ENC_NA);
		*offset += 32;
		proto_tree_add_item(tree,
				    hf_vnc_supported_messages_server2client,
				    tvb, *offset, 32, ENC_NA);
		*offset += 32;
		*offset += width - 64;
	} else {
		*offset += width;
	}

	return 0; /* bytes_needed */
}

static guint
vnc_supported_encodings(tvbuff_t *tvb, gint *offset, proto_tree *tree,
		        const guint16 width, const guint16 height)
{
	guint16 i = width;

	proto_tree_add_uint(tree, hf_vnc_num_supported_encodings, tvb, *offset, 0, height);

	VNC_BYTES_NEEDED(width);
	for (; i >= 4; i -= 4) {
		proto_tree_add_item(tree, hf_vnc_supported_encodings,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
	}
	*offset += i;

	return 0; /* bytes_needed */
}

static guint
vnc_server_identity(tvbuff_t *tvb, gint *offset, proto_tree *tree,
		    const guint16 width)
{
	VNC_BYTES_NEEDED(width);
	proto_tree_add_item(tree, hf_vnc_server_identity,
			    tvb, *offset, width, ENC_ASCII|ENC_NA);
	*offset += width;

	return 0; /* bytes_needed */
}

static guint
vnc_mirrorlink(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
	       proto_tree *tree)
{
	guint8 type;
	guint16 length;
	guint16 num, i;
	gint end;
	proto_tree *sub_tree;

	/* Header */
	VNC_BYTES_NEEDED(3);

	type = tvb_get_guint8(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_mirrorlink_type,
			    tvb, *offset, 1, ENC_BIG_ENDIAN);
	*offset += 1;

	length = tvb_get_ntohs(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_mirrorlink_length,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	col_add_fstr(pinfo->cinfo, COL_INFO, "MirrorLink (%s)",
		     val_to_str_const(type, vnc_mirrorlink_types_vs,
				      "Unknown"));

	/* Payload */
	end = *offset + length;

	switch(type) {

	case VNC_ML_EXT_BYE_BYE :
		break;

	case VNC_ML_EXT_SERVER_DISPLAY_CONFIGURATION :
		VNC_BYTES_NEEDED(12);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_version_major,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_version_minor,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_framebuffer_configuration,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pixel_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pixel_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pixel_format,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;

	case VNC_ML_EXT_CLIENT_DISPLAY_CONFIGURATION :
		VNC_BYTES_NEEDED(14);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_version_major,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_version_minor,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_framebuffer_configuration,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pixel_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pixel_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_display_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_display_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_display_distance,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		break;

	case VNC_ML_EXT_SERVER_EVENT_CONFIGURATION :
	case VNC_ML_EXT_CLIENT_EVENT_CONFIGURATION :
		VNC_BYTES_NEEDED(28);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_keyboard_language,
				    tvb, *offset, 2, ENC_ASCII|ENC_NA);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_keyboard_country,
				    tvb, *offset, 2, ENC_ASCII|ENC_NA);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_ui_language,
				    tvb, *offset, 2, ENC_ASCII|ENC_NA);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_ui_country,
				    tvb, *offset, 2, ENC_ASCII|ENC_NA);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_knob_keys,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_device_keys,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_multimedia_keys,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_key_related,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_pointer_related,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;

	case VNC_ML_EXT_EVENT_MAPPING :
	case VNC_ML_EXT_EVENT_MAPPING_REQUEST :
		VNC_BYTES_NEEDED(8);
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_key_symbol_value_client,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_key_symbol_value_server,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;

	case VNC_ML_EXT_KEY_EVENT_LISTING :
		VNC_BYTES_NEEDED(4);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_key_configuration,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		num = tvb_get_guint8(tvb, *offset);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_key_num_events,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_key_event_counter,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		VNC_BYTES_NEEDED((guint)(4 * num));
		sub_tree = proto_tree_add_subtree(tree, tvb, *offset, 4 * num,
					 ett_vnc_key_events, NULL, "Key Event List");
		for (; num > 0; num--) {
			proto_tree_add_item(sub_tree,
					    hf_vnc_mirrorlink_key_symbol_value,
					    tvb, *offset, 4, ENC_BIG_ENDIAN);
			*offset += 4 ;
		}
		break;

	case VNC_ML_EXT_KEY_EVENT_LISTING_REQUEST :
		VNC_BYTES_NEEDED(4);
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_key_request_configuration,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;

	case VNC_ML_EXT_VIRTUAL_KEYBOARD :
		VNC_BYTES_NEEDED(16);
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_keyboard_configuration,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_cursor_x,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_cursor_y,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_x,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_y,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		break;

	case VNC_ML_EXT_VIRTUAL_KEYBOARD_REQUEST :
		VNC_BYTES_NEEDED(4);
		proto_tree_add_item(tree,
				    hf_vnc_mirrorlink_keyboard_request_configuration,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;

	case VNC_ML_EXT_DEVICE_STATUS :
	case VNC_ML_EXT_DEVICE_STATUS_REQUEST :
		VNC_BYTES_NEEDED(4);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_device_status,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		break;
/*
	case VNC_ML_EXT_CONTENT_ATTESTATION :
		break;

	case VNC_ML_EXT_CONTENT_ATTESTATION_REQUEST :
		break;
*/
	case VNC_ML_EXT_FB_BLOCKING_NOTIFICATION :
		VNC_BYTES_NEEDED(14);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_fb_block_x,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_fb_block_y,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_fb_block_width,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_fb_block_height,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_app_id,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_fb_block_reason,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		break;

	case VNC_ML_EXT_AUDIO_BLOCKING_NOTIFICATION :
		VNC_BYTES_NEEDED(6);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_app_id,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		proto_tree_add_item(tree, hf_vnc_mirrorlink_audio_block_reason,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		break;

	case VNC_ML_EXT_TOUCH_EVENT :
		VNC_BYTES_NEEDED(1);
		num = tvb_get_guint8(tvb, *offset);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_touch_num_events,
				    tvb, *offset, 1, ENC_BIG_ENDIAN);
		*offset += 1;
		VNC_BYTES_NEEDED((guint)(6 * num));
		/*sub_tree = proto_item_add_subtree(tree, ett_vnc_touch_events);*/
		for (i = 0; i < num; i++) {
			sub_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 6,
						 ett_vnc_touch_events, NULL, "Touch Event #%d", i + 1);

			proto_tree_add_item(sub_tree, hf_vnc_mirrorlink_touch_x,
					    tvb, *offset, 2, ENC_BIG_ENDIAN);
			*offset += 2;
			proto_tree_add_item(sub_tree, hf_vnc_mirrorlink_touch_y,
					    tvb, *offset, 2, ENC_BIG_ENDIAN);
			*offset += 2;
			proto_tree_add_item(sub_tree,
					    hf_vnc_mirrorlink_touch_id,
					    tvb, *offset, 1, ENC_BIG_ENDIAN);
			*offset += 1;
			proto_tree_add_item(sub_tree,
					    hf_vnc_mirrorlink_touch_pressure,
					    tvb, *offset, 1, ENC_BIG_ENDIAN);
			*offset += 1;
		}
		break;

	case VNC_ML_EXT_FB_ALTERNATIVE_TEXT :
		VNC_BYTES_NEEDED(6);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_app_id,
				    tvb, *offset, 4, ENC_BIG_ENDIAN);
		*offset += 4;
		num = tvb_get_ntohs(tvb, *offset);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_length,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		VNC_BYTES_NEEDED(num);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text,
				    tvb, *offset, num, ENC_ASCII|ENC_NA);
		*offset += num;
		break;

	case VNC_ML_EXT_FB_ALTERNATIVE_TEXT_REQUEST :
		VNC_BYTES_NEEDED(2);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_text_max_length,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
		break;

	}

	if (end > *offset) {
		length = end - *offset;
		VNC_BYTES_NEEDED(length);
		proto_tree_add_item(tree, hf_vnc_mirrorlink_unknown,
				    tvb, *offset, length, ENC_NA);
		*offset = end;
	}

	return 0; /* bytes_needed */
}

static guint
vnc_fence(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
	  proto_tree *tree)
{
	guint payload_length;

	VNC_BYTES_NEEDED(8);

	payload_length = tvb_get_guint8(tvb, *offset+7);
	VNC_BYTES_NEEDED((8+payload_length));

	col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Fence");

	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 3, ENC_NA);
	*offset += 3;  /* skip padding */

	proto_tree_add_bitmask(tree, tvb, *offset, hf_vnc_fence_flags,
			       ett_vnc_fence_flags, vnc_fence_flags, ENC_BIG_ENDIAN);

	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_fence_payload_length,
			    tvb, *offset, 1, ENC_BIG_ENDIAN);

	*offset += 1;

	if (payload_length > 0) {
		proto_tree_add_item(tree, hf_vnc_fence_payload,
				    tvb, *offset, payload_length, ENC_NA);
		*offset += payload_length;
	}
	return 0;
}

static guint
vnc_context_information(tvbuff_t *tvb, gint *offset, proto_tree *tree)
{
	VNC_BYTES_NEEDED(20);

	proto_tree_add_item(tree, hf_vnc_context_information_app_id,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_context_information_app_trust_level,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree,
			    hf_vnc_context_information_content_trust_level,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	proto_tree_add_item(tree, hf_vnc_context_information_app_category,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_context_information_content_category,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_context_information_content_rules,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	return 0; /* bytes_needed */
}

static guint
vnc_slrle_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		   proto_tree *tree, const guint16 height)
{
	guint8 depth = vnc_get_depth(pinfo);
	guint8 depth_mod = depth % 8;
	guint8 bytes_per_run;
	guint16 num_runs, i;
	guint length;
	proto_tree *sub_tree;

	if (depth_mod <= 4)
		bytes_per_run = ( 8 - depth_mod + depth) / 8;
	else
		bytes_per_run = (16 - depth_mod + depth) / 8;

	for (i = 0; i < height; i++) {
		VNC_BYTES_NEEDED(2);
		num_runs = tvb_get_ntohs(tvb, *offset);

		length = num_runs * bytes_per_run;

		sub_tree = proto_tree_add_subtree_format(tree, tvb, *offset, 2 + length,
					 ett_vnc_slrle_subline, NULL, "Scanline #%d", i+1);

		proto_tree_add_item(sub_tree, hf_vnc_slrle_run_num,
				    tvb, *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		VNC_BYTES_NEEDED(length);
		proto_tree_add_item(sub_tree, hf_vnc_slrle_run_data,
				    tvb, *offset, length, ENC_NA);
		*offset += length;
	}

	return 0; /* bytes_needed */
}

static guint
vnc_h264_encoding(tvbuff_t *tvb, gint *offset, proto_tree *tree)
{
	guint32 nbytes;

	VNC_BYTES_NEEDED(16);

	/*0 == P-Frame; 1 == B-Frame; 2 == I-Frame*/
	proto_tree_add_item(tree, hf_vnc_h264_slice_type,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	nbytes = tvb_get_ntohl(tvb, *offset);
	proto_tree_add_item(tree, hf_vnc_h264_nbytes,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_h264_width,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	proto_tree_add_item(tree, hf_vnc_h264_height,
			    tvb, *offset, 4, ENC_BIG_ENDIAN);
	*offset += 4;

	VNC_BYTES_NEEDED(nbytes);
	proto_tree_add_item(tree, hf_vnc_h264_data,
			    tvb, *offset, nbytes, ENC_NA);
	*offset += nbytes;

	return 0; /* bytes_needed */
}

#ifdef HAVE_ZLIB
static guint
vnc_zrle_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		  proto_tree *tree, const guint16 width, const guint16 height)
#else
static guint
vnc_zrle_encoding(tvbuff_t *tvb, packet_info *pinfo _U_, gint *offset,
		  proto_tree *tree, const guint16 width _U_, const guint16 height _U_)
#endif
{
	guint32 data_len;
#ifdef HAVE_ZLIB
	guint8 palette_size;
	guint8 bytes_per_cpixel = vnc_get_bytes_per_pixel(pinfo);
	gint uncomp_offset = 0;
	guint length;
	gint subencoding_type;
	tvbuff_t *uncomp_tvb;
	proto_tree *zrle_subencoding_tree;
	proto_item *ti;
#endif

	VNC_BYTES_NEEDED(4);
	proto_tree_add_item(tree, hf_vnc_zrle_len, tvb, *offset,
			    4, ENC_BIG_ENDIAN);
	data_len = tvb_get_ntohl(tvb, *offset);

	*offset += 4;

	VNC_BYTES_NEEDED(data_len);

	proto_tree_add_item(tree, hf_vnc_zrle_data, tvb, *offset,
			    data_len, ENC_NA);

#ifdef HAVE_ZLIB
	uncomp_tvb = tvb_child_uncompress(tvb, tvb, *offset, data_len);

	if(uncomp_tvb != NULL) {
		add_new_data_source(pinfo, uncomp_tvb,
				    "Uncompressed ZRLE data");

		ti = proto_tree_add_item(tree, hf_vnc_zrle_subencoding,
					 uncomp_tvb, uncomp_offset, 1, ENC_BIG_ENDIAN);
		zrle_subencoding_tree =
			proto_item_add_subtree(ti, ett_vnc_zrle_subencoding);

		proto_tree_add_item(zrle_subencoding_tree, hf_vnc_zrle_rle,
				    uncomp_tvb, uncomp_offset, 1, ENC_BIG_ENDIAN);

		proto_tree_add_item(zrle_subencoding_tree,
				    hf_vnc_zrle_palette_size, uncomp_tvb,
				    uncomp_offset, 1, ENC_BIG_ENDIAN);

		subencoding_type = tvb_get_guint8(uncomp_tvb, uncomp_offset);
		palette_size = subencoding_type & 0x7F;

		uncomp_offset += 1;

		if(subencoding_type == 0) { /* Raw */
			length = width * height * bytes_per_cpixel;
			VNC_BYTES_NEEDED(length);

			/* XXX - not working yet! */

			proto_tree_add_item(zrle_subencoding_tree,
					    hf_vnc_zrle_raw, uncomp_tvb,
					    uncomp_offset, length, ENC_NA);

		} else if(subencoding_type >= 130 && subencoding_type <= 255) {
			length = palette_size * bytes_per_cpixel;
			VNC_BYTES_NEEDED(length);

			proto_tree_add_item(zrle_subencoding_tree,
					    hf_vnc_zrle_palette, uncomp_tvb,
					    uncomp_offset, length, ENC_NA);

			/* XXX - Not complete! */
		}

	} else {
		proto_tree_add_expert(tree, pinfo, &ei_vnc_zrle_failed, tvb, *offset, data_len);
	}
#endif /* HAVE_ZLIB */

	*offset += data_len;

	return 0; /* bytes_needed */
}


static guint
read_compact_len(tvbuff_t *tvb, gint *offset, gint *length, gint *value_length)
{
	gint b;

	VNC_BYTES_NEEDED(1);

	*value_length = 0;

	b = tvb_get_guint8(tvb, *offset);
	*offset += 1;
	*value_length += 1;

	*length = b & 0x7f;
	if ((b & 0x80) != 0) {
		VNC_BYTES_NEEDED(1);

		b = tvb_get_guint8(tvb, *offset);
		*offset += 1;
		*value_length += 1;

		*length |= (b & 0x7f) << 7;

		if ((b & 0x80) != 0) {
			VNC_BYTES_NEEDED (1);

			b = tvb_get_guint8(tvb, *offset);
			*offset += 1;
			*value_length += 1;

			*length |= (b & 0xff) << 14;
		}
	}

	return 0;
}


static guint
process_compact_length_and_image_data(tvbuff_t *tvb, gint *offset, proto_tree *tree)
{
	guint bytes_needed;
	guint length, value_length;

	bytes_needed = read_compact_len (tvb, offset, &length, &value_length);
	if (bytes_needed != 0)
		return bytes_needed;

	proto_tree_add_uint(tree, hf_vnc_tight_image_len, tvb, *offset - value_length, value_length, length);

	VNC_BYTES_NEEDED(length);
	proto_tree_add_item(tree, hf_vnc_tight_image_data, tvb, *offset, length, ENC_NA);
	*offset += length;

	return 0; /* bytes_needed */
}


static guint
process_tight_rect_filter_palette(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
				  proto_tree *tree, gint *bits_per_pixel)
{
	vnc_packet_t *per_packet_info;
	gint num_colors;
	guint palette_bytes;

	/* See TightVNC's vnc_unixsrc/vncviewer/tight.c:InitFilterPaletteBPP() */

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	VNC_BYTES_NEEDED(1);
	proto_tree_add_item(tree, hf_vnc_tight_palette_num_colors, tvb, *offset, 1, ENC_BIG_ENDIAN);
	num_colors = tvb_get_guint8(tvb, *offset);
	*offset += 1;

	num_colors++;
	if (num_colors < 2)
		return 0;

	if (per_packet_info->depth == 24)
		palette_bytes = num_colors * 3;
	else
		palette_bytes = num_colors * per_packet_info->depth / 8;

	VNC_BYTES_NEEDED(palette_bytes);
	proto_tree_add_item(tree, hf_vnc_tight_palette_data, tvb, *offset, palette_bytes, ENC_NA);
	*offset += palette_bytes;

	/* This is the number of bits per pixel *in the image data*, not the actual client depth */
	if (num_colors == 2)
		*bits_per_pixel = 1;
	else
		*bits_per_pixel = 8;

	return 0;
}

static guint
vnc_tight_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		   proto_tree *tree, const guint16 width _U_, const guint16 height _U_)
{
	vnc_packet_t *per_packet_info;
	guint8 comp_ctl;
	proto_item *compression_type_ti;
	gint bit_offset;
	gint bytes_needed = -1;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	/* See xserver/hw/vnc/rfbproto.h and grep for "Tight Encoding." for the following layout */

	VNC_BYTES_NEEDED(1);

	/* least significant bits 0-3 are "reset compression stream N" */
	bit_offset = *offset * 8;
	proto_tree_add_bits_item(tree, hf_vnc_tight_reset_stream0, tvb, bit_offset + 7, 1, ENC_BIG_ENDIAN);
	proto_tree_add_bits_item(tree, hf_vnc_tight_reset_stream1, tvb, bit_offset + 6, 1, ENC_BIG_ENDIAN);
	proto_tree_add_bits_item(tree, hf_vnc_tight_reset_stream2, tvb, bit_offset + 5, 1, ENC_BIG_ENDIAN);
	proto_tree_add_bits_item(tree, hf_vnc_tight_reset_stream3, tvb, bit_offset + 4, 1, ENC_BIG_ENDIAN);

	/* most significant bits 4-7 are "compression type" */
	compression_type_ti = proto_tree_add_bits_item(tree, hf_vnc_tight_rect_type, tvb, bit_offset + 0, 4, ENC_BIG_ENDIAN);

	comp_ctl = tvb_get_guint8(tvb, *offset);
	*offset += 1;

	comp_ctl >>= 4; /* skip over the "reset compression" bits from above */

	/* compression format */

	if (comp_ctl == TIGHT_RECT_FILL) {
		/* "fill" encoding (solid rectangle) */

		proto_item_append_text(compression_type_ti, " (fill encoding - solid rectangle)");

		if (per_packet_info->depth == 24) {
			VNC_BYTES_NEEDED(3);
			proto_tree_add_item(tree, hf_vnc_tight_fill_color, tvb, *offset, 3, ENC_NA);
			*offset += 3;
		} else {
			VNC_BYTES_NEEDED(per_packet_info->bytes_per_pixel);
			proto_tree_add_item(tree, hf_vnc_tight_fill_color, tvb, *offset, per_packet_info->bytes_per_pixel, ENC_NA);
			*offset += per_packet_info->bytes_per_pixel;
		}

		bytes_needed = 0;
	} else if (comp_ctl == TIGHT_RECT_JPEG) {
		/* jpeg encoding */

		proto_item_append_text(compression_type_ti, " (JPEG encoding)");
		bytes_needed = process_compact_length_and_image_data(tvb, offset, tree);
		if (bytes_needed != 0)
			return bytes_needed;
	} else if (comp_ctl > TIGHT_RECT_MAX_VALUE) {
		/* invalid encoding */

		expert_add_info(pinfo, compression_type_ti, &ei_vnc_invalid_encoding);
	} else {
		guint row_size;
		gint bits_per_pixel;

		/* basic encoding */

		proto_item_append_text(compression_type_ti, " (basic encoding)");

		proto_tree_add_bits_item(tree, hf_vnc_tight_filter_flag, tvb, bit_offset + 1, 1, ENC_BIG_ENDIAN);

		bits_per_pixel = per_packet_info->depth;

		if ((comp_ctl & TIGHT_RECT_EXPLICIT_FILTER_FLAG) != 0) {
			guint8 filter_id;

			/* explicit filter */

			VNC_BYTES_NEEDED(1);
			proto_tree_add_item(tree, hf_vnc_tight_filter_id, tvb, *offset, 1, ENC_BIG_ENDIAN);
			filter_id = tvb_get_guint8(tvb, *offset);
			*offset += 1;

			switch (filter_id) {
			case TIGHT_RECT_FILTER_COPY:
				/* nothing to do */
				break;

			case TIGHT_RECT_FILTER_PALETTE:
				bytes_needed = process_tight_rect_filter_palette(tvb, pinfo, offset, tree, &bits_per_pixel);
				if (bytes_needed != 0)
					return bytes_needed;

				break;

			case TIGHT_RECT_FILTER_GRADIENT:
				/* nothing to do */
				break;
			}
		} else {
			/* this is the same case as TIGHT_RECT_FILTER_COPY, so there's nothing special to do */
		}

		row_size = ((guint) width * bits_per_pixel + 7) / 8;
		if (row_size * height < TIGHT_MIN_BYTES_TO_COMPRESS) {
			guint num_bytes;

			/* The data is not compressed; just skip over it */

			num_bytes = row_size * height;
			VNC_BYTES_NEEDED(num_bytes);
			proto_tree_add_item(tree, hf_vnc_tight_image_data, tvb, *offset, num_bytes, ENC_NA);
			*offset += num_bytes;

			bytes_needed = 0;
		} else {
			/* The data is compressed; read its length and data */
			bytes_needed = process_compact_length_and_image_data(tvb, offset, tree);
			if (bytes_needed != 0)
				return bytes_needed;
		}
	}

	DISSECTOR_ASSERT(bytes_needed != -1);

	return bytes_needed;
}


static guint
decode_cursor(tvbuff_t *tvb, gint *offset, proto_tree *tree,
	      guint pixels_bytes, guint mask_bytes)
{
	guint total_bytes;

	total_bytes = pixels_bytes + mask_bytes;
	VNC_BYTES_NEEDED (total_bytes);

	proto_tree_add_item(tree, hf_vnc_cursor_encoding_pixels, tvb, *offset,
			    pixels_bytes, ENC_NA);
	*offset += pixels_bytes;

	proto_tree_add_item(tree, hf_vnc_cursor_encoding_bitmask, tvb, *offset,
			    mask_bytes, ENC_NA);
	*offset += mask_bytes;

	return 0; /* bytes_needed */
}


static guint
vnc_rich_cursor_encoding(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
			 proto_tree *tree, const guint16 width, const guint16 height)
{
	guint8 bytes_per_pixel = vnc_get_bytes_per_pixel(pinfo);
	guint  pixels_bytes, mask_bytes;

	pixels_bytes = width * height * bytes_per_pixel;
	mask_bytes   = ((width + 7) / 8) * height;

	return decode_cursor(tvb, offset, tree,
			     pixels_bytes, mask_bytes);
}


static guint
vnc_x_cursor_encoding(tvbuff_t *tvb, packet_info *pinfo _U_, gint *offset,
		      proto_tree *tree, const guint16 width, const guint16 height)
{
	gint bitmap_row_bytes = (width + 7) / 8;
	gint mask_bytes       = bitmap_row_bytes * height;

	VNC_BYTES_NEEDED (6);
	proto_tree_add_item(tree, hf_vnc_cursor_x_fore_back, tvb, *offset, 6, ENC_NA);
	*offset += 6;

	/* The length of the pixel data is the same as the length of the mask data (X cursors are strictly black/white) */
	return decode_cursor(tvb, offset, tree,
			     mask_bytes, mask_bytes);
}


static guint
vnc_server_set_colormap_entries(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
				proto_tree *tree)
{
	guint16 number_of_colors;
	guint counter, bytes_needed;
	proto_item *ti;
	proto_tree *vnc_colormap_num_groups, *vnc_colormap_color_group;

	col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Server set colormap entries");

	number_of_colors = tvb_get_ntohs(tvb, 4);

	VNC_BYTES_NEEDED(3);
	proto_tree_add_item(tree, hf_vnc_padding, tvb, *offset, 1, ENC_NA);
	*offset += 1; /* Skip over 1 byte of padding */

	proto_tree_add_item(tree, hf_vnc_colormap_first_color,
			    tvb, *offset, 2, ENC_BIG_ENDIAN);
	*offset += 2;

	/*  XXX - this is 3 bytes into the tvb, but number_of_colors is set off
	 *  of 4 bytes in... Bug???
	 */
	ti = proto_tree_add_item(tree, hf_vnc_colormap_num_colors, tvb,
				 *offset, 2, ENC_BIG_ENDIAN);

	if (number_of_colors > 10000) {
		expert_add_info_format(pinfo, ti, &ei_vnc_too_many_colors,"Too many colors (%d), aborting dissection",
				       number_of_colors);
		return(0);
	}

	bytes_needed = (number_of_colors * 6) + 5;
	VNC_BYTES_NEEDED(bytes_needed);

	*offset += 2;

	ti = proto_tree_add_item(tree, hf_vnc_color_groups, tvb,
				*offset, number_of_colors * 6, ENC_NA);
	vnc_colormap_num_groups =
		proto_item_add_subtree(ti, ett_vnc_colormap_num_groups);

	for(counter = 0; counter < number_of_colors; counter++) {
		vnc_colormap_color_group = proto_tree_add_subtree_format(vnc_colormap_num_groups, tvb,
					 *offset, 6, ett_vnc_colormap_color_group, NULL,
					 "Color group #%d", counter+1);

		proto_tree_add_item(vnc_colormap_color_group,
				    hf_vnc_colormap_red, tvb,
				    *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		proto_tree_add_item(vnc_colormap_color_group,
				    hf_vnc_colormap_green, tvb,
				    *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;

		proto_tree_add_item(vnc_colormap_color_group,
				    hf_vnc_colormap_blue, tvb,
				    *offset, 2, ENC_BIG_ENDIAN);
		*offset += 2;
	}
	return 0;
}


static void
vnc_server_ring_bell(tvbuff_t *tvb _U_, packet_info *pinfo, gint *offset _U_,
		     proto_tree *tree _U_)
{
	col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Server ring bell on client");
	/* This message type has no payload... */
}


static guint
vnc_server_cut_text(tvbuff_t *tvb, packet_info *pinfo, gint *offset,
		    proto_tree *tree)
{
	guint32     text_len;
	proto_item *pi;

	col_append_sep_str(pinfo->cinfo, COL_INFO, "; ", "Server cut text");

	text_len = tvb_get_ntohl(tvb, *offset);
	pi = proto_tree_add_item(tree, hf_vnc_server_cut_text_len, tvb, *offset, 4,
			    ENC_BIG_ENDIAN);
	*offset += 4;

	if (text_len > 100000) {
		expert_add_info_format(pinfo, pi, &ei_vnc_too_many_cut_text,
				"Too much cut text (%d), aborting dissection", text_len);
		return(0);
	}

	VNC_BYTES_NEEDED(text_len);

	proto_tree_add_item(tree, hf_vnc_server_cut_text, tvb, *offset,
			    text_len, ENC_ASCII|ENC_NA);
	*offset += text_len;

	return *offset;
}


static void
vnc_set_bytes_per_pixel(packet_info *pinfo, const guint8 bytes_per_pixel)
{
	vnc_packet_t *per_packet_info;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	per_packet_info->bytes_per_pixel = bytes_per_pixel;
}


static void
vnc_set_depth(packet_info *pinfo, const guint8 depth)
{
	vnc_packet_t *per_packet_info;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	per_packet_info->depth = depth;
}


static guint8
vnc_get_bytes_per_pixel(packet_info *pinfo)
{
	vnc_packet_t *per_packet_info;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	return per_packet_info->bytes_per_pixel;
}


static guint8
vnc_get_depth(packet_info *pinfo)
{
	vnc_packet_t *per_packet_info;

	per_packet_info = (vnc_packet_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_vnc, 0);
	/* Our calling function should have set the packet's proto data already */
	DISSECTOR_ASSERT(per_packet_info != NULL);

	return per_packet_info->depth;
}

/* Preference callbacks */
static void
apply_vnc_prefs(void) {
    g_free(vnc_tcp_range);
    vnc_tcp_range = prefs_get_range_value("vnc", "tcp.port");
}

/* Register the protocol with Wireshark */
void
proto_register_vnc(void)
{
	module_t *vnc_module; /* To handle our preferences */
	expert_module_t* expert_vnc;

	/* Setup list of header fields */
	static hf_register_info hf[] = {
		{ &hf_vnc_padding,
		  { "Padding", "vnc.padding",
		    FT_NONE, BASE_NONE, NULL, 0x0,
		    "Unused space", HFILL }
		},

		{ &hf_vnc_server_proto_ver,
		  { "Server protocol version", "vnc.server_proto_ver",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "VNC protocol version on server", HFILL }
		},
		{ &hf_vnc_client_proto_ver,
		  { "Client protocol version", "vnc.client_proto_ver",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "VNC protocol version on client", HFILL }
		},
		{ &hf_vnc_num_security_types,
		  { "Number of security types", "vnc.num_security_types",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of security (authentication) types supported by the server", HFILL }
		},
		{ &hf_vnc_security_type,
		  { "Security type", "vnc.security_type",
		    FT_UINT8, BASE_DEC, VALS(vnc_security_types_vs), 0x0,
		    "Security types offered by the server (VNC versions => 3.007", HFILL }
		},
		{ &hf_vnc_server_security_type,
		  { "Security type", "vnc.server_security_type",
		    FT_UINT32, BASE_DEC, VALS(vnc_security_types_vs), 0x0,
		    "Security type mandated by the server", HFILL }
		},
		{ &hf_vnc_client_security_type,
		  { "Security type selected", "vnc.client_security_type",
		    FT_UINT8, BASE_DEC, VALS(vnc_security_types_vs), 0x0,
		    "Security type selected by the client", HFILL }
		},
		{ &hf_vnc_tight_num_tunnel_types,
		  { "Number of supported tunnel types",  "vnc.num_tunnel_types",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Number of tunnel types for TightVNC", HFILL }
		},
		{ &hf_vnc_tight_tunnel_type,
		  { "Tunnel type", "vnc.tunnel_type",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Tunnel type specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_num_auth_types,
		  { "Number of supported authentication types", "vnc.num_auth_types",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Authentication types specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_auth_code,
		  { "Authentication code", "vnc.tight_auth_code",
		    FT_UINT32, BASE_DEC, VALS(vnc_security_types_vs), 0x0,
		    "Authentication code specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_server_message_type,
		  { "Server message type (TightVNC)", "vnc.tight_server_message_type",
		    FT_INT32, BASE_DEC, NULL, 0x0,
		    "Server message type specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_server_vendor,
		  { "Server vendor code", "vnc.server_vendor",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Server vendor code specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_signature,
		  { "Signature", "vnc.signature",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    NULL, HFILL }
		},
		{ &hf_vnc_tight_server_name,
		  { "Server name", "vnc.server_name",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Server name specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_client_message_type,
		  { "Client message type (TightVNC)", "vnc.tight_client_message_type",
		    FT_INT32, BASE_DEC, NULL, 0x0,
		    "Client message type specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_client_vendor,
		  { "Client vendor code", "vnc.client_vendor",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Client vendor code specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_client_name,
		  { "Client name", "vnc.client_name",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Client name specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_encoding_type,
		  { "Encoding type", "vnc.encoding_type",
		    FT_INT32, BASE_DEC, VALS(encoding_types_vs), 0x0,
		    "Encoding type specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_encoding_vendor,
		  { "Encoding vendor code", "vnc.encoding_vendor",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Encoding vendor code specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_encoding_name,
		  { "Encoding name", "vnc.encoding_name",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Encoding name specific to TightVNC", HFILL }
		},
		{ &hf_vnc_tight_reset_stream0,
		  { "Reset compression stream 0", "vnc.tight_reset_stream0",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Tight compression, reset compression stream 0", HFILL }
		},
		{ &hf_vnc_tight_reset_stream1,
		  { "Reset compression stream 1", "vnc.tight_reset_stream1",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Tight compression, reset compression stream 1", HFILL }
		},
		{ &hf_vnc_tight_reset_stream2,
		  { "Reset compression stream 2", "vnc.tight_reset_stream2",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Tight compression, reset compression stream 2", HFILL }
		},
		{ &hf_vnc_tight_reset_stream3,
		  { "Reset compression stream 3", "vnc.tight_reset_stream3",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Tight compression, reset compression stream 3", HFILL }
		},
		{ &hf_vnc_tight_rect_type,
		  { "Rectangle type", "vnc.tight_rect_type",
		    FT_UINT8, BASE_HEX, NULL, 0x0,
		    "Tight compression, rectangle type", HFILL }
		},
		{ &hf_vnc_tight_image_len,
		  { "Image data length", "vnc.tight_image_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Tight compression, length of image data", HFILL }
		},
		{ &hf_vnc_tight_image_data,
		  { "Image data", "vnc.tight_image_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Tight compression, image data", HFILL }
		},
		{ &hf_vnc_tight_fill_color,
		  { "Fill color (RGB)", "vnc.tight_fill_color",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Tight compression, fill color for solid rectangle", HFILL }
		},
		{ &hf_vnc_tight_filter_flag,
		  { "Explicit filter flag", "vnc.tight_filter_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Tight compression, explicit filter flag", HFILL }
		},
		{ &hf_vnc_tight_filter_id,
		  { "Filter ID", "vnc.tight_filter_id",
		    FT_UINT8, BASE_DEC, VALS(tight_filter_ids_vs), 0x0,
		    "Tight compression, filter ID", HFILL }
		},
		{ &hf_vnc_tight_palette_num_colors,
		  { "Number of colors in palette", "vnc.tight_palette_num_colors",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Tight compression, number of colors in rectangle's palette", HFILL }
		},
		{ &hf_vnc_tight_palette_data,
		  { "Palette data", "vnc.tight_palette_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Tight compression, palette data for a rectangle", HFILL }
		},
		{ &hf_vnc_auth_challenge,
		  { "Authentication challenge", "vnc.auth_challenge",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Random authentication challenge from server to client", HFILL }
		},
		{ &hf_vnc_auth_response,
		  { "Authentication response", "vnc.auth_response",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Client's encrypted response to the server's authentication challenge", HFILL }
		},
		{ &hf_vnc_auth_result,
		  { "Authentication result", "vnc.auth_result",
		    FT_BOOLEAN, 32, TFS(&auth_result_tfs), 0x1,
		    NULL, HFILL }
		},
		{ &hf_vnc_auth_error_length,
		  { "Length of authentication error", "vnc.auth_error_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Authentication error length (present only if the authentication result is fail", HFILL }
		},
		{ &hf_vnc_auth_error,
		  { "Authentication error", "vnc.auth_error",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Authentication error (present only if the authentication result is fail", HFILL }
		},
		{ &hf_vnc_ard_auth_generator,
		  { "Generator", "vnc.ard_auth_generator",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
			"Generator for Diffie-Hellman key exchange", HFILL }
		},
		{ &hf_vnc_ard_auth_key_len,
		  { "Key length", "vnc.ard_auth_key_len",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
			"Diffie-Hellman key length", HFILL }
		},
		{ &hf_vnc_ard_auth_modulus,
		  { "Prime modulus", "vnc.ard_auth_modulus",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
			"Prime modulus for Diffie-Hellman key exchange", HFILL }
		},
		{ &hf_vnc_ard_auth_server_key,
		  { "Server public key", "vnc.ard_auth_server_key",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
			"Server's public Diffie-Hellman key", HFILL }
		},
		{ &hf_vnc_ard_auth_credentials,
		  { "Encrypted credentials", "vnc.ard_auth_credentials",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
			"Encrypted client username and password", HFILL }
		},
		{ &hf_vnc_ard_auth_client_key,
		  { "Client public key", "vnc.ard_auth_client_key",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
			"Client's public Diffie-Hellman key", HFILL }
		},
		{ &hf_vnc_share_desktop_flag,
		  { "Share desktop flag", "vnc.share_desktop_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Client's desire to share the server's desktop with other clients", HFILL }
		},
		{ &hf_vnc_width,
		  { "Framebuffer width", "vnc.width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Width of the framebuffer (screen) in pixels", HFILL }
		},
		{ &hf_vnc_height,
		  { "Framebuffer height", "vnc.height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Height of the framebuffer (screen) in pixels", HFILL }
		},
		{ &hf_vnc_server_bits_per_pixel,
		  { "Bits per pixel", "vnc.server_bits_per_pixel",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of bits used by server for each pixel value on the wire from the server", HFILL }
		},
		{ &hf_vnc_server_depth,
		  { "Depth", "vnc.server_depth",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of useful bits in the pixel value on server", HFILL }
		},
		{ &hf_vnc_server_big_endian_flag,
		  { "Big endian flag", "vnc.server_big_endian_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "True if multi-byte pixels are interpreted as big endian by server", HFILL }
		},
		{ &hf_vnc_server_true_color_flag,
		  { "True color flag", "vnc.server_true_color_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "If true, then the next six items specify how to extract the red, green and blue intensities from the pixel value on the server.", HFILL }
		},
		{ &hf_vnc_server_red_max,
		  { "Red maximum", "vnc.server_red_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum red value on server as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_server_green_max,
		  { "Green maximum", "vnc.server_green_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum green value on server as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_server_blue_max,
		  { "Blue maximum", "vnc.server_blue_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum blue value on server as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_server_red_shift,
		  { "Red shift", "vnc.server_red_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the red value in a pixel to the least significant bit on the server", HFILL }
		},
		{ &hf_vnc_server_green_shift,
		  { "Green shift", "vnc.server_green_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the green value in a pixel to the least significant bit on the server", HFILL }
		},
		{ &hf_vnc_server_blue_shift,
		  { "Blue shift", "vnc.server_blue_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the blue value in a pixel to the least significant bit on the server", HFILL }
		},
		{ &hf_vnc_desktop_name_len,
		  { "Desktop name length", "vnc.desktop_name_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Length of desktop name in bytes", HFILL }
		},
		{ &hf_vnc_desktop_screen_num,
		  { "Number of screens", "vnc.screen_num",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    NULL, HFILL }
		},
		{ &hf_vnc_desktop_screen_id,
		  { "Screen ID", "vnc.screen_id",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "ID of screen", HFILL }
		},
		{ &hf_vnc_desktop_screen_x,
		  { "Screen X position", "vnc.screen_x",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "X coordinate of screen", HFILL }
		},
		{ &hf_vnc_desktop_screen_y,
		  { "Screen Y position", "vnc.screen_y",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Y coordinate of screen", HFILL }
		},
		{ &hf_vnc_desktop_screen_width,
		  { "Screen width", "vnc.screen_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Width of screen", HFILL }
		},
		{ &hf_vnc_desktop_screen_height,
		  { "Screen height", "vnc.screen_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Height of screen", HFILL }
		},
		{ &hf_vnc_desktop_screen_flags,
		  { "Screen flags", "vnc.screen_flags",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Flags of screen", HFILL }
		},
		{ &hf_vnc_desktop_name,
		  { "Desktop name", "vnc.desktop_name",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Name of the VNC desktop on the server", HFILL }
		},
		{ &hf_vnc_num_server_message_types,
		  { "Server message types", "vnc.num_server_message_types",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Unknown", HFILL } /* XXX - Needs description */
		},
		{ &hf_vnc_num_client_message_types,
		  { "Client message types", "vnc.num_client_message_types",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Unknown", HFILL } /* XXX - Needs description */
		},
		{ &hf_vnc_num_encoding_types,
		  { "Encoding types", "vnc.num_encoding_types",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Unknown", HFILL } /* XXX - Needs description */
		},
		{ &hf_vnc_client_message_type,
		  { "Client Message Type", "vnc.client_message_type",
		    FT_UINT8, BASE_DEC, VALS(vnc_client_message_types_vs), 0x0,
		    "Message type from client", HFILL }
		},
		{ &hf_vnc_client_bits_per_pixel,
		  { "Bits per pixel", "vnc.client_bits_per_pixel",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of bits used by server for each pixel value on the wire from the client", HFILL }
		},
		{ &hf_vnc_client_depth,
		  { "Depth", "vnc.client_depth",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of useful bits in the pixel value on client", HFILL }
		},
		{ &hf_vnc_client_big_endian_flag,
		  { "Big endian flag", "vnc.client_big_endian_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "True if multi-byte pixels are interpreted as big endian by client", HFILL }
		},
		{ &hf_vnc_client_true_color_flag,
		  { "True color flag", "vnc.client_true_color_flag",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "If true, then the next six items specify how to extract the red, green and blue intensities from the pixel value on the client.", HFILL }
		},
		{ &hf_vnc_client_red_max,
		  { "Red maximum", "vnc.client_red_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum red value on client as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_client_green_max,
		  { "Green maximum", "vnc.client_green_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum green value on client as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_client_blue_max,
		  { "Blue maximum", "vnc.client_blue_max",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum blue value on client as n: 2^n - 1", HFILL }
		},
		{ &hf_vnc_client_red_shift,
		  { "Red shift", "vnc.client_red_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the red value in a pixel to the least significant bit on the client", HFILL }
		},
		{ &hf_vnc_client_green_shift,
		  { "Green shift", "vnc.client_green_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the green value in a pixel to the least significant bit on the client", HFILL }
		},
		{ &hf_vnc_client_blue_shift,
		  { "Blue shift", "vnc.client_blue_shift",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of shifts needed to get the blue value in a pixel to the least significant bit on the client", HFILL }
		},

		/* Client Key Event */
		{ &hf_vnc_key_down,
		  { "Key down", "vnc.key_down",
		    FT_BOOLEAN, BASE_NONE, TFS(&tfs_yes_no), 0x0,
		    "Specifies whether the key is being pressed or not", HFILL }
		},
		{ &hf_vnc_key,
		  { "Key", "vnc.key",
		    FT_UINT32, BASE_HEX | BASE_EXT_STRING, &x11_keysym_vals_source_ext, 0x0, /* keysym_vals_source_exr is from packet-x11.c */
		    "Key being pressed/depressed", HFILL }
		},

		/* Client Pointer Event */
		{ &hf_vnc_button_1_pos,
		  { "Mouse button #1 position", "vnc.button_1_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x1,
		    "Whether mouse button #1 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_2_pos,
		  { "Mouse button #2 position", "vnc.button_2_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x2,
		    "Whether mouse button #2 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_3_pos,
		  { "Mouse button #3 position", "vnc.button_3_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x4,
		    "Whether mouse button #3 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_4_pos,
		  { "Mouse button #4 position", "vnc.button_4_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x8,
		    "Whether mouse button #4 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_5_pos,
		  { "Mouse button #5 position", "vnc.button_5_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x10,
		    "Whether mouse button #5 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_6_pos,
		  { "Mouse button #6 position", "vnc.button_6_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x20,
		    "Whether mouse button #6 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_7_pos,
		  { "Mouse button #7 position", "vnc.button_7_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x40,
		    "Whether mouse button #7 is being pressed or not", HFILL }
		},
		{ &hf_vnc_button_8_pos,
		  { "Mouse button #8 position", "vnc.button_8_pos",
		    FT_BOOLEAN, 8, TFS(&button_mask_tfs), 0x80,
		    "Whether mouse button #8 is being pressed or not", HFILL }
		},
		{ &hf_vnc_pointer_x_pos,
		  { "X position", "vnc.pointer_x_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Position of mouse cursor on the x-axis", HFILL }
		},
		{ &hf_vnc_pointer_y_pos,
		  { "Y position", "vnc.pointer_y_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Position of mouse cursor on the y-axis", HFILL }
		},
		{ &hf_vnc_encoding_num,
		  { "Number of encodings", "vnc.client_set_encodings_num",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Number of encodings used to send pixel data from server to client", HFILL }
		},
		{ &hf_vnc_client_set_encodings_encoding_type,
		  { "Encoding type", "vnc.client_set_encodings_encoding_type",
		    FT_INT32, BASE_DEC, VALS(encoding_types_vs), 0x0,
		    "Type of encoding used to send pixel data from server to client", HFILL }
		},

		/* Client Framebuffer Update Request */
		{ &hf_vnc_update_req_incremental,
		  { "Incremental update", "vnc.update_req_incremental",
		    FT_BOOLEAN, BASE_NONE, NULL, 0x0,
		    "Specifies if the client wants an incremental update instead of a full one", HFILL }
		},
		{ &hf_vnc_update_req_x_pos,
		  { "X position", "vnc.update_req_x_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "X position of framebuffer (screen) update requested", HFILL }
		},
		{ &hf_vnc_update_req_y_pos,
		  { "Y position", "vnc.update_req_y_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Y position of framebuffer (screen) update request", HFILL }
		},
		{ &hf_vnc_update_req_width,
		  { "Width", "vnc.update_req_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Width of framebuffer (screen) update request", HFILL }
		},
		{ &hf_vnc_update_req_height,
		  { "Height", "vnc.update_req_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Height of framebuffer (screen) update request", HFILL }
		},
		{ &hf_vnc_client_cut_text_len,
		  { "Length", "vnc.client_cut_text_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Length of client's copy/cut text (clipboard) string in bytes", HFILL }
		},
		{ &hf_vnc_client_cut_text,
		  { "Text", "vnc.client_cut_text",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Text string in the client's copy/cut text (clipboard)", HFILL }
		},


		/********** Server Message Types **********/
		{ &hf_vnc_server_message_type,
		  { "Server Message Type", "vnc.server_message_type",
		    FT_UINT8, BASE_DEC, VALS(vnc_server_message_types_vs), 0x0,
		    "Message type from server", HFILL }
		},

		{ &hf_vnc_rectangle_num,
		  { "Number of rectangles", "vnc.fb_update_num_rects",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Number of rectangles of this server framebuffer update", HFILL }
		},

		{ &hf_vnc_fb_update_x_pos,
		  { "X position", "vnc.fb_update_x_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "X position of this server framebuffer update", HFILL }
		},

		{ &hf_vnc_fb_update_y_pos,
		  { "Y position", "vnc.fb_update_y_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Y position of this server framebuffer update", HFILL }
		},

		{ &hf_vnc_fb_update_width,
		  { "Width", "vnc.fb_update_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Width of this server framebuffer update", HFILL }
		},

		{ &hf_vnc_fb_update_height,
		  { "Height", "vnc.fb_update_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Height of this server framebuffer update", HFILL }
		},

		{ &hf_vnc_fb_update_encoding_type,
		  { "Encoding type", "vnc.fb_update_encoding_type",
		    FT_INT32, BASE_DEC, VALS(encoding_types_vs), 0x0,
		    "Encoding type of this server framebuffer update", HFILL }
		},

		/* Cursor encoding */
		{ &hf_vnc_cursor_x_fore_back,
		  { "X Cursor foreground RGB / background RGB", "vnc.cursor_x_fore_back",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "RGB values for the X cursor's foreground and background", HFILL }
		},

		{ &hf_vnc_cursor_encoding_pixels,
		  { "Cursor encoding pixels", "vnc.cursor_encoding_pixels",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Cursor encoding pixel data", HFILL }
		},

		{ &hf_vnc_cursor_encoding_bitmask,
		  { "Cursor encoding bitmask", "vnc.cursor_encoding_bitmask",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Cursor encoding pixel bitmask", HFILL }
		},

		/* Raw Encoding */
		{ &hf_vnc_raw_pixel_data,
		  { "Pixel data", "vnc.raw_pixel_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Raw pixel data.", HFILL }
		},

		/* CopyRect Encoding*/
		{ &hf_vnc_copyrect_src_x_pos,
		  { "Source x position", "vnc.copyrect_src_x_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "X position of the rectangle to copy from", HFILL }
		},

		{ &hf_vnc_copyrect_src_y_pos,
		  { "Source y position", "vnc.copyrect_src_y_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Y position of the rectangle to copy from", HFILL }
		},

		/* RRE Encoding */
		{ &hf_vnc_rre_num_subrects,
		  { "Number of subrectangles", "vnc.rre_num_subrects",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Number of subrectangles contained in this encoding type", HFILL }
		},

		{ &hf_vnc_rre_bg_pixel,
		  { "Background pixel value", "vnc.rre_bg_pixel",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    NULL, HFILL }
		},

		{ &hf_vnc_rre_subrect_pixel,
		  { "Pixel value", "vnc.rre_subrect_pixel",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Subrectangle pixel value", HFILL }
		},

		{ &hf_vnc_rre_subrect_x_pos,
		  { "X position", "vnc.rre_subrect_x_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Position of this subrectangle on the x axis", HFILL }
		},

		{ &hf_vnc_rre_subrect_y_pos,
		  { "Y position", "vnc.rre_subrect_y_pos",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Position of this subrectangle on the y axis", HFILL }
		},

		{ &hf_vnc_rre_subrect_width,
		  { "Width", "vnc.rre_subrect_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Width of this subrectangle", HFILL }
		},

		{ &hf_vnc_rre_subrect_height,
		  { "Height", "vnc.rre_subrect_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Height of this subrectangle", HFILL }
		},


		/* Hextile Encoding */
		{ &hf_vnc_hextile_subencoding_mask,
		  { "Subencoding type", "vnc.hextile_subencoding",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Hextile subencoding type.", HFILL }
		},

		{ &hf_vnc_hextile_raw,
		  { "Raw", "vnc.hextile_raw",
		    FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x1,
		    "Raw subencoding is used in this tile", HFILL }
		},

		{ &hf_vnc_hextile_raw_value,
		  { "Raw pixel values", "vnc.hextile_raw_value",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Raw subencoding pixel values", HFILL }
		},

		{ &hf_vnc_hextile_bg,
		  { "Background Specified", "vnc.hextile_bg",
		    FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x2,
		    "Background Specified subencoding is used in this tile", HFILL }
		},

		{ &hf_vnc_hextile_bg_value,
		  { "Background pixel value", "vnc.hextile_bg_value",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Background color for this tile", HFILL }
		},

		{ &hf_vnc_hextile_fg,
		  { "Foreground Specified", "vnc.hextile_fg",
		    FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x4,
		    "Foreground Specified subencoding is used in this tile", HFILL }
		},

		{ &hf_vnc_hextile_fg_value,
		  { "Foreground pixel value", "vnc.hextile_fg_value",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Foreground color for this tile", HFILL }
		},

		{ &hf_vnc_hextile_anysubrects,
		  { "Any Subrects", "vnc.hextile_anysubrects",
		    FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x8,
		    "Any subrects subencoding is used in this tile", HFILL }
		},

		{ &hf_vnc_hextile_num_subrects,
		  { "Number of subrectangles", "vnc.hextile_num_subrects",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of subrectangles that follow", HFILL }
		},

		{ &hf_vnc_hextile_subrectscolored,
		  { "Subrects Colored", "vnc.hextile_subrectscolored",
		    FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x10,
		    "Subrects colored subencoding is used in this tile", HFILL }
		},

		{ &hf_vnc_hextile_subrect_pixel_value,
		  { "Pixel value", "vnc.hextile_subrect_pixel_value",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Pixel value of this subrectangle", HFILL }
		},

		{ &hf_vnc_hextile_subrect_x_pos,
		  { "X position", "vnc.hextile_subrect_x_pos",
		    FT_UINT8, BASE_DEC, NULL, 0xF0, /* Top 4 bits */
		    "X position of this subrectangle", HFILL }
		},

		{ &hf_vnc_hextile_subrect_y_pos,
		  { "Y position", "vnc.hextile_subrect_y_pos",
		    FT_UINT8, BASE_DEC, NULL, 0xF, /* Bottom 4 bits */
		    "Y position of this subrectangle", HFILL }
		},

		{ &hf_vnc_hextile_subrect_width,
		  { "Width", "vnc.hextile_subrect_width",
		    FT_UINT8, BASE_DEC, NULL, 0xF0, /* Top 4 bits */
		    "Subrectangle width minus one", HFILL }
		},

		{ &hf_vnc_hextile_subrect_height,
		  { "Height", "vnc.hextile_subrect_height",
		    FT_UINT8, BASE_DEC, NULL, 0xF, /* Bottom 4 bits */
		    "Subrectangle height minus one", HFILL }
		},


		/* ZRLE Encoding */
		{ &hf_vnc_zrle_len,
		  { "ZRLE compressed length", "vnc.zrle_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Length of compressed ZRLE data that follows", HFILL }
		},

		{ &hf_vnc_zrle_subencoding,
		  { "Subencoding type", "vnc.zrle_subencoding",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Subencoding type byte", HFILL }
		},

		{ &hf_vnc_zrle_rle,
		  { "RLE", "vnc.zrle_rle",
		    FT_UINT8, BASE_DEC, VALS(yes_no_vs), 0x80, /* Upper bit */
		    "Specifies that data is run-length encoded", HFILL }
		},

		{ &hf_vnc_zrle_palette_size,
		  { "Palette size", "vnc.zrle_palette_size",
		    FT_UINT8, BASE_DEC, NULL, 0x7F, /* Lower 7 bits */
		    NULL, HFILL }
		},

		{ &hf_vnc_zrle_data,
		  { "ZRLE compressed data", "vnc.zrle_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Compressed ZRLE data.  Compiling with zlib support will uncompress and dissect this data", HFILL }
		},

		{ &hf_vnc_zrle_raw,
		  { "Pixel values", "vnc.zrle_raw",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Raw pixel values for this tile", HFILL }
		},

		{ &hf_vnc_zrle_palette,
		  { "Palette", "vnc.zrle_palette",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Palette pixel values", HFILL }
		},

		/* Server Set Colormap Entries */
		{ &hf_vnc_colormap_first_color,
		  { "First color", "vnc.colormap_first_color",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "First color that should be mapped to given RGB intensities", HFILL }
		},

		{ &hf_vnc_color_groups,
		  { "Color groups", "vnc.color_groups",
		    FT_NONE, BASE_NONE, NULL, 0x0,
		    NULL, HFILL }
		},

		{ &hf_vnc_colormap_num_colors,
		  { "Number of color groups", "vnc.colormap_groups",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Number of red/green/blue color groups", HFILL }
		},
		{ &hf_vnc_colormap_red,
		  { "Red", "vnc.colormap_red",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Red intensity", HFILL }
		},
		{ &hf_vnc_colormap_green,
		  { "Green", "vnc.colormap_green",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Green intensity", HFILL }
		},
		{ &hf_vnc_colormap_blue,
		  { "Blue", "vnc.colormap_blue",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Blue intensity", HFILL }
		},

		/* Server Cut Text */
		{ &hf_vnc_server_cut_text_len,
		  { "Length", "vnc.server_cut_text_len",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Length of server's copy/cut text (clipboard) string in bytes", HFILL }
		},
		{ &hf_vnc_server_cut_text,
		  { "Text", "vnc.server_cut_text",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Text string in the server's copy/cut text (clipboard)", HFILL }
		},

		/* LibVNCServer additions */
		{ &hf_vnc_supported_messages_client2server,
		  { "Client2server", "vnc.supported_messages_client2server",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Supported client to server messages (bit flags)", HFILL }
		},
		{ &hf_vnc_supported_messages_server2client,
		  { "Server2client", "vnc.supported_messages_server2client",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Supported server to client messages (bit flags)", HFILL }
		},
		{ &hf_vnc_num_supported_encodings,
		  { "Number of supported encodings", "vnc.num_supported_encodings",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    NULL, HFILL }
		},
		{ &hf_vnc_supported_encodings,
		  { "Encoding", "vnc.supported_encodings",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Supported encoding", HFILL }
		},
		{ &hf_vnc_server_identity,
		  { "Server Identity", "vnc.server_identity",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Server identity string", HFILL }
		},

		/* MirrorLink */
		{ &hf_vnc_mirrorlink_type,
		  { "Type", "vnc.mirrorlink_type",
		    FT_UINT8, BASE_DEC, VALS(vnc_mirrorlink_types_vs), 0x0,
		    "MirrorLink extension message type", HFILL }
		},
		{ &hf_vnc_mirrorlink_length,
		  { "Length", "vnc.mirrorlink_length",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Payload length", HFILL }
		},
		{ &hf_vnc_mirrorlink_version_major,
		  { "Major Version", "vnc.mirrorlink_version_major",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "MirrorLink major version", HFILL }
		},
		{ &hf_vnc_mirrorlink_version_minor,
		  { "Minor Version", "vnc.mirrorlink_version_minor",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "MirrorLink minor version", HFILL }
		},
		{ &hf_vnc_mirrorlink_framebuffer_configuration,
		  { "Configuration",
		    "vnc.mirrorlink_framebuffer_configuration",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Framebuffer configuration", HFILL }
		},
		{ &hf_vnc_mirrorlink_pixel_width,
		  { "Pixel Width", "vnc.mirrorlink_pixel_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Display width [pixel]", HFILL }
		},
		{ &hf_vnc_mirrorlink_pixel_height,
		  { "Pixel Height", "vnc.mirrorlink_pixel_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Display height [pixel]", HFILL }
		},
		{ &hf_vnc_mirrorlink_pixel_format,
		  { "Pixel Format", "vnc.mirrorlink_pixel_format",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Pixel format support", HFILL }
		},
		{ &hf_vnc_mirrorlink_display_width,
		  { "Display Width", "vnc.mirrorlink_display_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Display width [mm]", HFILL }
		},
		{ &hf_vnc_mirrorlink_display_height,
		  { "Display Height", "vnc.mirrorlink_display_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Display height [mm]", HFILL }
		},
		{ &hf_vnc_mirrorlink_display_distance,
		  { "Display Distance", "vnc.mirrorlink_display_distance",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Display distance [mm]", HFILL }
		},
		{ &hf_vnc_mirrorlink_keyboard_language,
		  { "Keyboard Language", "vnc.mirrorlink_keyboard_language",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Keyboard layout - Language code (according ISO 639-1)",
		    HFILL }
		},
		{ &hf_vnc_mirrorlink_keyboard_country,
		  { "Keyboard Country", "vnc.mirrorlink_keyboard_country",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Keyboard layout - Country code (according ISO 3166-1 alpha-2)",
		    HFILL }
		},
		{ &hf_vnc_mirrorlink_ui_language,
		  { "UI Language", "vnc.mirrorlink_ui_language",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "UI language - Language code (according ISO 639-1)", HFILL }
		},
		{ &hf_vnc_mirrorlink_ui_country,
		  { "UI Country", "vnc.mirrorlink_ui_country",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "UI language - Country code (according ISO 3166-1 alpha 2)",
		    HFILL }
		},
		{ &hf_vnc_mirrorlink_knob_keys,
		  { "Knob Keys", "vnc.mirrorlink_knob_keys",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Supported knob keys", HFILL }
		},
		{ &hf_vnc_mirrorlink_device_keys,
		  { "Device Keys", "vnc.mirrorlink_device_keys",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Supported device keys", HFILL }
		},
		{ &hf_vnc_mirrorlink_multimedia_keys,
		  { "Multimedia Keys", "vnc.mirrorlink_multimedia_keys",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Supported multimedia keys", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_related,
		  { "Keyboard", "vnc.mirrorlink_key_related",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Keyboard related", HFILL }
		},
		{ &hf_vnc_mirrorlink_pointer_related,
		  { "Pointer", "vnc.mirrorlink_pointer_related",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Pointer related", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_symbol_value_client,
		  { "Client KeySymValue",
		    "vnc.mirrorlink_key_symbol_value_client",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Client key symbol value", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_symbol_value_server,
		  { "Server KeySymValue",
		    "vnc.mirrorlink_key_symbol_value_server",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Server key symbol value", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_configuration,
		  { "Configuration", "vnc.mirrorlink_key_configuration",
		    FT_UINT8, BASE_HEX, NULL, 0x0,
		    "Key event listing configuration", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_num_events,
		  { "Number of Key Events", "vnc.mirrorlink_key_num_events",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of key events in list", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_event_counter,
		  { "Key Event Counter", "vnc.mirrorlink_key_event_counter",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Key event listing counter", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_symbol_value,
		  { "KeySymValue",
		    "vnc.mirrorlink_key_symbol_value",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Key symbol value", HFILL }
		},
		{ &hf_vnc_mirrorlink_key_request_configuration,
		  { "Configuration", "vnc.mirrorlink_key_request_configuration",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Key event listing request configuration", HFILL }
		},
		{ &hf_vnc_mirrorlink_keyboard_configuration,
		  { "Configuration", "vnc.mirrorlink_keyboard_configuration",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Virtual keyboard configuration", HFILL }
		},
		{ &hf_vnc_mirrorlink_cursor_x,
		  { "Cursor X", "vnc.mirrorlink_cursor_x",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Cursor - X position", HFILL }
		},
		{ &hf_vnc_mirrorlink_cursor_y,
		  { "Cursor Y", "vnc.mirrorlink_cursor_y",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Cursor - Y position", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_x,
		  { "Text X", "vnc.mirrorlink_text_x",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Text input area - X position", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_y,
		  { "Text Y", "vnc.mirrorlink_text_y",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Text input area - Y position", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_width,
		  { "Text Width", "vnc.mirrorlink_text_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Text input area - Width", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_height,
		  { "Text Height", "vnc.mirrorlink_text_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Text input area - Height", HFILL }
		},
		{ &hf_vnc_mirrorlink_keyboard_request_configuration,
		  { "Configuration",
		    "vnc.mirrorlink_keyboard_request_configuration",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Virtual keyboard request configuration", HFILL }
		},
		{ &hf_vnc_mirrorlink_device_status,
		  { "Device Status", "vnc.mirrorlink_device_status",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Status of Device Features", HFILL }
		},
		{ &hf_vnc_mirrorlink_app_id,
		  { "App Id", "vnc.mirrorlink_app_id",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Unique application id", HFILL }
		},
		{ &hf_vnc_mirrorlink_fb_block_x,
		  { "Frambuffer X", "vnc.mirrorlink_fb_block_x",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Frambuffer blocking - X position", HFILL }
		},
		{ &hf_vnc_mirrorlink_fb_block_y,
		  { "Frambuffer Y", "vnc.mirrorlink_fb_block_y",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Frambuffer blocking - Y position", HFILL }
		},
		{ &hf_vnc_mirrorlink_fb_block_width,
		  { "Frambuffer Width", "vnc.mirrorlink_fb_block_width",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Frambuffer blocking - Width", HFILL }
		},
		{ &hf_vnc_mirrorlink_fb_block_height,
		  { "Frambuffer Height", "vnc.mirrorlink_fb_block_height",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Frambuffer blocking - Height", HFILL }
		},
		{ &hf_vnc_mirrorlink_fb_block_reason,
		  { "Reason", "vnc.mirrorlink_fb_block_reason",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Reason for blocking", HFILL }
		},
		{ &hf_vnc_mirrorlink_audio_block_reason,
		  { "Reason", "vnc.mirrorlink_audio_block_reason",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Reason for blocking", HFILL }
		},
		{ &hf_vnc_mirrorlink_touch_num_events,
		  { "Number of Touch Events", "vnc.mirrorlink_touch_num_events",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Number of touch events in list", HFILL }
		},
		{ &hf_vnc_mirrorlink_touch_x,
		  { "Touch X", "vnc.mirrorlink_touch_x",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Touch event - X position", HFILL }
		},
		{ &hf_vnc_mirrorlink_touch_y,
		  { "Touch Y", "vnc.mirrorlink_touch_y",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Touch event - Y position", HFILL }
		},
		{ &hf_vnc_mirrorlink_touch_id,
		  { "Touch Id", "vnc.mirrorlink_touch_id",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Touch event - identifier", HFILL }
		},
		{ &hf_vnc_mirrorlink_touch_pressure,
		  { "Touch Pressure", "vnc.mirrorlink_touch_pressure",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    "Touch event - pressure value", HFILL }
		},
		{ &hf_vnc_mirrorlink_text,
		  { "Text", "vnc.mirrorlink_text",
		    FT_STRING, BASE_NONE, NULL, 0x0,
		    "Textual information", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_length,
		  { "Length", "vnc.mirrorlink_text_length",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Length of textual information", HFILL }
		},
		{ &hf_vnc_mirrorlink_text_max_length,
		  { "Max Length", "vnc.mirrorlink_text_max_length",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Maximum length of textual information", HFILL }
		},
		{ &hf_vnc_mirrorlink_unknown,
		  { "Unknown", "vnc.mirrorlink_unknown",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Unknown data", HFILL }
		},

		/* Fence */
		{ &hf_vnc_fence_flags,
		  {"Fence flags", "vnc.fence_flags", FT_UINT32, BASE_HEX,
		   NULL, 0, NULL, HFILL}},

		{ &hf_vnc_fence_request,
		  { "Fence_request", "vnc.fence_request",
		    FT_BOOLEAN, 32, NULL, VNC_FENCE_REQUEST,
		    NULL, HFILL }
		},
		{ &hf_vnc_fence_sync_next,
		  { "Fence_sync_next", "vnc.fence_sync_next",
		    FT_BOOLEAN, 32, NULL, VNC_FENCE_SYNC_NEXT,
		    NULL, HFILL }
		},
		{ &hf_vnc_fence_block_after,
		  { "Fence_block_after", "vnc.fence_block_after",
		    FT_BOOLEAN, 32, NULL, VNC_FENCE_BLOCK_AFTER,
		    NULL, HFILL }
		},
		{ &hf_vnc_fence_block_before,
		  { "Fence block_before", "vnc.fence_block_before",
		    FT_BOOLEAN, 32, NULL, VNC_FENCE_BLOCK_BEFORE,
		    NULL, HFILL }
		},
		{ &hf_vnc_fence_payload_length,
		  { "Fence payload length", "vnc.fence_payload_length",
		    FT_UINT8, BASE_DEC, NULL, 0x0,
		    NULL, HFILL }
		},
		{ &hf_vnc_fence_payload,
		  { "Fence payload", "vnc.fence_payload",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    NULL, HFILL }
		},

		/* Context Information */
		{ &hf_vnc_context_information_app_id,
		  { "App Id", "vnc.context_information_app_id",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Unique application id", HFILL }
		},
		{ &hf_vnc_context_information_app_trust_level,
		  { "App Trust Level",
		    "vnc.context_information_app_trust_level",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Trust Level for Application Category", HFILL }
		},
		{ &hf_vnc_context_information_content_trust_level,
		  { "Content Trust Level",
		    "vnc.context_information_content_trust_level",
		    FT_UINT16, BASE_HEX, NULL, 0x0,
		    "Trust Level for Content Category", HFILL }
		},
		{ &hf_vnc_context_information_app_category,
		  { "App Category", "vnc.context_information_app_category",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Application Category", HFILL }
		},
		{ &hf_vnc_context_information_content_category,
		  { "Content Category",
		    "vnc.context_information_content_category",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Visual content category", HFILL }
		},
		{ &hf_vnc_context_information_content_rules,
		  { "Content Rules", "vnc.context_information_content_rules",
		    FT_UINT32, BASE_HEX, NULL, 0x0,
		    "Visual content rules", HFILL }
		},

		/* Scan Line based Run-Length Encoding */
		{ &hf_vnc_slrle_run_num,
		  { "Number of Runs", "vnc.slrle_run_num",
		    FT_UINT16, BASE_DEC, NULL, 0x0,
		    "Number of Runs within Line", HFILL }
		},
		{ &hf_vnc_slrle_run_data,
		  { "Raw RLE data", "vnc.slrle_run_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Raw Run-Length encoded data within Line", HFILL }
		},

		/* H.264 Encoding */
		{ &hf_vnc_h264_slice_type,
		  { "Slice Type", "vnc.h264_slice_type",
		    FT_UINT32, BASE_DEC, VALS(vnc_h264_slice_types_vs), 0x0,
		    "Frame slice type", HFILL }
		},
		{ &hf_vnc_h264_nbytes,
		  { "Number of Bytes", "vnc.h264_nbytes",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Number of bytes within frame", HFILL }
		},
		{ &hf_vnc_h264_width,
		  { "Width", "vnc.h264_width",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Frame Width", HFILL }
		},
		{ &hf_vnc_h264_height,
		  { "Height", "vnc.h264_height",
		    FT_UINT32, BASE_DEC, NULL, 0x0,
		    "Frame Height", HFILL }
		},
		{ &hf_vnc_h264_data,
		  { "Data", "vnc.h264_data",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    "Frame H.264 data", HFILL }
		},

	};

	/* Setup protocol subtree arrays */
	static gint *ett[] = {
		&ett_vnc,
		&ett_vnc_client_message_type,
		&ett_vnc_server_message_type,
		&ett_vnc_rect,
		&ett_vnc_encoding_type,
		&ett_vnc_rre_subrect,
		&ett_vnc_hextile_subencoding_mask,
		&ett_vnc_hextile_num_subrects,
		&ett_vnc_hextile_subrect,
		&ett_vnc_hextile_tile,
		&ett_vnc_zrle_subencoding,
		&ett_vnc_colormap_num_groups,
		&ett_vnc_desktop_screen,
		&ett_vnc_colormap_color_group,
		&ett_vnc_key_events,
		&ett_vnc_touch_events,
		&ett_vnc_slrle_subline,
		&ett_vnc_fence_flags
	};

	static ei_register_info ei[] = {
		{ &ei_vnc_possible_gtk_vnc_bug, { "vnc.possible_gtk_vnc_bug", PI_MALFORMED, PI_ERROR, "NULL found in greeting. client -> server greeting must be 12 bytes (possible gtk-vnc bug)", EXPFILL }},
		{ &ei_vnc_auth_code_mismatch, { "vnc.auth_code_mismatch", PI_PROTOCOL, PI_WARN, "Authentication code does not match vendor or signature", EXPFILL }},
		{ &ei_vnc_unknown_tight_vnc_auth, { "vnc.unknown_tight_vnc_auth", PI_PROTOCOL, PI_ERROR, "Unknown TIGHT VNC authentication", EXPFILL }},
		{ &ei_vnc_too_many_rectangles, { "vnc.too_many_rectangles", PI_MALFORMED, PI_ERROR, "Too many rectangles, aborting dissection", EXPFILL }},
		{ &ei_vnc_too_many_sub_rectangles, { "vnc.too_many_sub_rectangles", PI_MALFORMED, PI_ERROR, "Too many sub-rectangles, aborting dissection", EXPFILL }},
		{ &ei_vnc_invalid_encoding, { "vnc.invalid_encoding", PI_MALFORMED, PI_ERROR, "Invalid encoding", EXPFILL }},
		{ &ei_vnc_too_many_colors, { "vnc.too_many_colors", PI_MALFORMED, PI_ERROR, "Too many colors, aborting dissection", EXPFILL }},
		{ &ei_vnc_too_many_cut_text, { "vnc.too_many_cut_text", PI_MALFORMED, PI_ERROR, "Too much cut text, aborting dissection", EXPFILL }},
		{ &ei_vnc_zrle_failed, { "vnc.zrle_failed", PI_UNDECODED, PI_ERROR, "Decompression of ZRLE data failed", EXPFILL }},
		{ &ei_vnc_unknown_tight, { "vnc.unknown_tight_packet", PI_UNDECODED, PI_WARN, "Unknown packet (TightVNC)", EXPFILL }},
		{ &ei_vnc_reassemble, { "vnc.reassemble", PI_REASSEMBLE, PI_CHAT, "See further on for dissection of the complete (reassembled) PDU", EXPFILL }},
	};

	/* Register the protocol name and description */
	proto_vnc = proto_register_protocol("Virtual Network Computing", "VNC", "vnc");

	/* Required function calls to register the header fields and subtrees */
	proto_register_field_array(proto_vnc, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
	expert_vnc = expert_register_protocol(proto_vnc);
	expert_register_field_array(expert_vnc, ei, array_length(ei));

	/* Register our preferences module */
	vnc_module = prefs_register_protocol(proto_vnc, apply_vnc_prefs);

	prefs_register_bool_preference(vnc_module, "desegment",
				       "Reassemble VNC messages spanning multiple TCP segments.",
				       "Whether the VNC dissector should reassemble messages spanning "
				       "multiple TCP segments.  To use this option, you must also enable "
				       "\"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
				       &vnc_preference_desegment);
}

void
proto_reg_handoff_vnc(void)
{
	vnc_handle = create_dissector_handle(dissect_vnc, proto_vnc);

	dissector_add_uint_range_with_preference("tcp.port", VNC_PORT_RANGE, vnc_handle);
	heur_dissector_add("tcp", test_vnc_protocol, "VNC over TCP", "vnc_tcp", proto_vnc, HEURISTIC_ENABLE);
	/* We don't register a port for the VNC HTTP server because
	 * that simply provides a java program for download via the
	 * HTTP protocol.  The java program then connects to a standard
	 * VNC port. */
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */