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 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369
|
/*
* N U T T C P . C v8.2.2
*
* Copyright(c) 2000 - 2018 Bill Fink. All rights reserved.
* Copyright(c) 2003 - 2018 Rob Scott. All rights reserved.
*
* nuttcp is free, opensource software. You can redistribute it and/or
* modify it under the terms of Version 2 of the GNU General Public
* License (GPL), as published by the GNU Project (http://www.gnu.org).
* A copy of the license can also be found in the LICENSE file.
*
* 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.
*
* Based on nttcp
* Developed by Bill Fink, billfink@mindspring.com
* and Rob Scott, rob@hpcmo.hpc.mil
* Latest version available at:
* http://nuttcp.net/nuttcp/beta/
*
* Test TCP connection. Makes a connection on port 5000(ctl)/5101(data)
* and transfers fabricated buffers or data copied from stdin.
*
* Run nuttcp with no arguments to get a usage statement
*
* Modified for operation under 4.2BSD, 18 Dec 84
* T.C. Slattery, USNA
* Minor improvements, Mike Muuss and Terry Slattery, 16-Oct-85.
*
* 8.2.2, Bill Fink, 5-Oct-18
* Improve warning when third party "-4/-6" is not supported
* Add af=inet/inet6 to verbose UDP output
* Add ip=<server_ip> to verbose UDP output for client transmitter
* 8.2.1, Bill Fink, 3-Oct-18
* Fix to pass "-4" or "-6" argument to 3rd party
* 8.1.4, Rob Scott, 1-Nov-16
* Fix to allow compile with -Werror=format-security as noted by Dhiru Kholia in fedora bug 1037224
* Fix missing brackets caught by -Wmisleading-indentation
* Add code to print out address family of connect/accept
* Add code to translate v4mapped addresses
* 8.1.3, Bill Fink, 9-Sep-16
* Fix to allow direct I/O on block devices
* Fix parsing of "-R i[s]##[/##]" (blank between 'R' and 'i')
* Updated Copyright notice for new year
* 8.1.2, Bill Fink, 5-Sep-16
* Fix to not exercise 8.0.1 and 8.1.1 features for non-Linux systems
* Changed nuttcp site to http://nuttcp.net/nuttcp/beta/
* Added define test for NOT_LINUX to undefine LINUX for build testing
* 8.1.1, Bill Fink, 31-Aug-16
* Add "-Ris##" option to emulate smoothed slow start behavior (Linux only)
* 8.0.1, Bill Fink, 22-Aug-16
* Add reporting of TCP congestion window
* 7.3.4, Rob Scott & Bill Fink, 18-Jul-16
* Use clock_gettime() on Windows/CYGWIN and Linux (if available)
* 7.3.3, Rob Scott, 1-May-15
* Fix tos to work for ipv6 by setting traffic class
* 7.3.2, Bill Fink, 3-Aug-14
* Allow longer server info timeout for third party via --idle-data-timeout
* 7.3.1, Bill Fink, 27-Jul-14
* Added feature to specify source port with "-p#:#" and "-P#:#"
* Updated Copyright notice for new year
* 7.2.2, Bill Fink, 25-May-13
* Fix Linux bug of exceeding MAX_EOT_WAIT_SEC on lossy large RTT path
* with large window causing false "Error: receiver not ACKing data"
* Change Linux method for draining socket send queue at EOT while waiting
* for any TCP retransmissions to complete - instead of checking
* tcpi_unacked value from TCP_INFO getsockopt() use SIOCOUTQ ioctl()
* (new error message is "Error: timeout while draining socket send queue")
* 7.2.1, Bill Fink, 26-Dec-12
* Add "-g" option to specify multicast IP address to use
* Clean up really confused transmit code for IPv4/IPv6 SSM multicast
* Bug fix from Aristeu Rozanski:
* Crash caused by closing TCP_ADV_WIN_SCALE file even if open failed
* 7.1.6, Bill Fink, 25-Feb-12
* Add "-sd" direct I/O option for non-sinkmode (Linux only)
* Fix bug with server CPU affinity being parsed as %X instead of %d
* For non-sinkmode insure complete network block is written to stdout
* Above fixes nuttscp bug seen with --copy-dir getting premature EOF
* Updated Copyright notice for new year
* Whitespace style cleanups
* 7.1.5, Rob Scott, 19-Jul-11
* Not every system has ERESTART added in 7.1.4, wrapped in ifdef
* 7.1.4, Bill Fink, 30-May-11
* Updated Copyright notice
* Use -DHAVE_SS_FAMILY to override _AIX workaround for newer AIX
* AIX can get ERESTART rather than EINTR/EAGAIN error on interrupted I/O
* Fix non-Linux systems to properly count TCP retrans for multiple streams
* Allow xinetd nuttcp server to handle both IPv4 & IPv6 if no explicitaf
* Detect EOD for non-sinkmode UDP transfers
* Suppress bogus warning when using maximum size UDP packet
* 7.1.3, Bill Fink, 1-Apr-10
* Fix compiler warnings generated by Ubuntu 9.x gcc 4.3.x/4.4.x versions
* (to see warnings compile with -DWANT_WUR)
* 7.1.2, Bill Fink, 23-Jan-10
* Updated Copyright notice
* Terminate non-sinkmode after specified file size with "-n" option
* Allow multilink aggregation with "-N##m" option to work for receive
* Add "-sz" zero copy option for non-sinkmode when input is a regular file
* Fix compiler warnings about strict-aliasing rules for variable group
* Remove "-Sf" forced server mode from Usage: statement
* Fix zeroing of clientaddr6 during server cleanup
* Fix freeaddrinfo() processing during cleanup
* Change manually started oneshot server to have parent process just exit
* Some minor whitespace cleanup
* 7.1.1, Bill Fink, 24-Dec-09
* Provide summary TCP retrans info for multi-stream TCP
* Fix bug with retrans interval info when -fparse
* Add "+stride" or "+n.n.n.n" syntax for multi-stream TCP (IPv4)
* Fix third party bug with "-xc" option adding extraneous 't' character
* Add optional client-side name resolution for third party host
* Add "-N##m" option for multilink aggregation for multiple streams
* Add "-xc#/#" and "-P#/#" options to Usage: statement
* Some minor whitespace cleanup
* 7.0.1, Bill Fink, 18-Sep-09
* Enable jitter measurements with "-j" option
* Enable one-way delay measurements with "-o" option
* Fix bug with RTT and -fparse
* 6.2.10, Bill Fink, 1-Aug-09
* Change ctl/data port checks to < 1024 instead of < 5000
* Fix "--idle-data-timeout" Usage: statement for new default minimum
* Improve transmit performance with "-i" by setting poll() timeout to 0
* Remove commented out code for unused normal_eod
* Don't output interval retrans info if non-sinkmode (for nuttscp)
* 6.2.9, Bill Fink, 24-Jun-09
* Make retrans info reporting work again on newer Linux distros
* Skip check for unACKed data at end of transfer if -DBROKEN_UNACKED
* 6.2.8, Bill Fink, 8-Jun-09
* Play nice with iperf (change default data port to 5101)
* Delay sending of server "OK" until after successful server bind()
* Client check for server errors before starting data transfer
* Continue checking for server output while draining client transmission
* Correct "server not ACKing data" error message (server -> receiver)
* Add "--packet-burst" option for Rob
* Fix "--idle-data-timeout" Usage: statement for client
* Improve accuracy of retrans info timing synchronization (client xmitter)
* Change reference to nuttcp repository from ftp:// to http://
* Fix bug affecting nuttscp introduced in 6.2.4 (not honoring oneshot)
* Whitespace cleanup: get rid of <tab><spaces><tab>, <tab>$, & <spaces>$
* Whitespace cleanup: convert 8 spaces to <tab> where appropriate
* 6.2.7, Bill Fink, 22-May-09
* Allow rate limit to be exceeded temporarily by n packets ("-Rixxx/n")
* Fix several reqval parameter settings
* 6.2.6, Bill Fink, 17-Apr-09
* Allow setting server CPU affinity from client via "-xcs" option
* Allow setting client & server CPU affinity via third party
* Fix bug with option processing when reqval is set
* 6.2.5, Bill Fink, 16-Apr-09
* Allow passing of third party control port via "-Pctlport/ctlport3"
* Up default idle data minimum to 15 sec to better handle net transients
* Don't reset nstream until after last use (fix getaddrinfo() memory leak)
* 6.2.4, Bill Fink, 10-Apr-09
* Fix bug with simultaneous server connections to manually started server
* 6.2.3, Bill Fink, 5-Apr-09
* Add "-xc" option to set CPU affinity (Linux only)
* Fix Usage: statement: "--idle-data-timeout" both server & client option
* Don't reset priority on server cleanup
* Fix priority output for "-fparse"
* 6.2.2, Bill Fink, 3-Apr-09
* Fix bad third party bug causing >= 1 minute transfers to silently fail
* Fix Usage: statement: "--idle-data-timeout" not just a server option
* 6.2.1, Rob Scott, 22-Mar-09
* Added IPv6 and SSM MC support
* Ported from Rob's 5.5.5 based code by Bill Fink
* 6.1.5, Bill Fink, 5-Mar-09
* Fix client lockup with third party when network problem (for scripts)
* 6.1.4, Bill Fink, 5-Jan-09
* Updated Copyright notice
* Bugfix: set chk_idle_data on client (now also checks no data received)
* Use argv[0] instead of "nuttcp" for third party
* Bugfix: give error message again on error starting server
* 6.1.3, Bill Fink, 17-Sep-08
* Timeout client accept() too and give nice error message (for scripts)
* 6.1.2, Bill Fink, 29-Aug-08
* Don't wait forever for unacked data at EOT (limit to 1 minute max)
* Extend no data received protection to client too (for scripts)
* Give nice error messages to client for above cases
* Don't hang getting server info if server exited (timeout reads)
* 6.1.1, Bill Fink, 26-Aug-08
* Remove beta designation
* Report RTT by default (use "-f-rtt" to suppress)
* Moved RTT info to "connect to" line
* Correct bogus IP frag warning for e.g. "-l1472" or "-l8972"
* Don't report interval host-retrans if no data rcvd (e.g. initial PMTU)
* Correct reporting of retrans info with "-fparse" option
* Correct reporting of RTT with "-F" flip option
* Report doubled send and receive window sizes (for Linux)
* Add report of available send and receive window sizes (for Linux)
* Touchup TODO list to remove some already completed items
* 6.0.7, Bill Fink, 19-Aug-08
* Add delay (default 0.5 sec) to "-a" option & change max retries to 10
* Updated Copyright notice
* 6.0.6, Bill Fink, 11-Aug-08
* Delay server forking until after listen() for better error status
* Above suggested by Hans Blom (jblom@science.uva.nl)
* Make forced server mode the default behavior
* Check address family on getpeername() so "ssh host nuttcp -S" works
* Add setsid() call for manually started server to create new session
* Some minor code cleanup
* 6.0.5, Bill Fink, 10-Aug-08
* Allow "-s" from/to stdin/stdout with "-1" oneshot server mode
* Switch beta vers message to stderr to not interfere with "-s" option
* Don't set default timeout if "-s" specified
* Give error message for "-s" with "-S" (xinetd or manually started)
* 6.0.4, Bill Fink, 18-Jul-08
* Forgot about 3rd party support for RTT info - fix that
* 6.0.3, Bill Fink, 17-Jul-08
* A better (and accurate) way to get RTT info (and not just Linux)
* 6.0.2, Bill Fink, 16-Jul-08
* Add RTT info to brief output for Linux
* 6.0.1, Bill Fink, 17-Dec-07
* Add reporting of TCP retransmissions (interval reports on Linux TX only)
* Add reporting of data transfer RTT for verbose Linux output
* Add beta version messages and "-f-beta" option to suppress
* Automatically switch "classic" mode to oneshot server mode
* Fix UDP loss info bug not updating stream_idx when not need_swap
* Fix compiler warning doing sprintf of timeout
* Correct comment on NODROPS define
* 5.5.5, Bill Fink, 1-Feb-07
* Change default MC addr to be based on client addr instead of xmit addr
* 5.5.4, Bill Fink, 3-Nov-06
* Fix bug with negative loss causing huge drop counts on interval reports
* Updated Copyright notice and added GPL license notice
* 5.5.3, Bill Fink, 23-Oct-06
* Fix bug with "-Ri" instantaneous rate limiting not working properly
* 5.5.2, Bill Fink, 25-Jul-06
* Make manually started server multi-threaded
* Add "--single-threaded" server option to restore old behavior
* Add "-a" client option to retry a failed server connection "again"
* (for certain possibly transient errors)
* 5.5.1, Bill Fink, 22-Jul-06
* Fix bugs with nbuf_bytes and rate_pps used with 3rd party
* Pass "-D" option to server (and also make work for third party)
* Allow setting precedence with "-c##p"
* 5.4.3, Rob Scott & Bill Fink, 17-Jul-06
* Fix bug with buflen passed to server when no buflen option speicified
* (revert 5.3.2: Fix bug with default UDP buflen for 3rd party)
* Better way to fix bug with default UDP buflen for 3rd party
* Trim trailing '\n' character from err() calls
* Use fcntl() to set O_NONBLOCK instead of MSG_DONTWAIT to send() ABORT
* (and remove MSG_DONTWAIT from recv() because it's not needed)
* Don't re-initialize buflen at completion of server processing
* (non inetd: is needed to check for buffer memory allocation change,
* caused bug if smaller "-l" followed by larger default "-l")
* 5.4.2, Bill Fink, 1-Jul-06
* Fix bug with interrupted UDP receive reporting negative packet loss
* Make sure errors (or debug) from server are propagated to the client
* Make setsockopt SO_SNDBUF/SO_RCVBUF error not be fatal to server
* Don't send stderr to client if nofork is set (manually started server)
* 5.4.1, Bill Fink, 30-Jun-06
* Fix bug with UDP reporting > linerate because of bad correction
* Send 2nd UDP BOD packet in case 1st is lost, e.g. waiting for ARP reply
* (makes UDP BOD more robust for new separate control and data paths)
* Fix bug with interval reports after EOD for UDP with small interval
* Don't just exit inetd server on no data so can get partial results
* (keep an eye out that servers don't start hanging again)
* Make default idle data timeout 1/2 of timeout if interval not set
* (with a minimum of 5 seconds and a maximum of 60 seconds)
* Make server send abort via urgent TCP data if no UDP data received
* (non-interval only: so client won't keep transmitting for full period)
* Workaround for Windows not handling TCP_MAXSEG getsockopt()
* 5.3.4, Bill Fink, 21-Jun-06
* Add "--idle-data-timeout" server option
* (server ends transfer if no data received for the specified
* timeout interval, previously it was a fixed 60 second timeout)
* Shutdown client control connection for writing at end of UDP transfer
* (so server can cope better with loss of all EOD packets, which is
* mostly of benefit when using separate control and data paths)
* 5.3.3, Bill Fink & Mark S. Mathews, 18-Jun-06
* Add new capability for separate control and data paths
* (using syntax: nuttcp ctl_name_or_IP/data_name_or_IP)
* Extend new capability for multiple independent data paths
* (using syntax: nuttcp ctl/data1/data2/.../datan)
* Above only supported for transmit or flipped/reversed receive
* Fix -Wall compiler warnings on 64-bit systems
* Make manually started server also pass stderr to client
* (so client will get warning messages from server)
* 5.3.2, Bill Fink, 09-Jun-06
* Fix bug with default UDP buflen for 3rd party
* Fix compiler warnings with -Wall on FreeBSD
* Give warning that windows doesn't support TCP_MAXSEG
* 5.3.1, Rob Scott, 06-Jun-06
* Add "-c" COS option for setting DSCP/TOS setting
* Fix builds on latest MacOS X
* Fix bug with 3rd party unlimited rate UDP not working
* Change "-M" option to require a value
* Fix compiler warnings with -Wall (thanks to Daniel J Blueman)
* Remove 'v' from nuttcp version (simplify RPM packaging)
* V5.2.2, Bill Fink, 13-May-06
* Have client report server warnings even if not verbose
* V5.2.1, Bill Fink, 12-May-06
* Pass "-M" option to server so it also works for receives
* Make "-uu" be a shortcut for "-u -Ru"
* V5.1.14, Bill Fink, 11-May-06
* Fix cancellation of UDP receives to work properly
* Allow easy building without IPv6 support
* Set default UDP buflen to largest 2^n less than MSS of ctlconn
* Add /usr/local/sbin and /usr/etc to path
* Allow specifying rate in pps by using 'p' suffix
* Give warning if actual send/receive window size is less than requested
* Make UDP transfers have a default rate limit of 1 Mbps
* Allow setting MSS for client transmitter TCP transfers with "-M" option
* Give more precision on reporting small UDP percentage data loss
* Disallow UDP transfers in "classic" mode
* Notify when using "classic" mode
* V5.1.13, Bill Fink, 8-Apr-06
* Make "-Ri" instantaneous rate limit for very high rates more accurate
* (including compensating for microsecond gettimeofday() granularity)
* Fix bug giving bogus time/stats on UDP transmit side with "-Ri"
* Allow fractional rate limits (for 'm' and 'g' only)
* V5.1.12, Bill Fink & Rob Scott, 4-Oct-05
* Terminate server receiver if client control connection goes away
* or if no data received from client within CHECK_CLIENT_INTERVAL
* V5.1.11, Rob Scott, 25-Jun-04
* Add support for scoped ipv6 addresses
* V5.1.10, Bill Fink, 16-Jun-04
* Allow 'b' suffix on "-w" option to specify window size in bytes
* V5.1.9, Bill Fink, 23-May-04
* Fix bug with client error on "-d" option putting server into bad state
* Set server accept timeout (currently 5 seconds) to prevent stuck server
* Add nuttcp version info to error message from err() exit
* V5.1.8, Bill Fink, 22-May-04
* Allow 'd|D' suffix to "-T" option to specify days
* Fix compiler warning about unused variable cp in getoptvalp routine
* Interval value check against timeout value should be >=
* V5.1.7, Bill Fink, 29-Apr-04
* Drop "-nb" option in favor of "-n###[k|m|g|t|p]"
* V5.1.6, Bill Fink, 25-Apr-04
* Fix bug with using interval option without timeout
* V5.1.5, Bill Fink, 23-Apr-04
* Modification to allow space between option parameter and its value
* Permit 'k' or 'm' suffix on "-l" option
* Add "-nb" option to specify number of bytes to transfer
* Permit 'k', 'm', 'g', 't', or 'p' suffix on "-n" and "-nb" options
* V5.1.4, Bill Fink, 21-Apr-04
* Change usage statement to use standard out instead of standard error
* Fix bug with interval > timeout, give warning and ignore interval
* Fix bug with counting error value in nbytes on interrupted transfers
* Fix bug with TCP transmitted & received nbytes not matching
* Merge "-t" and "-r" options in Usage: statement
* V5.1.3, Bill Fink, 9-Apr-04
* Add "-Sf" force server mode (useful for starting server via rsh/ssh)
* Allow non-root user to find nuttcp binary in "."
* Fix bug with receives terminating early with manual server mode
* Fix bug with UDP receives not terminating with "-Ri" option
* Clean up output formatting of nbuf (from "%d" to "%llu")
* Add "-SP" to have 3rd party use same outgoing control port as incoming
* V5.1.2, Bill Fink & Rob Scott, 18-Mar-04
* Fix bug with nbuf wrapping on really long transfers (int -> uint64_t)
* Fix multicast address to be unsigned long to allow shift
* Add MacOS uint8_t definition for new use of uint8_t
* V5.1.1, Bill Fink, 8-Nov-03
* Add IPv4 multicast support
* Delay receiver EOD until EOD1 (for out of order last data packet)
* Above also drains UDP receive buffer (wait for fragmentation reassembly)
* V5.0.4, Bill Fink, 6-Nov-03
* Fix bug reporting 0 drops when negative loss percentage
* V5.0.3, Bill Fink, 6-Nov-03
* Kill server transmission if control connection goes away
* Kill 3rd party nuttcp if control connection goes away
* V5.0.2, Bill Fink, 4-Nov-03
* Fix bug: some dummy wasn't big enough :-)
* V5.0.1, Bill Fink, 3-Nov-03
* Add third party support
* Correct usage statement for "-xt" traceroute option
* Improved error messages on failed options requiring client/server mode
* V4.1.1, David Lapsley and Bill Fink, 24-Oct-03
* Added "-fparse" format option to generate key=value parsable output
* Fix bug: need to open data connection on abortconn to clear listen
* V4.0.3, Rob Scott, 13-Oct-03
* Minor tweaks to output format for alignment
* Interval option "-i" with no explicit value sets interval to 1.0
* V4.0.2, Bill Fink, 10-Oct-03
* Changed "-xt" option to do both forward and reverse traceroute
* Changed to use brief output by default ("-v" for old default behavior)
* V4.0.1, Rob Scott, 10-Oct-03
* Added IPv6 code
* Changed inet get functions to protocol independent versions
* Added fakepoll for hosts without poll() (macosx)
* Added ifdefs to only include setprio if os supports it (non-win)
* Added bits to handle systems without new inet functions (solaris < 2.8)
* Removed SYSV obsolete code
* Added ifdefs and code to handle cygwin and beginning of windows support
* Window size can now be in meg (m|M) and gig (g|G)
* Added additional directories to search for traceroute
* Changed default to transmit, time limit of 10 seconds, no buffer limit
* Added (h|H) as option to specify time in hours
* Added getservbyname calls for port, if all fails use old defaults
* Changed sockaddr to sockaddr_storage to handle v6 addresses
* v3.7.1, Bill Fink, 10-Aug-03
* Add "-fdebugpoll" option to help debug polling for interval reporting
* Fix Solaris compiler warning
* Use poll instead of separate process for interval reports
* v3.6.2, Rob Scott, 18-Mar-03
* Allow setting server window to use default value
* Cleaned out BSD42 old code
* Marked SYSV code for future removal as it no longer appears necessary
* Also set RCVBUF/SNDBUF for udp transfers
* Changed transmit SO_DEBUG code to be like receive
* Some code rearrangement for setting options before accept/connect
* v3.6.1, Bill Fink, 1-Mar-03
* Add -xP nuttcp process priority option
* Add instantaneous rate limit capability ("-Ri")
* Don't open data connection if server error or doing traceroute
* Better cleanup on server connection error (close open data connections)
* Don't give normal nuttcp output if server error requiring abort
* Implement -xt traceroute option
* v3.5.1, Bill Fink, 27-Feb-03
* Don't allow flip option to be used with UDP
* Fix bug with UDP and transmit interval option (set stdin unbuffered)
* Fix start of UDP timing to be when get BOD
* Fix UDP timing when don't get first EOD
* Fix ident option used with interval option
* Add "-f-percentloss" option to not give %loss info on brief output
* Add "-f-drops" option to not give packet drop info on brief output
* Add packet drop info to UDP brief output (interval report and final)
* Add "-frunningtotal" option to give cumulative stats for "-i"
* Add "-fdebuginterval" option to help debug interval reporting
* Add "-fxmitstats" option to give transmitter stats
* Change flip option from "-f" to "-F"
* Fix divide by zero bug with "-i" option and very low rate limit
* Fix to allow compiling with Irix native compiler
* Fix by Rob Scott to allow compiling on MacOS X
* v3.4.5, Bill Fink, 29-Jan-03
* Fix client/server endian issues with UDP loss info for interval option
* v3.4.4, Bill Fink, 29-Jan-03
* Remove some debug printout for interval option
* Fix bug when using interval option reporting 0.000 MB on final
* v3.4.3, Bill Fink, 24-Jan-03
* Added UDP approximate loss info for interval reporting
* Changed nbytes and pbytes from double to uint64_t
* Changed SIGUSR1 to SIGTERM to kill sleeping child when done
* v3.4.2, Bill Fink, 15-Jan-03
* Make <control-C> work right with receive too
* v3.4.1, Bill Fink, 13-Jan-03
* Fix bug interacting with old servers
* Add "-f" flip option to reverse direction of data connection open
* Fix bug by disabling interval timer when server done
* v3.3.2, Bill Fink, 11-Jan-03
* Make "-i" option work for client transmit too
* Fix bug which forced "-i" option to be at least 0.1 seconds
* v3.3.1, Bill Fink, 7-Jan-03
* Added -i option to set interval timer (client receive only)
* Fixed server bug not setting socket address family
* v3.2.1, Bill Fink, 25-Feb-02
* Fixed bug so second <control-C> will definitely kill nuttcp
* Changed default control port to 5000 (instead of data port - 1)
* Modified -T option to accept fractional seconds
* v3.1.10, Bill Fink, 6-Feb-02
* Added -I option to identify nuttcp output
* Made server always verbose (filtering is done by client)
* Update to usage statement
* Minor fix to "-b" output when "-D" option is used
* Fix bug with "-s" that appends nuttcp output to receiver data file
* Fix bug with "-b" that gave bogus CPU utilization on > 1 hour transfers
* v3.1.9, Bill Fink, 21-Dec-01
* Fix bug with "-b" option on SGI systems reporting 0% CPU utilization
* v3.1.8, Bill Fink, 21-Dec-01
* Minor change to brief output format to make it simpler to awk
* v3.1.7, Bill Fink, 20-Dec-01
* Implement "-b" option for brief output (old "-b" -> "-wb")
* Report udp loss percentage when using client/server mode
* Fix bug with nbytes on transmitter using timed transfer
* Combined send/receive window size printout onto a single line
* v3.1.6, Bill Fink, 11-Jun-01
* Fixed minor bug reporting error connecting to inetd server
* Previously, Bill Fink, 7-Jun-01
* Added -h (usage) and -V (version) options
* Fixed SGI compilation warnings
* Added reporting server version to client
* Added version info and changed ttcp prints to nuttcp
* Fixed bug with inetd server and client using -r option
* Added ability to run server from inetd
* Added udp capability to server option
* Added -T option to set timeout interval
* Added -ws option to set server window
* Added -S option to support running receiver as daemon
* Allow setting UDP buflen up to MAXUDPBUFLEN
* Provide -b option for braindead Solaris 2.8
* Added printing of transmit rate limit
* Added -w option to usage statement
* Added -N option to support multiple streams
* Added -R transmit rate limit option
* Fix setting of destination IP address on 64-bit Irix systems
* Only set window size in appropriate direction to save memory
* Fix throughput calculation for large transfers (>= 2 GB)
* Fix reporting of Mb/s to give actual millions of bits per second
* Fix setting of INET address family in local socket
* Fix setting of receiver window size
*
* TODO/Wish-List:
* Transmit interval marking option
* Allow at least some traceroute options
* Add "-ut" option to do both UDP and TCP simultaneously
* Default rate limit UDP if too much loss
* Ping option
* Other brief output formats
* Linux window size bug/feature note
* Network interface interrupts (for Linux only)
* netstat -i info
* Man page
* Forking for multiple streams
* Bidirectional option
* Graphical interface
* MTU info
* Warning for window size limiting throughput
* Auto window size optimization
* Transmitter profile and playback options
* Server side limitations (per client host/network)
* Server side logging
* Client/server security (password)
* nuttcp server registration
* nuttcp proxy support (firewalls)
* nuttcp network idle time
*
* Distribution Status -
* OpenSource(tm)
* Licensed under version 2 of the GNU GPL
* Please send source modifications back to the authors
* Derivative works should be redistributed with a modified
* source and executable name
*/
/*
#ifndef lint
static char RCSid[] = "@(#)$Revision: 1.2 $ (BRL)";
#endif
*/
#ifdef NOT_LINUX
#undef linux
#endif
#ifndef WANT_WUR
#undef _FORTIFY_SOURCE
#else
#define _FORTIFY_SOURCE 2
#endif
#define _FILE_OFFSET_BITS 64
#if defined(linux)
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h> /* struct timeval */
#include <stdlib.h>
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/resource.h>
#else
#include "win32nuttcp.h" /* from win32 */
#endif /* _WIN32 */
#include <limits.h>
#include <string.h>
#include <fcntl.h>
#if defined(linux)
#include <sys/stat.h>
#include <sys/sendfile.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#endif
/* Let's try changing the previous unwieldy check */
/* #if defined(linux) || defined(__FreeBSD__) || defined (sgi) || (defined(__MACH__) && defined(_SOCKLEN_T)) || defined(sparc) || defined(__CYGWIN__) */
/* to the following (hopefully equivalent) simpler form like we use
* for HAVE_POLL */
#if !defined(_WIN32) && (!(defined(__APPLE__) && defined(__MACH__)) || defined(_SOCKLEN_T))
#include <unistd.h>
#include <sys/wait.h>
#include <strings.h>
#endif
#ifndef USE_GETTIMEOFDAY
#ifndef HAVE_CLOCK_GETTIME
#if (defined(linux) && defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 17)) || defined(__CYGWIN__)
#define HAVE_CLOCK_GETTIME
#endif
#endif
#endif
#ifdef HAVE_CLOCK_GETTIME
#include <time.h> /* clock_gettime */
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX 18446744073709551615ULL
#endif
#define MAXRATE 0xffffffffUL
#if !defined(__CYGWIN__) && !defined(_WIN32)
#define HAVE_SETPRIO
#endif
#if defined(linux)
#define HAVE_SETAFFINITY
#endif
#if !defined(_WIN32) && (!(defined(__APPLE__) && defined(__MACH__)) || defined(_SOCKLEN_T))
#define HAVE_POLL
#endif
#if defined(__APPLE__) && defined(__MACH__)
#define uint64_t u_int64_t
#define uint32_t u_int32_t
#define uint16_t u_int16_t
#define uint8_t u_int8_t
#endif
#ifdef HAVE_POLL
#include <sys/poll.h>
#else
#include "fakepoll.h" /* from missing */
#endif
#ifdef HAVE_SETAFFINITY
#include <sched.h>
#endif
#ifndef CPU_SETSIZE
#undef HAVE_SETAFFINITY
#endif
/*
* _SOCKLEN_T is now defined by apple when they typedef socklen_t
*
* EAI_NONAME has nothing to do with socklen, but on sparc without it tells
* us it's an old enough solaris to need the typedef
*/
#if (defined(__APPLE__) && defined(__MACH__)) && !defined(_SOCKLEN_T) || (defined(sparc) && !defined(EAI_NONAME))
typedef int socklen_t;
#endif
#if defined(sparc) && !defined(EAI_NONAME) /* old sparc */
#define sockaddr_storage sockaddr
#define ss_family sa_family
#endif /* old sparc */
#if defined(_AIX) && !defined(HAVE_SS_FAMILY)
#define ss_family __ss_family
#endif
#if !defined(EAI_NONAME)
#include "addrinfo.h" /* from missing */
#endif
/*
* The following macro is from openssh defines.h by Tatu Ylonen and marked "can be used freely for any purpose"
*/
#if !defined(IN6_IS_ADDR_V4MAPPED)
#define IN6_IS_ADDR_V4MAPPED(a) \
((*(const __uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
(*(const __uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
(*(const __uint32_t *)(const void *)(&(a)->s6_addr[8]) == \
ntohl(0x0000ffff)))
#endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
#define BETA_STR "-beta8"
#define BETA_FEATURES "jitter/owd"
union sockaddr_union {
struct sockaddr_storage ss;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
};
static struct timeval time0; /* Time at which timing started */
static struct timeval timepk; /* Time at which last packet sent */
static struct timeval timepkr; /* Time at which last packet received */
static struct timeval timepkri; /* timepkr for interval reports */
static struct timeval timep; /* Previous time - for interval reporting */
static struct timeval timetx; /* Transmitter timestamp */
static struct timeval timerx; /* Receive timestamp */
static struct rusage ru0; /* Resource utilization at the start */
static struct sigaction sigact; /* signal handler for alarm */
static struct sigaction savesigact;
#define PERF_FMT_OUT "%.4f MB in %.2f real seconds = %.2f KB/sec" \
" = %.4f Mbps\n"
#define PERF_FMT_BRIEF "%10.4f MB / %6.2f sec = %9.4f Mbps %d %%TX %d %%RX"
#define PERF_FMT_BRIEF2 "%10.4f MB / %6.2f sec = %9.4f Mbps %d %%%s"
#define PERF_FMT_BRIEF3 " Trans: %.4f MB"
#define PERF_FMT_INTERVAL "%10.4f MB / %6.2f sec = %9.4f Mbps"
#define PERF_FMT_INTERVAL2 " Tot: %10.4f MB / %6.2f sec = %9.4f Mbps"
#define PERF_FMT_INTERVAL3 " Trans: %10.4f MB"
#define PERF_FMT_INTERVAL4 " Tot: %10.4f MB"
#define PERF_FMT_IN "%lf MB in %lf real seconds = %lf KB/sec = %lf Mbps\n"
#define CPU_STATS_FMT_IN "%*fuser %*fsys %*d:%*dreal %d%%"
#define CPU_STATS_FMT_IN2 "%*fuser %*fsys %*d:%*d:%*dreal %d%%"
#define LOSS_FMT " %.2f%% data loss"
#define LOSS_FMT_BRIEF " %.2f %%loss"
#define LOSS_FMT_INTERVAL " %5.2f ~%%loss"
#define LOSS_FMT5 " %.5f%% data loss"
#define LOSS_FMT_BRIEF5 " %.5f %%loss"
#define LOSS_FMT_INTERVAL5 " %7.5f ~%%loss"
#define DROP_FMT " %lld / %lld drop/pkt"
#define DROP_FMT_BRIEF " %lld / %lld drop/pkt"
#define DROP_FMT_INTERVAL " %5lld / %5lld ~drop/pkt"
#define JITTER_MIN 1
#define JITTER_AVG 2
#define JITTER_MAX 4
#define JITTER_IGNORE_OOO 8
#define JITTER_FMT "min-jitter = %.4f ms, avg-jitter = %.4f ms, " \
"max-jitter = %.4f ms"
#define JITTER_MIN_FMT_BRIEF " %.4f msMinJitter"
#define JITTER_AVG_FMT_BRIEF " %.4f msAvgJitter"
#define JITTER_MAX_FMT_BRIEF " %.4f msMaxJitter"
#define JITTER_MIN_FMT_INTERVAL " %.4f msMinJitter"
#define JITTER_AVG_FMT_INTERVAL " %.4f msAvgJitter"
#define JITTER_MAX_FMT_INTERVAL " %.4f msMaxJitter"
#define JITTER_FMT_IN "jitter = %lf ms, avg-jitter = %lf ms, " \
"max-jitter = %lf ms"
#define OWD_MIN 1
#define OWD_AVG 2
#define OWD_MAX 4
#define OWD_FMT "min-OWD = %.4f ms, avg-OWD = %.4f ms, " \
"max-OWD = %.4f ms"
#define OWD_MIN_FMT_BRIEF " %.4f msMinOWD"
#define OWD_AVG_FMT_BRIEF " %.4f msAvgOWD"
#define OWD_MAX_FMT_BRIEF " %.4f msMaxOWD"
#define OWD_MIN_FMT_INTERVAL " %.4f msMinOWD"
#define OWD_AVG_FMT_INTERVAL " %.4f msAvgOWD"
#define OWD_MAX_FMT_INTERVAL " %.4f msMaxOWD"
#define OWD_FMT_IN "OWD = %lf ms, avg-OWD = %lf ms, max-OWD = %lf ms"
#define RETRANS_FMT "%sretrans = %d"
#define RETRANS_FMT_BRIEF " %d %sretrans"
#define RETRANS_FMT_BRIEF_STR1 " %d = %d"
#define RETRANS_FMT_BRIEF_STR2 " retrans"
#define RETRANS_FMT_INTERVAL " %5d %sretrans"
#define RETRANS_FMT_IN "retrans = %d"
#define CWND_FMT " cwnd = %d KB"
#define CWND_FMT_BRIEF " %d KB-cwnd"
#define CWND_FMT_BRIEF_STR1 " %d = %d"
#define CWND_FMT_BRIEF_STR2 " KB-cwnd"
#define CWND_FMT_INTERVAL " %6d KB-cwnd"
#define CWND_FMT_IN "cwnd = %d"
#define RTT_FMT " RTT=%.3f ms"
#define RTT_FMT_BRIEF " %.2f msRTT"
#define RTT_FMT_IN "RTT=%lf"
#define RTT_FMT_INB "RTT = %lf"
#define SIZEOF_TCP_INFO_RETRANS 104
/* define NEW_TCP_INFO if struct tcp_info in /usr/include/netinet/tcp.h
* contains tcpi_total_retrans member
*
* tcpi_rcv_rtt, tcpi_rcv_space, & tcpi_total_retrans were added
* in glibc-headers-2.7 (Fedora 8) which fortunately also defined
* TCP_MD5SIG at the same time, so key off of that
*/
#if defined(linux) && defined(TCP_MD5SIG)
#define NEW_TCP_INFO
#endif
#ifndef NEW_TCP_INFO
#define OLD_TCP_INFO
#endif
/* Parsable output formats */
#define P_PERF_FMT_OUT "megabytes=%.4f real_seconds=%.2f " \
"rate_KBps=%.2f rate_Mbps=%.4f\n"
#define P_PERF_FMT_BRIEF "megabytes=%.4f real_seconds=%.2f rate_Mbps=%.4f " \
"tx_cpu=%d rx_cpu=%d"
#define P_PERF_FMT_BRIEF3 " tx_megabytes=%.4f"
#define P_PERF_FMT_INTERVAL "megabytes=%.4f real_sec=%.2f rate_Mbps=%.4f"
#define P_PERF_FMT_INTERVAL2 " total_megabytes=%.4f total_real_sec=%.2f" \
" total_rate_Mbps=%.4f"
#define P_PERF_FMT_INTERVAL3 " tx_megabytes=%.4f"
#define P_PERF_FMT_INTERVAL4 " tx_total_megabytes=%.4f"
#define P_PERF_FMT_IN "megabytes=%lf real_seconds=%lf rate_KBps=%lf " \
"rate_Mbps=%lf\n"
#define P_CPU_STATS_FMT_IN "user=%*f system=%*f elapsed=%*d:%*d cpu=%d%%"
#define P_CPU_STATS_FMT_IN2 "user=%*f system=%*f elapsed=%*d:%*d:%*d cpu=%d%%"
#define P_LOSS_FMT " data_loss=%.5f"
#define P_LOSS_FMT_BRIEF " data_loss=%.5f"
#define P_LOSS_FMT_INTERVAL " data_loss=%.5f"
#define P_DROP_FMT " drop=%lld pkt=%lld"
#define P_DROP_FMT_BRIEF " drop=%lld pkt=%lld"
#define P_DROP_FMT_INTERVAL " drop=%lld pkt=%lld"
#define P_JITTER_FMT "msminjitter=%.4f msavgjitter=%.4f " \
"msmaxjitter=%.4f"
#define P_JITTER_MIN_FMT_BRIEF " msminjitter=%.4f"
#define P_JITTER_AVG_FMT_BRIEF " msavgjitter=%.4f"
#define P_JITTER_MAX_FMT_BRIEF " msmaxjitter=%.4f"
#define P_JITTER_MIN_FMT_INTERVAL " msminjitter=%.4f"
#define P_JITTER_AVG_FMT_INTERVAL " msavgjitter=%.4f"
#define P_JITTER_MAX_FMT_INTERVAL " msmaxjitter=%.4f"
#define P_JITTER_FMT_IN "jitter=%lf msavgjitter=%lf msmaxjitter=%lf"
#define P_OWD_FMT "msminOWD=%.4f msavgOWD=%.4f msmaxOWD=%.4f"
#define P_OWD_MIN_FMT_BRIEF " msminOWD=%.4f"
#define P_OWD_AVG_FMT_BRIEF " msavgOWD=%.4f"
#define P_OWD_MAX_FMT_BRIEF " msmaxOWD=%.4f"
#define P_OWD_MIN_FMT_INTERVAL " msminOWD=%.4f"
#define P_OWD_AVG_FMT_INTERVAL " msavgOWD=%.4f"
#define P_OWD_MAX_FMT_INTERVAL " msmaxOWD=%.4f"
#define P_OWD_FMT_IN "OWD=%lf msavgOWD=%lf msmaxOWD=%lf"
#define P_RETRANS_FMT "%sretrans=%d"
#define P_RETRANS_FMT_STREAMS " retrans_by_stream=%d"
#define P_RETRANS_FMT_BRIEF " %sretrans=%d"
#define P_RETRANS_FMT_INTERVAL " %sretrans=%d"
#define P_RETRANS_FMT_IN "retrans=%d"
#define P_CWND_FMT " cwnd=%d"
#define P_CWND_FMT_STREAMS " cwnd_by_stream=%d"
#define P_CWND_FMT_BRIEF " cwnd=%d"
#define P_CWND_FMT_INTERVAL " cwnd=%d"
#define P_CWND_FMT_IN "cwnd=%d"
#define P_RTT_FMT " rtt_ms=%.3f"
#define P_RTT_FMT_BRIEF " rtt_ms=%.2f"
#define P_RTT_FMT_IN "rtt_ms=%lf"
#define HELO_FMT "HELO nuttcp v%d.%d.%d\n"
#ifndef MAXSTREAM
#define MAXSTREAM 128
#endif
#define DEFAULT_NBUF 2048
#define DEFAULT_NBYTES 134217728 /* 128 MB */
#define DEFAULT_TIMEOUT 10.0
#define DEFAULT_UDP_RATE 1000
#define DEFAULTUDPBUFLEN 8192
#define DEFAULT_MC_UDPBUFLEN 1024
#define MAXUDPBUFLEN 65507
#define LOW_RATE_HOST3 1000
#define MINMALLOC 1024
#define HI_MC 231ul
#define HI_MC_SSM 232ul
/* locally defined global scope IPv6 multicast, FF3E::8000:0-FF3E::FFFF:FFFF */
#define HI_MC6 "FF3E::8000:0000"
#define HI_MC6_LEN 13
#define HI_MC6_ASM "FF2E::0"
#define HI_MC6_ASM_LEN 8
#ifndef LISTEN_BACKLOG
#define LISTEN_BACKLOG 64
#endif
#define ACCEPT_TIMEOUT 5
#ifndef MAX_CONNECT_TRIES
#define MAX_CONNECT_TRIES 10 /* maximum server connect attempts */
#endif
#ifndef SERVER_RETRY_USEC
#define SERVER_RETRY_USEC 500000 /* server retry time in usec */
#endif
#define MAX_EOT_WAIT_SEC 60.0 /* max wait for unsent data at EOT */
#define SRVR_INFO_TIMEOUT 60 /* timeout for reading server info */
#define IDLE_DATA_MIN 15.0 /* minimum value for chk_idle_data */
#define DEFAULT_IDLE_DATA 30.0 /* default value for chk_idle_data */
#define IDLE_DATA_MAX 60.0 /* maximum value for chk_idle_data */
#define NON_JUMBO_ETHER_MSS 1448 /* 1500 - 20:IP - 20:TCP -12:TCPOPTS */
#define TCP_UDP_HDRLEN_DELTA 12 /* difference in tcp & udp hdr sizes */
#define TCP_TIMESTAMPS_OPTLEN 12 /* size of TCP timestamps options */
#if defined(linux)
#define TCP_ADV_WIN_SCALE "/proc/sys/net/ipv4/tcp_adv_win_scale"
#endif
#define DEBUGOUTPUT "/tmp/nuttcp-debugout.foo"
#define BRIEF_RETRANS_STREAMS 0x2 /* brief per stream retrans info */
#define BRIEF_CWND_STREAMS 0x4 /* brief per stream cwnd info */
#define XMITSTATS 0x1 /* also give transmitter stats (MB) */
#define DEBUGINTERVAL 0x2 /* add info to assist with
* debugging interval reports */
#define RUNNINGTOTAL 0x4 /* give cumulative stats for "-i" */
#define NODROPS 0x8 /* no packet drop stats for "-i" */
#define NOPERCENTLOSS 0x10 /* don't give percent loss for "-i" */
#define DEBUGPOLL 0x20 /* add info to assist with debugging
* polling for interval reports */
#define PARSE 0x40 /* generate key=value parsable output */
#define DEBUGMTU 0x80 /* debug info for MTU/MSS code */
#define NORETRANS 0x100 /* no retrans stats for "-i" */
#define DEBUGRETRANS 0x200 /* output info for debugging collection
* of TCP retransmission info */
#define NOBETAMSG 0x400 /* suppress beta version message */
#define WANTRTT 0x800 /* output RTT info (default) */
#define DEBUGJITTER 0x1000 /* debugging info for jitter option */
#define NOCWND 0x2000 /* no cwnd stats for "-i" */
#define DEBUGIRATE 0x4000 /* debugging info for irate option */
#ifdef NO_IPV6 /* Build without IPv6 support */
#undef AF_INET6
#undef IPV6_V6ONLY
#endif
void sigpipe( int signum );
void sigint( int signum );
void ignore_alarm( int signum );
void sigalarm( int signum );
static void err( char *s );
static void mes( char *s );
static void errmes( char *s );
void pattern( char *cp, int cnt );
void get_timeofday( struct timeval *tv, struct timezone *tz );
void prep_timer();
double read_timer( char *str, int len );
static void prusage( struct rusage *r0, struct rusage *r1, struct timeval *e, struct timeval *b, char *outp );
static void tvadd( struct timeval *tsum, struct timeval *t0, struct timeval *t1 );
static void tvsub( struct timeval *tdiff, struct timeval *t1, struct timeval *t0 );
static void psecs( long l, char *cp );
int Nread( int fd, char *buf, int count );
int Nwrite( int fd, char *buf, int count );
int delay( int us );
int mread( int fd, char *bufp, unsigned n );
int mwrite( int fd, char *bufp, unsigned n, int last_write );
char *getoptvalp( char **argv, int index, int reqval, int *skiparg );
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
void print_tcpinfo();
#endif
int vers_major = 8;
int vers_minor = 2;
int vers_delta = 2;
int ivers;
int rvers_major = 0;
int rvers_minor = 0;
int rvers_delta = 0;
int irvers;
int beta = 0;
struct sockaddr_in sinme[MAXSTREAM + 1];
struct sockaddr_in sinhim[MAXSTREAM + 1];
struct sockaddr_in save_sinhim, save_mc;
#ifdef AF_INET6
struct sockaddr_in6 sinme6[MAXSTREAM + 1];
struct sockaddr_in6 sinhim6[MAXSTREAM + 1];
struct sockaddr_in6 save_sinhim6, save_mc6;
struct in6_addr hi_mc6, hi_mc6_asm;
#endif
struct sockaddr_storage frominet;
int domain = PF_UNSPEC;
int af = AF_UNSPEC;
int mc_af = AF_UNSPEC;
int explicitaf = 0; /* address family explicit specified (-4|-6) */
int fd[MAXSTREAM + 1]; /* fd array of network sockets */
int nfd; /* fd for accept call */
struct pollfd pollfds[MAXSTREAM + 4]; /* used for reading interval reports */
socklen_t fromlen;
int buflen = 64 * 1024; /* length of buffer */
int nbuflen;
int mallocsize;
char *buf; /* ptr to dynamic buffer */
unsigned long long nbuf = 0; /* number of buffers to send in sinkmode */
int nbuf_bytes = 0; /* set to 1 if nbuf is actually bytes */
/* nick code */
int sendwin=0, sendwinval=0, origsendwin=0;
socklen_t optlen;
int rcvwin=0, rcvwinval=0, origrcvwin=0;
int srvrwin=0;
/* end nick code */
#if defined(linux)
int sendwinavail=0, rcvwinavail=0, winadjust=0;
#endif
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
#ifdef OLD_TCP_INFO
#define STRUCT_TCPINFO tcpinfo
struct tcpinfo { /* for collecting TCP retransmission info */
struct tcp_info _tcpinf;
/* add missing structure elements */
u_int32_t tcpi_rcv_rtt;
u_int32_t tcpi_rcv_space;
u_int32_t tcpi_total_retrans;
} tcpinf;
#define tcpinfo_state _tcpinf.tcpi_state
#define tcpinfo_ca_state _tcpinf.tcpi_ca_state
#define tcpinfo_retransmits _tcpinf.tcpi_retransmits
#define tcpinfo_unacked _tcpinf.tcpi_unacked
#define tcpinfo_sacked _tcpinf.tcpi_sacked
#define tcpinfo_lost _tcpinf.tcpi_lost
#define tcpinfo_retrans _tcpinf.tcpi_retrans
#define tcpinfo_fackets _tcpinf.tcpi_fackets
#define tcpinfo_rtt _tcpinf.tcpi_rtt
#define tcpinfo_rttvar _tcpinf.tcpi_rttvar
#define tcpinfo_snd_ssthresh _tcpinf.tcpi_snd_ssthresh
#define tcpinfo_snd_cwnd _tcpinf.tcpi_snd_cwnd
#else
#define STRUCT_TCPINFO tcp_info
struct tcp_info tcpinf;
#define tcpinfo_state tcpi_state
#define tcpinfo_ca_state tcpi_ca_state
#define tcpinfo_retransmits tcpi_retransmits
#define tcpinfo_unacked tcpi_unacked
#define tcpinfo_sacked tcpi_sacked
#define tcpinfo_lost tcpi_lost
#define tcpinfo_retrans tcpi_retrans
#define tcpinfo_fackets tcpi_fackets
#define tcpinfo_rtt tcpi_rtt
#define tcpinfo_rttvar tcpi_rttvar
#define tcpinfo_snd_ssthresh tcpi_snd_ssthresh
#define tcpinfo_snd_cwnd tcpi_snd_cwnd
#endif
#else
#define STRUCT_TCPINFO dummy_tcp_info
struct dummy_tcp_info {
int dummy1;
} tcpinf;
#endif
int get_retrans( int sockfd, struct STRUCT_TCPINFO *tcpinfo );
int udp = 0; /* 0 = tcp, !0 = udp */
int udplossinfo = 0; /* set to 1 to give UDP loss info for
* interval reporting */
int do_jitter = 0; /* set to 1 to enable jitter measurements */
int do_owd = 0; /* set to 1 to enable one-way delay reports */
int retransinfo = 0; /* set to 1 to give TCP retransmission info
* for interval reporting */
int force_retrans = 0; /* set to force sending retrans info */
int send_retrans = 1; /* set to 0 if no need to send retrans info */
int do_retrans = 0; /* set to 1 for client transmitter */
int read_retrans = 1; /* set to 0 if no need to read retrans info */
int got_0retrans = 0; /* set to 1 by client transmitter after
* processing initial server output
* having "0 retrans" */
int init_pkt_cwnd = 0; /* initial congestion window in packets */
int sss_pkt_cwnd = 0; /* smoothed slow start congestion window */
int cwndinfo = 0; /* set to 1 to give TCP congestion window info
* for interval reporting */
int send_cwnd = 1; /* set to 0 if no need to send cwnd info */
int do_cwnd = 0; /* set to 1 for client transmitter */
int read_cwnd = 1; /* set to 0 if no need to read cwnd info */
int need_swap; /* client and server are different endian */
int options = 0; /* socket options */
int one = 1; /* for 4.3 BSD style setsockopt() */
/* default port numbers if command arg or getserv doesn't get a port # */
#define DEFAULT_PORT 5101
#define DEFAULT_CTLPORT 5000
#define IPERF_PORT 5001
unsigned short port = 0; /* TCP port number */
unsigned short srcport = 0; /* TCP source port */
unsigned short ctlport = 0; /* control port for server connection */
unsigned short srcctlport = 0; /* TCP source port for server connection */
unsigned short ctlport3 = 0; /* control port for 3rd party server conn */
int tmpport;
char *host; /* ptr to name of host */
char *stride = NULL; /* ptr to address stride for multi-stream */
char *host3 = NULL; /* ptr to 3rd party host */
int thirdparty = 0; /* set to 1 indicates doing 3rd party nuttcp */
int no3rd = 0; /* set to 1 by server to disallow 3rd party */
int forked = 0; /* set to 1 after server has forked */
int pass_ctlport = 0; /* set to 1 to use same outgoing control port
as incoming with 3rd party usage */
char *nut_cmd; /* command used to invoke nuttcp */
char *cmdargs[50]; /* command arguments array */
char tmpargs[50][50];
#ifndef AF_INET6
#define ADDRSTRLEN 16
#else
#define ADDRSTRLEN INET6_ADDRSTRLEN
int v4mapped = 0; /* set to 1 to enable v4 mapping in v6 server */
#endif
#define HOSTNAMELEN 80
#define HOST3BUFLEN HOSTNAMELEN + 2 + ADDRSTRLEN + 1 + ADDRSTRLEN
/* host3=[=]host3addr[+host3stride] */
char hostbuf[ADDRSTRLEN]; /* buffer to hold text of address */
char host3addr[ADDRSTRLEN]; /* buffer to hold text of 3rd party address */
char host3buf[HOST3BUFLEN + 1]; /* buffer to hold 3rd party name or address */
char clientbuf[NI_MAXHOST]; /* buffer to hold client's resolved hostname */
int trans = 1; /* 0=receive, !0=transmit mode */
int sinkmode = 1; /* 0=normal I/O, !0=sink/source mode */
#if defined(linux)
int zerocopy = 0; /* set to enable zero copy via sendfile() */
int directio = 0; /* set to enable direct I/O */
#endif
int nofork = 0; /* set to 1 to not fork server */
int verbose = 0; /* 0=print basic info, 1=print cpu rate, proc
* resource usage. */
int nodelay = 0; /* set TCP_NODELAY socket option */
unsigned long rate = MAXRATE; /* transmit rate limit in Kbps */
int maxburst = 1; /* number of packets allowed to exceed rate */
int nburst = 1; /* number of packets currently exceeding rate */
int irate = -1; /* instantaneous rate limit if set */
int iratesss = 0; /* set if emulating smoothed slow start */
int af3 = 0; /* used for third party explicitaf */
double pkt_time; /* packet transmission time in seconds */
double pkt_time_ms; /* packet transmission time in milliseconds */
uint64_t irate_pk_usec; /* packet transmission time in microseconds */
double irate_pk_nsec; /* nanosecond portion of pkt xmit time */
double irate_cum_nsec = 0.0; /* cumulative nanaseconds over several pkts */
int rate_pps = 0; /* set to 1 if rate is given as pps */
double timeout = 0.0; /* timeout interval in seconds */
double interval = 0.0; /* interval timer in seconds */
double chk_idle_data = 0.0; /* server receiver checks this often */
/* for client having gone away */
double chk_interval = 0.0; /* timer (in seconds) for checking client */
int ctlconnmss; /* control connection maximum segment size */
int datamss = 0; /* data connection maximum segment size */
unsigned int tos = 0; /* 8-bit TOS field for setting DSCP/TOS */
char intervalbuf[256+2]; /* buf for interval reporting */
char linebuf[256+2]; /* line buffer */
int do_poll = 0; /* set to read interval reports (client xmit) */
int got_done = 0; /* set when read last of interval reports */
int reverse = 0; /* reverse direction of data connection open */
int format = 0; /* controls formatting of output */
char fmt[257];
int traceroute = 0; /* do traceroute back to client if set */
int skip_data = 0; /* skip opening of data channel */
#if defined(linux)
int multicast = 0; /* set to 1 for multicast UDP transfer */
#else
uint8_t multicast = 0; /* set to 1 for multicast UDP transfer */
#endif
int ssm = -1; /* set to 1 for Source Specific Multicast */
/* set to 0 to NOT do SSM */
/* set to -1 to have SSM follow protocol */
/* (off for ipv4, on for ipv6) */
int mc_param;
char *mc_addr = NULL; /* user specified multicast IP address */
char mcgaddr[ADDRSTRLEN]; /* buffer to hold text of MC group address */
struct ip_mreq mc_group; /* holds multicast group address */
#ifdef AF_INET6
struct ipv6_mreq mc6_group; /* holds multicast group address */
#endif
#ifdef MCAST_JOIN_SOURCE_GROUP
struct group_source_req group_source_req; /* holds multicast SSM group and */
/* source information */
#endif
#ifdef HAVE_SETPRIO
int priority = 0; /* nuttcp process priority */
#endif
/* affinity and srvr_affinity need to be defined even if don't
* HAVE_SETAFFINITY, to make parameter passing between client and
* server work out OK, since far end may HAVE_SETAFFINITY
*
* they are set to -1 so they have no effect even if don't
* HAVE_SETAFFINITY
*/
int affinity = -1; /* nuttcp process CPU affinity */
int srvr_affinity = -1; /* nuttcp server process CPU affinity */
#ifdef HAVE_SETAFFINITY
int ncores = 1; /* number of CPU cores */
cpu_set_t cpu_set; /* processor CPU set */
#endif
long timeout_sec = 0;
struct itimerval itimer; /* for setitimer */
int srvr_helo = 1; /* set to 0 if server doesn't send HELO */
char ident[40 + 1 + 1] = ""; /* identifier for nuttcp output */
int intr = 0;
int abortconn = 0;
int braindead = 0; /* for braindead Solaris 2.8 systems */
int brief = 1; /* set for brief output */
int brief3 = 1; /* for third party nuttcp */
int done = 0; /* don't output interval report if done */
int got_begin = 0; /* don't output interval report if not begun */
int two_bod = 0; /* newer versions send 2 BOD packets for UDP */
int handle_urg = 0; /* newer versions send/recv urgent TCP data */
int got_eod0 = 0; /* got EOD0 packet - marks end of UDP xfer */
int buflenopt = 0; /* whether or not user specified buflen */
int haverateopt = 0; /* whether or not user specified rate */
int clientserver = 0; /* client server mode (use control channel) */
int client = 0; /* 0=server side, 1=client (initiator) side */
int oneshot = 0; /* 1=run server only once */
int inetd = 0; /* set to 1 if server run from inetd */
pid_t pid; /* process id when forking server process */
pid_t wait_pid; /* return of wait system call */
int pidstat; /* status of forked process */
FILE *ctlconn; /* uses fd[0] for control channel */
FILE *debugout; /* used for voluminous nuttcp debug output */
int savestdin; /* used to save real standard in */
int savestdout; /* used to save real standard out */
int firsttime = 1; /* flag for first pass through server */
struct in_addr clientaddr; /* IP address of client connecting to server */
#ifdef AF_INET6
struct in6_addr clientaddr6; /* IP address of client connecting to server */
uint32_t clientscope6; /* scope part of IP address of client */
#endif
struct hostent *addr;
extern int errno;
const char Usage[] = "\
Usage: nuttcp or nuttcp -h prints this usage info\n\
Usage: nuttcp -V prints version info\n\
Usage: nuttcp -xt [-m] host forward and reverse traceroute to/from server\n\
Usage (transmitter): nuttcp [-t] [-options] [ctl_addr/]host [3rd-party] [<in]\n\
|(receiver): nuttcp -r [-options] [host] [3rd-party] [>out]\n\
-4 Use IPv4\n"
#ifdef AF_INET6
" -6 Use IPv6\n"
#endif
" -c## cos dscp value on data streams (t|T suffix for full TOS field)\n\
-l## length of network write|read buf (default 1K|8K/udp, 64K/tcp)\n"
#if defined(linux)
" -s[d][z] use stdin|stdout for data input|output instead of pattern data\n"
" ('d' suboption uses direct I/O if input|output is regular file)\n"
" ('z' suboption enables zero copy tx if input is regular file)\n"
#else
" -s use stdin|stdout for data input|output instead of pattern data\n"
#endif
" -n## number of source bufs written to network (default unlimited)\n\
-w## transmitter|receiver window size in KB (or (m|M)B or (g|G)B)\n\
-ws## server receive|transmit window size in KB (or (m|M)B or (g|G)B)\n\
-wb braindead Solaris 2.8 (sets both xmit and rcv windows)\n\
-p## port number to send to|listen at (default 5101)\n\
-p#:# specify both source:destination port for -p option\n\
-P## port number for control connection (default 5000)\n\
-P#:# specify both source:destination port for -P option\n\
-P#/# control port to/from 3rd-party host (default 5000)\n\
-u use UDP instead of TCP\n\
-m## use multicast with specified TTL instead of unicast (UDP)\n\
-gxxx user specified multicast IP address for -m option\n\
-M## MSS for data connection (TCP)\n\
-N## number of streams (starting at port number), implies -B\n\
-R## transmit rate limit in Kbps (or (m|M)bps or (g|G)bps or (p)ps)\n\
-Ri#[/#] instantaneous rate limit with optional packet burst\n"
#if defined(linux)
" -Ris## emulated smoothed slow start option for -Ri option (TCP)\n"
#endif
" -T## transmit timeout in seconds (or (m|M)inutes or (h|H)ours)\n\
-j enable jitter measurements (assumes -u and -Ri options)\n\
-o enable one-way delay reports (needs synchronized clocks)\n\
-i## receiver interval reporting in seconds (or (m|M)inutes)\n\
-Ixxx identifier for nuttcp output (max of 40 characters)\n\
-F flip option to reverse direction of data connection open\n\
-a retry failed server connection \"again\" for transient errors\n"
#ifdef HAVE_SETPRIO
" -xP## set nuttcp process priority (must be root)\n"
#endif
#ifdef HAVE_SETAFFINITY
" -xc## set nuttcp client process CPU affinity\n"
" -xcs## set nuttcp server process CPU affinity\n"
" -xc#/# set nuttcp client/server process CPU affinity\n"
#endif
" -d set TCP SO_DEBUG option on data socket\n\
-v[v] verbose [or very verbose] output\n\
-b brief output (default)\n\
-br add per-stream TCP retrans info to brief summary (Linux only)\n"
#if defined(linux)
" -bc add per-stream TCP cwnd info to brief summary (Linux only)\n"
#endif
" -D xmit only: don't buffer TCP writes (sets TCP_NODELAY sockopt)\n\
-B recv only: only output full blocks of size from -l## (for TAR)\n"
" --packet-burst packet burst value for instantaneous rate limit option\n"
" --idle-data-timeout <value|minimum/default/maximum> (default: 15/30/60)\n"
" client timeout in seconds for idle data connection\n"
#ifdef IPV6_V6ONLY
" --disable-v4-mapped disable v4 mapping in v6 server (default)\n"
" --enable-v4-mapped enable v4 mapping in v6 server\n"
#endif
"\n\
Usage (server): nuttcp -S[P] [-options]\n\
note server mode excludes use of -s except for -1 one-shot mode\n\
'P' suboption makes 3rd party {in,out}bound control ports same\n\
-4 Use IPv4 (default)\n"
#ifdef AF_INET6
" -6 Use IPv6\n"
#endif
" -1 oneshot server mode (implied with inetd/xinetd), implies -S\n"
#if defined(linux)
" -s[d][z] use stdin|stdout for data input|output instead of pattern data\n"
" ('d' suboption uses direct I/O if input|output is regular file)\n"
" ('z' suboption enables zero copy tx if input is regular file)\n"
#else
" -s use stdin|stdout for data input|output instead of pattern data\n"
#endif
" -P## port number for server connection (default 5000)\n\
note don't use with inetd/xinetd (use services file instead)\n"
#ifdef HAVE_SETPRIO
" -xP## set nuttcp process priority (must be root)\n"
#endif
#ifdef HAVE_SETAFFINITY
" -xc## set nuttcp server process CPU affinity\n"
#endif
" --idle-data-timeout <value|minimum/default/maximum> (default: 15/30/60)\n"
" server timeout in seconds for idle data connection\n"
" --no3rdparty don't allow 3rd party capability\n"
" --nofork don't fork server\n"
" --single-threaded make manually started server be single threaded\n"
#ifdef IPV6_V6ONLY
" --disable-v4-mapped disable v4 mapping in v6 server (default)\n"
" --enable-v4-mapped enable v4 mapping in v6 server\n"
#endif
"\n\
Multilink aggregation options (TCP only):\n\
nuttcp [-options] -N## [ctl_addr]/host1/host2/.../host## (xmit only)\n\
nuttcp [-options] -N## [ctl_addr/]host+addr_stride (IPv4 only)\n\
nuttcp [-options] -N## [ctl_addr/]host+n.n.n.n (IPv4 only)\n\
nuttcp [-options] -N##m [ctl_addr/]host\n\
where host resolves to multiple addresses\n\
\n\
separate [ctl_addr/] option available only for xmit\n\
\n\
Format options:\n\
-fxmitstats also give transmitter stats (MB) with -i (UDP only)\n\
-frunningtotal also give cumulative stats on interval reports\n\
-f-drops don't give packet drop info on brief output (UDP)\n\
-f-retrans don't give retrans info on brief output (TCP)\n"
#if defined(linux)
" -f-cwnd don't give cwnd info on brief output (TCP)\n"
#endif
" -f-percentloss don't give %%loss info on brief output (UDP)\n\
-fparse generate key=value parsable output\n\
-f-beta suppress beta version message\n\
-f-rtt suppress RTT info \n\
";
char stats[128];
char srvrbuf[4096];
char tmpbuf[257];
uint64_t nbytes = 0; /* bytes on net */
int64_t pbytes = 0; /* previous bytes - for interval reporting */
int64_t ntbytes = 0; /* bytes sent by transmitter */
int64_t ptbytes = 0; /* previous bytes sent by transmitter */
uint64_t ntbytesc = 0; /* bytes sent by transmitter that have
* been counted */
uint64_t ntbytescp = 0; /* previous ntbytesc count */
uint64_t ntbytescpi = 0; /* ntbytescp for interval reports */
uint64_t chk_nbytes = 0; /* byte counter used to test if no more data
* being received by server (presumably because
* client transmitter went away */
double rtt = 0.0; /* RTT between client and server in ms */
int which_rt = 1; /* which round trip for "-Ris" */
uint32_t nretrans[MAXSTREAM+1]; /* number of TCP retransmissions */
uint32_t iretrans[MAXSTREAM+1]; /* initial number of TCP retransmissions */
uint32_t pretrans = 0; /* previous number of TCP retransmissions */
uint32_t sretrans = 0; /* number of system TCP retransmissions */
uint32_t cwnd[MAXSTREAM+1]; /* TCP congestion window in KB */
int numCalls = 0; /* # of NRead/NWrite calls. */
int nstream = 1; /* number of streams */
int multilink = 0; /* set to use multilink aggregation */
int stream_idx = 0; /* current stream */
int start_idx = 1; /* set to use or bypass control channel */
int b_flag = 1; /* use mread() */
int got_srvr_output = 0; /* set when server output has been read */
int reading_srvr_info = 0; /* set when starting to read server info */
int retry_server = 0; /* set to retry control connect() to server */
int num_connect_tries = 0; /* tracks attempted connects to server */
int single_threaded = 0; /* set to make server single threaded */
double srvr_MB;
double srvr_realt;
double srvr_KBps;
double srvr_Mbps;
int srvr_cpu_util;
double cput = 0.000001, realt = 0.000001; /* user, real time (seconds) */
double realtd = 0.000001; /* real time delta - for interval reporting */
double pkt_delta; /* time delta between packets in ms */
double jitter; /* current jitter measurement in ms */
unsigned long long njitter; /* number of jitter measurements */
double jitter_min; /* jitter minimum */
double jitter_max; /* jitter maximum */
double jitter_avg; /* jitter average */
double jitteri; /* current jitter interval measurement in ms */
unsigned long long njitteri; /* number of jitter interval measurements */
double jitter_mini; /* jitter minimum for interval report */
double jitter_maxi; /* jitter maximum for interval report */
double jitter_avgi; /* jitter average for interval report */
double owd; /* current one-way delay measurement in ms */
unsigned long long nowd; /* number of one-way delay measurements */
double owd_min; /* one-way delay minimum */
double owd_max; /* one-way delay maximum */
double owd_avg; /* one-way delay average */
unsigned long long nowdi; /* number of OWD interval measurements */
double owd_mini; /* OWD minimum for interval report */
double owd_maxi; /* OWD maximum for interval report */
double owd_avgi; /* OWD average for interval report */
void
close_data_channels()
{
if (fd[1] == -1) return;
if (clientserver && client && !host3 && udp && trans) {
/* If all the EOD packets get lost at the end of a UDP
* transfer, having the client do a shutdown() for writing
* on the control connection allows the server to more
* quickly realize that the UDP transfer has completed
* (mostly of benefit for separate control and data paths)
*
* Can't do this in the opposite direction since the
* server needs to send info back to client */
shutdown(0, SHUT_WR);
}
if (multicast && !trans) {
/* Leave the multicast group */
if ((af == AF_INET) && !ssm) {
if (setsockopt(fd[1], IPPROTO_IP, IP_DROP_MEMBERSHIP,
(void *)&mc_group,
sizeof(mc_group)) < 0) {
err("setsockopt: IP_DROP_MEMBERSHIP");
}
}
#ifdef AF_INET6
else if ((af == AF_INET6) && !ssm) {
if (setsockopt(fd[1], IPPROTO_IPV6, IPV6_LEAVE_GROUP,
(void *)&mc6_group,
sizeof(mc6_group)) < 0) {
err("setsockopt: IPV6_LEAVE_GROUP");
}
}
#endif
#ifdef MCAST_JOIN_SOURCE_GROUP
else if ((af == AF_INET) && ssm) {
/* Leave the source specific multicast group */
if (setsockopt(fd[1], IPPROTO_IP,
MCAST_LEAVE_SOURCE_GROUP,
&group_source_req,
sizeof(group_source_req)) < 0) {
err("setsockopt: MCAST_LEAVE_SOURCE_GROUP");
}
}
#ifdef AF_INET6
else if ((af == AF_INET6) && ssm) {
/* Leave the source specific multicast group */
if (setsockopt(fd[1], IPPROTO_IPV6,
MCAST_LEAVE_SOURCE_GROUP,
&group_source_req,
sizeof(group_source_req)) < 0) {
err("setsockopt: MCAST_LEAVE_SOURCE_GROUP");
}
}
#endif /* AF_INET6 */
#endif /* MCAST_JOIN_SOURCE_GROUP */
}
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
close(fd[stream_idx]);
fd[stream_idx] = -1;
}
}
#ifdef SIGPIPE
void
sigpipe( int signum )
{
signal(SIGPIPE, sigpipe);
}
#endif
void
sigint( int signum )
{
signal(SIGINT, SIG_DFL);
fputs("\n*** transfer interrupted ***\n", stdout);
if (clientserver && client && !host3 && udp && !trans)
shutdown(0, SHUT_WR);
else
intr = 1;
done++;
return;
}
void
ignore_alarm( int signum )
{
return;
}
void
sigalarm( int signum )
{
struct timeval timec; /* Current time */
struct timeval timed; /* Delta time */
int64_t nrbytes;
uint64_t deltarbytes, deltatbytes;
double fractloss;
int nodata;
int i;
char *cp1, *cp2;
short save_events;
long flags, saveflags;
if (host3 && clientserver) {
if (client)
intr = 1;
return;
}
if (clientserver && client && reading_srvr_info) {
mes("Error: not receiving server info");
exit(1);
}
#ifdef HAVE_CLOCK_GETTIME
timec.tv_sec = 0; /* silence bogus compiler warning */
timec.tv_usec = 0; /* silence bogus compiler warning */
#endif
if (interval && !trans) {
/* Get real time */
get_timeofday(&timec, (struct timezone *)0);
tvsub( &timed, &timec, &timep );
realtd = timed.tv_sec + ((double)timed.tv_usec) / 1000000;
if (realtd <= 0.0) realtd = 0.000001;
tvsub( &timed, &timec, &time0 );
realt = timed.tv_sec + ((double)timed.tv_usec)
/ 1000000;
if (realt <= 0.0) realt = 0.000001;
}
if (clientserver && !trans) {
struct sockaddr_in peer;
socklen_t peerlen = sizeof(peer);
nodata = 0;
if (getpeername(fd[0], (struct sockaddr *)&peer, &peerlen) < 0)
nodata = 1;
if (!client && udp && got_begin) {
/* checks if client did a shutdown() for writing
* on the control connection */
pollfds[0].fd = fileno(ctlconn);
save_events = pollfds[0].events;
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0) > 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI))) {
nodata = 1;
}
pollfds[0].events = save_events;
}
if (interval) {
chk_interval += realtd;
if (chk_interval >= chk_idle_data) {
chk_interval = 0;
if ((nbytes - chk_nbytes) == 0)
nodata = 1;
chk_nbytes = nbytes;
}
}
else {
if ((nbytes - chk_nbytes) == 0)
nodata = 1;
chk_nbytes = nbytes;
}
if (nodata) {
/* Don't just exit anymore so can get partial results
* (shouldn't be a problem but keep an eye out that
* servers don't start hanging again) */
if (!client && udp && !interval && handle_urg) {
/* send 'A' for ABORT as urgent TCP data
* on control connection (don't block)
*
* Only server can do this since client
* does a shutdown() for writing on the
* control connection */
saveflags = fcntl(fd[0], F_GETFL, 0);
if (saveflags != -1) {
flags = saveflags | O_NONBLOCK;
fcntl(fd[0], F_SETFL, flags);
}
send(fd[0], "A", 1, MSG_OOB);
if (saveflags != -1) {
flags = saveflags;
fcntl(fd[0], F_SETFL, flags);
}
}
if (client) {
mes("Error: not receiving data from server");
exit(1);
}
close_data_channels();
intr = 1;
return;
}
if (!interval)
return;
}
if (interval && !trans) {
if ((udp && !got_begin) || done) {
timep.tv_sec = timec.tv_sec;
timep.tv_usec = timec.tv_usec;
return;
}
if (clientserver) {
nrbytes = nbytes;
if (udplossinfo) {
ntbytes = *(int64_t *)(buf + 24);
if (need_swap) {
cp1 = (char *)&ntbytes;
cp2 = buf + 31;
for ( i = 0; i < 8; i++ )
*cp1++ = *cp2--;
}
if (ntbytes > ntbytesc)
/* received bytes not counted yet */
nrbytes += buflen;
if ((nrbytes > ntbytes) ||
((nrbytes - pbytes) > (ntbytes - ptbytes)))
/* yes they were counted */
nrbytes -= buflen;
}
if (read_retrans) {
nretrans[1] = *(uint32_t *)(buf + 24);
if (need_swap) {
cp1 = (char *)&nretrans[1];
cp2 = buf + 27;
for ( i = 0; i < 4; i++ )
*cp1++ = *cp2--;
}
}
if (read_cwnd) {
cwnd[1] = *(uint32_t *)(buf + 28);
if (need_swap) {
cp1 = (char *)&cwnd[1];
cp2 = buf + 31;
for ( i = 0; i < 4; i++ )
*cp1++ = *cp2--;
}
if ((cwnd[1] == 0x5254524Eu) || /* "RTRN" */
(cwnd[1] == 0x48525452u)) /* "HRTR" */
cwnd[1] = init_pkt_cwnd;
}
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_INTERVAL);
else
strcpy(fmt, PERF_FMT_INTERVAL);
fprintf(stdout, fmt,
(double)(nrbytes - pbytes)/(1024*1024), realtd,
(double)(nrbytes - pbytes)/realtd/125000);
if (udplossinfo) {
if (!(format & NODROPS)) {
if (format & PARSE)
strcpy(fmt,
P_DROP_FMT_INTERVAL);
else
strcpy(fmt, DROP_FMT_INTERVAL);
fprintf(stdout, fmt,
((ntbytes - ptbytes)
- (nrbytes - pbytes))
/buflen,
(ntbytes - ptbytes)/buflen);
}
if (!(format & NOPERCENTLOSS)) {
deltarbytes = nrbytes - pbytes;
deltatbytes = ntbytes - ptbytes;
fractloss = (deltatbytes ?
1.0 -
(double)deltarbytes
/(double)deltatbytes :
0.0);
if (format & PARSE)
strcpy(fmt,
P_LOSS_FMT_INTERVAL);
else if ((fractloss != 0.0) &&
(fractloss < 0.001))
strcpy(fmt,
LOSS_FMT_INTERVAL5);
else
strcpy(fmt, LOSS_FMT_INTERVAL);
fprintf(stdout, fmt, fractloss * 100);
}
}
if ((do_jitter & JITTER_MIN) && njitteri) {
if (format & PARSE)
strcpy(fmt, P_JITTER_MIN_FMT_INTERVAL);
else
strcpy(fmt, JITTER_MIN_FMT_INTERVAL);
fprintf(stdout, fmt, jitter_mini);
}
if ((do_jitter & JITTER_AVG) && njitteri) {
if (format & PARSE)
strcpy(fmt, P_JITTER_AVG_FMT_INTERVAL);
else
strcpy(fmt, JITTER_AVG_FMT_INTERVAL);
fprintf(stdout, fmt, jitter_avgi/njitteri);
}
if ((do_jitter & JITTER_MAX) && njitteri) {
if (format & PARSE)
strcpy(fmt, P_JITTER_MAX_FMT_INTERVAL);
else
strcpy(fmt, JITTER_MAX_FMT_INTERVAL);
fprintf(stdout, fmt, jitter_maxi);
}
if (do_jitter && njitteri) {
njitteri = 0;
jitter_mini = 1000000.0;
jitter_maxi = -1000000.0;
jitter_avgi = 0.0;
}
if (read_retrans && sinkmode) {
if (format & PARSE)
fprintf(stdout, P_RETRANS_FMT_INTERVAL,
((retransinfo == 1) ||
!nrbytes) ? "" : "host-",
(nretrans[1] - pretrans));
else
fprintf(stdout, RETRANS_FMT_INTERVAL,
(nretrans[1] - pretrans),
((retransinfo == 1) ||
!nrbytes) ? "" : "host-");
}
if (read_cwnd && sinkmode) {
if (format & PARSE)
fprintf(stdout, P_CWND_FMT_INTERVAL,
cwnd[1]);
else
fprintf(stdout, CWND_FMT_INTERVAL,
cwnd[1]);
}
if ((do_owd & OWD_MIN) && nowdi) {
if (format & PARSE)
strcpy(fmt, P_OWD_MIN_FMT_INTERVAL);
else
strcpy(fmt, OWD_MIN_FMT_INTERVAL);
fprintf(stdout, fmt, owd_mini);
}
if ((do_owd & OWD_AVG) && nowdi) {
if (format & PARSE)
strcpy(fmt, P_OWD_AVG_FMT_INTERVAL);
else
strcpy(fmt, OWD_AVG_FMT_INTERVAL);
fprintf(stdout, fmt, owd_avgi/nowdi);
}
if ((do_owd & OWD_MAX) && nowdi) {
if (format & PARSE)
strcpy(fmt, P_OWD_MAX_FMT_INTERVAL);
else
strcpy(fmt, OWD_MAX_FMT_INTERVAL);
fprintf(stdout, fmt, owd_maxi);
}
if (do_owd && nowdi) {
nowdi = 0;
owd_mini = 1000000.0;
owd_maxi = -1000000.0;
owd_avgi = 0.0;
}
if (format & RUNNINGTOTAL) {
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_INTERVAL2);
else
strcpy(fmt, PERF_FMT_INTERVAL2);
fprintf(stdout, fmt,
(double)nrbytes/(1024*1024), realt,
(double)nrbytes/realt/125000);
if (udplossinfo) {
if (!(format & NODROPS)) {
if (format & PARSE)
strcpy(fmt,
P_DROP_FMT_INTERVAL);
else
strcpy(fmt,
DROP_FMT_INTERVAL);
fprintf(stdout, fmt,
(ntbytes - nrbytes)
/buflen,
ntbytes/buflen);
}
if (!(format & NOPERCENTLOSS)) {
fractloss = (ntbytes ?
1.0 -
(double)nrbytes
/(double)ntbytes :
0.0);
if (format & PARSE)
strcpy(fmt,
P_LOSS_FMT_INTERVAL);
else if ((fractloss != 0.0) &&
(fractloss < 0.001))
strcpy(fmt,
LOSS_FMT_INTERVAL5);
else
strcpy(fmt,
LOSS_FMT_INTERVAL);
fprintf(stdout, fmt,
fractloss * 100);
}
}
if (read_retrans && sinkmode) {
if (format & PARSE)
fprintf(stdout,
P_RETRANS_FMT_INTERVAL,
((retransinfo == 1) ||
!nrbytes) ?
"" : "host-",
nretrans[1]);
else
fprintf(stdout,
RETRANS_FMT_INTERVAL,
nretrans[1],
((retransinfo == 1) ||
!nrbytes) ?
"" : "host-");
}
if (read_cwnd && sinkmode) {
if (format & PARSE)
fprintf(stdout,
P_CWND_FMT_INTERVAL,
cwnd[1]);
else
fprintf(stdout,
CWND_FMT_INTERVAL,
cwnd[1]);
}
}
if (udplossinfo && (format & XMITSTATS)) {
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_INTERVAL3);
else
strcpy(fmt, PERF_FMT_INTERVAL3);
fprintf(stdout, fmt,
(double)(ntbytes - ptbytes)/1024/1024);
if (format & RUNNINGTOTAL) {
if (format & PARSE)
strcpy(fmt,
P_PERF_FMT_INTERVAL4);
else
strcpy(fmt, PERF_FMT_INTERVAL4);
fprintf(stdout, fmt,
(double)ntbytes/1024/1024);
if (format & DEBUGINTERVAL)
fprintf(stdout, " Pre: %.4f MB",
(double)ntbytesc
/1024/1024);
}
}
fprintf(stdout, "\n");
fflush(stdout);
timep.tv_sec = timec.tv_sec;
timep.tv_usec = timec.tv_usec;
pbytes = nrbytes;
ptbytes = ntbytes;
pretrans = nretrans[1];
}
}
else
intr = 1;
return;
}
int
main( int argc, char **argv )
{
double MB;
double rate_opt;
double fractloss;
int cpu_util;
int first_read;
int first_jitter, first_jitteri;
int ocorrection = 0;
double correction = 0.0;
int pollst = 0;
int i = 0, j = 0;
char *cp1 = NULL, *cp2 = NULL, *cp3 = NULL;
char *hostaddr;
char ch = '\0';
int error_num = 0;
int sockopterr = 0;
int save_errno;
struct servent *sp = 0;
struct addrinfo hints, *res[MAXSTREAM + 1] = { NULL },
*host3res, *mcres = NULL;
union sockaddr_union client_ipaddr;
struct sockaddr_storage dummy;
struct timeval time_eod = {0}; /* time EOD packet was received */
struct timeval time_eod0 = {0}; /* time EOD0 packet was received */
struct timeval timed; /* time delta */
struct timeval timeconn1 = {0}; /* time before connect() for RTT */
struct timeval timeconn2 = {0}; /* time after connect() for RTT */
struct timeval timeconn; /* time to connect() == RTT */
union {
unsigned char buf[sizeof(struct in_addr)];
uint32_t ip32;
} ipad_stride; /* IPv4 address stride */
short save_events;
int skiparg;
int reqval;
int got_srvr_retrans;
int got_srvr_cwnd;
uint32_t total_retrans = 0; /* total retrans for all streams */
uint32_t total_snd_cwnd = 0; /* total cwnd for all streams in KB */
double idle_data_min = IDLE_DATA_MIN;
double idle_data_max = IDLE_DATA_MAX;
double default_idle_data = DEFAULT_IDLE_DATA;
char multsrc[ADDRSTRLEN] = "\0";
char multaddr[ADDRSTRLEN] = "\0";
long flags;
int nameinfo_flags;
int implicit_hostaddr;
sendwin = 0;
rcvwin = 0;
srvrwin = -1;
format |= WANTRTT;
if (argc < 2) goto usage;
nut_cmd = argv[0];
argv++; argc--;
while (argc>0 && argv[0][0] == '-') {
skiparg = 0;
switch (argv[0][1]) {
case '4':
domain = PF_INET;
af = AF_INET;
explicitaf = 1;
break;
#ifdef AF_INET6
case '6':
domain = PF_INET6;
af = AF_INET6;
explicitaf = 1;
break;
#endif
case 'B':
b_flag = 1;
break;
case 't':
trans = 1;
break;
case 'r':
trans = 0;
break;
case 'd':
options |= SO_DEBUG;
break;
case 'D':
nodelay = 1;
break;
case 'n':
reqval = 0;
if (argv[0][2] == 'b') {
fprintf(stderr, "option \"-nb\" no longer supported, use \"-n###[k|m|g|t|p]\" instead\n");
fflush(stderr);
exit(1);
}
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
nbuf = strtoull(cp1, NULL, 0);
if (nbuf == 0) {
if (errno == EINVAL) {
fprintf(stderr, "invalid nbuf = %s\n",
&argv[0][2]);
fflush(stderr);
exit(1);
}
else {
nbuf = DEFAULT_NBUF;
break;
}
}
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'b') || (ch == 'B'))
nbuf_bytes = 1;
else if ((ch == 'k') || (ch == 'K')) {
nbuf *= 1024;
nbuf_bytes = 1;
}
else if ((ch == 'm') || (ch == 'M')) {
nbuf *= 1048576;
nbuf_bytes = 1;
}
else if ((ch == 'g') || (ch == 'G')) {
nbuf *= 1073741824;
nbuf_bytes = 1;
}
else if ((ch == 't') || (ch == 'T')) {
nbuf *= 1099511627776ull;
nbuf_bytes = 1;
}
else if ((ch == 'p') || (ch == 'P')) {
nbuf *= 1125899906842624ull;
nbuf_bytes = 1;
}
break;
case 'l':
reqval = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
buflen = atoi(cp1);
buflenopt = 1;
if (buflen < 1) {
fprintf(stderr, "invalid buflen = %d\n", buflen);
fflush(stderr);
exit(1);
}
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'k') || (ch == 'K'))
buflen *= 1024;
else if ((ch == 'm') || (ch == 'M'))
buflen *= 1048576;
break;
case 'w':
reqval = 1;
if (argv[0][2] == 's') {
cp1 = getoptvalp(argv, 3, reqval, &skiparg);
srvrwin = atoi(cp1);
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'k') || (ch == 'K'))
srvrwin *= 1024;
else if ((ch == 'm') || (ch == 'M'))
srvrwin *= 1048576;
else if ((ch == 'g') || (ch == 'G'))
srvrwin *= 1073741824;
else if ((ch != 'b') && (ch != 'B'))
srvrwin *= 1024;
if (srvrwin < 0) {
fprintf(stderr, "invalid srvrwin = %d\n", srvrwin);
fflush(stderr);
exit(1);
}
}
else {
if (argv[0][2] == 'b') {
braindead = 1;
cp1 = getoptvalp(argv, 3, reqval,
&skiparg);
if (*cp1 == '\0')
break;
sendwin = atoi(cp1);
}
else {
cp1 = getoptvalp(argv, 2, reqval,
&skiparg);
sendwin = atoi(cp1);
}
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'k') || (ch == 'K'))
sendwin *= 1024;
else if ((ch == 'm') || (ch == 'M'))
sendwin *= 1048576;
else if ((ch == 'g') || (ch == 'G'))
sendwin *= 1073741824;
else if ((ch != 'b') && (ch != 'B'))
sendwin *= 1024;
rcvwin = sendwin;
if (sendwin < 0) {
fprintf(stderr, "invalid sendwin = %d\n", sendwin);
fflush(stderr);
exit(1);
}
}
if (srvrwin == -1) {
srvrwin = sendwin;
}
break;
case 's':
sinkmode = 0; /* sink/source data */
#if defined(linux)
if (strchr(argv[0], 'z'))
zerocopy = 1;
if (strchr(argv[0], 'd'))
directio = 1;
#endif
break;
case 'p':
reqval = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if ((cp2 = strchr(cp1, ':'))) {
tmpport = atoi(cp1);
if ((tmpport < 1024) || (tmpport > 65535)) {
fprintf(stderr,
"invalid source port = %d\n",
tmpport);
fflush(stderr);
exit(1);
}
srcport = tmpport;
cp1 = cp2 + 1;
}
tmpport = atoi(cp1);
if ((tmpport < 1024) || (tmpport > 65535)) {
fprintf(stderr, "invalid port = %d\n", tmpport);
fflush(stderr);
exit(1);
}
port = tmpport;
break;
case 'P':
reqval = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if ((cp2 = strchr(cp1, ':'))) {
tmpport = atoi(cp1);
if ((tmpport < 1024) || (tmpport > 65535)) {
fprintf(stderr,
"invalid source "
"control port = %d\n", tmpport);
fflush(stderr);
exit(1);
}
srcctlport = tmpport;
cp1 = cp2 + 1;
}
tmpport = atoi(cp1);
if ((tmpport < 1024) || (tmpport > 65535)) {
fprintf(stderr,
"invalid ctlport = %d\n", tmpport);
fflush(stderr);
exit(1);
}
ctlport = tmpport;
if ((cp2 = strchr(argv[0], '/'))) {
if (strchr(cp2, ':')) {
fprintf(stderr,
"can't specify source control "
"port with third party\n");
fflush(stderr);
exit(1);
}
tmpport = atoi(cp2 + 1);
if ((tmpport < 1024) || (tmpport > 65535)) {
fprintf(stderr,
"invalid third party "
"ctlport = %d\n", tmpport);
fflush(stderr);
exit(1);
}
ctlport3 = tmpport;
}
break;
case 'u':
udp = 1;
if (!buflenopt) buflen = DEFAULTUDPBUFLEN;
if (argv[0][2] == 'u') {
haverateopt = 1;
rate = MAXRATE;
}
break;
case 'j':
reqval = 0;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if (strchr(cp1, 'm'))
do_jitter |= JITTER_MIN;
if (strchr(cp1, 'a'))
do_jitter |= JITTER_AVG;
if (strchr(cp1, 'x'))
do_jitter |= JITTER_MAX;
if (do_jitter == 0)
do_jitter = JITTER_MAX;
if (strchr(cp1, 'o'))
do_jitter |= JITTER_IGNORE_OOO;
udp = 1;
if (!buflenopt) buflen = DEFAULTUDPBUFLEN;
break;
case 'o':
reqval = 0;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if (strchr(cp1, 'm'))
do_owd |= OWD_MIN;
if (strchr(cp1, 'a'))
do_owd |= OWD_AVG;
if (strchr(cp1, 'x'))
do_owd |= OWD_MAX;
if (do_owd == 0)
do_owd = OWD_AVG;
break;
case 'v':
brief = 0;
if (argv[0][2] == 'v')
verbose = 1;
break;
case 'N':
reqval = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
nstream = atoi(cp1);
if (strchr(cp1, 'm'))
multilink = 1;
if (nstream < 1) {
fprintf(stderr, "invalid nstream = %d\n", nstream);
fflush(stderr);
exit(1);
}
if (nstream > MAXSTREAM) {
fprintf(stderr, "nstream = %d > MAXSTREAM, set to %d\n",
nstream, MAXSTREAM);
nstream = MAXSTREAM;
}
if (nstream > 1) {
b_flag = 1;
send_retrans = 0;
read_retrans = 0;
send_cwnd = 0;
read_cwnd = 0;
}
break;
case 'R':
reqval = 1;
haverateopt = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if (*cp1 == 'i') {
cp1++;
if (*cp1 == 's') {
cp1++;
#if defined(linux)
iratesss = 1;
#else
fprintf(stderr, "smoothed slow start not supported for non-Linux\n");
fflush(stderr);
#endif
}
sscanf(cp1, "%lf", &rate_opt);
irate = 1;
}
else if (*cp1 == 'a') {
cp1++;
sscanf(cp1, "%lf", &rate_opt);
irate = 0;
}
else if (*cp1 == 'u') {
cp1++;
rate_opt = 0.0;
irate = 0;
}
else {
sscanf(cp1, "%lf", &rate_opt);
}
if ((cp2 = strchr(cp1, '/'))) {
*cp2++ = '\0';
maxburst = atoi(cp2);
if (maxburst <= 0) {
fprintf(stderr,
"invalid maxburst = %d\n",
maxburst);
fflush(stderr);
exit(1);
}
}
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'm') || (ch == 'M'))
rate_opt *= 1000;
else if ((ch == 'g') || (ch == 'G'))
rate_opt *= 1000000;
else if (ch == 'p') {
rate_pps = 1;
if (strlen(cp1) >= 2) {
ch = *(cp1 + strlen(cp1) - 2);
if ((ch == 'k') || (ch == 'K'))
rate_opt *= 1000;
if ((ch == 'm') || (ch == 'M'))
rate_opt *= 1000000;
}
}
rate = rate_opt;
if (rate == 0)
rate = MAXRATE;
break;
case 'T':
reqval = 0;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
sscanf(cp1, "%lf", &timeout);
if (timeout < 0) {
fprintf(stderr, "invalid timeout = %f\n", timeout);
fflush(stderr);
exit(1);
}
else if (timeout == 0.0)
timeout = DEFAULT_TIMEOUT;
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'm') || (ch == 'M'))
timeout *= 60.0;
else if ((ch == 'h') || (ch == 'H'))
timeout *= 3600.0;
else if ((ch == 'd') || (ch == 'D'))
timeout *= 86400.0;
itimer.it_value.tv_sec = timeout;
itimer.it_value.tv_usec =
(timeout - itimer.it_value.tv_sec)*1000000;
if (timeout && !nbuf)
nbuf = INT_MAX;
break;
case 'i':
reqval = 0;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
sscanf(cp1, "%lf", &interval);
if (interval < 0.0) {
fprintf(stderr, "invalid interval = %f\n", interval);
fflush(stderr);
exit(1);
}
else if (interval == 0.0)
interval = 1.0;
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'm') || (ch == 'M'))
interval *= 60.0;
else if ((ch == 'h') || (ch == 'H'))
interval *= 3600.0;
break;
case 'I':
reqval = 1;
ident[0] = '-';
strncpy(&ident[1],
getoptvalp(argv, 2, reqval, &skiparg), 40);
ident[41] = '\0';
break;
case 'F':
reverse = 1;
break;
case 'b':
reqval = 0;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
if (*cp1) {
if (isalpha((int)(*cp1)))
brief = 1;
else
brief = atoi(cp1);
if (strchr(cp1, 'r'))
brief |= BRIEF_RETRANS_STREAMS;
if (strchr(cp1, 'c')) {
#if defined(linux)
brief |= BRIEF_CWND_STREAMS;
#else
fprintf(stderr, "\"-bc\" option not supported for non-Linux\n");
fflush(stderr);
#endif
}
}
else
brief = 1;
break;
case 'S':
if (strchr(&argv[0][2], 'P'))
pass_ctlport = 1;
trans = 0;
clientserver = 1;
brief = 0;
verbose = 1;
break;
case '1':
oneshot = 1;
trans = 0;
clientserver = 1;
brief = 0;
verbose = 1;
break;
case 'V':
fprintf(stdout, "nuttcp-%d.%d.%d%s\n", vers_major,
vers_minor, vers_delta,
beta ? BETA_STR : "");
exit(0);
case 'f':
if (strcmp(&argv[0][2], "xmitstats") == 0)
format |= XMITSTATS;
else if (strcmp(&argv[0][2], "debuginterval") == 0)
format |= DEBUGINTERVAL;
else if (strcmp(&argv[0][2], "runningtotal") == 0)
format |= RUNNINGTOTAL;
else if (strcmp(&argv[0][2], "-percentloss") == 0)
format |= NOPERCENTLOSS;
else if (strcmp(&argv[0][2], "-drops") == 0)
format |= NODROPS;
else if (strcmp(&argv[0][2], "-retrans") == 0) {
format |= NORETRANS;
format |= NOCWND;
}
else if (strcmp(&argv[0][2], "debugretrans") == 0)
format |= DEBUGRETRANS;
else if (strcmp(&argv[0][2], "-cwnd") == 0)
format |= NOCWND;
else if (strcmp(&argv[0][2], "debugpoll") == 0)
format |= DEBUGPOLL;
else if (strcmp(&argv[0][2], "debugmtu") == 0)
format |= DEBUGMTU;
else if (strcmp(&argv[0][2], "debugjitter") == 0)
format |= DEBUGJITTER;
#if defined(linux)
else if (strcmp(&argv[0][2], "debugirate") == 0)
format |= DEBUGIRATE;
#endif
else if (strcmp(&argv[0][2], "parse") == 0)
format |= PARSE;
else if (strcmp(&argv[0][2], "-beta") == 0)
format |= NOBETAMSG;
/* below is for compatibility with 6.0.x beta */
else if (strcmp(&argv[0][2], "rtt") == 0)
format |= WANTRTT;
else if (strcmp(&argv[0][2], "-rtt") == 0)
format &= ~WANTRTT;
else {
if (argv[0][2]) {
fprintf(stderr, "invalid format option \"%s\"\n", &argv[0][2]);
fflush(stderr);
exit(1);
}
else {
fprintf(stderr, "invalid null format option\n");
fprintf(stderr, "perhaps the \"-F\" flip option was intended\n");
fflush(stderr);
exit(1);
}
}
break;
case 'x':
reqval = 1;
if (argv[0][2] == 't') {
traceroute = 1;
brief = 1;
}
#ifdef HAVE_SETPRIO
else if (argv[0][2] == 'P') {
priority = atoi(getoptvalp(argv, 3, reqval,
&skiparg));
}
#endif
#ifdef HAVE_SETAFFINITY
else if (argv[0][2] == 'c') {
reqval = 1;
if (argv[0][3] == 's') {
cp1 = getoptvalp(argv, 4, reqval,
&skiparg);
srvr_affinity = atoi(cp1);
if (srvr_affinity < 0) {
fprintf(stderr,
"invalid srvr_affinity "
"= %d\n",
srvr_affinity);
fflush(stderr);
exit(1);
}
}
else {
cp1 = getoptvalp(argv, 3, reqval,
&skiparg);
affinity = atoi(cp1);
if ((affinity < 0) ||
(affinity >= CPU_SETSIZE)) {
fprintf(stderr,
"invalid affinity "
"= %d\n", affinity);
fflush(stderr);
exit(1);
}
if ((cp2 = strchr(cp1, '/'))) {
srvr_affinity = atoi(cp2 + 1);
if (srvr_affinity < 0) {
fprintf(stderr,
"invalid "
"srvr_affinity "
"= %d\n",
srvr_affinity);
fflush(stderr);
exit(1);
}
}
}
}
#endif
else {
if (argv[0][2]) {
fprintf(stderr, "invalid x option \"%s\"\n", &argv[0][2]);
fflush(stderr);
exit(1);
}
else {
fprintf(stderr, "invalid null x option\n");
fflush(stderr);
exit(1);
}
}
break;
case '3':
thirdparty = 1;
break;
case 'm':
reqval = 0;
if (argv[0][2] == 'a') {
ssm = 0;
cp1 = getoptvalp(argv, 3, reqval, &skiparg);
}
else if (argv[0][2] == 's') {
#ifdef MCAST_JOIN_SOURCE_GROUP
ssm = 1;
cp1 = getoptvalp(argv, 3, reqval, &skiparg);
#else
fprintf(stderr,
"This system does not support SSM\n");
fflush(stderr);
exit(1);
#endif
}
else {
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
}
if (*cp1)
mc_param = atoi(cp1);
else
mc_param = 1;
if ((mc_param < 1) || (mc_param > 255)) {
fprintf(stderr, "invalid multicast ttl = %d\n", mc_param);
fflush(stderr);
exit(1);
}
multicast = mc_param;
break;
case 'g':
reqval = 1;
mc_addr = getoptvalp(argv, 2, reqval, &skiparg);
break;
case 'M':
reqval = 1;
datamss = atoi(getoptvalp(argv, 2, reqval, &skiparg));
if (datamss < 0) {
fprintf(stderr, "invalid datamss = %d\n", datamss);
fflush(stderr);
exit(1);
}
break;
case 'c':
reqval = 1;
cp1 = getoptvalp(argv, 2, reqval, &skiparg);
tos = strtol(cp1, NULL, 0);
if (*cp1)
ch = *(cp1 + strlen(cp1) - 1);
else
ch = '\0';
if ((ch == 'p') || (ch == 'P')) {
/* Precedence */
if (tos > 7) {
fprintf(stderr, "invalid precedence = %d\n", tos);
fflush(stderr);
exit(1);
}
tos <<= 5;
}
else if ((ch != 't') && (ch != 'T')) {
/* DSCP */
if (tos > 63) {
fprintf(stderr, "invalid dscp = %d\n", tos);
fflush(stderr);
exit(1);
}
tos <<= 2;
}
if (tos > 255) {
fprintf(stderr, "invalid tos = %d\n", tos);
fflush(stderr);
exit(1);
}
break;
case 'a':
retry_server = 1;
break;
case '-':
if (strcmp(&argv[0][2], "nofork") == 0) {
nofork=1;
}
else if (strcmp(&argv[0][2], "no3rdparty") == 0) {
no3rd=1;
}
else if (strcmp(&argv[0][2],
"idle-data-timeout") == 0) {
if ((cp1 = strchr(argv[1], '/'))) {
if (strchr(cp1 + 1, '/')) {
if (sscanf(argv[1],
"%lf/%lf/%lf",
&idle_data_min,
&default_idle_data,
&idle_data_max) != 3) {
fprintf(stderr, "error scanning idle-data-timeout parameter = %s\n", argv[1]);
fflush(stderr);
exit(1);
}
if (idle_data_min <= 0.0) {
fprintf(stderr, "invalid value for idle-data-timeout minimum = %f\n", idle_data_min);
fflush(stderr);
exit(1);
}
if (default_idle_data <= 0.0) {
fprintf(stderr, "invalid value for idle-data-timeout default = %f\n", default_idle_data);
fflush(stderr);
exit(1);
}
if (idle_data_max <= 0.0) {
fprintf(stderr, "invalid value for idle-data-timeout maximum = %f\n", idle_data_max);
fflush(stderr);
exit(1);
}
if (idle_data_max <
idle_data_min) {
fprintf(stderr, "error: idle-data-timeout maximum of %f < minimum of %f\n", idle_data_max, idle_data_min);
fflush(stderr);
exit(1);
}
}
else {
fprintf(stderr, "invalid idle-data-timeout parameter = %s\n", argv[1]);
fflush(stderr);
exit(1);
}
}
else {
sscanf(argv[1], "%lf", &idle_data_min);
if (idle_data_min <= 0.0) {
fprintf(stderr, "invalid value for idle-data-timeout = %f\n", idle_data_min);
fflush(stderr);
exit(1);
}
idle_data_max = idle_data_min;
default_idle_data = idle_data_min;
}
argv++;
argc--;
}
else if (strcmp(&argv[0][2], "single-threaded") == 0) {
single_threaded=1;
}
else if (strcmp(&argv[0][2], "packet-burst") == 0) {
maxburst = atoi(argv[1]);
if (maxburst <= 0) {
fprintf(stderr,
"invalid maxburst = %d\n",
maxburst);
fflush(stderr);
exit(1);
}
argv++;
argc--;
}
#ifdef IPV6_V6ONLY
else if (strcmp(&argv[0][2], "disable-v4-mapped") == 0) {
v4mapped=0;
}
else if (strcmp(&argv[0][2], "enable-v4-mapped") == 0) {
v4mapped=1;
}
#endif
else {
goto usage;
}
break;
case 'h':
default:
goto usage;
}
argv++;
argc--;
if (skiparg) {
argv++;
argc--;
}
}
if (argc > 2) goto usage;
if (trans && (argc < 1)) goto usage;
if (clientserver && (argc != 0)) goto usage;
if (!clientserver && !trans && (argc < 1)) {
fprintf(stderr,
"nuttcp: Warning: Using obsolete \"classic\" mode:\n");
fprintf(stderr,
" Automatically switching to "
"oneshot server mode "
"(\"nuttcp -1\")\n");
oneshot = 1;
trans = 0;
clientserver = 1;
brief = 0;
verbose = 1;
}
host3 = NULL;
if (argc == 2) {
host3 = argv[1];
if (strlen(host3) > HOSTNAMELEN) {
fprintf(stderr, "3rd party host '%s' too long\n", host3);
fflush(stderr);
exit(1);
}
cp1 = host3;
while (*cp1) {
if (!isalnum((int)(*cp1)) && (*cp1 != '-') && (*cp1 != '.')
&& (*cp1 != ':') && (*cp1 != '/')
&& (*cp1 != '+') && (*cp1 != '=')) {
fprintf(stderr, "invalid 3rd party host '%s'\n", host3);
fflush(stderr);
exit(1);
}
cp1++;
}
}
if (multicast) {
udp = 1;
if (!buflenopt) buflen = DEFAULT_MC_UDPBUFLEN;
nstream = 1;
}
if (mc_addr && !multicast) {
fprintf(stderr, "can't use \"-g\" option for non-multicast\n");
fflush(stderr);
exit(1);
}
if (mc_addr && !*mc_addr) {
fprintf(stderr, "no multicast IP address specified for "
"\"-g\" option\n");
fflush(stderr);
exit(1);
}
#ifdef AF_INET6
if (!inet_pton(AF_INET6, HI_MC6, &hi_mc6)) {
err("inet_pton");
}
if (!inet_pton(AF_INET6, HI_MC6_ASM, &hi_mc6_asm)) {
err("inet_pton");
}
#endif
if (udp && !haverateopt)
rate = DEFAULT_UDP_RATE;
bzero((char *)&frominet, sizeof(frominet));
bzero((char *)&clientaddr, sizeof(clientaddr));
#ifdef AF_INET6
bzero((char *)&clientaddr6, sizeof(clientaddr6));
clientscope6 = 0;
#endif
if (!nbuf) {
if (timeout == 0.0) {
if (sinkmode) {
timeout = DEFAULT_TIMEOUT;
itimer.it_value.tv_sec = timeout;
itimer.it_value.tv_usec =
(timeout - itimer.it_value.tv_sec)
*1000000;
}
nbuf = INT_MAX;
}
}
if (srvrwin == -1) {
srvrwin = sendwin;
}
if ((argc == 0) && !explicitaf) {
domain = PF_INET;
af = AF_INET;
}
if (multilink) {
if (nstream == 1) {
fprintf(stderr, "Warning: multilink mode not meaningful for a single stream\n");
fflush(stderr);
}
}
if (argc >= 1) {
host = argv[0];
if ((cp1 = strchr(host, '+'))) {
*cp1++ = '\0';
if (*cp1)
stride = cp1;
}
if (multilink) {
if (stride) {
fprintf(stderr, "don't use both multilink and address stride\n");
fflush(stderr);
exit(1);
}
if ((cp1 = strchr(host, '/')) && strchr(cp1 + 1, '/')) {
fprintf(stderr, "multilink mode not compatible with multiple hosts %s\n", host);
fflush(stderr);
exit(1);
}
}
hostaddr = NULL;
implicit_hostaddr = 0;
if ((cp1 = strchr(host, '='))) {
*cp1++ = '\0';
if (strchr(cp1, '/')) {
fprintf(stderr, "host=addr format not supported for multiple control/data paths\n");
fflush(stderr);
exit(1);
}
if (*cp1) {
if (*cp1 == '=') {
implicit_hostaddr = 1;
cp1++;
}
hostaddr = cp1;
if (!implicit_hostaddr)
host = hostaddr;
}
}
stream_idx = 0;
res[0] = NULL;
cp1 = host;
if (host[strlen(host) - 1] == '/') {
fprintf(stderr, "bad hostname or address: trailing '/' not allowed: %s\n", host);
fflush(stderr);
exit(1);
}
if (strchr(host, '/') && !trans && !reverse) {
fprintf(stderr, "multiple control/data paths not supported for receive\n");
fflush(stderr);
exit(1);
}
if (strchr(host, '/') && trans && reverse) {
fprintf(stderr, "multiple control/data paths not supported for flipped transmit\n");
fflush(stderr);
exit(1);
}
if (host[0] == '/') {
host++;
cp1++;
stream_idx = 1;
}
else if ((cp2 = strchr(host, '/'))) {
host = cp2 + 1;
}
while (stream_idx <= nstream) {
bzero(&hints, sizeof(hints));
res[stream_idx] = NULL;
if (explicitaf) hints.ai_family = af;
if (udp)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
if ((cp2 = strchr(cp1, '/'))) {
if (stream_idx == nstream) {
fprintf(stderr, "bad hostname or address: too many data paths for nstream=%d: %s\n", nstream, argv[0]);
fflush(stderr);
exit(1);
}
*cp2 = '\0';
}
if (!(multilink && (stream_idx > 1)) &&
(error_num = getaddrinfo(cp1, NULL, &hints,
&res[stream_idx]))) {
if (implicit_hostaddr && hostaddr) {
if (res[stream_idx]) {
freeaddrinfo(res[stream_idx]);
res[stream_idx] = NULL;
}
error_num =
getaddrinfo(hostaddr, NULL,
&hints,
&res[stream_idx]);
}
if (error_num) {
if (cp2)
*cp2++ = '/';
if (hostaddr) {
if (implicit_hostaddr)
*(hostaddr - 2) = '=';
else
*(hostaddr - 1) = '=';
}
fprintf(stderr, "bad hostname or address: %s: %s\n", gai_strerror(error_num), argv[0]);
fflush(stderr);
exit(1);
}
if (implicit_hostaddr && hostaddr &&
(stream_idx == 1)) {
if (stride)
*(stride - 1) = '+';
cp3 = hostaddr;
while (*cp3) {
*(cp3 - 1) = *cp3;
cp3++;
}
*(cp3 - 1) = '\0';
hostaddr--;
implicit_hostaddr = 0;
if (stride) {
stride--;
*(stride - 1) = '\0';
}
}
}
else if (multilink && (stream_idx > 1)) {
if (res[stream_idx - 1]->ai_next)
res[stream_idx] =
res[stream_idx - 1]->ai_next;
else
res[stream_idx] = res[1];
}
else if (!(multilink && (stream_idx > 1)) &&
implicit_hostaddr && hostaddr) {
if (stride) {
strcat(host, "+");
strncat(host, stride, ADDRSTRLEN);
*(hostaddr - 2) = '\0';
stride = hostaddr - 1;
}
hostaddr = NULL;
}
af = res[stream_idx]->ai_family;
/*
* At the moment PF_ matches AF_ but are maintained seperate and the socket
* call is supposed to be PF_
*
* For now we set domain from the address family we looked up, but if these
* ever get changed to not match some code will have to go here to find the
* domain appropriate for the family
*/
domain = af;
stream_idx++;
if (cp2) {
*cp2++ = '/';
cp1 = cp2;
}
else
cp1 = host;
}
if (!res[0]) {
if ((cp1 = strchr(host, '/')))
*cp1 = '\0';
if ((error_num = getaddrinfo(host, NULL, &hints, &res[0]))) {
if (cp1)
*cp1++ = '/';
fprintf(stderr, "bad hostname or address: %s: %s\n", gai_strerror(error_num), argv[0]);
fflush(stderr);
exit(1);
}
af = res[0]->ai_family;
/* see previous comment about domain */
domain = af;
if (cp1)
*cp1 = '/';
}
if (hostaddr) {
host = argv[0];
if (implicit_hostaddr)
*(hostaddr - 2) = '=';
else
*(hostaddr - 1) = '=';
}
}
ipad_stride.ip32 = 0;
if (stride) {
if (strlen(stride) >= ADDRSTRLEN) {
fprintf(stderr, "address stride '%s' too long\n", stride);
fflush(stderr);
exit(1);
}
if (nstream == 1) {
fprintf(stderr, "Warning: stride %s not meaningful for a single stream\n", stride);
fflush(stderr);
}
if (udp) {
fprintf(stderr, "stride %s not valid for UDP\n",
stride);
fflush(stderr);
exit(1);
}
if ((cp1 = strchr(argv[0], '/')) && strchr(cp1 + 1, '/')) {
fprintf(stderr, "stride %s not compatible with multiple hosts %s\n", stride, argv[0]);
fflush(stderr);
exit(1);
}
if (af == AF_INET) {
if (strchr(stride, '.')) {
error_num = inet_pton(AF_INET, stride,
ipad_stride.buf);
if (error_num == 0) {
fprintf(stderr,
"stride %s not in correct presentation format\n",
stride);
fflush(stderr);
exit(1);
}
else if (error_num < 0)
err("inet_pton: stride");
}
else {
ipad_stride.ip32 = atoi(stride);
ipad_stride.ip32 = htonl(ipad_stride.ip32);
}
}
else {
fprintf(stderr, "stride %s not valid for IPv6\n",
stride);
fflush(stderr);
exit(1);
}
*(stride - 1) = '+';
}
if (host3 && !strchr(host3, '=') && !strchr(host3, '/')) {
cp1 = strchr(host3, '+');
if (cp1) {
if (strlen(cp1 + 1) >= ADDRSTRLEN) {
fprintf(stderr, "3rd party address stride '%s' too long\n", cp1 + 1);
fflush(stderr);
exit(1);
}
*cp1 = '\0';
}
if (inet_pton(af, host3, &dummy) != 1) {
bzero(&hints, sizeof(hints));
hints.ai_family = af;
if (udp)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
host3res = NULL;
error_num = getaddrinfo(host3, NULL, &hints, &host3res);
if (error_num == 0) {
nameinfo_flags = NI_NUMERICHOST;
error_num = getnameinfo(host3res->ai_addr,
host3res->ai_addrlen,
host3addr, ADDRSTRLEN,
NULL, 0,
nameinfo_flags);
}
if (host3res) {
freeaddrinfo(host3res);
host3res = NULL;
}
if (error_num == 0) {
strncpy(host3buf, host3, HOSTNAMELEN);
strcat(host3buf, "==");
strncat(host3buf, host3addr, ADDRSTRLEN);
if (cp1) {
strcat(host3buf, "+");
strncat(host3buf, cp1 + 1, ADDRSTRLEN);
}
host3 = host3buf;
}
}
if (cp1)
*cp1 = '+';
}
if (!port) {
if (af == AF_INET) {
if ((sp = getservbyname( "nuttcp-data", "tcp" )))
port = ntohs(sp->s_port);
else
port = DEFAULT_PORT;
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if ((sp = getservbyname( "nuttcp6-data", "tcp" )))
port = ntohs(sp->s_port);
else {
if ((sp = getservbyname( "nuttcp-data", "tcp" )))
port = ntohs(sp->s_port);
else
port = DEFAULT_PORT;
}
}
#endif
else {
err("unsupported AF");
}
}
if (!ctlport) {
if (af == AF_INET) {
if ((sp = getservbyname( "nuttcp", "tcp" )))
ctlport = ntohs(sp->s_port);
else
ctlport = DEFAULT_CTLPORT;
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if ((sp = getservbyname( "nuttcp6", "tcp" )))
ctlport = ntohs(sp->s_port);
else {
if ((sp = getservbyname( "nuttcp", "tcp" )))
ctlport = ntohs(sp->s_port);
else
ctlport = DEFAULT_CTLPORT;
}
}
#endif
else {
err("unsupported AF");
}
}
if ((port < 1024) || ((port + nstream - 1) > 65535)) {
fprintf(stderr, "invalid port/nstream = %d/%d\n", port, nstream);
fflush(stderr);
exit(1);
}
if ((ctlport >= port) && (ctlport <= (port + nstream - 1))) {
fprintf(stderr, "ctlport = %d overlaps port/nstream = %d/%d\n", ctlport, port, nstream);
fflush(stderr);
exit(1);
}
if (timeout && (interval >= timeout)) {
fprintf(stderr, "ignoring interval=%f which is greater than or equal timeout=%f\n", interval, timeout);
fflush(stderr);
interval = 0;
}
if (iratesss) {
if (udp) {
fprintf(stderr, "ignoring smoothed slow start option for udp transfer\n");
fflush(stderr);
iratesss = 0;
}
if (maxburst > 1) {
fprintf(stderr, "ignoring maxburst option with smoothed slow start option\n");
fflush(stderr);
maxburst = 1;
}
if (nstream > 1) {
fprintf(stderr, "ignoring smoothed slow start option for multiple streams\n");
fflush(stderr);
iratesss = 0;
}
if (format & NORETRANS) {
fprintf(stderr, "can't do smoothed slow start if no retransmission info\n");
fflush(stderr);
iratesss = 0;
}
if (!(format & NORETRANS) && (format & NOCWND)) {
fprintf(stderr, "can't do smoothed slow start if no congestion window info\n");
fflush(stderr);
iratesss = 0;
}
}
if (clientserver) {
if (trans) {
fprintf(stderr, "server mode only allowed for receiver\n");
goto usage;
}
udp = 0;
start_idx = 0;
ident[0] = '\0';
if (af == AF_INET) {
union peer46 {
struct sockaddr_in peer4;
#ifdef AF_INET6
struct sockaddr_in6 peer6;
#endif
} peer;
socklen_t peerlen = sizeof(peer);
if (getpeername(0, (struct sockaddr *)&peer, &peerlen) == 0) {
#ifndef AF_INET6
if (peer.peer4.sin_family == AF_INET)
#else
if ((peer.peer4.sin_family == AF_INET) ||
(peer.peer6.sin6_family == AF_INET6))
#endif
{
#ifdef AF_INET6
if (!explicitaf &&
(peer.peer6.sin6_family == AF_INET6)) {
af = AF_INET6;
domain = af;
clientaddr6 = peer.peer6.sin6_addr;
clientscope6 = peer.peer6.sin6_scope_id;
client_ipaddr.ss.ss_family = AF_INET6;
client_ipaddr.sin6.sin6_addr =
clientaddr6;
}
else {
clientaddr = peer.peer4.sin_addr;
client_ipaddr.ss.ss_family = AF_INET;
client_ipaddr.sin.sin_addr = clientaddr;
}
#else
clientaddr = peer.peer4.sin_addr;
client_ipaddr.ss.ss_family = AF_INET;
client_ipaddr.sin.sin_addr = clientaddr;
#endif
inetd = 1;
oneshot = 1;
start_idx = 1;
}
}
}
#ifdef AF_INET6
else if (af == AF_INET6) {
struct sockaddr_in6 peer;
socklen_t peerlen = sizeof(peer);
if (getpeername(0, (struct sockaddr *)&peer, &peerlen) == 0) {
if ((peer.sin6_family == AF_INET) ||
(peer.sin6_family == AF_INET6)) {
clientaddr6 = peer.sin6_addr;
clientscope6 = peer.sin6_scope_id;
client_ipaddr.ss.ss_family = AF_INET6;
client_ipaddr.sin6.sin6_addr = clientaddr6;
inetd = 1;
oneshot = 1;
start_idx = 1;
}
}
}
#endif
else {
err("unsupported AF");
}
}
if (clientserver && !inetd && !oneshot && !sinkmode) {
fprintf(stderr, "option \"-s\" invalid with \"-S\" server mode\n");
fprintf(stderr, "option \"-s\" can be used with \"-1\" oneshot server mode\n");
fflush(stderr);
exit(1);
}
#ifdef HAVE_SETPRIO
if (priority) {
if (setpriority(PRIO_PROCESS, 0, priority) != 0)
err("couldn't change priority");
}
#endif
#ifdef HAVE_SETAFFINITY
if ((affinity >= 0) && !host3) {
if ((ncores = sysconf(_SC_NPROCESSORS_CONF)) <= 0)
err("sysconf: couldn't get _SC_NPROCESSORS_CONF");
CPU_ZERO(&cpu_set);
CPU_SET(affinity, &cpu_set);
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set) != 0)
err("couldn't change CPU affinity");
}
#endif
if (argc >= 1) {
start_idx = 0;
client = 1;
clientserver = 1;
}
if (clientserver && !client && srcctlport) {
fprintf(stderr, "can't specify source control port in server mode\n");
fflush(stderr);
exit(1);
}
if (!host3 && clientserver && client && (ssm < 0)) {
if (af == AF_INET) {
ssm = 0;
}
#ifdef AF_INET6
else if (af == AF_INET6) {
#ifdef MCAST_JOIN_SOURCE_GROUP
ssm = 1;
#else
ssm = 0;
#endif
}
#endif
}
mc_af = af;
if (!host3 && clientserver && client && mc_addr) {
bzero(&hints, sizeof(hints));
if (explicitaf)
hints.ai_family = af;
if (udp)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
mcres = NULL;
error_num = getaddrinfo(mc_addr, NULL, &hints, &mcres);
if (error_num) {
fprintf(stderr, "getaddrinfo: "
"bad multicast IP address: %s: %s\n",
mc_addr, gai_strerror(error_num));
fflush(stderr);
exit(1);
}
nameinfo_flags = NI_NUMERICHOST;
error_num = getnameinfo(mcres->ai_addr, mcres->ai_addrlen,
mcgaddr, ADDRSTRLEN, NULL, 0,
nameinfo_flags);
if (error_num) {
fprintf(stderr, "getnameinfo: "
"bad multicast IP address: %s: %s\n",
mc_addr, gai_strerror(error_num));
fflush(stderr);
exit(1);
}
mc_addr = mcgaddr;
if (mcres->ai_family == AF_INET) {
struct sockaddr_in *group;
struct in_addr ipv4_mcaddr;
group = (struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)&(group->sin_addr), (char *)&ipv4_mcaddr,
sizeof(struct in_addr));
if (ssm) {
if (((htonl(ipv4_mcaddr.s_addr) & 0xFF000000) !=
(HI_MC_SSM << 24))) {
fprintf(stderr, "bad SSM multicast "
"IP address: %s: "
"use 232.x.y.z\n",
mcgaddr);
fflush(stderr);
exit(1);
}
}
else {
if (((htonl(ipv4_mcaddr.s_addr) & 0xFF000000) !=
(HI_MC << 24))) {
fprintf(stderr, "bad ASM multicast "
"IP address: %s: "
"use 231.x.y.z\n",
mcgaddr);
fflush(stderr);
exit(1);
}
}
}
#ifdef AF_INET6
if (mcres->ai_family == AF_INET6) {
struct sockaddr_in6 *group;
group = (struct sockaddr_in6 *)mcres->ai_addr;
if (ssm) {
if ((bcmp((char *)&(group->sin6_addr),
(char *)&hi_mc6,
HI_MC6_LEN - 1) != 0) ||
(group->sin6_addr.s6_addr[HI_MC6_LEN - 1]
< 0x80)) {
fprintf(stderr,
"bad SSM multicast IP address: "
"%s: use ff3e::[8-f]xxx:yyyy\n",
mcgaddr);
fflush(stderr);
exit(1);
}
}
else {
if ((bcmp((char *)&(group->sin6_addr),
(char *)&hi_mc6_asm,
HI_MC6_ASM_LEN) != 0)) {
fprintf(stderr,
"bad ASM multicast IP address: "
"%s: use ff2e::wwww:xxxx:"
"yyyy:zzzz\n",
mcgaddr);
fflush(stderr);
exit(1);
}
}
}
#endif
mc_af = mcres->ai_family;
}
if (irate < 0) {
if (do_jitter)
irate = 1;
else
irate = 0;
}
if (do_jitter && (rate == MAXRATE)) {
fprintf(stderr, "jitter option not supported for "
"unlimited rate\n");
fflush(stderr);
exit(1);
}
if (do_jitter && !irate) {
fprintf(stderr, "jitter option requires"
" \"-Ri\" instantaneous rate limit option\n");
fflush(stderr);
exit(1);
}
if (interval && !clientserver) {
fprintf(stderr, "interval option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (reverse && !clientserver) {
fprintf(stderr, "flip option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (reverse && udp) {
fprintf(stderr, "flip option not supported for UDP\n");
fflush(stderr);
exit(1);
}
if (client && !sinkmode && udp) {
fprintf(stderr, "Warning: UDP transfers unreliable for non-sinkmode - use at own risk\n");
fflush(stderr);
}
if (traceroute) {
nstream = 1;
if (!clientserver) {
fprintf(stderr, "traceroute option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
}
if (host3) {
if (!clientserver) {
fprintf(stderr, "3rd party nuttcp only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
}
if (udp && (buflen < 5)) {
fprintf(stderr, "UDP buflen = %d < 5, set to 5\n", buflen);
buflen = 5; /* send more than the sentinel size */
}
if (udp && (buflen > MAXUDPBUFLEN)) {
fprintf(stderr, "UDP buflen = %d > MAXUDPBUFLEN, set to %d\n",
buflen, MAXUDPBUFLEN);
buflen = MAXUDPBUFLEN;
}
if (nbuf_bytes && !host3 && !traceroute) {
nbuf /= buflen;
}
if ((rate != MAXRATE) && rate_pps && !host3 && !traceroute) {
uint64_t llrate = rate;
llrate *= ((double)buflen * 8 / 1000);
rate = llrate;
}
if (udp && interval) {
if (buflen >= 32)
udplossinfo = 1;
else
fprintf(stderr, "Unable to print interval loss information if UDP buflen < 32\n");
}
if (udp && (do_jitter & JITTER_IGNORE_OOO)) {
if (buflen >= 32)
udplossinfo = 1;
else
fprintf(stderr, "Unable to check out of order when calculating jitter if UDP buflen < 32\n");
}
if (!udp && trans) {
if (buflen >= 32) {
retransinfo = 1;
#if defined(linux)
cwndinfo = 1;
#endif
b_flag = 1;
}
else
fprintf(stderr, "Unable to print retransmission information if TCP buflen < 32\n");
}
if (udp && do_owd && (buflen < 16)) {
fprintf(stderr, "Unable to calculate one-way delay if UDP buflen < 16\n");
}
ivers = vers_major*10000 + vers_minor*100 + vers_delta;
mallocsize = buflen;
if (mallocsize < MINMALLOC) mallocsize = MINMALLOC;
#if defined(linux)
if (directio) {
error_num = posix_memalign((void **)&buf, sysconf(_SC_PAGESIZE),
mallocsize);
if (error_num) {
errno = error_num;
err("posix_memalign");
}
}
else
#endif
if ((buf = (char *)malloc(mallocsize)) == (char *)NULL)
err("malloc");
pattern( buf, buflen );
#ifdef SIGPIPE
signal(SIGPIPE, sigpipe);
#endif
signal(SIGINT, sigint);
if (clientserver && client && !thirdparty &&
beta && !(format & NOBETAMSG) && (do_jitter || do_owd)) {
fprintf(stderr, "nuttcp-%d.%d.%d: ",
vers_major, vers_minor, vers_delta);
fprintf(stderr, "Using beta vers: %s interface/output "
"subject to change\n", BETA_FEATURES);
fprintf(stderr, " (to suppress this message "
"use \"-f-beta\")\n\n");
fflush(stderr);
}
doit:
if (!udp && trans && (format & DEBUGRETRANS)) {
sretrans = get_retrans(-1, &tcpinf);
fprintf(stdout, "initial system retrans = %d\n", sretrans);
}
nretrans[0] = 0;
cwnd[0] = 0;
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
fd[stream_idx] = -1;
nretrans[stream_idx] = 0;
cwnd[stream_idx] = 0;
}
for ( stream_idx = start_idx; stream_idx <= nstream; stream_idx++ ) {
if (clientserver && (stream_idx == 1)) {
retransinfo = 0;
cwndinfo = 0;
if (nstream == 1) {
send_retrans = 1;
read_retrans = 1;
send_cwnd = 1;
read_cwnd = 1;
}
do_retrans = 0;
do_cwnd = 0;
got_0retrans = 0;
if (client) {
if (udp && !host3 && !traceroute) {
ctlconnmss = 0;
optlen = sizeof(ctlconnmss);
if (getsockopt(fd[0], IPPROTO_TCP, TCP_MAXSEG, (void *)&ctlconnmss, &optlen) < 0)
err("get ctlconn maximum segment size didn't work");
if (!ctlconnmss) {
ctlconnmss = NON_JUMBO_ETHER_MSS;
if (format & DEBUGMTU) {
fprintf(stderr, "nuttcp%s%s: Warning: Control connection MSS reported as 0, using %d\n", trans?"-t":"-r", ident, ctlconnmss);
fflush(stderr);
}
}
else if (format & DEBUGMTU)
fprintf(stderr, "ctlconnmss = %d\n", ctlconnmss);
if (buflenopt) {
if (buflen >
ctlconnmss +
TCP_UDP_HDRLEN_DELTA +
TCP_TIMESTAMPS_OPTLEN) {
if (format & PARSE)
fprintf(stderr, "nuttcp%s%s: Warning=\"IP_frags_or_no_data_reception_since_buflen=%d_>_ctlconnmss=%d\"\n", trans?"-t":"-r", ident, buflen, ctlconnmss);
else
fprintf(stderr, "nuttcp%s%s: Warning: IP frags or no data reception since buflen=%d > ctlconnmss=%d\n", trans?"-t":"-r", ident, buflen, ctlconnmss);
fflush(stderr);
}
}
else {
while (buflen > ctlconnmss) {
buflen >>= 1;
if (nbuf_bytes)
nbuf <<= 1;
if ((rate != MAXRATE) &&
rate_pps)
rate >>= 1;
}
}
if (format & DEBUGMTU)
fprintf(stderr, "buflen = %d\n", buflen);
}
if (!(ctlconn = fdopen(fd[0], "w")))
err("fdopen: ctlconn for writing");
if (!sinkmode) {
if (trans)
savestdin=dup(0);
else {
savestdout=dup(1);
close(1);
dup(2);
}
}
close(0);
dup(fd[0]);
if (srvr_helo) {
fprintf(ctlconn,
HELO_FMT, vers_major,
vers_minor, vers_delta);
fflush(ctlconn);
if (!fgets(buf, mallocsize, stdin)) {
if ((errno == ECONNRESET) &&
(num_connect_tries <
MAX_CONNECT_TRIES) &&
retry_server) {
/* retry control
* connection to server
* for certain possibly
* transient errors */
fclose(ctlconn);
goto doit;
}
mes("error from server");
fprintf(stderr, "server aborted connection\n");
fflush(stderr);
exit(1);
}
if (sscanf(buf, HELO_FMT,
&rvers_major,
&rvers_minor,
&rvers_delta) < 3) {
rvers_major = 0;
rvers_minor = 0;
rvers_delta = 0;
srvr_helo = 0;
while (fgets(buf, mallocsize,
stdin)) {
if (strncmp(buf, "KO", 2) == 0)
break;
}
fclose(ctlconn);
goto doit;
}
irvers = rvers_major*10000
+ rvers_minor*100
+ rvers_delta;
}
if (host3 && nbuf_bytes && (irvers < 50501))
nbuf /= buflen;
if (host3 && (rate != MAXRATE) && rate_pps &&
(irvers < 50501)) {
uint64_t llrate = rate;
llrate *= ((double)buflen * 8 / 1000);
rate = llrate;
}
if (host3 && !buflenopt && (irvers >= 50302))
buflen = 0;
fprintf(ctlconn, "buflen = %d, nbuf = %llu, win = %d, nstream = %d, rate = %lu, port = %hu, trans = %d, braindead = %d", buflen, nbuf, srvrwin, nstream, rate, port, trans, braindead);
if (irvers >= 30200)
fprintf(ctlconn, ", timeout = %f", timeout);
else {
timeout_sec = timeout;
if (itimer.it_value.tv_usec)
timeout_sec++;
fprintf(ctlconn, ", timeout = %ld", timeout_sec);
if (!trans && itimer.it_value.tv_usec &&
(brief <= 0)) {
fprintf(stdout, "nuttcp-r%s: transmit timeout value rounded up to %ld second%s for old server\n",
ident, timeout_sec,
(timeout_sec == 1)?"":"s");
}
}
fprintf(ctlconn, ", udp = %d, vers = %d.%d.%d", udp, vers_major, vers_minor, vers_delta);
if (irvers >= 30302)
fprintf(ctlconn, ", interval = %f", interval);
else {
if (interval) {
fprintf(stdout, "nuttcp%s%s: interval option not supported by server version %d.%d.%d, need >= 3.3.2\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
interval = 0.0;
abortconn = 1;
}
}
if (irvers >= 30401)
fprintf(ctlconn, ", reverse = %d", reverse);
else {
if (reverse) {
fprintf(stdout, "nuttcp%s%s: flip option not supported by server version %d.%d.%d, need >= 3.4.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
reverse = 0;
abortconn = 1;
}
}
if (irvers >= 30501)
fprintf(ctlconn, ", format = %d", format);
else {
if (format) {
fprintf(stdout, "nuttcp%s%s: format option not supported by server version %d.%d.%d, need >= 3.5.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
format = 0;
}
}
if (irvers >= 30601) {
fprintf(ctlconn, ", traceroute = %d", traceroute);
if (traceroute)
skip_data = 1;
fprintf(ctlconn, ", irate = %d", irate);
}
else {
if (traceroute) {
fprintf(stdout, "nuttcp%s%s: traceroute option not supported by server version %d.%d.%d, need >= 3.6.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
traceroute = 0;
abortconn = 1;
}
if (irate && !trans) {
fprintf(stdout, "nuttcp%s%s: instantaneous rate option not supported by server version %d.%d.%d, need >= 3.6.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
irate = 0;
}
}
if (srvrwin && udp && (irvers < 30602)) {
fprintf(stdout, "nuttcp%s%s: server version %d.%d.%d ignores UDP window parameter, need >= 3.6.2\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
}
if ((irvers < 40101) && (format & PARSE)) {
fprintf(stdout, "nuttcp%s%s: \"-fparse\" option not supported by server version %d.%d.%d, need >= 4.1.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
format &= ~PARSE;
abortconn = 1;
}
if (irvers >= 50001) {
cp1 = NULL;
if (host3 && (irvers < 70101) &&
(cp1 = strchr(host3, '=')))
*cp1 = '\0';
fprintf(ctlconn, ", thirdparty = %.*s", HOST3BUFLEN, host3 ? host3 : "_NULL_");
if (host3) {
skip_data = 1;
fprintf(ctlconn, " , brief3 = %d", brief);
}
if (cp1)
*cp1 = '=';
}
else {
if (host3) {
fprintf(stdout, "nuttcp%s%s: 3rd party nuttcp not supported by server version %d.%d.%d, need >= 5.0.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
host3 = NULL;
abortconn = 1;
}
}
if (host3 && !abortconn) {
if (irvers >= 60205) {
fprintf(ctlconn,
" , ctlport3 = %hu",
ctlport3);
}
else {
if (ctlport3) {
fprintf(stdout, "nuttcp%s%s: ctlport3 option not supported by server version %d.%d.%d, need >= 6.2.5\n",
trans?"-t":"-r",
ident,
rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
ctlport3 = 0;
abortconn = 1;
}
}
}
if (irvers >= 50101) {
fprintf(ctlconn, " , multicast = %d", multicast);
}
else {
if (multicast) {
fprintf(stdout, "nuttcp%s%s: multicast not supported by server version %d.%d.%d, need >= 5.1.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
multicast = 0;
abortconn = 1;
}
}
if (irvers >= 60201) {
fprintf(ctlconn, " , ssm = %d", ssm);
}
else {
if (multicast && (ssm == 1)) {
fprintf(stdout, "nuttcp%s%s: ssm not supported by server version %d.%d.%d, need >= 6.2.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
ssm = 0;
abortconn = 1;
}
}
if (irvers >= 50201) {
fprintf(ctlconn, " , datamss = %d", datamss);
}
else {
if (datamss && !trans) {
fprintf(stdout, "nuttcp%s%s: mss option not supported by server version %d.%d.%d, need >= 5.2.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
datamss = 0;
abortconn = 1;
}
}
if (irvers >= 50301) {
fprintf(ctlconn, " , tos = %X", tos);
}
else {
if (tos && !trans) {
fprintf(stdout, "nuttcp%s%s: tos option not supported by server version %d.%d.%d, need >= 5.3.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
tos = 0;
abortconn = 1;
}
}
if (irvers >= 50501) {
fprintf(ctlconn, " , nbuf_bytes = %d", nbuf_bytes);
fprintf(ctlconn, " , rate_pps = %d", rate_pps);
fprintf(ctlconn, " , nodelay = %d", nodelay);
}
else {
if (host3 && udp && nbuf_bytes) {
fprintf(stdout, "nuttcp%s%s: Warning: \"-n\" option in bytes for third party not supported\n",
trans?"-t":"-r", ident);
fprintf(stdout, " Warning: by server version %d.%d.%d, need >= 5.5.1\n",
rvers_major,
rvers_minor,
rvers_delta);
fprintf(stdout, " Warning: third party request may not transfer\n");
fprintf(stdout, " Warning: desired number of bytes in some UDP cases\n");
fflush(stdout);
nbuf_bytes = 0;
}
if (host3 && udp && rate_pps) {
fprintf(stdout, "nuttcp%s%s: Warning: \"-R\" option in pps for third party not supported\n",
trans?"-t":"-r", ident);
fprintf(stdout, " Warning: by server version %d.%d.%d, need >= 5.5.1\n",
rvers_major,
rvers_minor,
rvers_delta);
fprintf(stdout, " Warning: third party request may not produce\n");
fprintf(stdout, " Warning: desired pps rate in some UDP cases\n");
fflush(stdout);
rate_pps = 0;
}
if (nodelay && !trans) {
fprintf(stdout, "nuttcp%s%s: TCP_NODELAY opt not supported by server version %d.%d.%d, need >= 5.5.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
nodelay = 0;
abortconn = 1;
}
}
if (irvers >= 60206) {
if (host3) {
fprintf(ctlconn,
" , affinity = %d",
affinity);
fprintf(ctlconn,
" , srvr_affinity = %d",
srvr_affinity);
}
else {
fprintf(ctlconn,
" , affinity = %d",
srvr_affinity);
}
}
else {
if (srvr_affinity >= 0) {
fprintf(stdout, "nuttcp%s%s: affinity option not supported by server version %d.%d.%d, need >= 6.2.6\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
srvr_affinity = -1;
abortconn = 1;
}
}
if (irvers >= 60207) {
fprintf(ctlconn, " , maxburst = %d",
maxburst);
}
else {
if ((maxburst > 1) &&
(!trans || host3)) {
fprintf(stdout, "nuttcp%s%s: packet burst not supported by server version %d.%d.%d, need >= 6.2.7\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
maxburst = 1;
abortconn = 1;
}
}
if (irvers >= 70001) {
fprintf(ctlconn, " , do_jitter = %d", do_jitter);
}
else {
if (do_jitter && trans) {
fprintf(stdout, "nuttcp%s%s: jitter not supported by server version %d.%d.%d, need >= 7.0.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
do_jitter = 0;
abortconn = 1;
}
if ((do_jitter & JITTER_IGNORE_OOO) &&
!trans && !(udp && interval)) {
udplossinfo = 0;
fprintf(stdout, "nuttcp%s%s: Unable to check out of order when calculating jitter\n",
trans?"-t":"-r", ident);
fprintf(stdout, " due to using older server version %d.%d.%d, need >= 7.0.1\n",
rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
}
}
if (irvers >= 70001) {
fprintf(ctlconn, " , do_owd = %d", do_owd);
}
else {
if (do_owd) {
fprintf(stdout, "nuttcp%s%s: owd not supported by server version %d.%d.%d, need >= 7.0.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
do_owd = 0;
abortconn = 1;
}
}
if (irvers >= 70101) {
fprintf(ctlconn, " , stride = %d", ipad_stride.ip32);
}
else {
if (ipad_stride.ip32) {
fprintf(stdout, "nuttcp%s%s: stride not supported by server version %d.%d.%d, need >= 7.1.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
ipad_stride.ip32 = 0;
abortconn = 1;
}
}
if (irvers >= 70101) {
fprintf(ctlconn, " , multilink = %d", multilink);
}
else {
if (multilink) {
fprintf(stdout, "nuttcp%s%s: multilink not supported by server version %d.%d.%d, need >= 7.1.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
multilink = 0;
abortconn = 1;
}
}
if (irvers >= 70201) {
fprintf(ctlconn, ", group = %.*s", ADDRSTRLEN, mc_addr ? mc_addr : "_NULL_");
}
else {
if (mc_addr) {
fprintf(stdout, "nuttcp%s%s: multicast group option not supported by server version %d.%d.%d, need >= 7.2.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
mc_addr = NULL;
abortconn = 1;
}
}
if (irvers >= 70301) {
fprintf(ctlconn, " , srcport = %hu", srcport);
}
else {
if (srcport &&
((!trans && !reverse) ||
(trans && reverse) ||
host3)) {
fprintf(stdout, "nuttcp%s%s: source port option not supported by server version %d.%d.%d, need >= 7.3.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
srcport = 0;
abortconn = 1;
}
}
if (irvers >= 80101) {
fprintf(ctlconn, ", iratesss = %d", iratesss);
}
else {
if (iratesss && !trans) {
fprintf(stdout, "nuttcp%s%s: smoothed slow start option not supported by server version %d.%d.%d, need >= 8.1.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
iratesss = 0;
}
}
if ((irvers >= 80201) && host3) {
if (explicitaf) {
if (af == AF_INET)
fprintf(ctlconn,
", af3 = 4");
if (af == AF_INET6)
fprintf(ctlconn,
", af3 = 6");
}
else {
fprintf(ctlconn, ", af3 = 0");
}
}
else {
if (host3 && explicitaf) {
fprintf(stdout, "nuttcp%s%s: third party \"-4/-6\" not supported by server version %d.%d.%d, need >= 8.2.1\n",
trans?"-t":"-r",
ident, rvers_major,
rvers_minor,
rvers_delta);
fflush(stdout);
}
}
fprintf(ctlconn, "\n");
fflush(ctlconn);
if (abortconn) {
brief = 1;
if ((!trans && !reverse) ||
(trans && reverse))
skip_data = 1;
}
if (!fgets(buf, mallocsize, stdin)) {
mes("error from server");
fprintf(stderr, "server aborted connection\n");
fflush(stderr);
exit(1);
}
if (irvers < 30403)
udplossinfo = 0;
if (irvers >= 50401) {
two_bod = 1;
handle_urg = 1;
}
if (udp || (buflen < 32) || (irvers < 60001)) {
if (trans)
send_retrans = 0;
else
read_retrans = 0;
}
if (udp || (buflen < 32) || (irvers < 80001)) {
if (trans)
send_cwnd = 0;
else
read_cwnd = 0;
}
if (strncmp(buf, "OK", 2) != 0) {
mes("error from server");
fprintf(stderr, "server ");
while (fgets(buf, mallocsize, stdin)) {
if (strncmp(buf, "KO", 2) == 0)
break;
fputs(buf, stderr);
}
fflush(stderr);
exit(1);
}
if (sscanf(buf, "OK v%d.%d.%d\n", &rvers_major, &rvers_minor, &rvers_delta) < 3) {
rvers_major = 0;
rvers_minor = 0;
rvers_delta = 0;
}
irvers = rvers_major*10000
+ rvers_minor*100
+ rvers_delta;
usleep(10000);
}
else {
if (inetd) {
ctlconn = stdin;
}
else {
if (!(ctlconn = fdopen(fd[0], "r")))
err("fdopen: ctlconn for reading");
}
fflush(stdout);
if (!inetd) {
/* manually started server */
/* send stdout to client */
savestdout=dup(1);
close(1);
dup(fd[0]);
if (!nofork) {
/* send stderr to client */
close(2);
dup(1);
}
}
if (!fgets(buf, mallocsize, ctlconn)) {
fputs("KO\n", stdout);
mes("no nuttcp HELO message");
fputs("KO\n", stdout);
goto cleanup;
}
if (sscanf(buf, HELO_FMT, &rvers_major,
&rvers_minor, &rvers_delta) == 3) {
fprintf(stdout, HELO_FMT, vers_major,
vers_minor, vers_delta);
fflush(stdout);
if (!fgets(buf, mallocsize, ctlconn)) {
fputs("KO\n", stdout);
mes("no nuttcp parameters");
fputs("KO\n", stdout);
goto cleanup;
}
}
irvers = rvers_major*10000
+ rvers_minor*100
+ rvers_delta;
if (sscanf(buf, "buflen = %d, nbuf = %llu, win = %d, nstream = %d, rate = %lu, port = %hu, trans = %d, braindead = %d, timeout = %lf, udp = %d, vers = %d.%d.%d", &nbuflen, &nbuf, &sendwin, &nstream, &rate, &port, &trans, &braindead, &timeout, &udp, &rvers_major, &rvers_minor, &rvers_delta) < 13) {
trans = !trans;
fputs("KO\n", stdout);
mes("error scanning parameters");
fprintf(stdout, "may be using older client version than server\n");
fputs(buf, stdout);
fputs("KO\n", stdout);
goto cleanup;
}
irvers = rvers_major*10000
+ rvers_minor*100
+ rvers_delta;
if (irvers >= 30302)
sscanf(strstr(buf, ", interval =") + 13,
"%lf", &interval);
else
interval = 0.0;
if (irvers >= 30401)
sscanf(strstr(buf, ", reverse =") + 12,
"%d", &reverse);
else
reverse = 0;
if (irvers >= 30501)
sscanf(strstr(buf, ", format =") + 11,
"%d", &format);
else
format = 0;
if (irvers >= 30601) {
sscanf(strstr(buf, ", traceroute =") + 15,
"%d", &traceroute);
if (traceroute) {
skip_data = 1;
brief = 1;
}
sscanf(strstr(buf, ", irate =") + 10,
"%d", &irate);
}
else {
traceroute = 0;
irate = 0;
}
if (irvers >= 50001) {
sprintf(fmt, "%%%ds", HOST3BUFLEN);
sscanf(strstr(buf, ", thirdparty =") + 15,
fmt, host3buf);
host3buf[HOST3BUFLEN] = '\0';
if (strcmp(host3buf, "_NULL_") == 0)
host3 = NULL;
else
host3 = host3buf;
if (host3) {
if (no3rd) {
fputs("KO\n", stdout);
fprintf(stdout, "doesn't allow 3rd party nuttcp\n");
fputs("KO\n", stdout);
goto cleanup;
}
cp1 = host3;
while (*cp1) {
if (!isalnum((int)(*cp1))
&& (*cp1 != '-')
&& (*cp1 != '.')
&& (*cp1 != ':')
&& (*cp1 != '/')
&& (*cp1 != '+')
&& (*cp1 != '=')) {
fputs("KO\n", stdout);
mes("invalid 3rd party host");
fprintf(stdout, "3rd party host = '%s'\n", host3);
fputs("KO\n", stdout);
goto cleanup;
}
cp1++;
}
skip_data = 1;
brief = 1;
sscanf(strstr(buf, ", brief3 =") + 11,
"%d", &brief3);
}
}
else {
host3 = NULL;
}
if (host3 && (irvers >= 60205)) {
sscanf(strstr(buf, ", ctlport3 =") + 13,
"%hu", &ctlport3);
}
else {
ctlport3 = 0;
}
if (irvers >= 50101) {
sscanf(strstr(buf, ", multicast =") + 14,
"%d", &mc_param);
}
else {
mc_param = 0;
}
if (irvers >= 60201) {
sscanf(strstr(buf, ", ssm =") + 8,
"%d", &ssm);
}
else {
ssm = 0;
}
#ifndef MCAST_JOIN_SOURCE_GROUP
if (mc_param && (ssm == 1)) {
fputs("KO\n", stdout);
fprintf(stdout, "server does not support ssm\n");
fputs("KO\n", stdout);
goto cleanup;
}
#endif
if (irvers >= 50201) {
sscanf(strstr(buf, ", datamss =") + 12,
"%d", &datamss);
}
else {
datamss = 0;
}
if (irvers >= 50301) {
sscanf(strstr(buf, ", tos =") + 8,
"%X", &tos);
}
else {
tos = 0;
}
if (irvers >= 50501) {
sscanf(strstr(buf, ", nbuf_bytes =")
+ 15,
"%d", &nbuf_bytes);
sscanf(strstr(buf, ", rate_pps =") + 13,
"%d", &rate_pps);
sscanf(strstr(buf, ", nodelay =") + 12,
"%d", &nodelay);
}
else {
nbuf_bytes = 0;
rate_pps = 0;
nodelay = 0;
}
if (irvers >= 60206) {
if (host3) {
sscanf(strstr(buf,
", affinity =") + 13,
"%d", &affinity);
sscanf(strstr(buf,
", srvr_affinity =")
+ 18,
"%d", &srvr_affinity);
}
else {
sscanf(strstr(buf,
", affinity =") + 13,
"%d", &srvr_affinity);
}
}
else {
srvr_affinity = -1;
}
if (irvers >= 60207) {
sscanf(strstr(buf, ", maxburst =") + 13,
"%d", &maxburst);
}
else {
maxburst = 1;
}
if (irvers >= 70001) {
sscanf(strstr(buf, ", do_jitter =") + 14,
"%d", &do_jitter);
}
else {
do_jitter = 0;
}
if (irvers >= 70001) {
sscanf(strstr(buf, ", do_owd =") + 11,
"%d", &do_owd);
}
else {
do_owd = 0;
}
if (irvers >= 70101) {
sscanf(strstr(buf, ", stride =") + 11,
"%d", &ipad_stride.ip32);
}
else {
ipad_stride.ip32 = 0;
}
if (irvers >= 70101) {
sscanf(strstr(buf,
", multilink =") + 14,
"%d", &multilink);
}
else {
multilink = 0;
}
if (irvers >= 70201) {
sprintf(fmt, "%%%ds", ADDRSTRLEN);
sscanf(strstr(buf, ", group =") + 10,
fmt, mcgaddr);
mcgaddr[ADDRSTRLEN - 1] = '\0';
if (strcmp(mcgaddr, "_NULL_") == 0)
mc_addr = NULL;
else
mc_addr = mcgaddr;
if (mc_addr) {
cp1 = mc_addr;
while (*cp1) {
if (!isxdigit((int)(*cp1))
&& (*cp1 != '.')
&& (*cp1 != ':')) {
fputs("KO\n", stdout);
mes("invalid multicast group");
fprintf(stdout, "multicast group = '%s'\n", mc_addr);
fputs("KO\n", stdout);
goto cleanup;
}
cp1++;
}
}
}
else {
mc_addr = NULL;
}
if (irvers >= 70301) {
sscanf(strstr(buf,
", srcport =") + 12,
"%hu", &srcport);
}
else {
srcport = 0;
}
if (irvers >= 80101) {
sscanf(strstr(buf, ", iratesss =") + 13,
"%d", &iratesss);
}
else {
iratesss = 0;
}
if ((irvers >= 80201) && host3) {
sscanf(strstr(buf, ", af3 =") + 8,
"%d", &af3);
}
else {
af3 = 0;
}
#if !defined(linux)
iratesss = 0;
#endif
trans = !trans;
if (inetd && !sinkmode) {
fputs("KO\n", stdout);
mes("option \"-s\" invalid with inetd server");
fputs("KO\n", stdout);
goto cleanup;
}
if (!traceroute && !host3 &&
(nbuflen != buflen)) {
if (nbuflen < 1) {
fputs("KO\n", stdout);
mes("invalid buflen");
fprintf(stdout, "buflen = %d\n", nbuflen);
fputs("KO\n", stdout);
goto cleanup;
}
free(buf);
mallocsize = nbuflen;
if (mallocsize < MINMALLOC) mallocsize = MINMALLOC;
#if defined(linux)
if (directio) {
error_num = posix_memalign(
(void **)&buf,
sysconf(_SC_PAGESIZE),
mallocsize);
if (error_num) {
errno = error_num;
err("posix_memalign");
}
}
else
#endif
if ((buf = (char *)malloc(mallocsize)) == (char *)NULL)
err("malloc");
pattern( buf, nbuflen );
}
buflen = nbuflen;
if (nbuf < 1) {
fputs("KO\n", stdout);
mes("invalid nbuf");
fprintf(stdout, "nbuf = %llu\n", nbuf);
fputs("KO\n", stdout);
goto cleanup;
}
rcvwin = sendwin;
if (sendwin < 0) {
fputs("KO\n", stdout);
mes("invalid win");
fprintf(stdout, "win = %d\n", sendwin);
fputs("KO\n", stdout);
goto cleanup;
}
if ((nstream < 1) || (nstream > MAXSTREAM)) {
fputs("KO\n", stdout);
mes("invalid nstream");
fprintf(stdout, "nstream = %d\n", nstream);
fputs("KO\n", stdout);
goto cleanup;
}
if (nstream > 1) {
b_flag = 1;
send_retrans = 0;
read_retrans = 0;
send_cwnd = 0;
read_cwnd = 0;
}
if (rate == 0)
rate = MAXRATE;
if (timeout < 0) {
fputs("KO\n", stdout);
mes("invalid timeout");
fprintf(stdout, "timeout = %f\n", timeout);
fputs("KO\n", stdout);
goto cleanup;
}
itimer.it_value.tv_sec = timeout;
itimer.it_value.tv_usec =
(timeout - itimer.it_value.tv_sec)
*1000000;
if ((port < 1024) || ((port + nstream - 1) > 65535)) {
fputs("KO\n", stdout);
mes("invalid port/nstream");
fprintf(stdout, "port/nstream = %hu/%d\n", port, nstream);
fputs("KO\n", stdout);
goto cleanup;
}
if (srcport && (srcport < 1024)) {
fputs("KO\n", stdout);
mes("invalid srcport");
fprintf(stdout, "srcport = %hu\n", srcport);
fputs("KO\n", stdout);
goto cleanup;
}
if ((ctlport >= port) && (ctlport <= (port + nstream - 1))) {
fputs("KO\n", stdout);
mes("ctlport overlaps port/nstream");
fprintf(stdout, "ctlport = %hu, port/nstream = %hu/%d\n", ctlport, port, nstream);
fputs("KO\n", stdout);
goto cleanup;
}
if (iratesss) {
if (udp) {
fputs("KO\n", stdout);
mes("iratesss not allowed for udp");
fputs("KO\n", stdout);
goto cleanup;
}
if (maxburst > 1) {
fputs("KO\n", stdout);
mes("maxburst > 1 not allowed with iratesss");
fprintf(stdout, "maxburst = %d\n", maxburst);
fputs("KO\n", stdout);
goto cleanup;
}
if (nstream > 1) {
fputs("KO\n", stdout);
mes("nstream > 1 not allowed with iratesss");
fprintf(stdout, "nstream = %d\n", nstream);
fputs("KO\n", stdout);
goto cleanup;
}
}
if (host3 && ctlport3 && (ctlport3 < 1024)) {
fputs("KO\n", stdout);
mes("invalid ctlport3");
fprintf(stdout, "ctlport3 = %hu\n",
ctlport3);
fputs("KO\n", stdout);
goto cleanup;
}
if (interval < 0) {
fputs("KO\n", stdout);
mes("invalid interval");
fprintf(stdout, "interval = %f\n", interval);
fputs("KO\n", stdout);
goto cleanup;
}
if (mc_param) {
if ((mc_param < 1) ||
(mc_param > 255)) {
fputs("KO\n", stdout);
mes("invalid multicast ttl");
fprintf(stdout, "multicast ttl = %d\n", mc_param);
fputs("KO\n", stdout);
goto cleanup;
}
udp = 1;
nstream = 1;
if (rate == MAXRATE)
rate = DEFAULT_UDP_RATE;
}
multicast = mc_param;
if ((!host3 && ((ssm < 0) || (ssm > 1))) ||
(host3 && ((ssm < -1) || (ssm > 1)))) {
fputs("KO\n", stdout);
mes("invalid ssm value");
fprintf(stdout, "ssm = %d\n", ssm);
fputs("KO\n", stdout);
goto cleanup;
}
if (datamss < 0) {
fputs("KO\n", stdout);
mes("invalid datamss");
fprintf(stdout, "datamss = %d\n", datamss);
fputs("KO\n", stdout);
goto cleanup;
}
if (tos > 255) {
fputs("KO\n", stdout);
mes("invalid tos");
fprintf(stdout, "tos = %d\n", tos);
fputs("KO\n", stdout);
goto cleanup;
}
if (nbuf_bytes < 0) {
fputs("KO\n", stdout);
mes("invalid nbuf_bytes");
fprintf(stdout, "nbuf_bytes = %d\n",
nbuf_bytes);
fputs("KO\n", stdout);
goto cleanup;
}
if (rate_pps < 0) {
fputs("KO\n", stdout);
mes("invalid rate_pps");
fprintf(stdout, "rate_pps = %d\n",
rate_pps);
fputs("KO\n", stdout);
goto cleanup;
}
if (nodelay < 0) {
fputs("KO\n", stdout);
mes("invalid nodelay");
fprintf(stdout, "nodelay = %d\n",
nodelay);
fputs("KO\n", stdout);
goto cleanup;
}
if ((srvr_affinity >= 0) && !host3) {
#ifdef HAVE_SETAFFINITY
CPU_ZERO(&cpu_set);
CPU_SET(srvr_affinity, &cpu_set);
if (sched_setaffinity(0,
sizeof(cpu_set_t),
&cpu_set) != 0) {
fputs("KO\n", stdout);
mes("couldn't change server "
"CPU affinity");
fprintf(stdout,
"srvr_affinity = %d\n",
srvr_affinity);
fputs("KO\n", stdout);
goto cleanup;
}
#else
fputs("KO\n", stdout);
mes("server doesn't support setting "
"CPU affinity");
fprintf(stdout,
"srvr_affinity = %d\n",
srvr_affinity);
fputs("KO\n", stdout);
goto cleanup;
#endif
}
if (maxburst < 1) {
fputs("KO\n", stdout);
mes("invalid maxburst");
fprintf(stdout, "maxburst = %d\n",
maxburst);
fputs("KO\n", stdout);
goto cleanup;
}
if (do_jitter < 0) {
fputs("KO\n", stdout);
mes("invalid do_jitter");
fprintf(stdout, "do_jitter = %d\n",
do_jitter);
fputs("KO\n", stdout);
goto cleanup;
}
if (do_jitter && !udp) {
fputs("KO\n", stdout);
fprintf(stdout,
"jitter option"
" not supported for TCP\n");
fputs("KO\n", stdout);
goto cleanup;
}
if (do_jitter && (!rate || (rate == MAXRATE))) {
fputs("KO\n", stdout);
fprintf(stdout,
"jitter option not supported"
" for unlimited rate\n");
fputs("KO\n", stdout);
goto cleanup;
}
if (do_jitter && !irate) {
fputs("KO\n", stdout);
fprintf(stdout,
"jitter option requires"
" instantaneous rate limit\n");
fputs("KO\n", stdout);
goto cleanup;
}
if (do_owd < 0) {
fputs("KO\n", stdout);
mes("invalid do_owd");
fprintf(stdout, "do_owd = %d\n",
do_owd);
fputs("KO\n", stdout);
goto cleanup;
}
if (mc_addr) {
error_num = inet_pton(AF_INET, mc_addr,
&dummy);
#ifdef AF_INET6
if (error_num != 1)
error_num = inet_pton(AF_INET6,
mc_addr,
&dummy);
#endif
if (error_num != 1) {
fputs("KO\n", stdout);
mes("invalid multicast group");
fprintf(stdout, "multicast group = '%s'\n",
mc_addr);
fputs("KO\n", stdout);
goto cleanup;
}
}
/* used to send server "OK" here -
* now delay sending of server OK until
* after successful server bind() -
* catches data port collision */
if (udp && (interval ||
(do_jitter & JITTER_IGNORE_OOO)) &&
(buflen >= 32) && (irvers >= 30403))
udplossinfo = 1;
if (irvers >= 50401) {
two_bod = 1;
handle_urg = 1;
}
if (udp || (buflen < 32) || (irvers < 60001)) {
if (trans)
send_retrans = 0;
else
read_retrans = 0;
}
if (udp || (buflen < 32) || (irvers < 80001)) {
if (trans)
send_cwnd = 0;
else
read_cwnd = 0;
}
}
}
if (clientserver && client && (stream_idx == 1)) {
reading_srvr_info = 1;
pollfds[0].fd = fileno(ctlconn);
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 1");
flags |= O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 2");
itimer.it_value.tv_sec = SRVR_INFO_TIMEOUT;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
}
if (clientserver && client && (stream_idx == 1) &&
((pollst = poll(pollfds, 1, 0)) > 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI)) && !got_done) {
/* check for server output (mainly for server error) */
while (fgets(intervalbuf, sizeof(intervalbuf), stdin)) {
setitimer(ITIMER_REAL, &itimer, 0);
if (strncmp(intervalbuf, "DONE", 4) == 0) {
if (format & DEBUGPOLL) {
fprintf(stdout, "got DONE\n");
fflush(stdout);
}
got_done = 1;
intr = 1;
break;
}
else if (strncmp(intervalbuf,
"nuttcp-", 7) == 0) {
if ((brief <= 0) ||
strstr(intervalbuf, "Warning") ||
strstr(intervalbuf, "Error") ||
strstr(intervalbuf, "Debug")) {
if (*ident) {
fputs("nuttcp", stdout);
fputs(trans ?
"-r" : "-t",
stdout);
fputs(ident, stdout);
fputs(intervalbuf + 8,
stdout);
}
else
fputs(intervalbuf,
stdout);
fflush(stdout);
}
if (strstr(intervalbuf, "Error"))
exit(1);
}
else {
if (*ident)
fprintf(stdout, "%s: ",
ident + 1);
fputs(intervalbuf, stdout);
fflush(stdout);
}
}
}
if (clientserver && client && (stream_idx == 1)) {
reading_srvr_info = 0;
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 1");
flags &= ~O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 2");
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
}
if (!client) {
if (af == AF_INET) {
inet_ntop(af, &clientaddr.s_addr, hostbuf, sizeof(hostbuf));
}
#ifdef AF_INET6
else if (af == AF_INET6) {
inet_ntop(af, clientaddr6.s6_addr, hostbuf, sizeof(hostbuf));
}
#endif
host = hostbuf;
}
if (multilink && !client &&
((trans && !reverse) || (!trans && reverse)) &&
!udp && (stream_idx == 1)) {
nameinfo_flags = NI_NAMEREQD;
if (getnameinfo((struct sockaddr *)&client_ipaddr,
sizeof(struct in6_addr),
clientbuf, NI_MAXHOST,
NULL, 0,
nameinfo_flags) == 0) {
bzero(&hints, sizeof(hints));
res[0] = NULL;
res[1] = NULL;
hints.ai_family = af;
if (udp)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(clientbuf, NULL, &hints,
&res[1]) == 0) {
for ( i = 2; i <= nstream; i++ ) {
if (res[i - 1]->ai_next)
res[i] =
res[i - 1]->ai_next;
else
res[i] = res[1];
}
}
else {
if (res[1]) {
freeaddrinfo(res[1]);
res[1] = NULL;
}
multilink = 0;
}
}
else
multilink = 0;
}
if ((stream_idx > 0) && skip_data) {
if (clientserver && !client && (stream_idx == 1)) {
/* send server "OK" message */
fprintf(stdout, "OK v%d.%d.%d\n", vers_major,
vers_minor, vers_delta);
fflush(stdout);
}
break;
}
bzero((char *)&sinme[stream_idx], sizeof(sinme[stream_idx]));
bzero((char *)&sinhim[stream_idx], sizeof(sinhim[stream_idx]));
#ifdef AF_INET6
bzero((char *)&sinme6[stream_idx], sizeof(sinme6[stream_idx]));
bzero((char *)&sinhim6[stream_idx], sizeof(sinhim6[stream_idx]));
#endif
if (((trans && !reverse) && (stream_idx > 0)) ||
((!trans && reverse) && (stream_idx > 0)) ||
(client && (stream_idx == 0))) {
/* xmitr initiates connections (unless reversed) */
if (client) {
if (af == AF_INET) {
sinhim[stream_idx].sin_family = af;
if (ipad_stride.ip32 && (stream_idx > 1)) {
sinhim[stream_idx].sin_addr.s_addr =
sinhim[stream_idx - 1].sin_addr.s_addr
+ ipad_stride.ip32;
}
else {
bcopy((char *)&(((struct sockaddr_in *)res[stream_idx]->ai_addr)->sin_addr),
(char *)&sinhim[stream_idx].sin_addr.s_addr,
sizeof(sinhim[stream_idx].sin_addr.s_addr));
}
}
#ifdef AF_INET6
else if (af == AF_INET6) {
sinhim6[stream_idx].sin6_family = af;
bcopy((char *)&(((struct sockaddr_in6 *)res[stream_idx]->ai_addr)->sin6_addr),
(char *)&sinhim6[stream_idx].sin6_addr.s6_addr,
sizeof(sinhim6[stream_idx].sin6_addr.s6_addr));
sinhim6[stream_idx].sin6_scope_id = ((struct sockaddr_in6 *)res[stream_idx]->ai_addr)->sin6_scope_id;
}
#endif
else {
err("unsupported AF");
}
}
else {
sinhim[stream_idx].sin_family = af;
if (ipad_stride.ip32 && (stream_idx > 1)) {
sinhim[stream_idx].sin_addr.s_addr =
sinhim[stream_idx - 1].sin_addr.s_addr
+ ipad_stride.ip32;
}
else {
if (multilink && (stream_idx > 0))
sinhim[stream_idx].sin_addr =
((struct sockaddr_in *)res[stream_idx]->ai_addr)->sin_addr;
else
sinhim[stream_idx].sin_addr =
clientaddr;
}
#ifdef AF_INET6
sinhim6[stream_idx].sin6_family = af;
if (multilink && (stream_idx > 0))
sinhim6[stream_idx].sin6_addr =
((struct sockaddr_in6 *)res[stream_idx]->ai_addr)->sin6_addr;
else
sinhim6[stream_idx].sin6_addr =
clientaddr6;
sinhim6[stream_idx].sin6_scope_id = clientscope6;
#endif
}
if (stream_idx == 0) {
sinhim[stream_idx].sin_port = htons(ctlport);
sinme[stream_idx].sin_port = htons(srcctlport); /* default is free choice */
#ifdef AF_INET6
sinhim6[stream_idx].sin6_port = htons(ctlport);
sinme6[stream_idx].sin6_port = htons(srcctlport); /* default is free choice */
#endif
}
else {
sinhim[stream_idx].sin_port = htons(port + stream_idx - 1);
sinme[stream_idx].sin_port = htons(srcport); /* default is free choice */
#ifdef AF_INET6
sinhim6[stream_idx].sin6_port = htons(port + stream_idx - 1);
sinme6[stream_idx].sin6_port = htons(srcport); /* default is free choice */
#endif
}
}
else {
/* rcvr listens for connections (unless reversed) */
if (stream_idx == 0) {
sinme[stream_idx].sin_port = htons(ctlport);
sinhim[stream_idx].sin_port = htons(srcctlport); /* default is free choice */
#ifdef AF_INET6
sinme6[stream_idx].sin6_port = htons(ctlport);
sinhim6[stream_idx].sin6_port = htons(srcctlport); /* default is free choice */
#endif
}
else {
sinme[stream_idx].sin_port = htons(port + stream_idx - 1);
sinhim[stream_idx].sin_port = htons(srcport); /* default is free choice */
#ifdef AF_INET6
sinme6[stream_idx].sin6_port = htons(port + stream_idx - 1);
sinhim6[stream_idx].sin6_port = htons(srcport); /* default is free choice */
#endif
}
}
sinme[stream_idx].sin_family = af;
#ifdef AF_INET6
sinme6[stream_idx].sin6_family = af;
#endif
if ((fd[stream_idx] = socket(domain, (udp && (stream_idx != 0))?SOCK_DGRAM:SOCK_STREAM, 0)) < 0) {
if (clientserver && !client && (stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: socket() on data stream failed");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
err("socket");
}
if (setsockopt(fd[stream_idx], SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)) < 0) {
if (clientserver && !client && (stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: setsockopt()"
" to so_reuseaddr failed");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
err("setsockopt: so_reuseaddr");
}
#ifdef IPV6_V6ONLY
if ((af == AF_INET6) && explicitaf && !v4mapped) {
if (setsockopt(fd[stream_idx], IPPROTO_IPV6, IPV6_V6ONLY, (void *)&one, sizeof(int)) < 0) {
if (clientserver && !client &&
(stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: setsockopt()"
" to ipv6_only failed");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
err("setsockopt: ipv6_only");
}
}
#endif
if (af == AF_INET) {
if (bind(fd[stream_idx], (struct sockaddr *)&sinme[stream_idx], sizeof(sinme[stream_idx])) < 0) {
if (clientserver && !client && (stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: bind() on data stream failed");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
if (((!trans && !reverse)
|| (trans && reverse)) &&
(errno == EADDRINUSE) &&
(port == IPERF_PORT))
fputs("Info: Possible collision"
" with iperf server\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
if (clientserver && client && (stream_idx == 1) &&
((!trans && !reverse) || (trans && reverse)) &&
(errno == EADDRINUSE) && (port == IPERF_PORT)) {
errmes("bind");
fputs("Info: Possible collision"
" with iperf server\n", stderr);
fflush(stderr);
exit(1);
}
err("bind");
}
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if (bind(fd[stream_idx], (struct sockaddr *)&sinme6[stream_idx], sizeof(sinme6[stream_idx])) < 0) {
if (clientserver && !client && (stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: bind() on data stream failed");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
err("bind");
}
}
#endif
else {
if (clientserver && !client && (stream_idx == 1)) {
save_errno = errno;
fputs("KO\n", stdout);
mes("Error: unsupported AF on data stream");
fputs("Error: ", stdout);
fputs(strerror(save_errno), stdout);
fputs("\n", stdout);
fputs("KO\n", stdout);
goto cleanup;
}
err("unsupported AF");
}
if (clientserver && !client && (stream_idx == 1)) {
/* finally OK to send server "OK" message */
fprintf(stdout, "OK v%d.%d.%d\n", vers_major,
vers_minor, vers_delta);
fflush(stdout);
if ((trans && !reverse) || (!trans && reverse))
usleep(50000);
}
if (clientserver && (stream_idx == 1)) {
if (!udp && trans) {
nretrans[0] = get_retrans(fd[0], &tcpinf);
if ((retransinfo > 0) || cwndinfo)
b_flag = 1;
}
}
if (stream_idx == nstream) {
if (brief <= 0)
mes("socket");
#ifdef HAVE_SETPRIO
if (priority && (brief <= 0)) {
errno = 0;
priority = getpriority(PRIO_PROCESS, 0);
if (errno)
mes("couldn't get priority");
else {
if (format & PARSE)
fprintf(stdout,
"nuttcp%s%s: "
"priority=%d\n",
trans ? "-t" : "-r",
ident, priority);
else
fprintf(stdout,
"nuttcp%s%s: "
"priority = %d\n",
trans ? "-t" : "-r",
ident, priority);
}
}
#endif
#ifdef HAVE_SETAFFINITY
if ((affinity >= 0) && (brief <= 0) && !host3) {
int cpu_affinity;
errno = 0;
sched_getaffinity(0, sizeof(cpu_set_t),
&cpu_set);
if (errno)
mes("couldn't get affinity");
else {
for ( cpu_affinity = 0;
cpu_affinity < ncores;
cpu_affinity++ ) {
if (CPU_ISSET(cpu_affinity,
&cpu_set))
break;
}
if (format & PARSE)
fprintf(stdout,
"nuttcp%s%s: "
"cpu_affinity=%d\n",
trans ? "-t" : "-r",
ident, cpu_affinity);
else
fprintf(stdout,
"nuttcp%s%s: "
"affinity = CPU %d\n",
trans ? "-t" : "-r",
ident, cpu_affinity);
}
}
#endif
if (trans) {
if ((brief <= 0) && (format & PARSE)) {
fprintf(stdout, "nuttcp-t%s: buflen=%d ",
ident, buflen);
if (nbuf != INT_MAX)
fprintf(stdout, "nbuf=%llu ", nbuf);
fprintf(stdout, "nstream=%d port=%d",
nstream, port);
if (srcport)
fprintf(stdout, " srcport=%d", srcport);
fprintf(stdout, " mode=%s host=%s",
udp?"udp":"tcp",
host);
if (multicast)
fprintf(stdout, " multicast_ttl=%d",
multicast);
if (udp) {
char tmphost[ADDRSTRLEN] = "\0";
if (af == AF_INET) {
fprintf(stdout, " af=inet");
inet_ntop(af, &sinhim[stream_idx].sin_addr.s_addr,
tmphost, sizeof(tmphost));
if (client && (strcmp(host, tmphost) != 0))
fprintf(stdout, " ip=%s", tmphost);
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
inet_ntop(af, &sinhim6[stream_idx].sin6_addr.s6_addr,
tmphost, sizeof(tmphost));
if (client && (strcmp(host, tmphost) != 0))
fprintf(stdout, " ip=%s", tmphost);
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
}
fprintf(stdout, "\n");
if (timeout)
fprintf(stdout, "nuttcp-t%s: time_limit=%.2f\n",
ident, timeout);
if ((rate != MAXRATE) || tos)
fprintf(stdout, "nuttcp-t%s:", ident);
if (rate != MAXRATE) {
fprintf(stdout, " rate_limit=%.3f rate_unit=Mbps rate_mode=%s",
(double)rate/1000,
irate ? "instantaneous" : "aggregate");
if (iratesss)
fprintf(stdout, " smoothed_slow_start=on");
if (maxburst > 1)
fprintf(stdout, " packet_burst=%d",
maxburst);
if (udp) {
unsigned long long ppsrate =
((uint64_t)rate * 1000)/8/buflen;
fprintf(stdout, " pps_rate=%llu",
ppsrate);
}
}
if (tos)
fprintf(stdout, " tos=0x%X", tos);
if ((rate != MAXRATE) || tos)
fprintf(stdout, "\n");
}
else if (brief <= 0) {
fprintf(stdout, "nuttcp-t%s: buflen=%d, ",
ident, buflen);
if (nbuf != INT_MAX)
fprintf(stdout, "nbuf=%llu, ", nbuf);
fprintf(stdout, "nstream=%d, port=%d",
nstream, port);
if (srcport)
fprintf(stdout, ", srcport=%d", srcport);
fprintf(stdout, " %s -> %s",
udp?"udp":"tcp",
host);
if (multicast)
fprintf(stdout, " ttl=%d", multicast);
if (udp) {
char tmphost[ADDRSTRLEN] = "\0";
if (af == AF_INET) {
fprintf(stdout, " af=inet");
inet_ntop(af, &sinhim[stream_idx].sin_addr.s_addr,
tmphost, sizeof(tmphost));
if (client && (strcmp(host, tmphost) != 0))
fprintf(stdout, " ip=%s", tmphost);
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
inet_ntop(af, &sinhim6[stream_idx].sin6_addr.s6_addr,
tmphost, sizeof(tmphost));
if (client && (strcmp(host, tmphost) != 0))
fprintf(stdout, " ip=%s", tmphost);
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
}
fprintf(stdout, "\n");
if (timeout)
fprintf(stdout, "nuttcp-t%s: time limit = %.2f second%s\n",
ident, timeout,
(timeout == 1.0)?"":"s");
if ((rate != MAXRATE) || tos)
fprintf(stdout, "nuttcp-t%s:", ident);
if (rate != MAXRATE) {
fprintf(stdout, " rate limit = %.3f Mbps (%s)",
(double)rate/1000,
irate ? "instantaneous" : "aggregate");
if (iratesss)
fprintf(stdout, " with smoothed slow start");
if (maxburst > 1)
fprintf(stdout, ", packet burst = %d",
maxburst);
if (udp) {
unsigned long long ppsrate =
((uint64_t)rate * 1000)/8/buflen;
fprintf(stdout, ", %llu pps", ppsrate);
}
if (tos)
fprintf(stdout, ",");
}
if (tos)
fprintf(stdout, " tos = 0x%X", tos);
if ((rate != MAXRATE) || tos)
fprintf(stdout, "\n");
}
}
else {
if ((brief <= 0) && (format & PARSE)) {
fprintf(stdout, "nuttcp-r%s: buflen=%d ",
ident, buflen);
if (nbuf != INT_MAX)
fprintf(stdout, "nbuf=%llu ", nbuf);
fprintf(stdout, "nstream=%d port=%d",
nstream, port);
if (srcport)
fprintf(stdout, " srcport=%d", srcport);
fprintf(stdout, " mode=%s", udp ? "udp":"tcp");
if (udp) {
if (af == AF_INET) {
fprintf(stdout, " af=inet");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
}
fprintf(stdout, "\n");
if (tos)
fprintf(stdout, "nuttcp-r%s: tos=0x%X\n",
ident, tos);
if (interval)
fprintf(stdout, "nuttcp-r%s: reporting_interval=%.2f\n",
ident, interval);
}
else if (brief <= 0) {
fprintf(stdout, "nuttcp-r%s: buflen=%d, ",
ident, buflen);
if (nbuf != INT_MAX)
fprintf(stdout, "nbuf=%llu, ", nbuf);
fprintf(stdout, "nstream=%d, port=%d",
nstream, port);
if (srcport)
fprintf(stdout, ", srcport=%d", srcport);
fprintf(stdout, " %s", udp ? "udp":"tcp");
if (udp) {
if (af == AF_INET) {
fprintf(stdout, " af=inet");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
}
fprintf(stdout, "\n");
if (tos)
fprintf(stdout, "nuttcp-r%s: tos = 0x%X\n",
ident, tos);
if (interval)
fprintf(stdout, "nuttcp-r%s: interval reporting every %.2f second%s\n",
ident, interval,
(interval == 1.0)?"":"s");
}
}
}
if (stream_idx > 0) {
if (trans) {
/* Set the transmitter options */
if (sendwin) {
if (setsockopt(fd[stream_idx], SOL_SOCKET, SO_SNDBUF,
(void *)&sendwin, sizeof(sendwin)) < 0)
errmes("unable to setsockopt SO_SNDBUF");
if (braindead && (setsockopt(fd[stream_idx], SOL_SOCKET, SO_RCVBUF,
(void *)&rcvwin, sizeof(rcvwin)) < 0))
errmes("unable to setsockopt SO_RCVBUF");
}
if (tos) {
if (af == AF_INET) {
if (setsockopt(fd[stream_idx], IPPROTO_IP, IP_TOS,
(void *)&tos, sizeof(tos)) < 0)
err("setsockopt");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if (setsockopt(fd[stream_idx], IPPROTO_IPV6, IPV6_TCLASS,
(void *)&tos, sizeof(tos)) < 0)
err("setsockopt");
}
#endif
else {
err("unsupported AF");
}
}
if (nodelay && !udp) {
struct protoent *p;
p = getprotobyname("tcp");
if (p && setsockopt(fd[stream_idx], p->p_proto, TCP_NODELAY,
(void *)&one, sizeof(one)) < 0)
err("setsockopt: nodelay");
if ((stream_idx == nstream) && (brief <= 0))
mes("nodelay");
}
}
else {
/* Set the receiver options */
if (rcvwin) {
if (setsockopt(fd[stream_idx], SOL_SOCKET, SO_RCVBUF,
(void *)&rcvwin, sizeof(rcvwin)) < 0)
errmes("unable to setsockopt SO_RCVBUF");
if (braindead && (setsockopt(fd[stream_idx], SOL_SOCKET, SO_SNDBUF,
(void *)&sendwin, sizeof(sendwin)) < 0))
errmes("unable to setsockopt SO_SNDBUF");
}
if (tos) {
if (af == AF_INET) {
if (setsockopt(fd[stream_idx], IPPROTO_IP, IP_TOS,
(void *)&tos, sizeof(tos)) < 0)
err("setsockopt");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if (setsockopt(fd[stream_idx], IPPROTO_IPV6, IPV6_TCLASS,
(void *)&tos, sizeof(tos)) < 0)
err("setsockopt");
}
#endif
else {
err("unsupported AF");
}
}
}
}
if (!udp || (stream_idx == 0)) {
if (((trans && !reverse) && (stream_idx > 0)) ||
((!trans && reverse) && (stream_idx > 0)) ||
(client && (stream_idx == 0))) {
/* The transmitter initiates the connection
* (unless reversed by the flip option)
*/
if (options && (stream_idx > 0)) {
if (setsockopt(fd[stream_idx], SOL_SOCKET, options, (void *)&one, sizeof(one)) < 0)
errmes("unable to setsockopt options");
}
usleep(20000);
if (trans && (stream_idx > 0) && datamss) {
#if defined(__CYGWIN__) || defined(_WIN32)
if (format & PARSE)
fprintf(stderr, "nuttcp%s%s: Warning=\"setting_maximum_segment_size_not_supported_on_windows\"\n",
trans?"-t":"-r", ident);
else
fprintf(stderr, "nuttcp%s%s: Warning: setting maximum segment size not supported on windows\n",
trans?"-t":"-r", ident);
fflush(stderr);
#endif
optlen = sizeof(datamss);
if ((sockopterr = setsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, optlen)) < 0)
if (errno != EINVAL)
err("unable to set maximum segment size");
}
if (clientserver && !client && (stream_idx == 1)) {
/* check if client went away */
pollfds[0].fd = fileno(ctlconn);
save_events = pollfds[0].events;
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0) > 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI)))
goto cleanup;
pollfds[0].events = save_events;
}
num_connect_tries++;
if (stream_idx == 1)
get_timeofday(&timeconn1, (struct timezone *)0);
if (af == AF_INET) {
error_num = connect(fd[stream_idx], (struct sockaddr *)&sinhim[stream_idx], sizeof(sinhim[stream_idx]));
}
#ifdef AF_INET6
else if (af == AF_INET6) {
error_num = connect(fd[stream_idx], (struct sockaddr *)&sinhim6[stream_idx], sizeof(sinhim6[stream_idx]));
}
#endif
else {
err("unsupported AF");
}
if (error_num < 0) {
if (clientserver && client && (stream_idx == 0)
&& ((errno == ECONNREFUSED) ||
(errno == ECONNRESET))
&& (num_connect_tries <
MAX_CONNECT_TRIES)
&& retry_server) {
/* retry control connection to
* server for certain possibly
* transient errors */
usleep(SERVER_RETRY_USEC);
goto doit;
}
if (!trans && (stream_idx == 0))
err("connect");
if (stream_idx > 0) {
if (clientserver && !client) {
for ( i = 1; i <= stream_idx;
i++ )
close(fd[i]);
goto cleanup;
}
err("connect");
}
if (stream_idx == 0) {
clientserver = 0;
if (thirdparty) {
perror("3rd party connect failed");
fprintf(stderr, "3rd party nuttcp only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (interval) {
perror("connect failed");
fprintf(stderr, "interval option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (reverse) {
perror("connect failed");
fprintf(stderr, "flip option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (traceroute) {
perror("connect failed");
fprintf(stderr, "traceroute option only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (host3) {
perror("connect failed");
fprintf(stderr, "3rd party nuttcp only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (multicast) {
perror("connect failed");
fprintf(stderr, "multicast only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (udp) {
perror("connect failed");
fprintf(stderr, "UDP transfers only supported for client/server mode\n");
fflush(stderr);
exit(1);
}
if (format & PARSE) {
fprintf(stderr, "nuttcp%s%s: Info=\"attempting_to_switch_to_deprecated_classic_mode\"\n",
trans?"-t":"-r", ident);
fprintf(stderr, "nuttcp%s%s: Info=\"will_use_less_reliable_transmitter_side_statistics\"\n",
trans?"-t":"-r", ident);
}
else {
fprintf(stderr, "nuttcp%s%s: Info: attempting to switch to deprecated \"classic\" mode\n",
trans?"-t":"-r", ident);
fprintf(stderr, "nuttcp%s%s: Info: will use less reliable transmitter side statistics\n",
trans?"-t":"-r", ident);
}
fflush(stderr);
}
}
if (stream_idx == 1) {
get_timeofday(&timeconn2, (struct timezone *)0);
tvsub( &timeconn, &timeconn2, &timeconn1 );
rtt = timeconn.tv_sec*1000 +
((double)timeconn.tv_usec)/1000;
}
if (sockopterr && trans &&
(stream_idx > 0) && datamss) {
optlen = sizeof(datamss);
if ((sockopterr = setsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, optlen)) < 0) {
if (errno != EINVAL)
err("unable to set maximum segment size");
else
err("setting maximum segment size not supported on this OS");
}
}
if (stream_idx == nstream) {
optlen = sizeof(datamss);
if (getsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, &optlen) < 0)
err("get dataconn maximum segment size didn't work");
if (format & DEBUGMTU)
fprintf(stderr, "datamss = %d\n", datamss);
}
if ((stream_idx == nstream) && (brief <= 0)) {
char tmphost[ADDRSTRLEN] = "\0";
if (af == AF_INET) {
inet_ntop(af, &sinhim[stream_idx].sin_addr.s_addr, tmphost, sizeof(tmphost));
}
#ifdef AF_INET6
else if (af == AF_INET6) {
if (!IN6_IS_ADDR_V4MAPPED(&sinhim6[stream_idx].sin6_addr)) {
inet_ntop(af, sinhim6[stream_idx].sin6_addr.s6_addr, tmphost, sizeof(tmphost));
}
else {
af = AF_INET;
bcopy(((char *)&sinhim6[stream_idx].sin6_addr) + 12,
(char *)&sinhim[stream_idx].sin_addr,
sizeof(struct in_addr));
sinhim[stream_idx].sin_family = AF_INET;
// port gets put in both structs, no translate or copy needed
inet_ntop(af, &sinhim[stream_idx].sin_addr.s_addr, tmphost, sizeof(tmphost));
}
}
#endif
else {
err("unsupported AF");
}
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: connect=%s",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d",
datamss);
}
if (rtt)
fprintf(stdout, P_RTT_FMT, rtt);
}
else {
fprintf(stdout,
"nuttcp%s%s: connect to %s with",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d",
datamss);
if (rtt)
fprintf(stdout, ",");
}
if (rtt)
fprintf(stdout, RTT_FMT, rtt);
}
if (af == AF_INET) {
fprintf(stdout, " af=inet");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
fprintf(stdout, "\n");
}
}
else {
/* The receiver listens for the connection
* (unless reversed by the flip option)
*/
if (trans && (stream_idx > 0) && datamss) {
#if defined(__CYGWIN__) || defined(_WIN32)
if (format & PARSE)
fprintf(stderr, "nuttcp%s%s: Warning=\"setting_maximum_segment_size_not_supported_on_windows\"\n",
trans?"-t":"-r", ident);
else
fprintf(stderr, "nuttcp%s%s: Warning: setting maximum segment size not supported on windows\n",
trans?"-t":"-r", ident);
fflush(stderr);
#endif
optlen = sizeof(datamss);
if ((sockopterr = setsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, optlen)) < 0)
if (errno != EINVAL)
err("unable to set maximum segment size");
}
listen(fd[stream_idx], LISTEN_BACKLOG);
if (clientserver && !client && (stream_idx == 0)
&& !inetd && !nofork && !forked) {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0)
exit(0);
forked = 1;
if (sinkmode) {
close(0);
close(1);
close(2);
open("/dev/null", O_RDWR);
dup(0);
dup(0);
}
setsid();
}
if (options && (stream_idx > 0)) {
if (setsockopt(fd[stream_idx], SOL_SOCKET, options, (void *)&one, sizeof(one)) < 0)
errmes("unable to setsockopt options");
}
if (sockopterr && trans &&
(stream_idx > 0) && datamss) {
optlen = sizeof(datamss);
if ((sockopterr = setsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, optlen)) < 0)
if (errno != EINVAL)
err("unable to set maximum segment size");
}
if (clientserver && (stream_idx > 0)) {
sigact.sa_handler = ignore_alarm;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGALRM, &sigact, &savesigact);
alarm(ACCEPT_TIMEOUT);
}
acceptnewconn:
fromlen = sizeof(frominet);
nfd=accept(fd[stream_idx], (struct sockaddr *)&frominet, &fromlen);
save_errno = errno;
if (clientserver && (stream_idx > 0)) {
alarm(0);
sigact.sa_handler = savesigact.sa_handler;
sigact.sa_mask = savesigact.sa_mask;
sigact.sa_flags = savesigact.sa_flags;
sigaction(SIGALRM, &sigact, 0);
}
if (nfd < 0) {
/* check for interrupted system call - on
* server, close data streams, cleanup and
* try again - all other errors just die
*/
if ((save_errno == EINTR) && clientserver
&& (stream_idx > 0)) {
if (client) {
/* if client, just give nice
* error message and exit
*/
mes("Error: accept() timeout");
exit(1);
}
for ( i = 1; i <= stream_idx; i++ )
close(fd[i]);
goto cleanup;
}
err("accept");
}
if (clientserver && !client && (stream_idx == 0)
&& !inetd && !nofork
&& !single_threaded) {
/* multi-threaded manually started server */
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0) {
/* parent just waits for quick
* child exit */
while ((wait_pid = wait(&pidstat))
!= pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
/* and then accept()s another client
* connection */
close(nfd);
stream_idx = 0;
if (oneshot)
exit(0);
goto acceptnewconn;
}
/* child just makes a grandchild and then
* immediately exits (avoid zombie processes) */
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0)
exit(0);
/* grandkid does all the work */
oneshot = 1;
}
af = frominet.ss_family;
close(fd[stream_idx]);
fd[stream_idx]=nfd;
if (sockopterr && trans &&
(stream_idx > 0) && datamss) {
optlen = sizeof(datamss);
if ((sockopterr = setsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, optlen)) < 0) {
if (errno != EINVAL)
err("unable to set maximum segment size");
else
err("setting maximum segment size not supported on this OS");
}
}
if (stream_idx == nstream) {
optlen = sizeof(datamss);
if (getsockopt(fd[stream_idx], IPPROTO_TCP, TCP_MAXSEG, (void *)&datamss, &optlen) < 0)
err("get dataconn maximum segment size didn't work");
if (format & DEBUGMTU)
fprintf(stderr, "datamss = %d\n", datamss);
}
if (af == AF_INET) {
struct sockaddr_in peer;
socklen_t peerlen = sizeof(peer);
if (getpeername(fd[stream_idx],
(struct sockaddr *)&peer,
&peerlen) < 0) {
err("getpeername");
}
if ((stream_idx == nstream) && (brief <= 0)) {
char tmphost[ADDRSTRLEN] = "\0";
inet_ntop(af, &peer.sin_addr.s_addr, tmphost, sizeof(tmphost));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: accept=%s",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d",
datamss);
}
}
else {
fprintf(stdout,
"nuttcp%s%s: accept from %s with",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d,",
datamss);
}
}
if (af == AF_INET) {
fprintf(stdout, " af=inet");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
fprintf(stdout, "\n");
}
if (stream_idx == 0) {
clientaddr = peer.sin_addr;
client_ipaddr.ss.ss_family = AF_INET;
client_ipaddr.sin.sin_addr = clientaddr;
}
}
#ifdef AF_INET6
else if (af == AF_INET6) {
struct sockaddr_in6 peer6;
struct sockaddr_in peer4;
socklen_t peerlen = sizeof(peer6);
if (getpeername(fd[stream_idx],
(struct sockaddr *)&peer6,
&peerlen) < 0) {
err("getpeername");
}
if ((stream_idx == nstream) && (brief <= 0)) {
char tmphost[ADDRSTRLEN] = "\0";
if (!IN6_IS_ADDR_V4MAPPED(&peer6.sin6_addr)) {
inet_ntop(af, peer6.sin6_addr.s6_addr, tmphost, sizeof(tmphost));
}
else {
af = AF_INET;
bcopy(((char *)&peer6.sin6_addr.s6_addr) + 12,
(char *)&peer4.sin_addr.s_addr,
sizeof(struct in_addr));
peer4.sin_family = AF_INET;
peer4.sin_port = peer6.sin6_port;
inet_ntop(af, &peer4.sin_addr.s_addr, tmphost, sizeof(tmphost));
}
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: accept=%s",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d", datamss);
}
}
else {
fprintf(stdout,
"nuttcp%s%s: accept from %s with",
trans?"-t":"-r", ident,
tmphost);
if (trans && datamss) {
fprintf(stdout, " mss=%d,",
datamss);
}
}
if (af == AF_INET) {
fprintf(stdout, " af=inet");
}
#ifdef AF_INET6
else if (af == AF_INET6) {
fprintf(stdout, " af=inet6");
}
#endif
else {
fprintf(stdout, " af=%d", af);
}
fprintf(stdout, "\n");
}
if (stream_idx == 0) {
if (af == AF_INET6) { // we didnt fix a mapped v4 ip
clientaddr6 = peer6.sin6_addr;
clientscope6 = peer6.sin6_scope_id;
client_ipaddr.ss.ss_family = AF_INET6;
client_ipaddr.sin6.sin6_addr = clientaddr6;
}
else { // mapped so af is AF_INET
clientaddr = peer4.sin_addr;
client_ipaddr.ss.ss_family = AF_INET;
client_ipaddr.sin.sin_addr = clientaddr;
}
}
}
#endif
else {
err("unsupported AF");
}
}
}
if (!udp && trans && (stream_idx >= 1) && (retransinfo > 0)) {
if ((stream_idx == 1) || (retransinfo == 1)) {
nretrans[stream_idx] =
get_retrans(fd[stream_idx], &tcpinf);
iretrans[stream_idx] = nretrans[stream_idx];
#if defined(linux)
if (retransinfo == 1) {
cwnd[stream_idx] =
tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
if (stream_idx == 1) {
init_pkt_cwnd =
tcpinf.tcpinfo_snd_cwnd;
sss_pkt_cwnd = init_pkt_cwnd;
}
}
#endif
}
}
optlen = sizeof(sendwinval);
if (getsockopt(fd[stream_idx], SOL_SOCKET, SO_SNDBUF, (void *)&sendwinval, &optlen) < 0)
err("get send window size didn't work");
#if defined(linux)
sendwinval /= 2;
#endif
if ((stream_idx > 0) && sendwin && (trans || braindead) &&
(sendwinval < (0.98 * sendwin))) {
if (format & PARSE)
fprintf(stderr, "nuttcp%s%s: Warning=\"send_window_size_%d_<_requested_window_size_%d\"\n",
trans?"-t":"-r", ident,
sendwinval, sendwin);
else
fprintf(stderr, "nuttcp%s%s: Warning: send window size %d < requested window size %d\n",
trans?"-t":"-r", ident,
sendwinval, sendwin);
fflush(stderr);
}
optlen = sizeof(rcvwinval);
if (getsockopt(fd[stream_idx], SOL_SOCKET, SO_RCVBUF, (void *)&rcvwinval, &optlen) < 0)
err("Get recv window size didn't work");
#if defined(linux)
rcvwinval /= 2;
#endif
if ((stream_idx > 0) && rcvwin && (!trans || braindead) &&
(rcvwinval < (0.98 * rcvwin))) {
if (format & PARSE)
fprintf(stderr, "nuttcp%s%s: Warning=\"receive_window_size_%d_<_requested_window_size_%d\"\n",
trans?"-t":"-r", ident,
rcvwinval, rcvwin);
else
fprintf(stderr, "nuttcp%s%s: Warning: receive window size %d < requested window size %d\n",
trans?"-t":"-r", ident,
rcvwinval, rcvwin);
fflush(stderr);
}
if (firsttime) {
firsttime = 0;
origsendwin = sendwinval;
origrcvwin = rcvwinval;
}
if ((stream_idx == nstream) && (brief <= 0)) {
#if defined(linux)
FILE *adv_ws;
sendwinval *= 2;
rcvwinval *= 2;
if ((adv_ws = fopen(TCP_ADV_WIN_SCALE, "r"))) {
if (fscanf(adv_ws, "%d", &winadjust) <= 0)
winadjust = 2;
fclose(adv_ws);
}
else {
winadjust = 2;
}
if (winadjust < 0) {
sendwinavail = sendwinval >> -winadjust;
rcvwinavail = rcvwinval >> -winadjust;
}
else if (winadjust > 0) {
sendwinavail = sendwinval -
(sendwinval >> winadjust);
rcvwinavail = rcvwinval -
(rcvwinval >> winadjust);
}
#endif
if (format & PARSE)
fprintf(stdout, "nuttcp%s%s: send_window_size=%d receive_window_size=%d\n", trans?"-t":"-r", ident, sendwinval, rcvwinval);
else
fprintf(stdout, "nuttcp%s%s: send window size = %d, receive window size = %d\n", trans?"-t":"-r", ident, sendwinval, rcvwinval);
#if defined(linux)
if (format & PARSE)
fprintf(stdout, "nuttcp%s%s: send_window_avail=%d receive_window_avail=%d\n", trans?"-t":"-r", ident, sendwinavail, rcvwinavail);
else
fprintf(stdout, "nuttcp%s%s: available send window = %d, available receive window = %d\n", trans?"-t":"-r", ident, sendwinavail, rcvwinavail);
if (!udp && trans && init_pkt_cwnd) {
if (format & PARSE)
fprintf(stdout, "nuttcp%s%s: initial_congestion_window_kb=%d initial_congestion_window_pkt=%d\n", trans?"-t":"-r", ident, init_pkt_cwnd*datamss/1024, init_pkt_cwnd);
else
fprintf(stdout, "nuttcp%s%s: initial congestion window = %d KB (%d packets)\n", trans?"-t":"-r", ident, init_pkt_cwnd*datamss/1024, init_pkt_cwnd);
}
#endif
}
}
if (abortconn)
exit(1);
if (host3 && clientserver) {
char path[64];
char *cmd;
fflush(stdout);
fflush(stderr);
cmd = nut_cmd;
if (client) {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid == 0) {
if (interval) {
itimer.it_value.tv_sec = interval;
}
else if (timeout) {
itimer.it_value.tv_sec = timeout;
}
else {
if (rate != MAXRATE)
itimer.it_value.tv_sec =
(double)(2*nbuf*buflen)
/rate/125;
else
itimer.it_value.tv_sec =
(double)(nbuf*buflen)
/LOW_RATE_HOST3/125;
if (itimer.it_value.tv_sec < 7200)
itimer.it_value.tv_sec = 7200;
}
itimer.it_value.tv_sec +=
idle_data_max < SRVR_INFO_TIMEOUT ?
SRVR_INFO_TIMEOUT : idle_data_max;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
while (fgets(linebuf, sizeof(linebuf),
stdin) && !intr) {
setitimer(ITIMER_REAL, &itimer, 0);
if (strncmp(linebuf, "DONE", 4)
== 0)
exit(0);
if (*ident && (*linebuf != '\n'))
fprintf(stdout, "%s: ",
ident + 1);
fputs(linebuf, stdout);
fflush(stdout);
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
exit(0);
}
signal(SIGINT, SIG_IGN);
while ((wait_pid = wait(&pidstat)) != pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
exit(0);
}
else {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0) {
sigact.sa_handler = &sigalarm;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGALRM, &sigact, 0);
alarm(10);
while ((wait_pid = wait(&pidstat))
!= pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
if (errno == EINTR) {
pollfds[0].fd =
fileno(ctlconn);
pollfds[0].events =
POLLIN | POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0)
> 0)
&& (pollfds[0].revents &
(POLLIN | POLLPRI))) {
kill(pid,
SIGINT);
sleep(1);
kill(pid,
SIGINT);
continue;
}
sigact.sa_handler =
&sigalarm;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGALRM,
&sigact, 0);
alarm(10);
continue;
}
err("wait failed");
}
}
fprintf(stdout, "DONE\n");
fflush(stdout);
goto cleanup;
}
close(2);
dup(1);
i = 0;
j = 0;
cmdargs[i++] = cmd;
cmdargs[i++] = "-3";
if (af3) {
if (af3 == 4)
cmdargs[i++] = "-4";
if (af3 == 6)
cmdargs[i++] = "-6";
}
if (ctlport3) {
sprintf(tmpargs[j], "-P%hu", ctlport3);
cmdargs[i++] = tmpargs[j++];
}
else {
if (pass_ctlport) {
sprintf(tmpargs[j], "-P%hu", ctlport);
cmdargs[i++] = tmpargs[j++];
}
}
if (affinity >= 0) {
sprintf(tmpargs[j], "-xc%d", affinity);
cmdargs[i++] = tmpargs[j++];
}
if (srvr_affinity >= 0) {
sprintf(tmpargs[j], "-xcs%d", srvr_affinity);
cmdargs[i++] = tmpargs[j++];
}
if (irvers < 50302) {
if ((udp && !multicast
&& (buflen != DEFAULTUDPBUFLEN)) ||
(udp && multicast
&& (buflen != DEFAULT_MC_UDPBUFLEN)) ||
(!udp && (buflen != 65536))) {
sprintf(tmpargs[j], "-l%d", buflen);
cmdargs[i++] = tmpargs[j++];
}
}
else if (buflen) {
sprintf(tmpargs[j], "-l%d", buflen);
cmdargs[i++] = tmpargs[j++];
}
if (nbuf != INT_MAX) {
if (nbuf_bytes)
sprintf(tmpargs[j], "-n%llub", nbuf);
else
sprintf(tmpargs[j], "-n%llu", nbuf);
cmdargs[i++] = tmpargs[j++];
}
if (brief3 != 1) {
sprintf(tmpargs[j], "-b%d", brief3);
cmdargs[i++] = tmpargs[j++];
}
if (sendwin) {
sprintf(tmpargs[j], "-w%d", sendwin/1024);
cmdargs[i++] = tmpargs[j++];
}
if (nstream != 1) {
sprintf(tmpargs[j], "-N%d%s", nstream,
multilink ? "m" : "");
cmdargs[i++] = tmpargs[j++];
}
if (rate != MAXRATE) {
if (maxburst > 1) {
if (rate_pps)
sprintf(tmpargs[j],
"-R%s%lup/%d",
irate ? "i" : "",
rate, maxburst);
else
sprintf(tmpargs[j],
"-R%s%lu/%d",
irate ? "i" : "",
rate, maxburst);
}
else {
if (rate_pps)
sprintf(tmpargs[j],
"-R%s%s%lup",
irate ? "i" : "",
iratesss ? "s" : "",
rate);
else
sprintf(tmpargs[j],
"-R%s%s%lu",
irate ? "i" : "",
iratesss ? "s" : "",
rate);
}
cmdargs[i++] = tmpargs[j++];
}
else {
if (udp && !multicast)
cmdargs[i++] = "-R0";
}
if (srcport) {
sprintf(tmpargs[j], "-p%hu:%hu", srcport, port);
cmdargs[i++] = tmpargs[j++];
}
else if (port != DEFAULT_PORT) {
sprintf(tmpargs[j], "-p%hu", port);
cmdargs[i++] = tmpargs[j++];
}
if (trans)
cmdargs[i++] = "-r";
if (braindead)
cmdargs[i++] = "-wb";
if (timeout && (timeout != DEFAULT_TIMEOUT)) {
sprintf(tmpargs[j], "-T%f", timeout);
cmdargs[i++] = tmpargs[j++];
}
if (udp) {
if (multicast) {
if (ssm == 1)
sprintf(tmpargs[j], "-ms%d",
multicast);
else if (ssm == 0)
sprintf(tmpargs[j], "-ma%d",
multicast);
else
sprintf(tmpargs[j], "-m%d",
multicast);
cmdargs[i++] = tmpargs[j++];
if (mc_addr) {
sprintf(tmpargs[j], "-g%s",
mc_addr);
cmdargs[i++] = tmpargs[j++];
}
}
else
cmdargs[i++] = "-u";
}
if (do_jitter) {
cmdargs[i++] = "-j";
}
if (do_owd) {
cmdargs[i++] = "-o";
}
if (interval) {
sprintf(tmpargs[j], "-i%f", interval);
cmdargs[i++] = tmpargs[j++];
}
if (reverse)
cmdargs[i++] = "-F";
if (format) {
if (format & XMITSTATS)
cmdargs[i++] = "-fxmitstats";
if (format & RUNNINGTOTAL)
cmdargs[i++] = "-frunningtotal";
if (format & NOPERCENTLOSS)
cmdargs[i++] = "-f-percentloss";
if (format & NODROPS)
cmdargs[i++] = "-f-drops";
if (format & NORETRANS)
cmdargs[i++] = "-f-retrans";
if (!(format & NORETRANS) && (format & NOCWND))
cmdargs[i++] = "-f-cwnd";
if (format & PARSE)
cmdargs[i++] = "-fparse";
}
else {
cmdargs[i++] = "-f-rtt";
}
if (traceroute)
cmdargs[i++] = "-xt";
if (datamss) {
sprintf(tmpargs[j], "-M%d", datamss);
cmdargs[i++] = tmpargs[j++];
}
if (tos) {
sprintf(tmpargs[j], "-c0x%Xt", tos);
cmdargs[i++] = tmpargs[j++];
}
if (nodelay)
cmdargs[i++] = "-D";
if (ipad_stride.ip32) {
sprintf(tmpargs[j], "%s+%d", host3,
ipad_stride.ip32);
cmdargs[i++] = tmpargs[j++];
}
else
cmdargs[i++] = host3;
cmdargs[i] = NULL;
execvp(cmd, cmdargs);
if (errno == ENOENT) {
strcpy(path, "/usr/local/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/local/bin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/etc/");
strcat(path, cmd);
execv(path, cmdargs);
}
if ((errno == ENOENT) && (getuid() != 0)
&& (geteuid() != 0)) {
strcpy(path, "./");
strcat(path, cmd);
execv(path, cmdargs);
}
perror("execvp failed");
fprintf(stderr, "failed to execute %s\n", cmd);
fflush(stdout);
fflush(stderr);
if (!inetd)
exit(0);
goto cleanup;
}
}
if (traceroute && clientserver) {
char path[64];
char *cmd;
fflush(stdout);
fflush(stderr);
if (multicast) {
cmd = "mtrace";
#ifdef AF_INET6
if (af == AF_INET6)
cmd = "mtrace6";
#endif
}
else {
cmd = "traceroute";
#ifdef AF_INET6
if (af == AF_INET6)
cmd = "traceroute6";
#endif
}
if (client) {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0) {
while ((wait_pid = wait(&pidstat)) != pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
fflush(stdout);
}
else {
signal(SIGINT, SIG_DFL);
close(2);
dup(1);
i = 0;
cmdargs[i++] = cmd;
cmdargs[i++] = host;
cmdargs[i] = NULL;
execvp(cmd, cmdargs);
if (errno == ENOENT) {
strcpy(path, "/usr/local/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/local/bin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/etc/");
strcat(path, cmd);
execv(path, cmdargs);
}
perror("execvp failed");
fprintf(stderr, "failed to execute %s\n", cmd);
fflush(stdout);
fflush(stderr);
exit(0);
}
}
fprintf(stdout, "\n");
if (intr) {
intr = 0;
fprintf(stdout, "\n");
signal(SIGINT, sigint);
}
if (!skip_data) {
for ( stream_idx = 1; stream_idx <= nstream;
stream_idx++ )
close(fd[stream_idx]);
}
if (client) {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid == 0) {
while (fgets(linebuf, sizeof(linebuf),
stdin) && !intr) {
if (strncmp(linebuf, "DONE", 4)
== 0)
exit(0);
fputs(linebuf, stdout);
fflush(stdout);
}
exit(0);
}
signal(SIGINT, SIG_IGN);
while ((wait_pid = wait(&pidstat)) != pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
exit(0);
}
else {
if (!inetd) {
if ((pid = fork()) == (pid_t)-1)
err("can't fork");
if (pid != 0) {
while ((wait_pid = wait(&pidstat))
!= pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
fprintf(stdout, "DONE\n");
fflush(stdout);
goto cleanup;
}
}
close(2);
dup(1);
i = 0;
cmdargs[i++] = cmd;
cmdargs[i++] = host;
cmdargs[i] = NULL;
execvp(cmd, cmdargs);
if (errno == ENOENT) {
strcpy(path, "/usr/local/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/local/bin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/sbin/");
strcat(path, cmd);
execv(path, cmdargs);
}
if (errno == ENOENT) {
strcpy(path, "/usr/etc/");
strcat(path, cmd);
execv(path, cmdargs);
}
perror("execvp failed");
fprintf(stderr, "failed to execute %s\n", cmd);
fflush(stdout);
fflush(stderr);
if (!inetd)
exit(0);
goto cleanup;
}
}
if (multicast) {
struct sockaddr_in peer;
socklen_t peerlen = sizeof(peer);
struct sockaddr_in me;
socklen_t melen = sizeof(me);
#ifdef AF_INET6
struct sockaddr_in6 peer6;
socklen_t peer6len = sizeof(peer6);
struct sockaddr_in6 me6;
socklen_t me6len = sizeof(me6);
#endif
if (mc_addr && !client) {
bzero(&hints, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
if (udp)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
mcres = NULL;
error_num = getaddrinfo(mc_addr, NULL, &hints, &mcres);
if (error_num) {
sprintf(tmpbuf, "getaddrinfo: "
"bad multicast IP address: "
"%s: %s",
mc_addr, gai_strerror(error_num));
errno = EINVAL;
err(tmpbuf);
}
if (mcres->ai_family == AF_INET) {
struct sockaddr_in *group;
struct in_addr ipv4_mcaddr;
group = (struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)&(group->sin_addr),
(char *)&ipv4_mcaddr,
sizeof(struct in_addr));
if (ssm) {
if (((htonl(ipv4_mcaddr.s_addr)
& 0xFF000000) !=
(HI_MC_SSM << 24))) {
sprintf(tmpbuf,
"bad SSM multicast "
"IP address: %s: "
"use 232.x.y.z",
mcgaddr);
errno = EINVAL;
err(tmpbuf);
}
}
else {
if (((htonl(ipv4_mcaddr.s_addr)
& 0xFF000000) !=
(HI_MC << 24))) {
sprintf(tmpbuf,
"bad ASM multicast "
"IP address: %s: "
"use 231.x.y.z",
mcgaddr);
errno = EINVAL;
err(tmpbuf);
}
}
}
#ifdef AF_INET6
if (mcres->ai_family == AF_INET6) {
struct sockaddr_in6 *group;
group = (struct sockaddr_in6 *)mcres->ai_addr;
if (ssm) {
if ((bcmp((char *)&(group->sin6_addr),
(char *)&hi_mc6,
HI_MC6_LEN - 1) != 0) ||
(group->sin6_addr.s6_addr[HI_MC6_LEN - 1]
< 0x80)) {
sprintf(tmpbuf,
"bad SSM multicast "
"IP address: %s: use "
"ff3e::[8-f]xxx:yyyy",
mcgaddr);
errno = EINVAL;
err(tmpbuf);
}
}
else {
if ((bcmp((char *)&(group->sin6_addr),
(char *)&hi_mc6_asm,
HI_MC6_ASM_LEN) != 0)) {
sprintf(tmpbuf,
"bad ASM multicast "
"IP address: %s: use "
"ff2e::wwww:xxxx:"
"yyyy:zzzz",
mcgaddr);
errno = EINVAL;
err(tmpbuf);
}
}
}
#endif
mc_af = mcres->ai_family;
}
if (mc_af == AF_INET) {
if (getpeername(fd[0], (struct sockaddr *)&peer,
&peerlen) < 0) {
err("getpeername");
}
if (getsockname(fd[0], (struct sockaddr *)&me,
&melen) < 0) {
err("getsockname");
}
}
#ifdef AF_INET6
else if (mc_af == AF_INET6) {
if (getpeername(fd[0], (struct sockaddr *)&peer6,
&peer6len) < 0) {
err("getpeername");
}
if (getsockname(fd[0], (struct sockaddr *)&me6,
&me6len) < 0) {
err("getsockname");
}
}
#endif /* AF_INET6 */
else {
err("unsupported AF");
}
if (!trans) {
if ((mc_af == AF_INET) && !ssm) { /* IPv4 ASM */
/* The multicast receiver must join the mc group */
if (mc_addr) {
struct sockaddr_in *user_group;
user_group =
(struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)&(user_group->sin_addr.s_addr),
(char *)&mc_group.imr_multiaddr.s_addr,
sizeof(struct in_addr));
}
else if (client && (irvers >= 50505)) {
bcopy((char *)&me.sin_addr.s_addr,
(char *)&mc_group.imr_multiaddr.s_addr,
sizeof(struct in_addr));
}
else {
bcopy((char *)&peer.sin_addr.s_addr,
(char *)&mc_group.imr_multiaddr.s_addr,
sizeof(struct in_addr));
}
if (!mc_addr) {
mc_group.imr_multiaddr.s_addr &=
htonl(0xFFFFFF);
mc_group.imr_multiaddr.s_addr |=
htonl(HI_MC << 24);
}
if (setsockopt(fd[1], IPPROTO_IP, IP_ADD_MEMBERSHIP,
(void *)&mc_group, sizeof(mc_group)) < 0)
err("setsockopt: IP_ADD_MEMBERSHIP");
if (brief <= 0) {
inet_ntop(mc_af, &peer.sin_addr.s_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &mc_group.imr_multiaddr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=0\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: receive from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using asm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#ifdef AF_INET6
else if ((mc_af == AF_INET6) && !ssm) { /* IPv6 ASM */
/* The multicast receiver must join the mc group */
if (mc_addr) {
struct sockaddr_in6 *user_group;
user_group =
(struct sockaddr_in6 *)mcres->ai_addr;
bcopy((char *)&(user_group->sin6_addr),
(char *)&mc6_group.ipv6mr_multiaddr,
sizeof(struct in6_addr));
}
else if (client) {
bcopy((char *)&me6.sin6_addr,
(char *)&mc6_group.ipv6mr_multiaddr,
sizeof(struct in6_addr));
}
else {
bcopy((char *)&peer6.sin6_addr,
(char *)&mc6_group.ipv6mr_multiaddr,
sizeof(struct in6_addr));
}
if (!mc_addr) {
bcopy((char *)&hi_mc6_asm,
(char *)&mc6_group.ipv6mr_multiaddr,
HI_MC6_ASM_LEN);
}
if (setsockopt(fd[1], IPPROTO_IPV6, IPV6_JOIN_GROUP,
(void *)&mc6_group,
sizeof(mc6_group)) < 0)
err("setsockopt: IPV6_JOIN_GROUP");
if (brief <= 0) {
inet_ntop(mc_af, &peer6.sin6_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &mc6_group.ipv6mr_multiaddr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=0\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: receive from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using asm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#endif /* AF_INET6 */
#ifdef MCAST_JOIN_SOURCE_GROUP
else if ((mc_af == AF_INET) && ssm) { /* IPv4 SSM */
/* multicast receiver joins the mc source group */
union sockaddr_union group_ipaddr;
struct sockaddr_in *group;
struct sockaddr_in *source;
group = &group_ipaddr.sin;
source =
(struct sockaddr_in *)&group_source_req.gsr_source;
group_source_req.gsr_interface = 0; /* any interface */
if (mc_addr) {
struct sockaddr_in *user_group;
user_group =
(struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)user_group, (char *)group,
sizeof(struct sockaddr_in));
}
else if (client) {
bcopy((char *)&me, (char *)group,
sizeof(struct sockaddr_in));
}
else {
bcopy((char *)&peer, (char *)group,
sizeof(struct sockaddr_in));
}
bcopy((char *)&peer, (char *)source,
sizeof(struct sockaddr_in));
if (!mc_addr) {
group->sin_addr.s_addr &= htonl(0xFFFFFF);
group->sin_addr.s_addr |=
htonl(HI_MC_SSM << 24);
}
group_source_req.gsr_group = group_ipaddr.ss;
if (setsockopt(fd[1], IPPROTO_IP,
MCAST_JOIN_SOURCE_GROUP,
&group_source_req,
sizeof(group_source_req)) < 0)
err("setsockopt: MCAST_JOIN_SOURCE_GROUP");
if (brief <= 0) {
inet_ntop(mc_af, &source->sin_addr.s_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &group->sin_addr.s_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=1\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: receive from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using ssm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#ifdef AF_INET6
else if ((mc_af == AF_INET6) && ssm) { /* IPv6 SSM */
/* multicast receiver joins the mc source group */
struct sockaddr_in6 *group;
struct sockaddr_in6 *source;
group =
(struct sockaddr_in6 *)&group_source_req.gsr_group;
source =
(struct sockaddr_in6 *)&group_source_req.gsr_source;
group_source_req.gsr_interface = 0; /* any interface */
if (mc_addr) {
struct sockaddr_in6 *user_group;
user_group =
(struct sockaddr_in6 *)mcres->ai_addr;
bcopy((char *)user_group, (char *)group,
sizeof(struct sockaddr_in6));
}
else if (client) {
bcopy((char *)&me6, (char *)group,
sizeof(struct sockaddr_in6));
}
else {
bcopy((char *)&peer6, (char *)group,
sizeof(struct sockaddr_in6));
}
bcopy((char *)&peer6, (char *)source,
sizeof(struct sockaddr_in6));
if (!mc_addr) {
bcopy((char *)&hi_mc6,
(char *)&group->sin6_addr,
HI_MC6_LEN);
}
if (setsockopt(fd[1], IPPROTO_IPV6,
MCAST_JOIN_SOURCE_GROUP,
&group_source_req,
sizeof(group_source_req)) < 0)
err("setsockopt: MCAST_JOIN_SOURCE_GROUP");
if (brief <= 0) {
inet_ntop(mc_af, &source->sin6_addr.s6_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &group->sin6_addr.s6_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=1\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: receive from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using ssm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#endif /* AF_INET6 */
#endif /* MCAST_JOIN_SOURCE_GROUP */
else {
err("unsupported AF");
}
}
else { /* trans */
if (mc_af == AF_INET) {
bcopy((char *)&sinhim[1].sin_addr.s_addr,
(char *)&save_sinhim.sin_addr.s_addr,
sizeof(struct in_addr));
}
#ifdef AF_INET6
else if (mc_af == AF_INET6) {
bcopy((char *)&sinhim6[1], (char *)&save_sinhim6,
sizeof(struct sockaddr_in6));
}
#endif
if ((mc_af == AF_INET) && !ssm) { /* IPv4 ASM */
/* The multicast transmitter just sends to mc group */
if (mc_addr) {
struct sockaddr_in *user_group;
user_group =
(struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)&(user_group->sin_addr.s_addr),
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
else if (client || (irvers < 50505)) {
bcopy((char *)&me.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
else {
bcopy((char *)&peer.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
if (!mc_addr) {
sinhim[1].sin_addr.s_addr &= htonl(0xFFFFFF);
sinhim[1].sin_addr.s_addr |= htonl(HI_MC << 24);
}
if (setsockopt(fd[1], IPPROTO_IP, IP_MULTICAST_TTL,
(void *)&multicast,
sizeof(multicast)) < 0)
err("setsockopt: IP_MULTICAST_TTL");
if (brief <= 0) {
inet_ntop(mc_af, &me.sin_addr.s_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &sinhim[1].sin_addr.s_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=0\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: sending from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using asm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#ifdef AF_INET6
else if ((mc_af == AF_INET6) && !ssm) { /* IPv6 ASM */
/* The multicast transmitter just sends to mc group */
if (mc_addr) {
struct sockaddr_in6 *user_group;
user_group =
(struct sockaddr_in6 *)mcres->ai_addr;
bcopy((char *)&(user_group->sin6_addr),
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
else if (client) {
bcopy((char *)&me6.sin6_addr,
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
else {
bcopy((char *)&peer6.sin6_addr,
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
if (!mc_addr) {
bcopy((char *)&hi_mc6_asm,
(char *)&sinhim6[1].sin6_addr,
HI_MC6_ASM_LEN);
}
if (setsockopt(fd[1], IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
(void *)&multicast,
sizeof(multicast)) < 0)
err("setsockopt: IPV6_MULTICAST_HOPS");
if (brief <= 0) {
inet_ntop(mc_af, &me6.sin6_addr.s6_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &sinhim6[1].sin6_addr.s6_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=0\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: sending from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using asm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#endif /* AF_INET6 */
#ifdef MCAST_JOIN_SOURCE_GROUP
else if ((mc_af == AF_INET) && ssm) { /* IPv4 SSM */
/* The multicast transmitter just sends to mc group */
if (mc_addr) {
struct sockaddr_in *user_group;
user_group =
(struct sockaddr_in *)mcres->ai_addr;
bcopy((char *)&(user_group->sin_addr.s_addr),
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
else if (client) {
bcopy((char *)&me.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
else {
bcopy((char *)&peer.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
if (!mc_addr) {
sinhim[1].sin_addr.s_addr &= htonl(0xFFFFFF);
sinhim[1].sin_addr.s_addr |=
htonl(HI_MC_SSM << 24);
}
if (setsockopt(fd[1], IPPROTO_IP, IP_MULTICAST_TTL,
(void *)&multicast,
sizeof(multicast)) < 0)
err("setsockopt: IP_MULTICAST_TTL");
if (brief <= 0) {
inet_ntop(mc_af, &me.sin_addr.s_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &sinhim[1].sin_addr.s_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=1\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: sending from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using ssm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#ifdef AF_INET6
else if ((mc_af == AF_INET6) && ssm) { /* IPv6 SSM */
/* The multicast transmitter just sends to mc group */
if (mc_addr) {
struct sockaddr_in6 *user_group;
user_group =
(struct sockaddr_in6 *)mcres->ai_addr;
bcopy((char *)&(user_group->sin6_addr),
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
else if (client) {
bcopy((char *)&me6.sin6_addr,
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
else {
bcopy((char *)&peer6.sin6_addr,
(char *)&sinhim6[1].sin6_addr,
sizeof(struct in6_addr));
}
if (!mc_addr) {
bcopy((char *)&hi_mc6,
(char *)&sinhim6[1].sin6_addr,
HI_MC6_LEN);
}
if (setsockopt(fd[1], IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
(void *)&multicast,
sizeof(multicast)) < 0)
err("setsockopt: IPV6_MULTICAST_HOPS");
if (brief <= 0) {
inet_ntop(mc_af, &me6.sin6_addr.s6_addr,
multsrc, sizeof(multsrc));
inet_ntop(mc_af, &sinhim6[1].sin6_addr.s6_addr,
multaddr, sizeof(multaddr));
if (format & PARSE) {
fprintf(stdout,
"nuttcp%s%s: multicast_source=%s multicast_group=%s ssm=1\n",
trans?"-t":"-r", ident,
multsrc, multaddr);
}
else {
fprintf(stdout,
"nuttcp%s%s: sending from multicast source %s\n",
trans?"-t":"-r", ident,
multsrc);
fprintf(stdout,
"nuttcp%s%s: using ssm on multicast group %s\n",
trans?"-t":"-r", ident,
multaddr);
}
}
}
#endif /* AF_INET6 */
#endif /* MCAST_JOIN_SOURCE_GROUP */
else {
err("unsupported AF");
}
}
if (mcres) {
freeaddrinfo(mcres);
mcres = NULL;
}
}
if (trans && timeout) {
itimer.it_value.tv_sec = timeout;
itimer.it_value.tv_usec =
(timeout - itimer.it_value.tv_sec)*1000000;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
signal(SIGALRM, sigalarm);
if (!udp)
setitimer(ITIMER_REAL, &itimer, 0);
}
else if (!trans && interval) {
sigact.sa_handler = &sigalarm;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_RESTART;
sigaction(SIGALRM, &sigact, 0);
itimer.it_value.tv_sec = interval;
itimer.it_value.tv_usec =
(interval - itimer.it_value.tv_sec)*1000000;
itimer.it_interval.tv_sec = interval;
itimer.it_interval.tv_usec =
(interval - itimer.it_interval.tv_sec)*1000000;
setitimer(ITIMER_REAL, &itimer, 0);
if (clientserver) {
chk_idle_data = (interval < idle_data_min) ?
idle_data_min : interval;
chk_idle_data = (chk_idle_data > idle_data_max) ?
idle_data_max : chk_idle_data;
}
}
else if (clientserver && !trans) {
sigact.sa_handler = &sigalarm;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = SA_RESTART;
sigaction(SIGALRM, &sigact, 0);
if (timeout) {
chk_idle_data = timeout/2;
}
else {
if (rate != MAXRATE)
chk_idle_data = (double)(nbuf*buflen)
/rate/125/2;
else
chk_idle_data = default_idle_data;
}
chk_idle_data = (chk_idle_data < idle_data_min) ?
idle_data_min : chk_idle_data;
chk_idle_data = (chk_idle_data > idle_data_max) ?
idle_data_max : chk_idle_data;
itimer.it_value.tv_sec = chk_idle_data;
itimer.it_value.tv_usec =
(chk_idle_data - itimer.it_value.tv_sec)
*1000000;
itimer.it_interval.tv_sec = chk_idle_data;
itimer.it_interval.tv_usec =
(chk_idle_data - itimer.it_interval.tv_sec)
*1000000;
setitimer(ITIMER_REAL, &itimer, 0);
}
if (interval && clientserver && client && trans)
do_poll = 1;
if (irate) {
pkt_time = (double)buflen/rate/125;
irate_pk_usec = pkt_time*1000000;
irate_pk_nsec = (pkt_time*1000000 - irate_pk_usec)*1000;
pkt_time_ms = pkt_time*1000;
}
#ifdef DEBUG
if (irate && (format & DEBUGIRATE)) {
debugout = fopen(DEBUGOUTPUT, "a+");
if (debugout)
fprintf(debugout, "BEGIN nuttcp debug output\n");
}
#endif
prep_timer();
errno = 0;
stream_idx = 0;
ocorrection = 0;
correction = 0.0;
if (do_poll) {
long flags;
pollfds[0].fd = fileno(ctlconn);
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
for ( i = 1; i <= nstream; i++ ) {
pollfds[i].fd = fd[i];
pollfds[i].events = POLLOUT;
pollfds[i].revents = 0;
}
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 1");
flags |= O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 2");
}
if (sinkmode) {
register int cnt = 0;
if (trans) {
if (udp) {
strcpy(buf, "BOD0");
if (multicast) {
bcopy((char *)&sinhim[1].sin_addr.s_addr,
(char *)&save_mc.sin_addr.s_addr,
sizeof(struct in_addr));
bcopy((char *)&save_sinhim.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr start */
if (two_bod) {
usleep(250000);
strcpy(buf, "BOD1");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr start */
}
if (multicast) {
bcopy((char *)&save_mc.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
}
if (timeout)
setitimer(ITIMER_REAL, &itimer, 0);
prep_timer();
}
bzero(buf + 8, 8); /* zero out timestamp */
nbytes += buflen;
if (do_poll && (format & DEBUGPOLL)) {
fprintf(stdout, "do_poll is set\n");
fflush(stdout);
}
if (udplossinfo)
bcopy(&nbytes, buf + 24, 8);
if (!udp && !(format & NORETRANS) &&
(nstream == 1) &&
((retransinfo == 1) ||
((retransinfo >= 2) &&
(force_retrans >= retransinfo)))) {
uint32_t tmp;
if (client) {
if (trans || send_retrans)
do_retrans = 1;
if (trans)
send_retrans = 1;
if (!udp)
bzero(buf + 24, 8);
}
else {
if (retransinfo == 1)
tmp = 0x5254524Eu; /* "RTRN" */
else
tmp = 0x48525452u; /* "HRTR" */
bcopy(&nretrans[1], buf + 24, 4);
bcopy(&tmp, buf + 28, 4);
do_retrans = 0;
}
}
else {
send_retrans = 0;
do_retrans = 0;
if (!udp)
bzero(buf + 24, 8);
}
if (!udp && !(format & NOCWND) &&
(nstream == 1) && cwndinfo) {
if (client) {
if (trans || send_cwnd)
do_cwnd = 1;
if (trans)
send_cwnd = 1;
}
else {
do_cwnd = 0;
}
}
else {
send_cwnd = 0;
do_cwnd = 0;
}
if (nbuf == INT_MAX)
nbuf = ULLONG_MAX;
if (!client) {
/* check if client went away */
pollfds[0].fd = fileno(ctlconn);
save_events = pollfds[0].events;
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0) > 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI))) {
nbuf = 0;
intr = 1;
}
pollfds[0].events = save_events;
}
while (nbuf-- && ((cnt = Nwrite(fd[stream_idx + 1], buf, buflen)) == buflen) && !intr) {
if (clientserver && ((nbuf & 0x3FF) == 0)) {
if (!client) {
/* check if client went away */
pollfds[0].fd = fileno(ctlconn);
save_events = pollfds[0].events;
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0) > 0)
&& (pollfds[0].revents &
(POLLIN | POLLPRI)))
intr = 1;
pollfds[0].events = save_events;
}
else if (handle_urg) {
/* check for urgent TCP data
* on control connection */
pollfds[0].fd = fileno(ctlconn);
save_events = pollfds[0].events;
pollfds[0].events = POLLPRI;
pollfds[0].revents = 0;
if ((poll(pollfds, 1, 0) > 0)
&& (pollfds[0].revents &
POLLPRI)) {
tmpbuf[0] = '\0';
if ((recv(fd[0], tmpbuf, 1,
MSG_OOB) == -1) &&
(errno == EINVAL))
recv(fd[0], tmpbuf,
1, 0);
if (tmpbuf[0] == 'A')
intr = 1;
else
err("recv urgent data");
}
pollfds[0].events = save_events;
}
}
nbytes += buflen;
cnt = 0;
if (udplossinfo)
bcopy(&nbytes, buf + 24, 8);
if (send_retrans) {
nretrans[1] = get_retrans(
fd[stream_idx + 1],
&tcpinf);
nretrans[1] -= iretrans[1];
bcopy(&nretrans[1], buf + 24, 4);
}
#if defined(linux)
if (send_cwnd) {
cwnd[1] = tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
bcopy(&cwnd[1], buf + 28, 4);
}
#endif
stream_idx++;
stream_idx = stream_idx % nstream;
if (do_poll &&
((pollst = poll(pollfds, nstream + 1, 0))
> 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI)) && !intr) {
/* check for server output */
#ifdef DEBUG
if (format & DEBUGPOLL) {
fprintf(stdout, "got something %d: ", i);
for ( i = 0; i < nstream + 1; i++ ) {
if (pollfds[i].revents & POLLIN) {
fprintf(stdout, " rfd %d",
pollfds[i].fd);
}
if (pollfds[i].revents & POLLPRI) {
fprintf(stdout, " pfd %d",
pollfds[i].fd);
}
if (pollfds[i].revents & POLLOUT) {
fprintf(stdout, " wfd %d",
pollfds[i].fd);
}
if (pollfds[i].revents & POLLERR) {
fprintf(stdout, " xfd %d",
pollfds[i].fd);
}
if (pollfds[i].revents & POLLHUP) {
fprintf(stdout, " hfd %d",
pollfds[i].fd);
}
if (pollfds[i].revents & POLLNVAL) {
fprintf(stdout, " nfd %d",
pollfds[i].fd);
}
}
fprintf(stdout, "\n");
fflush(stdout);
}
if (format & DEBUGPOLL) {
fprintf(stdout, "got server output: %s", intervalbuf);
fflush(stdout);
}
#endif
while (fgets(intervalbuf, sizeof(intervalbuf), stdin))
{
if (strncmp(intervalbuf, "DONE", 4) == 0) {
if (format & DEBUGPOLL) {
fprintf(stdout, "got DONE\n");
fflush(stdout);
}
got_done = 1;
intr = 1;
do_poll = 0;
break;
}
else if (strncmp(intervalbuf, "nuttcp-r", 8) == 0) {
if ((brief <= 0) ||
strstr(intervalbuf,
"Warning") ||
strstr(intervalbuf,
"Error") ||
strstr(intervalbuf,
"Debug")) {
if (*ident) {
fputs("nuttcp-r", stdout);
fputs(ident, stdout);
fputs(intervalbuf + 8, stdout);
}
else
fputs(intervalbuf, stdout);
fflush(stdout);
}
}
else {
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
cp1 = intervalbuf +
strlen(intervalbuf) - 1;
/* ugly kludge to get rid of
* server "0 retrans" info at
* start of transfer for small
* interval reports -
* hopefully it won't be
* necessary to also check
* at end of transfer when
* processing server output */
if (!got_0retrans) {
if (format & PARSE) {
if ((cp2 = strstr(
intervalbuf,
"host-"
"retrans")))
*(cp2 - 1) = '\0';
else if ((cp2 = strstr(
intervalbuf,
"retrans")))
*(cp2 - 1) = '\0';
else {
*cp1 = '\0';
got_0retrans = 1;
}
}
else if (strstr(intervalbuf,
"KB-cwnd")) {
if (strstr(intervalbuf,
"host-retrans"))
*(cp1 - 34) = '\0';
else if (strstr(
intervalbuf,
"retrans"))
*(cp1 - 29) = '\0';
else {
*cp1 = '\0';
got_0retrans = 1;
}
}
else {
if (strstr(intervalbuf,
"host-retrans"))
*(cp1 - 19) = '\0';
else if (strstr(
intervalbuf,
"retrans"))
*(cp1 - 14) = '\0';
else {
*cp1 = '\0';
got_0retrans = 1;
}
}
}
else {
*cp1 = '\0';
}
if (do_retrans) {
cp1 = strstr(intervalbuf,
"Mbps") + 4;
ch = '\0';
if (cp1) {
if (format & PARSE) {
cp1 = strchr(cp1,
'.');
if (cp1)
cp1 += 5;
}
ch = *cp1;
}
if (ch)
*cp1 = '\0';
}
fputs(intervalbuf, stdout);
if (do_retrans && sinkmode) {
nretrans[1] =
get_retrans(fd[stream_idx
+ 1],
&tcpinf);
nretrans[1] -= iretrans[1];
if (format & PARSE)
fprintf(stdout,
P_RETRANS_FMT_INTERVAL,
(retransinfo == 1) ?
"" : "host-",
(nretrans[1] -
pretrans));
else
fprintf(stdout,
RETRANS_FMT_INTERVAL,
(nretrans[1] -
pretrans),
(retransinfo == 1) ?
"" : "host-");
pretrans = nretrans[1];
}
#if defined(linux)
if (do_cwnd && sinkmode) {
cwnd[1] =
tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
if (format & PARSE)
fprintf(stdout,
P_CWND_FMT_INTERVAL,
cwnd[1]);
else
fprintf(stdout,
CWND_FMT_INTERVAL,
cwnd[1]);
}
#endif
if (do_retrans && cp1 && ch) {
*cp1 = ch;
fputs(cp1, stdout);
}
fprintf(stdout, "\n");
fflush(stdout);
}
}
}
if (do_poll && (pollst < 0)) {
if (errno == EINTR)
break;
err("poll");
}
}
nbytes -= buflen;
if (intr && (cnt > 0))
nbytes += cnt;
if (udp) {
if (multicast)
bcopy((char *)&save_sinhim.sin_addr.s_addr,
(char *)&sinhim[1].sin_addr.s_addr,
sizeof(struct in_addr));
strcpy(buf, "EOD0");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
}
}
else {
first_read = 1;
first_jitter = 1;
first_jitteri = 1;
nowd = 0;
nowdi = 0;
owd_min = 1000000.0;
owd_mini = 1000000.0;
owd_max = -1000000.0;
owd_maxi = -1000000.0;
owd_avg = 0.0;
owd_avgi = 0.0;
need_swap = 0;
bzero(buf + 24, 8);
if (udp) {
ntbytesc = 0;
got_eod0 = 0;
while (((cnt=Nread(fd[stream_idx + 1], buf, buflen)) > 0) && !intr) {
if (cnt <= 4) {
if (strncmp(buf, "EOD0", 4) == 0) {
get_timeofday(&time_eod0,
(struct timezone *)0);
got_eod0 = 1;
done = 1;
continue;
}
if (strncmp(buf, "EOD", 3) == 0) {
ocorrection = buf[3] - '0';
get_timeofday(&time_eod,
(struct timezone *)0);
done = 1;
break; /* "EOF" */
}
if (strncmp(buf, "BOD", 3) == 0) {
if (two_bod &&
(buf[3] == '0'))
continue;
if (interval)
setitimer(ITIMER_REAL,
&itimer, 0);
prep_timer();
got_begin = 1;
continue;
}
break;
}
else if (!got_begin) {
if (interval)
setitimer(ITIMER_REAL,
&itimer, 0);
prep_timer();
got_begin = 1;
}
else if (got_eod0) {
/* got data after EOD0, so
* extend EOD0 time */
get_timeofday(&time_eod0,
(struct timezone *)0);
}
if (!got_begin)
continue;
nbytes += cnt;
cnt = 0;
/* problematic if the interval timer
* goes off right here */
if (udplossinfo) {
if (first_read) {
bcopy(buf + 24, &ntbytesc,
8);
first_read = 0;
if (ntbytesc > 0x100000000ull)
need_swap = 1;
if (!need_swap) {
stream_idx++;
stream_idx =
stream_idx
% nstream;
continue;
}
}
if (!need_swap)
bcopy(buf + 24, &ntbytesc,
8);
else {
cp1 = (char *)&ntbytesc;
cp2 = buf + 31;
for ( i = 0; i < 8; i++ )
*cp1++ = *cp2--;
}
}
if (do_jitter) {
if (first_jitter) {
get_timeofday(
&timepkr,
(struct timezone *)0);
timepkri = timepkr;
first_jitter = 0;
first_jitteri = 0;
ntbytescp = ntbytesc;
ntbytescpi = ntbytesc;
jitter = 0.0;
jitteri = 0.0;
njitter = 0;
njitteri = 0;
jitter_min = 1000000.0;
jitter_mini = 1000000.0;
jitter_max = -1000000.0;
jitter_maxi = -1000000.0;
jitter_avg = 0.0;
jitter_avgi = 0.0;
#ifdef DEBUG
if (clientserver &&
client &&
(format & DEBUGJITTER))
fprintf(stdout,
"pkt_time_ms"
" = %6.3f ms\n",
pkt_time_ms);
#endif
stream_idx++;
stream_idx =
stream_idx % nstream;
continue;
}
/* formula for jitter is from
* RFC1889 - note synchronized
* clocks are not required since
* source packet delta time is
* known (pkt_time_ms)
*
* D(i,j)=(Rj-Ri)-(Sj-Si)
* =(Rj-Sj)-(Ri-Si)
* J=J+(|D(i-1,i)|-J)/16
*
* for nuttcp we just use the raw
* absolute value of the delta
*
* J=|D(i-1,i)|
*/
if (!do_owd) {
get_timeofday(&timerx,
(struct timezone *)0);
}
if (do_jitter & JITTER_IGNORE_OOO) {
/* first check that packet
* is next in sequence */
if (udplossinfo &&
(ntbytescp + buflen)
!= ntbytesc) {
ntbytescp = ntbytesc;
ntbytescpi = ntbytesc;
timepkr = timerx;
timepkri = timerx;
stream_idx++;
stream_idx =
stream_idx % nstream;
continue;
}
}
tvsub( &timed, &timerx, &timepkr );
pkt_delta =
timed.tv_sec*1000
+ ((double)timed.tv_usec)
/ 1000;
pkt_delta -= pkt_time_ms;
if (pkt_delta >= 0)
jitter = pkt_delta;
else
jitter = -pkt_delta;
njitter++;
if (jitter < jitter_min)
jitter_min = jitter;
if (jitter > jitter_max)
jitter_max = jitter;
jitter_avg += jitter;
#ifdef DEBUG
if (clientserver && client &&
(format & DEBUGJITTER))
fprintf(stdout,
"pkt_delta = %6.3f ms, "
"jitter = %9.6f ms\n",
pkt_delta, jitter);
#endif
timepkr = timerx;
ntbytescp = ntbytesc;
if (!interval) {
stream_idx++;
stream_idx =
stream_idx % nstream;
continue;
}
if (first_jitteri) {
get_timeofday(
&timepkri,
(struct timezone *)0);
first_jitteri = 0;
ntbytescpi = ntbytesc;
jitteri = 0.0;
njitteri = 0;
jitter_mini = 1000000.0;
jitter_maxi = -1000000.0;
jitter_avgi = 0.0;
stream_idx++;
stream_idx =
stream_idx % nstream;
continue;
}
tvsub( &timed, &timerx, &timepkri );
pkt_delta =
timed.tv_sec*1000
+ ((double)timed.tv_usec)
/ 1000;
pkt_delta -= pkt_time_ms;
if (pkt_delta >= 0)
jitteri = pkt_delta;
else
jitteri = -pkt_delta;
njitteri++;
if (jitteri < jitter_mini)
jitter_mini = jitteri;
if (jitteri > jitter_maxi)
jitter_maxi = jitteri;
jitter_avgi += jitteri;
timepkri = timerx;
ntbytescpi = ntbytesc;
}
stream_idx++;
stream_idx = stream_idx % nstream;
}
if (intr && (cnt > 0))
nbytes += cnt;
if (got_eod0) {
tvsub( &timed, &time_eod, &time_eod0 );
correction = timed.tv_sec +
((double)timed.tv_usec)
/ 1000000;
}
}
else {
while (((cnt=Nread(fd[stream_idx + 1], buf, buflen)) > 0) && !intr) {
nbytes += cnt;
cnt = 0;
if (first_read) {
if (interval && !(format & NORETRANS)) {
uint32_t tmp;
first_read = 0;
bcopy(buf + 24, &nretrans[1], 4);
bcopy(buf + 28, &tmp, 4);
if (tmp == 0x5254524Eu) {
/* "RTRN" */
retransinfo = 1;
#if defined(linux)
cwndinfo = 1;
#endif
b_flag = 1;
}
else if (tmp == 0x48525452u) {
/* "HRTR" */
retransinfo = 2;
cwndinfo = 0;
read_cwnd = 0;
b_flag = 1;
}
else if (tmp == 0x4E525452u) {
/* "NRTR" */
need_swap = 1;
retransinfo = 1;
#if defined(linux)
cwndinfo = 1;
#endif
b_flag = 1;
}
else if (tmp == 0x52545248u) {
/* "RTRH" */
need_swap = 1;
retransinfo = 2;
cwndinfo = 0;
read_cwnd = 0;
b_flag = 1;
}
else {
retransinfo = -1;
cwndinfo = 0;
read_retrans = 0;
read_cwnd = 0;
}
if (format & NOCWND) {
cwndinfo = 0;
read_cwnd = 0;
}
}
else {
read_retrans = 0;
read_cwnd = 0;
}
}
if (read_retrans) {
if (!need_swap)
bcopy(buf + 24,
&nretrans[1], 4);
else {
cp1 = (char *)&nretrans[1];
cp2 = buf + 27;
for ( i = 0; i < 4; i++ )
*cp1++ = *cp2--;
}
}
if (read_cwnd) {
if (!need_swap)
bcopy(buf + 28,
&cwnd[1], 4);
else {
cp1 = (char *)&cwnd[1];
cp2 = buf + 31;
for ( i = 0; i < 4; i++ )
*cp1++ = *cp2--;
}
}
stream_idx++;
stream_idx = stream_idx % nstream;
}
if (intr && (cnt > 0))
nbytes += cnt;
}
}
}
else {
register int cnt;
if (trans) {
#if defined(linux)
struct stat instat;
if (fstat(savestdin, &instat) == 0) {
if (!S_ISREG(instat.st_mode) &&
!S_ISBLK(instat.st_mode)) {
zerocopy = 0;
directio = 0;
}
}
else {
zerocopy = 0;
directio = 0;
}
if (directio) {
flags = fcntl(savestdin, F_GETFL, 0);
if (flags < 0)
errmes("fcntl get O_DIRECT");
else {
flags |= O_DIRECT;
if (fcntl(savestdin,
F_SETFL, flags) < 0)
errmes("fcntl set O_DIRECT");
}
}
if (zerocopy) {
while (nbuf-- &&
((cnt=sendfile(fd[stream_idx + 1],
savestdin,
(off_t *)&nbytes,
buflen)) > 0)) {
cnt = 0;
stream_idx++;
stream_idx = stream_idx % nstream;
}
}
else
#endif
{
while (nbuf-- &&
((cnt=read(savestdin, buf, buflen)) > 0) &&
(Nwrite(fd[stream_idx + 1], buf, cnt)
== cnt)) {
nbytes += cnt;
cnt = 0;
stream_idx++;
stream_idx = stream_idx % nstream;
}
}
if (udp) {
strcpy(buf, "EOD0");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
}
}
else {
#if defined(linux)
struct stat outstat;
if (fstat(savestdout, &outstat) == 0) {
if (!S_ISREG(outstat.st_mode) &&
!S_ISBLK(outstat.st_mode))
directio = 0;
}
else
directio = 0;
if (directio) {
flags = fcntl(savestdout, F_GETFL, 0);
if (flags < 0)
errmes("fcntl get O_DIRECT");
else {
flags |= O_DIRECT;
if (fcntl(savestdout,
F_SETFL, flags) < 0)
errmes("fcntl set O_DIRECT");
}
}
#endif
while ((cnt=Nread(fd[stream_idx + 1], buf, buflen)) > 0 &&
((cnt != 4) || strncmp(buf, "EOD", 3) != 0) &&
mwrite(savestdout, buf, cnt,
cnt != buflen) == cnt) {
nbytes += cnt;
cnt = 0;
stream_idx++;
stream_idx = stream_idx % nstream;
}
}
}
if (errno && (errno != EAGAIN)) {
if ((errno != EINTR) &&
#ifdef ERESTART
(errno != ERESTART) &&
#endif
(!clientserver || client)) err("IO");
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
done = 1;
(void)read_timer(stats, sizeof(stats));
if (udp&&trans) {
usleep(500000);
strcpy(buf, "EOD1");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
stream_idx++;
stream_idx = stream_idx % nstream;
usleep(500000);
strcpy(buf, "EOD2");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
stream_idx++;
stream_idx = stream_idx % nstream;
usleep(500000);
strcpy(buf, "EOD3");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
stream_idx++;
stream_idx = stream_idx % nstream;
usleep(500000);
strcpy(buf, "EOD4");
(void)Nwrite( fd[stream_idx + 1], buf, 4 ); /* rcvr end */
stream_idx++;
stream_idx = stream_idx % nstream;
}
if (!udp && trans && (format & DEBUGRETRANS)) {
sretrans = get_retrans(-1, &tcpinf);
fprintf(stdout, "before closing system retrans = %d\n",
sretrans);
}
#ifdef DEBUG
if (clientserver && client && !trans && do_jitter && njitter &&
(format & DEBUGJITTER)) {
fprintf(stdout, "njitter = %lld\n", njitter);
fprintf(stdout, "jitter_min = %9.6f ms\n", jitter_min);
fprintf(stdout, "jitter_max = %9.6f ms\n", jitter_max);
fprintf(stdout, "jitter_avg = %9.6f ms\n", jitter_avg/njitter);
}
#endif
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
if (!udp && trans) {
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS) && !defined(BROKEN_UNACKED)
/* if -DBROKEN_UNACKED skip check for unACKed data
* (workaround motivated by possible bug encountered
* on a Suse Linux 10.1 system)
*/
struct timeval timeunsent, timec, timed;
double xmitrate;
int unsent, xmitunsent;
long flags;
optlen = sizeof(tcpinf);
if (getsockopt(fd[stream_idx], SOL_TCP, TCP_INFO,
(void *)&tcpinf, &optlen) < 0) {
mes("couldn't collect TCP info\n");
retransinfo = -1;
cwndinfo = 0;
}
if (ioctl(fd[stream_idx], SIOCOUTQ, &unsent) < 0) {
mes("couldn't get SIOCOUTQ value\n");
unsent = -1;
}
get_timeofday(&timeunsent, (struct timezone *)0);
realtd = 0.0;
xmitrate = ((double)nbytes-(double)unsent)/realt;
xmitunsent = (double)unsent/xmitrate;
xmitunsent = 2*xmitunsent + MAX_EOT_WAIT_SEC;
if (clientserver && client) {
reading_srvr_info = 1;
pollfds[0].fd = fileno(ctlconn);
pollfds[0].events = POLLIN | POLLPRI;
pollfds[0].revents = 0;
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 1");
flags |= O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 2");
itimer.it_value.tv_sec = xmitunsent + 10;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
}
while ((unsent > 0) && (realtd < xmitunsent)) {
if (clientserver && client &&
((pollst = poll(pollfds, 1, 0)) > 0) &&
(pollfds[0].revents & (POLLIN | POLLPRI)) &&
!got_done) {
/* check for server output */
while (fgets(intervalbuf,
sizeof(intervalbuf), stdin))
{
setitimer(ITIMER_REAL, &itimer, 0);
get_timeofday(&timeunsent,
(struct timezone *)0);
if (strncmp(intervalbuf, "DONE", 4)
== 0) {
if (format & DEBUGPOLL) {
fprintf(stdout,
"got DONE\n");
fflush(stdout);
}
got_done = 1;
intr = 1;
break;
}
else if (strncmp(intervalbuf,
"nuttcp-", 7) == 0) {
if ((brief <= 0) ||
strstr(intervalbuf,
"Warning") ||
strstr(intervalbuf,
"Error") ||
strstr(intervalbuf,
"Debug")) {
if (*ident) {
fputs("nuttcp",
stdout);
fputs(trans ?
"-r" : "-t",
stdout);
fputs(ident,
stdout);
fputs(intervalbuf
+ 8,
stdout);
}
else
fputs(intervalbuf,
stdout);
fflush(stdout);
}
if (strstr(intervalbuf,
"Error"))
exit(1);
}
else {
if (*ident)
fprintf(stdout, "%s: ",
ident + 1);
intervalbuf[strlen(intervalbuf)
- 1] = '\0';
if (do_retrans) {
cp1 = strstr(intervalbuf,
"Mbps") + 4;
ch = '\0';
if (cp1) {
if (format & PARSE) {
cp1 = strchr(cp1,
'.');
if (cp1)
cp1 += 5;
}
ch = *cp1;
}
if (ch)
*cp1 = '\0';
}
fputs(intervalbuf, stdout);
if (do_retrans && sinkmode &&
(nstream == 1)) {
nretrans[1] =
get_retrans(
fd[stream_idx],
&tcpinf);
nretrans[1] -= iretrans[1];
if (format & PARSE)
fprintf(stdout,
P_RETRANS_FMT_INTERVAL,
(retransinfo == 1) ?
"" : "host-",
(nretrans[1]
- pretrans));
else
fprintf(stdout,
RETRANS_FMT_INTERVAL,
(nretrans[1]
- pretrans),
(retransinfo == 1) ?
"" : "host-");
pretrans =
nretrans[1];
}
if (do_cwnd && sinkmode &&
(nstream == 1)) {
cwnd[1] =
tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
if (format & PARSE)
fprintf(stdout,
P_CWND_FMT_INTERVAL,
cwnd[1]);
else
fprintf(stdout,
CWND_FMT_INTERVAL,
cwnd[1]);
}
if (do_retrans && cp1 && ch) {
*cp1 = ch;
fputs(cp1, stdout);
}
fprintf(stdout, "\n");
fflush(stdout);
}
}
}
if (format & DEBUGRETRANS)
print_tcpinfo();
if (format & DEBUGRETRANS)
usleep(100000);
else
usleep(1000);
optlen = sizeof(tcpinf);
if (getsockopt(fd[stream_idx],
SOL_TCP, TCP_INFO,
(void *)&tcpinf, &optlen) < 0) {
mes("couldn't collect TCP info\n");
retransinfo = -1;
cwndinfo = 0;
}
if (ioctl(fd[stream_idx], SIOCOUTQ,
&unsent) < 0) {
mes("couldn't get SIOCOUTQ value\n");
unsent = -1;
}
get_timeofday(&timec, (struct timezone *)0);
tvsub(&timed, &timec, &timeunsent);
realtd = timed.tv_sec
+ ((double)timed.tv_usec) / 1000000;
}
if (clientserver && client) {
reading_srvr_info = 0;
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 1");
flags &= ~O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 2");
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
}
if (getsockopt(fd[stream_idx], SOL_TCP, TCP_INFO,
(void *)&tcpinf, &optlen) < 0) {
mes("couldn't collect TCP info\n");
retransinfo = -1;
cwndinfo = 0;
}
if (unsent > 0) {
/* assume receiver went away */
if (clientserver && client) {
mes("Error: timeout while draining "
"socket send queue");
exit(1);
}
goto cleanup;
}
if (format & DEBUGRETRANS)
print_tcpinfo();
#endif
if (retransinfo > 0) {
if ((stream_idx == 1) || (retransinfo == 1)) {
nretrans[stream_idx] =
get_retrans(fd[stream_idx],
&tcpinf);
nretrans[stream_idx] -=
iretrans[stream_idx];
#if defined(linux)
if (retransinfo == 1)
cwnd[stream_idx] =
tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
#endif
}
}
}
}
if (!udp && trans && (format & DEBUGRETRANS)) {
sretrans = get_retrans(-1, &tcpinf);
fprintf(stdout, "after closing system retrans = %d\n",
sretrans);
}
if (interval && clientserver && client && do_retrans && !got_done) {
/* don't fully close data channels yet since there
* may be some straggler interval reports to which we
* will need to append retrans info, so just shutdown()
* for writing for now */
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ )
shutdown(fd[stream_idx], SHUT_WR);
}
else
close_data_channels();
if (interval && clientserver && !client && !trans) {
fprintf(stdout, "DONE\n");
fflush(stdout);
}
if (cput <= 0.0) cput = 0.000001;
if (realt <= 0.0) realt = 0.000001;
if (udp && !trans) {
if (got_eod0)
realt -= correction;
else
realt -= ocorrection * 0.5;
}
sprintf(srvrbuf, "%.4f", (double)nbytes/1024/1024);
sscanf(srvrbuf, "%lf", &MB);
if (clientserver && client)
reading_srvr_info = 1;
if (interval && clientserver && client && trans && !got_done) {
long flags;
if (format & DEBUGPOLL) {
fprintf(stdout, "getting rest of server output\n");
fflush(stdout);
}
flags = fcntl(0, F_GETFL, 0);
if (flags < 0)
err("fcntl 3");
flags &= ~O_NONBLOCK;
if (fcntl(0, F_SETFL, flags) < 0)
err("fcntl 4");
itimer.it_value.tv_sec = SRVR_INFO_TIMEOUT;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
while (fgets(intervalbuf, sizeof(intervalbuf), stdin)) {
setitimer(ITIMER_REAL, &itimer, 0);
if (strncmp(intervalbuf, "DONE", 4) == 0) {
if (format & DEBUGPOLL) {
fprintf(stdout, "got DONE 2\n");
fflush(stdout);
}
break;
}
if ((!strstr(intervalbuf, " MB / ") ||
!strstr(intervalbuf, " sec = ")) && (brief > 0))
continue;
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
intervalbuf[strlen(intervalbuf) - 1] = '\0';
if (do_retrans) {
cp1 = strstr(intervalbuf, "Mbps") + 4;
ch = '\0';
if (cp1) {
if (format & PARSE) {
cp1 = strchr(cp1, '.');
if (cp1)
cp1 += 5;
}
ch = *cp1;
}
if (ch)
*cp1 = '\0';
}
fputs(intervalbuf, stdout);
if (do_retrans && sinkmode) {
nretrans[1] = get_retrans(fd[1], &tcpinf);
nretrans[1] -= iretrans[1];
if (format & PARSE)
fprintf(stdout, P_RETRANS_FMT_INTERVAL,
(retransinfo == 1) ?
"" : "host-",
(nretrans[1] - pretrans));
else
fprintf(stdout, RETRANS_FMT_INTERVAL,
(nretrans[1] - pretrans),
(retransinfo == 1) ?
"" : "host-");
pretrans = nretrans[1];
}
#if defined(linux)
if (do_cwnd && sinkmode) {
cwnd[1] = tcpinf.tcpinfo_snd_cwnd
*datamss/1024;
if (format & PARSE)
fprintf(stdout, P_CWND_FMT_INTERVAL,
cwnd[1]);
else
fprintf(stdout, CWND_FMT_INTERVAL,
cwnd[1]);
}
#endif
if (do_retrans && cp1 && ch) {
*cp1 = ch;
fputs(cp1, stdout);
}
fprintf(stdout, "\n");
fflush(stdout);
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
}
if (interval && clientserver && client && do_retrans) {
/* it's OK to fully close the data channels now */
close_data_channels();
}
if (clientserver && client) {
itimer.it_value.tv_sec = SRVR_INFO_TIMEOUT;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
cp1 = srvrbuf;
got_srvr_retrans = 0;
got_srvr_cwnd = 0;
while (fgets(cp1, sizeof(srvrbuf) - (cp1 - srvrbuf), stdin)) {
setitimer(ITIMER_REAL, &itimer, 0);
if (*(cp1 + strlen(cp1) - 1) != '\n') {
*cp1 = '\0';
break;
}
if (strstr(cp1, "real") && strstr(cp1, "seconds")) {
strcpy(fmt, "nuttcp-%*c: ");
if (format & PARSE)
strcat(fmt, P_PERF_FMT_IN);
else
strcat(fmt, PERF_FMT_IN);
sscanf(cp1, fmt,
&srvr_MB, &srvr_realt, &srvr_KBps,
&srvr_Mbps);
if (trans && udp) {
strncpy(tmpbuf, cp1, 256);
*(tmpbuf + 256) = '\0';
if (strncmp(tmpbuf,
"nuttcp-r", 8) == 0)
sprintf(cp1, "nuttcp-r%s%s",
ident, tmpbuf + 8);
cp1 += strlen(cp1);
cp2 = cp1;
sprintf(cp2, "nuttcp-r:");
cp2 += 9;
if (format & PARSE)
strcpy(fmt, P_DROP_FMT);
else
strcpy(fmt, DROP_FMT);
sprintf(cp2, fmt,
(int64_t)(((MB - srvr_MB)
*1024*1024)
/buflen + 0.5),
(uint64_t)((MB*1024*1024)
/buflen + 0.5));
cp2 += strlen(cp2);
fractloss = ((MB != 0.0) ?
1 - srvr_MB/MB : 0.0);
if (format & PARSE)
strcpy(fmt, P_LOSS_FMT);
else if ((fractloss != 0.0) &&
(fractloss < 0.001))
strcpy(fmt, LOSS_FMT5);
else
strcpy(fmt, LOSS_FMT);
sprintf(cp2, fmt, fractloss * 100);
cp2 += strlen(cp2);
sprintf(cp2, "\n");
}
}
else if (strstr(cp1, "sys")) {
strcpy(fmt, "nuttcp-%*c: ");
if (format & PARSE) {
strcat(fmt, "stats=cpu ");
strcat(fmt, P_CPU_STATS_FMT_IN2);
}
else
strcat(fmt, CPU_STATS_FMT_IN2);
if (sscanf(cp1, fmt,
&srvr_cpu_util) != 7) {
strcpy(fmt, "nuttcp-%*c: ");
if (format & PARSE) {
strcat(fmt, "stats=cpu ");
strcat(fmt,
P_CPU_STATS_FMT_IN);
}
else
strcat(fmt, CPU_STATS_FMT_IN);
sscanf(cp1, fmt,
&srvr_cpu_util);
}
}
else if ((cp2 = strstr(cp1, "retrans"))) {
got_srvr_retrans = 1;
retransinfo = 1;
if (strstr(cp1, "host-retrans"))
retransinfo = 2;
if (format & PARSE)
sscanf(cp2, P_RETRANS_FMT_IN,
&total_retrans);
else
sscanf(cp2, RETRANS_FMT_IN,
&total_retrans);
if (format & PARSE) {
if ((cp2 = strstr(cp2,
"retrans_by_stream=")))
cp2 += 18;
else
cp2 = NULL;
}
else {
if ((cp2 = strstr(cp2, "( ")))
cp2 += 2;
else
cp2 = NULL;
}
if (cp2) {
sscanf(cp2, "%d", &nretrans[1]);
stream_idx = 2;
while ((stream_idx <= nstream) &&
(cp2 = strchr(cp2, '+'))) {
cp2++;
sscanf(cp2, "%d",
&nretrans[stream_idx]);
stream_idx++;
}
}
/* below is for compatibility with 6.0.x beta */
if ((cp2 = strstr(cp1, "RTT"))) {
if (format & PARSE)
sscanf(cp2, P_RTT_FMT_IN, &rtt);
else
sscanf(cp2, RTT_FMT_INB, &rtt);
}
if ((cp2 = strstr(cp1, "cwnd"))) {
got_srvr_cwnd = 1;
cwndinfo = 1;
if (format & PARSE)
sscanf(cp2, P_CWND_FMT_IN,
&total_snd_cwnd);
else
sscanf(cp2, CWND_FMT_IN,
&total_snd_cwnd);
if (format & PARSE) {
if ((cp2 = strstr(cp2,
"cwnd_by_stream=")))
cp2 += 15;
else
cp2 = NULL;
}
else {
if ((cp2 = strstr(cp2, "( ")))
cp2 += 2;
else
cp2 = NULL;
}
if (cp2) {
sscanf(cp2, "%d", &cwnd[1]);
stream_idx = 2;
while ((stream_idx <=
nstream) &&
(cp2 = strchr(cp2,
'+'))) {
cp2++;
sscanf(cp2, "%d",
&cwnd[stream_idx]);
stream_idx++;
}
}
}
}
else if ((cp2 = strstr(cp1, "RTT")) ||
(cp2 = strstr(cp1, "rtt"))) {
if (format & PARSE)
sscanf(cp2, P_RTT_FMT_IN, &rtt);
else
sscanf(cp2, RTT_FMT_IN, &rtt);
}
else if ((cp2 = strstr(cp1, "jitter"))) {
if (format & PARSE)
sscanf(cp2, P_JITTER_FMT_IN,
&jitter_min, &jitter_avg,
&jitter_max);
else
sscanf(cp2, JITTER_FMT_IN,
&jitter_min, &jitter_avg,
&jitter_max);
njitter = 1;
}
else if ((cp2 = strstr(cp1, "OWD"))) {
if (format & PARSE)
sscanf(cp2, P_OWD_FMT_IN,
&owd_min, &owd_avg, &owd_max);
else
sscanf(cp2, OWD_FMT_IN,
&owd_min, &owd_avg, &owd_max);
nowd = 1;
}
else if ((strstr(cp1, "KB/cpu")) && !verbose)
continue;
strncpy(tmpbuf, cp1, 256);
*(tmpbuf + 256) = '\0';
if (strncmp(tmpbuf, "nuttcp-", 7) == 0)
sprintf(cp1, "nuttcp-%c%s%s",
tmpbuf[7], ident, tmpbuf + 8);
if ((strstr(cp1, "Warning") ||
strstr(cp1, "Error") ||
strstr(cp1, "Debug"))
&& (brief > 0)) {
fputs(cp1, stdout);
fflush(stdout);
}
cp1 += strlen(cp1);
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
got_srvr_output = 1;
if (!udp && !trans) {
if (!got_srvr_retrans)
retransinfo = -1;
if (!got_srvr_cwnd)
cwndinfo = 0;
}
}
if (!udp && trans) {
if (retransinfo > 0) {
total_retrans = 0;
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
total_retrans += nretrans[stream_idx];
}
}
if (cwndinfo) {
total_snd_cwnd = 0;
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
total_snd_cwnd += cwnd[stream_idx];
}
}
}
if (brief <= 0) {
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, P_PERF_FMT_OUT);
else
strcat(fmt, PERF_FMT_OUT);
fprintf(stdout, fmt, trans?"-t":"-r", ident,
(double)nbytes/(1024*1024), realt,
(double)nbytes/realt/1024,
(double)nbytes/realt/125000);
if (clientserver && client && !trans && udp) {
fprintf(stdout, "nuttcp-r%s:", ident);
if (format & PARSE)
strcpy(fmt, P_DROP_FMT);
else
strcpy(fmt, DROP_FMT);
fprintf(stdout, fmt,
(int64_t)(((srvr_MB - MB)*1024*1024)
/buflen + 0.5),
(uint64_t)((srvr_MB*1024*1024)/buflen + 0.5));
fractloss = ((srvr_MB != 0.0) ? 1 - MB/srvr_MB : 0.0);
if (format & PARSE)
strcpy(fmt, P_LOSS_FMT);
else if ((fractloss != 0.0) && (fractloss < 0.001))
strcpy(fmt, LOSS_FMT5);
else
strcpy(fmt, LOSS_FMT);
fprintf(stdout, fmt, fractloss * 100);
fprintf(stdout, "\n");
}
if (clientserver && udp && !trans && do_jitter && njitter) {
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, P_JITTER_FMT);
else
strcat(fmt, JITTER_FMT);
fprintf(stdout, fmt, trans?"-t":"-r", ident,
jitter_min, jitter_avg/njitter, jitter_max);
fprintf(stdout, "\n");
}
if (clientserver && !trans && do_owd && nowd) {
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, P_OWD_FMT);
else
strcat(fmt, OWD_FMT);
fprintf(stdout, fmt, trans?"-t":"-r", ident,
owd_min, owd_avg/nowd, owd_max);
fprintf(stdout, "\n");
}
if (verbose) {
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, "megabytes=%.4f cpu_seconds=%.2f KB_per_cpu_second=%.2f\n");
else
strcat(fmt, "%.4f MB in %.2f CPU seconds = %.2f KB/cpu sec\n");
fprintf(stdout, fmt,
trans?"-t":"-r", ident,
(double)nbytes/(1024*1024), cput,
(double)nbytes/cput/1024);
}
if (!udp && trans && (retransinfo > 0)) {
fprintf(stdout, "nuttcp%s%s: ",
trans ? "-t" : "-r", ident);
if (format & PARSE)
strcpy(fmt, P_RETRANS_FMT);
else
strcpy(fmt, RETRANS_FMT);
fprintf(stdout, fmt,
retransinfo == 1 ? "" : "host-", total_retrans);
if ((nstream > 1) && (retransinfo == 1) &&
total_retrans) {
if (format & PARSE)
fprintf(stdout, P_RETRANS_FMT_STREAMS,
nretrans[1]);
else
fprintf(stdout, " ( %d", nretrans[1]);
for ( stream_idx = 2; stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
nretrans[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout, " )");
}
#if defined(linux)
if (cwndinfo) {
if (format & PARSE)
strcpy(fmt, P_CWND_FMT);
else
strcpy(fmt, CWND_FMT);
fprintf(stdout, fmt, total_snd_cwnd);
if ((nstream > 1) && (retransinfo == 1) &&
total_snd_cwnd) {
if (format & PARSE)
fprintf(stdout, P_CWND_FMT_STREAMS,
cwnd[1]);
else
fprintf(stdout, " ( %d", cwnd[1]);
for ( stream_idx = 2; stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
cwnd[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout, " )");
}
}
#endif
fprintf(stdout, "\n");
}
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, "io_calls=%d msec_per_call=%.2f calls_per_sec=%.2f\n");
else
strcat(fmt, "%d I/O calls, msec/call = %.2f, calls/sec = %.2f\n");
fprintf(stdout, fmt,
trans?"-t":"-r", ident,
numCalls,
1024.0 * realt/((double)numCalls),
((double)numCalls)/realt);
strcpy(fmt, "nuttcp%s%s: ");
if (format & PARSE)
strcat(fmt, "stats=cpu %s\n");
else
strcat(fmt, "%s\n");
fprintf(stdout, fmt, trans?"-t":"-r", ident, stats);
}
if (format & PARSE)
strcpy(fmt, P_CPU_STATS_FMT_IN2);
else
strcpy(fmt, CPU_STATS_FMT_IN2);
if (sscanf(stats, fmt, &cpu_util) != 6) {
if (format & PARSE)
strcpy(fmt, P_CPU_STATS_FMT_IN);
else
strcpy(fmt, CPU_STATS_FMT_IN);
sscanf(stats, fmt, &cpu_util);
}
if (brief && clientserver && client) {
if ((brief < 0) || interval)
fprintf(stdout, "\n");
if (udp) {
if (trans) {
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF);
else
strcpy(fmt, PERF_FMT_BRIEF);
fprintf(stdout, fmt,
srvr_MB, srvr_realt, srvr_Mbps,
cpu_util, srvr_cpu_util);
if (!(format & NODROPS)) {
if (format & PARSE)
strcpy(fmt, P_DROP_FMT_BRIEF);
else
strcpy(fmt, DROP_FMT_BRIEF);
fprintf(stdout, fmt,
(int64_t)(((MB - srvr_MB)
*1024*1024)
/buflen + 0.5),
(uint64_t)((MB*1024*1024)
/buflen + 0.5));
}
if (!(format & NOPERCENTLOSS)) {
fractloss = ((MB != 0.0) ?
1 - srvr_MB/MB : 0.0);
if (format & PARSE)
strcpy(fmt, P_LOSS_FMT_BRIEF);
else if ((fractloss != 0.0) &&
(fractloss < 0.001))
strcpy(fmt, LOSS_FMT_BRIEF5);
else
strcpy(fmt, LOSS_FMT_BRIEF);
fprintf(stdout, fmt, fractloss * 100);
}
if (format & XMITSTATS) {
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF3);
else
strcpy(fmt, PERF_FMT_BRIEF3);
fprintf(stdout, fmt, MB);
}
if ((do_jitter & JITTER_MIN) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_MIN_FMT_BRIEF);
else
strcpy(fmt,
JITTER_MIN_FMT_BRIEF);
fprintf(stdout, fmt, jitter_min);
}
if ((do_jitter & JITTER_AVG) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_AVG_FMT_BRIEF);
else
strcpy(fmt,
JITTER_AVG_FMT_BRIEF);
fprintf(stdout, fmt,
jitter_avg/njitter);
}
if ((do_jitter & JITTER_MAX) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_MAX_FMT_BRIEF);
else
strcpy(fmt,
JITTER_MAX_FMT_BRIEF);
fprintf(stdout, fmt, jitter_max);
}
if ((do_owd & OWD_MIN) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MIN_FMT_BRIEF);
else
strcpy(fmt, OWD_MIN_FMT_BRIEF);
fprintf(stdout, fmt, owd_min);
}
if ((do_owd & OWD_AVG) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_AVG_FMT_BRIEF);
else
strcpy(fmt, OWD_AVG_FMT_BRIEF);
fprintf(stdout, fmt, owd_avg/nowd);
}
if ((do_owd & OWD_MAX) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MAX_FMT_BRIEF);
else
strcpy(fmt, OWD_MAX_FMT_BRIEF);
fprintf(stdout, fmt, owd_max);
}
}
else {
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF);
else
strcpy(fmt, PERF_FMT_BRIEF);
fprintf(stdout, fmt,
MB, realt, (double)nbytes/realt/125000,
srvr_cpu_util, cpu_util);
if (!(format & NODROPS)) {
if (format & PARSE)
strcpy(fmt, P_DROP_FMT_BRIEF);
else
strcpy(fmt, DROP_FMT_BRIEF);
fprintf(stdout, fmt,
(int64_t)(((srvr_MB - MB)
*1024*1024)
/buflen + 0.5),
(uint64_t)((srvr_MB*1024*1024)
/buflen + 0.5));
}
if (!(format & NOPERCENTLOSS)) {
fractloss = ((srvr_MB != 0.0) ?
1 - MB/srvr_MB : 0.0);
if (format & PARSE)
strcpy(fmt, P_LOSS_FMT_BRIEF);
else if ((fractloss != 0.0) &&
(fractloss < 0.001))
strcpy(fmt, LOSS_FMT_BRIEF5);
else
strcpy(fmt, LOSS_FMT_BRIEF);
fprintf(stdout, fmt, fractloss * 100);
}
if (format & XMITSTATS) {
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF3);
else
strcpy(fmt, PERF_FMT_BRIEF3);
fprintf(stdout, fmt, srvr_MB);
}
if ((do_jitter & JITTER_MIN) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_MIN_FMT_BRIEF);
else
strcpy(fmt,
JITTER_MIN_FMT_BRIEF);
fprintf(stdout, fmt, jitter_min);
}
if ((do_jitter & JITTER_AVG) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_AVG_FMT_BRIEF);
else
strcpy(fmt,
JITTER_AVG_FMT_BRIEF);
fprintf(stdout, fmt,
jitter_avg/njitter);
}
if ((do_jitter & JITTER_MAX) && njitter) {
if (format & PARSE)
strcpy(fmt,
P_JITTER_MAX_FMT_BRIEF);
else
strcpy(fmt,
JITTER_MAX_FMT_BRIEF);
fprintf(stdout, fmt, jitter_max);
}
if ((do_owd & OWD_MIN) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MIN_FMT_BRIEF);
else
strcpy(fmt, OWD_MIN_FMT_BRIEF);
fprintf(stdout, fmt, owd_min);
}
if ((do_owd & OWD_AVG) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_AVG_FMT_BRIEF);
else
strcpy(fmt, OWD_AVG_FMT_BRIEF);
fprintf(stdout, fmt, owd_avg/nowd);
}
if ((do_owd & OWD_MAX) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MAX_FMT_BRIEF);
else
strcpy(fmt, OWD_MAX_FMT_BRIEF);
fprintf(stdout, fmt, owd_max);
}
}
fprintf(stdout, "\n");
}
else
if (trans) {
if ((retransinfo > 0) &&
(!(format & NORETRANS))) {
if (format & DEBUGRETRANS) {
sretrans = get_retrans(-1, &tcpinf);
fprintf(stdout,
"report system retrans = %d\n",
sretrans);
}
}
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF);
else
strcpy(fmt, PERF_FMT_BRIEF);
fprintf(stdout, fmt,
srvr_MB, srvr_realt, srvr_Mbps,
cpu_util, srvr_cpu_util);
if ((nstream > 1) && (retransinfo == 1) &&
total_retrans && !(format & NORETRANS) &&
(brief & BRIEF_RETRANS_STREAMS)) {
if (format & PARSE) {
fprintf(stdout, P_RETRANS_FMT_BRIEF,
"", total_retrans);
fprintf(stdout,
P_RETRANS_FMT_STREAMS,
nretrans[1]);
}
else {
fprintf(stdout,
RETRANS_FMT_BRIEF_STR1,
total_retrans,
nretrans[1]);
}
for ( stream_idx = 2;
stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
nretrans[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout,
RETRANS_FMT_BRIEF_STR2);
}
else if ((retransinfo > 0) &&
(!(format & NORETRANS))) {
if (format & PARSE)
fprintf(stdout,
P_RETRANS_FMT_BRIEF,
retransinfo == 1 ?
"" : "host-",
total_retrans);
else
fprintf(stdout,
RETRANS_FMT_BRIEF,
total_retrans,
retransinfo == 1 ?
"" : "host-");
}
#if defined(linux)
if ((nstream > 1) && cwndinfo &&
(retransinfo == 1) &&
total_snd_cwnd && !(format & NOCWND) &&
(brief & BRIEF_CWND_STREAMS)) {
if (format & PARSE) {
fprintf(stdout, P_CWND_FMT_BRIEF,
total_snd_cwnd);
fprintf(stdout,
P_CWND_FMT_STREAMS,
cwnd[1]);
}
else {
fprintf(stdout,
CWND_FMT_BRIEF_STR1,
total_snd_cwnd,
cwnd[1]);
}
for ( stream_idx = 2;
stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
cwnd[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout,
CWND_FMT_BRIEF_STR2);
}
else if (cwndinfo && (!(format & NOCWND))) {
if (format & PARSE)
fprintf(stdout,
P_CWND_FMT_BRIEF,
total_snd_cwnd);
else
fprintf(stdout,
CWND_FMT_BRIEF,
total_snd_cwnd);
}
#endif
if (rtt && (format & WANTRTT)) {
if (format & PARSE)
strcpy(fmt, P_RTT_FMT_BRIEF);
else
strcpy(fmt, RTT_FMT_BRIEF);
fprintf(stdout, fmt, rtt);
}
if ((do_owd & OWD_MIN) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MIN_FMT_BRIEF);
else
strcpy(fmt, OWD_MIN_FMT_BRIEF);
fprintf(stdout, fmt, owd_min);
}
if ((do_owd & OWD_AVG) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_AVG_FMT_BRIEF);
else
strcpy(fmt, OWD_AVG_FMT_BRIEF);
fprintf(stdout, fmt, owd_avg/nowd);
}
if ((do_owd & OWD_MAX) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MAX_FMT_BRIEF);
else
strcpy(fmt, OWD_MAX_FMT_BRIEF);
fprintf(stdout, fmt, owd_max);
}
fprintf(stdout, "\n");
}
else {
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
if (format & PARSE)
strcpy(fmt, P_PERF_FMT_BRIEF);
else
strcpy(fmt, PERF_FMT_BRIEF);
fprintf(stdout, fmt,
MB, realt, (double)nbytes/realt/125000,
srvr_cpu_util, cpu_util);
if ((nstream > 1) && (retransinfo == 1) &&
total_retrans && !(format & NORETRANS) &&
(brief & BRIEF_RETRANS_STREAMS) &&
(irvers >= 70101)) {
if (format & PARSE) {
fprintf(stdout, P_RETRANS_FMT_BRIEF,
"", total_retrans);
fprintf(stdout,
P_RETRANS_FMT_STREAMS,
nretrans[1]);
}
else {
fprintf(stdout,
RETRANS_FMT_BRIEF_STR1,
total_retrans,
nretrans[1]);
}
for ( stream_idx = 2;
stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
nretrans[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout,
RETRANS_FMT_BRIEF_STR2);
}
else if ((retransinfo > 0) &&
(!(format & NORETRANS))) {
if (format & PARSE)
fprintf(stdout,
P_RETRANS_FMT_BRIEF,
retransinfo == 1 ?
"" : "host-",
total_retrans);
else
fprintf(stdout,
RETRANS_FMT_BRIEF,
total_retrans,
retransinfo == 1 ?
"" : "host-");
}
if ((nstream > 1) && cwndinfo &&
(retransinfo == 1) &&
total_snd_cwnd && !(format & NOCWND) &&
(brief & BRIEF_CWND_STREAMS) &&
(irvers >= 80001)) {
if (format & PARSE) {
fprintf(stdout, P_CWND_FMT_BRIEF,
total_snd_cwnd);
fprintf(stdout,
P_CWND_FMT_STREAMS,
cwnd[1]);
}
else {
fprintf(stdout,
CWND_FMT_BRIEF_STR1,
total_snd_cwnd,
cwnd[1]);
}
for ( stream_idx = 2;
stream_idx <= nstream;
stream_idx++ ) {
fprintf(stdout, "+%d",
cwnd[stream_idx]);
}
if (!(format & PARSE))
fprintf(stdout,
CWND_FMT_BRIEF_STR2);
}
else if (cwndinfo && (!(format & NOCWND))) {
if (format & PARSE)
fprintf(stdout,
P_CWND_FMT_BRIEF,
total_snd_cwnd);
else
fprintf(stdout,
CWND_FMT_BRIEF,
total_snd_cwnd);
}
if (rtt && (format & WANTRTT)) {
if (format & PARSE)
strcpy(fmt, P_RTT_FMT_BRIEF);
else
strcpy(fmt, RTT_FMT_BRIEF);
fprintf(stdout, fmt, rtt);
}
if ((do_owd & OWD_MIN) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MIN_FMT_BRIEF);
else
strcpy(fmt, OWD_MIN_FMT_BRIEF);
fprintf(stdout, fmt, owd_min);
}
if ((do_owd & OWD_AVG) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_AVG_FMT_BRIEF);
else
strcpy(fmt, OWD_AVG_FMT_BRIEF);
fprintf(stdout, fmt, owd_avg/nowd);
}
if ((do_owd & OWD_MAX) && nowd) {
if (format & PARSE)
strcpy(fmt,
P_OWD_MAX_FMT_BRIEF);
else
strcpy(fmt, OWD_MAX_FMT_BRIEF);
fprintf(stdout, fmt, owd_max);
}
fprintf(stdout, "\n");
}
}
else {
if (brief && !clientserver) {
if (brief < 0)
fprintf(stdout, "\n");
if (*ident)
fprintf(stdout, "%s: ", ident + 1);
fprintf(stdout, PERF_FMT_BRIEF2 "\n", MB,
realt, (double)nbytes/realt/125000, cpu_util,
trans?"TX":"RX");
}
}
cleanup:
if (clientserver) {
if (client) {
itimer.it_value.tv_sec = SRVR_INFO_TIMEOUT;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
if (brief <= 0)
fputs("\n", stdout);
if (brief <= 0) {
if (got_srvr_output) {
fputs(srvrbuf, stdout);
}
}
else {
while (fgets(buf, mallocsize, stdin)) {
setitimer(ITIMER_REAL, &itimer, 0);
fputs(buf, stdout);
}
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
fflush(stdout);
close(0);
}
else {
fflush(stdout);
close(1);
if (!inetd) {
dup(savestdout);
close(savestdout);
fflush(stderr);
if (!nofork) {
close(2);
dup(1);
}
}
}
fclose(ctlconn);
#ifdef DEBUG
if (irate && (format & DEBUGIRATE))
if (debugout) {
fprintf(debugout, "END nuttcp debug output\n");
fclose(debugout);
}
#endif
if (!inetd)
close(fd[0]);
if (!udp && trans && (retransinfo > 0)) {
if (format & DEBUGRETRANS) {
sretrans = get_retrans(-1, &tcpinf);
fprintf(stdout, "final system retrans = %d\n",
sretrans);
}
}
}
if (clientserver && !client) {
for ( stream_idx = 1; stream_idx <= nstream; stream_idx++ ) {
fd[stream_idx] = -1;
}
if (multilink &&
((trans && !reverse) || (!trans && reverse)) && !udp) {
for ( stream_idx = 2; stream_idx <= nstream;
stream_idx++ ) {
res[stream_idx] = NULL;
}
}
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &itimer, 0);
signal(SIGALRM, SIG_DFL);
bzero((char *)&frominet, sizeof(frominet));
bzero((char *)&clientaddr, sizeof(clientaddr));
#ifdef AF_INET6
bzero((char *)&clientaddr6, sizeof(clientaddr6));
clientscope6 = 0;
#endif
cput = 0.000001;
realt = 0.000001;
nbytes = 0;
ntbytes = 0;
ntbytesc = 0;
chk_nbytes = 0;
numCalls = 0;
/* Don't re-initialize buflen since it's used to */
/* determine if we need to change the buffer memory */
/* allocation for the next client data stream request */
/* buflen = 64 * 1024; */
/* if (udp) buflen = DEFAULTUDPBUFLEN; */
nbuf = 0;
sendwin = origsendwin;
rcvwin = origrcvwin;
b_flag = 1;
rate = MAXRATE;
maxburst = 1;
nburst = 1;
irate = 0;
iratesss = 0;
irate_cum_nsec = 0.0;
af3 = 0;
timeout = 0.0;
interval = 0.0;
chk_interval = 0.0;
chk_idle_data = 0.0;
datamss = 0;
tos = 0;
nodelay = 0;
do_poll = 0;
pbytes = 0;
ptbytes = 0;
ident[0] = '\0';
intr = 0;
abortconn = 0;
ipad_stride.ip32 = 0;
port = 5101;
srcport = 0;
trans = 0;
braindead = 0;
udp = 0;
udplossinfo = 0;
do_jitter = 0;
do_owd = 0;
retransinfo = 0;
init_pkt_cwnd = 0;
sss_pkt_cwnd = 0;
cwndinfo = 0;
force_retrans = 0;
rtt = 0.0;
which_rt = 1;
pretrans = 0;
sretrans = 0;
got_srvr_output = 0;
reading_srvr_info = 0;
reverse = 0;
format = 0;
traceroute = 0;
multicast = 0;
mc_addr = NULL;
ssm = -1;
skip_data = 0;
host3 = NULL;
thirdparty = 0;
ctlport3 = 0;
nbuf_bytes = 0;
rate_pps = 0;
brief = 0;
done = 0;
got_begin = 0;
two_bod = 0;
handle_urg = 0;
for ( stream_idx = 0; stream_idx <= nstream; stream_idx++ ) {
if (res[stream_idx]) {
freeaddrinfo(res[stream_idx]);
res[stream_idx] = NULL;
}
nretrans[stream_idx] = 0;
iretrans[stream_idx] = 0;
cwnd[stream_idx] = 0;
}
nstream = 1;
multilink = 0;
if (!oneshot)
goto doit;
exit(0);
}
if (multilink) {
for ( stream_idx = 2; stream_idx <= nstream; stream_idx++ ) {
res[stream_idx] = NULL;
}
}
for ( stream_idx = 0; stream_idx <= nstream; stream_idx++ ) {
if (res[stream_idx]) {
freeaddrinfo(res[stream_idx]);
res[stream_idx] = NULL;
}
}
exit(0);
usage:
fprintf(stdout, Usage);
exit(1);
}
static void
err( char *s )
{
long flags, saveflags;
fprintf(stderr, "nuttcp%s%s: v%d.%d.%d%s: Error: ", trans?"-t":"-r",
ident, vers_major, vers_minor, vers_delta,
beta ? BETA_STR : "");
perror(s);
fprintf(stderr, "errno=%d\n", errno);
fflush(stderr);
if ((stream_idx > 0) && !done &&
clientserver && !client && !trans && handle_urg) {
/* send 'A' for ABORT as urgent TCP data
* on control connection (don't block) */
saveflags = fcntl(fd[0], F_GETFL, 0);
if (saveflags != -1) {
flags = saveflags | O_NONBLOCK;
fcntl(fd[0], F_SETFL, flags);
}
send(fd[0], "A", 1, MSG_OOB);
if (saveflags != -1) {
flags = saveflags;
fcntl(fd[0], F_SETFL, flags);
}
}
exit(1);
}
static void
mes( char *s )
{
fprintf(stdout, "nuttcp%s%s: v%d.%d.%d%s: %s\n", trans?"-t":"-r", ident,
vers_major, vers_minor, vers_delta,
beta ? BETA_STR : "", s);
}
static void
errmes( char *s )
{
fprintf(stderr, "nuttcp%s%s: v%d.%d.%d%s: Error: ", trans?"-t":"-r",
ident, vers_major, vers_minor, vers_delta,
beta ? BETA_STR : "");
perror(s);
fprintf(stderr, "errno=%d\n", errno);
fflush(stderr);
}
void
pattern( register char *cp, register int cnt )
{
register char c;
c = 0;
while (cnt-- > 0) {
while (!isprint((c&0x7F))) c++;
*cp++ = (c++&0x7F);
}
}
void
get_timeofday( struct timeval *tv, struct timezone *tz )
{
#ifdef HAVE_CLOCK_GETTIME
struct timespec tod;
clockid_t clk_id;
#if defined(_POSIX_MONOTONIC_CLOCK) || defined(__CYGWIN__)
if (do_owd) {
clk_id = CLOCK_REALTIME;
}
else {
clk_id = CLOCK_MONOTONIC;
}
#else /* !(defined(_POSIX_MONOTONIC_CLOCK) || defined(__CYGWIN__)) */
clk_id = CLOCK_REALTIME;
#endif /* defined(_POSIX_MONOTONIC_CLOCK) || defined(__CYGWIN__) */
clock_gettime( clk_id, &tod );
tv->tv_sec = tod.tv_sec;
tv->tv_usec = tod.tv_nsec / 1000;
#else /* !HAVE_CLOCK_GETTIME */
gettimeofday( tv, tz );
#endif /* HAVE_CLOCK_GETTIME */
return;
}
/*
* P R E P _ T I M E R
*/
void
prep_timer()
{
get_timeofday(&time0, (struct timezone *)0);
timep.tv_sec = time0.tv_sec;
timep.tv_usec = time0.tv_usec;
timepk.tv_sec = time0.tv_sec;
timepk.tv_usec = time0.tv_usec;
getrusage(RUSAGE_SELF, &ru0);
}
/*
* R E A D _ T I M E R
*
*/
double
read_timer( char *str, int len )
{
struct timeval timedol;
struct rusage ru1;
struct timeval td;
struct timeval tend, tstart;
char line[132];
getrusage(RUSAGE_SELF, &ru1);
get_timeofday(&timedol, (struct timezone *)0);
prusage(&ru0, &ru1, &timedol, &time0, line);
(void)strncpy( str, line, len );
/* Get real time */
tvsub( &td, &timedol, &time0 );
realt = td.tv_sec + ((double)td.tv_usec) / 1000000;
/* Get CPU time (user+sys) */
tvadd( &tend, &ru1.ru_utime, &ru1.ru_stime );
tvadd( &tstart, &ru0.ru_utime, &ru0.ru_stime );
tvsub( &td, &tend, &tstart );
cput = td.tv_sec + ((double)td.tv_usec) / 1000000;
if (cput < 0.00001) cput = 0.00001;
return( cput );
}
static void
prusage( register struct rusage *r0, register struct rusage *r1, struct timeval *e, struct timeval *b, char *outp )
{
struct timeval tdiff;
register time_t t;
register char *cp;
register int i;
int ms;
t = (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+
(r1->ru_utime.tv_usec-r0->ru_utime.tv_usec)/10000+
(r1->ru_stime.tv_sec-r0->ru_stime.tv_sec)*100+
(r1->ru_stime.tv_usec-r0->ru_stime.tv_usec)/10000;
ms = (e->tv_sec-b->tv_sec)*100 + (e->tv_usec-b->tv_usec)/10000;
#define END(x) { while (*x) x++; }
if (format & PARSE)
cp = "user=%U system=%S elapsed=%E cpu=%P memory=%Xi+%Dd-%Mmaxrss io=%F+%Rpf swaps=%Ccsw";
else
cp = "%Uuser %Ssys %Ereal %P %Xi+%Dd %Mmaxrss %F+%Rpf %Ccsw";
for ( ; *cp; cp++ ) {
if (*cp != '%')
*outp++ = *cp;
else if (cp[1]) switch(*++cp) {
case 'U':
tvsub(&tdiff, &r1->ru_utime, &r0->ru_utime);
sprintf(outp, "%ld.%01ld", (long)tdiff.tv_sec, (long)tdiff.tv_usec/100000);
END(outp);
break;
case 'S':
tvsub(&tdiff, &r1->ru_stime, &r0->ru_stime);
sprintf(outp, "%ld.%01ld", (long)tdiff.tv_sec, (long)tdiff.tv_usec/100000);
END(outp);
break;
case 'E':
psecs(ms / 100, outp);
END(outp);
break;
case 'P':
sprintf(outp, "%d%%", (int) (t*100 / ((ms ? ms : 1))));
END(outp);
break;
case 'W':
i = r1->ru_nswap - r0->ru_nswap;
sprintf(outp, "%d", i);
END(outp);
break;
case 'X':
sprintf(outp, "%ld", t == 0 ? 0 : (r1->ru_ixrss-r0->ru_ixrss)/t);
END(outp);
break;
case 'D':
sprintf(outp, "%ld", t == 0 ? 0 :
(r1->ru_idrss+r1->ru_isrss-(r0->ru_idrss+r0->ru_isrss))/t);
END(outp);
break;
case 'K':
sprintf(outp, "%ld", t == 0 ? 0 :
((r1->ru_ixrss+r1->ru_isrss+r1->ru_idrss) -
(r0->ru_ixrss+r0->ru_idrss+r0->ru_isrss))/t);
END(outp);
break;
case 'M':
sprintf(outp, "%ld", r1->ru_maxrss/2);
END(outp);
break;
case 'F':
sprintf(outp, "%ld", r1->ru_majflt-r0->ru_majflt);
END(outp);
break;
case 'R':
sprintf(outp, "%ld", r1->ru_minflt-r0->ru_minflt);
END(outp);
break;
case 'I':
sprintf(outp, "%ld", r1->ru_inblock-r0->ru_inblock);
END(outp);
break;
case 'O':
sprintf(outp, "%ld", r1->ru_oublock-r0->ru_oublock);
END(outp);
break;
case 'C':
sprintf(outp, "%ld+%ld", r1->ru_nvcsw-r0->ru_nvcsw,
r1->ru_nivcsw-r0->ru_nivcsw);
END(outp);
break;
}
}
*outp = '\0';
}
static void
tvadd( struct timeval *tsum, struct timeval *t0, struct timeval *t1 )
{
tsum->tv_sec = t0->tv_sec + t1->tv_sec;
tsum->tv_usec = t0->tv_usec + t1->tv_usec;
if (tsum->tv_usec > 1000000)
tsum->tv_sec++, tsum->tv_usec -= 1000000;
}
static void
tvsub( struct timeval *tdiff, struct timeval *t1, struct timeval *t0 )
{
tdiff->tv_sec = t1->tv_sec - t0->tv_sec;
tdiff->tv_usec = t1->tv_usec - t0->tv_usec;
if (tdiff->tv_usec < 0)
tdiff->tv_sec--, tdiff->tv_usec += 1000000;
}
static void
psecs( long l, register char *cp )
{
register int i;
i = l / 3600;
if (i) {
sprintf(cp, "%d:", i);
END(cp);
i = l % 3600;
sprintf(cp, "%d%d", (i/60) / 10, (i/60) % 10);
END(cp);
}
else {
i = l;
sprintf(cp, "%d", i / 60);
END(cp);
}
i %= 60;
*cp++ = ':';
sprintf(cp, "%d%d", i / 10, i % 10);
}
/*
* N R E A D
*/
int
Nread( int fd, char *buf, int count )
{
struct sockaddr_storage from;
socklen_t len = sizeof(from);
struct timeval timed; /* time delta */
register int cnt;
if (udp) {
cnt = recvfrom( fd, buf, count, 0, (struct sockaddr *)&from, &len );
numCalls++;
}
else {
if (b_flag)
cnt = mread( fd, buf, count ); /* fill buf */
else {
cnt = read( fd, buf, count );
numCalls++;
}
}
if (do_owd && (cnt > 4)) {
uint32_t secs, usecs;
/* get transmitter timestamp */
bcopy(buf + 8, &secs, 4);
bcopy(buf + 12, &usecs, 4);
timetx.tv_sec = ntohl(secs);
timetx.tv_usec = ntohl(usecs);
get_timeofday(&timerx, (struct timezone *)0);
tvsub( &timed, &timerx, &timetx );
owd = timed.tv_sec*1000 + ((double)timed.tv_usec)/1000;
nowd++;
if (owd < owd_min)
owd_min = owd;
if (owd > owd_max)
owd_max = owd;
owd_avg += owd;
nowdi++;
if (owd < owd_mini)
owd_mini = owd;
if (owd > owd_maxi)
owd_maxi = owd;
owd_avgi += owd;
}
return(cnt);
}
/*
* N W R I T E
*/
int
Nwrite( int fd, char *buf, int count )
{
struct timeval timedol;
struct timeval td;
register int cnt = 0;
double deltat, delta0;
double pktdelay = 0;
int pktdelay_sec, pktdelay_usec, sssdelay;
if (irate) {
sssdelay = 0;
/* Get real time */
get_timeofday(&timedol, (struct timezone *)0);
tvsub( &td, &timedol, &timepk );
deltat = td.tv_sec + ((double)td.tv_usec) / 1000000;
if (deltat >= (1 + maxburst)*pkt_time) {
timepk.tv_sec = timedol.tv_sec;
timepk.tv_usec = timedol.tv_usec;
irate_cum_nsec = 0;
deltat = 0.0;
nburst = 1;
}
if (nburst++ >= maxburst) {
if (iratesss && cwndinfo) {
/* note iratesss only supported for 1 stream */
tvsub( &td, &timedol, &time0 );
delta0 = td.tv_sec + ((double)td.tv_usec)
/ 1000000;
if (delta0 > which_rt*rtt/1000) {
which_rt++;
sss_pkt_cwnd = (cwnd[1] + 1)*1024/datamss;
sss_pkt_cwnd *= 2;
}
pktdelay = rtt/1000/sss_pkt_cwnd*count/datamss;
if (pktdelay <
maxburst*(double)count/rate/125) {
pktdelay =
maxburst*(double)count/rate/125;
iratesss = 0;
}
else {
sssdelay = 1;
}
}
else {
pktdelay = maxburst*(double)count/rate/125;
}
while ((pktdelay > deltat) && !intr) {
/* Get real time */
get_timeofday(&timedol, (struct timezone *)0);
tvsub( &td, &timedol, &timepk );
deltat = td.tv_sec + ((double)td.tv_usec)
/ 1000000;
}
}
if (nburst > maxburst) {
if (sssdelay) {
pktdelay_sec = pktdelay;
pktdelay_usec = (pktdelay - pktdelay_sec)
*1000000;
timepk.tv_usec += pktdelay_usec;
if (timepk.tv_usec >= 1000000) {
timepk.tv_usec -= 1000000;
timepk.tv_sec += 1;
}
timepk.tv_sec += pktdelay_sec;
}
else {
irate_cum_nsec += maxburst*irate_pk_nsec;
while (irate_cum_nsec >= 1000.0) {
irate_cum_nsec -= 1000.0;
timepk.tv_usec++;
}
timepk.tv_usec += maxburst*irate_pk_usec;
while (timepk.tv_usec >= 1000000) {
timepk.tv_usec -= 1000000;
timepk.tv_sec++;
}
}
nburst = 1;
}
if (intr && (!udp || (count != 4))) return(0);
}
else {
while ((double)nbytes/realt/125 > rate) {
/* Get real time */
get_timeofday(&timedol, (struct timezone *)0);
tvsub( &td, &timedol, &time0 );
realt = td.tv_sec + ((double)td.tv_usec) / 1000000;
if (realt <= 0.0) realt = 0.000001;
}
}
if (do_owd && (count > 4)) {
uint32_t secs, usecs;
/* record transmitter timestamp in packet */
get_timeofday(&timedol, (struct timezone *)0);
secs = htonl(timedol.tv_sec);
usecs = htonl(timedol.tv_usec);
bcopy(&secs, buf + 8, 4);
bcopy(&usecs, buf + 12, 4);
}
if (udp) {
again:
if (af == AF_INET) {
cnt = sendto( fd, buf, count, 0, (struct sockaddr *)&sinhim[stream_idx + 1], sizeof(sinhim[stream_idx + 1]) );
}
#ifdef AF_INET6
else if (af == AF_INET6) {
cnt = sendto( fd, buf, count, 0, (struct sockaddr *)&sinhim6[stream_idx + 1], sizeof(sinhim6[stream_idx + 1]) );
}
#endif
else {
err("unsupported AF");
}
numCalls++;
if (cnt<0 && errno == ENOBUFS) {
delay(18000);
errno = 0;
goto again;
}
}
else {
#if defined(linux) && defined(DEBUG)
if (irate && (format & DEBUGIRATE) && debugout) {
struct timeval timewr;
double pktwrtime;
static int cnt = 0;
cnt++;
if (cnt == 1) {
fprintf(debugout, "count = %d, datamss = %d, "
"pktxmit = %.8f, "
"rtt = %.6f, maxburst = %d\n",
count, datamss,
(double)count/rate/125,
rtt/1000, maxburst);
}
get_timeofday(&timewr, (struct timezone *)0);
tvsub( &td, &timewr, &time0 );
pktwrtime = td.tv_sec + (double)td.tv_usec/1000000;
fprintf(debugout, "pktwrtime = %.6f, pktdelay = %.6f, "
"sss_pkt_cwnd = %d, "
"cur_pkt_cwnd = %d, iratesss = %d, "
"which_rt = %d\n",
pktwrtime, pktdelay,
sss_pkt_cwnd,
(cwnd[1] + 1)*1024/datamss, iratesss,
which_rt);
}
#endif
cnt = write( fd, buf, count );
numCalls++;
}
return(cnt);
}
int
delay( int us )
{
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = us;
(void)select( 1, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv );
return(1);
}
/*
* M R E A D
*
* This function performs the function of a read(II) but will
* call read(II) multiple times in order to get the requested
* number of characters. This can be necessary because
* network connections don't deliver data with the same
* grouping as it is written with. Written by Robert S. Miles, BRL.
*/
int
mread( int fd, register char *bufp, unsigned n )
{
register unsigned count = 0;
register int nread;
do {
nread = read(fd, bufp, n-count);
numCalls++;
if (nread < 0) {
if (errno != EINTR)
perror("nuttcp_mread");
return(-1);
}
if (nread == 0)
return((int)count);
count += (unsigned)nread;
bufp += nread;
} while (count < n);
return((int)count);
}
/*
* M W R I T E
*
* This function performs the function of a write(II) but will
* call write(II) multiple times in order to put the requested
* number of characters. This can be necessary because
* piped connections may not be able to deliver data with
* the full requested count.
*/
int
mwrite( int fd, register char *bufp, unsigned n, int last_write )
{
register unsigned count = 0;
register int nwrite;
#if defined(linux)
long flags;
if (directio && last_write) {
flags = fcntl(savestdout, F_GETFL, 0);
if (flags < 0)
errmes("fcntl get O_DIRECT");
else {
flags &= ~O_DIRECT;
if (fcntl(savestdout, F_SETFL, flags) < 0)
errmes("fcntl set O_DIRECT");
}
}
#endif
do {
nwrite = write(fd, bufp, n-count);
numCalls++;
if (nwrite < 0) {
if (errno != EINTR)
perror("nuttcp_mwrite");
return(-1);
}
count += (unsigned)nwrite;
bufp += nwrite;
} while (count < n);
return((int)count);
}
/*
* G E T O P T V A L P
*
* This function returns a character pointer to the option value
* pointed at by argv and sets skiparg to 1 if the option and its
* value were passed as separate arguments (otherwise it sets
* skiparg to 0). index is the position within argv where the
* option value resides if the option was specified as a single
* argument. reqval indicates whether or not the option requires
* a value
*/
char *
getoptvalp( char **argv, int index, int reqval, int *skiparg )
{
struct sockaddr_storage dummy;
char **nextarg;
*skiparg = 0;
nextarg = argv + 1;
/* if there is a value in the current arg return it */
if (argv[0][index])
return(&argv[0][index]);
/* if there isn't a next arg return a pointer to the
current arg value (which will be an empty string) */
if (*nextarg == NULL)
return(&argv[0][index]);
/* if the next arg is another option, and a value isn't
* required, return a pointer to the current arg value
* (which will be an empty string) */
if ((**nextarg == '-') && !reqval)
return(&argv[0][index]);
/* if there is an arg after the next arg and it is another
option, return the next arg as the option value */
if (*(nextarg + 1) && (**(nextarg + 1) == '-')) {
*skiparg = 1;
return(*nextarg);
}
/* if the option requires a value, return the next arg
as the option value */
if (reqval) {
*skiparg = 1;
return(*nextarg);
}
/* if the next arg is an Ipv4 address, return a pointer to the
current arg value (which will be an empty string) */
if (inet_pton(AF_INET, *nextarg, &dummy) > 0)
return(&argv[0][index]);
#ifdef AF_INET6
/* if the next arg is an Ipv6 address, return a pointer to the
current arg value (which will be an empty string) */
if (inet_pton(AF_INET6, *nextarg, &dummy) > 0)
return(&argv[0][index]);
#endif
/* if the next arg begins with an alphabetic character,
assume it is a hostname and thus return a pointer to the
current arg value (which will be an empty string).
note all current options which don't require a value
have numeric values (start with a digit) */
if (isalpha((int)(**nextarg)))
return(&argv[0][index]);
/* assume the next arg is the option value */
*skiparg = 1;
return(*nextarg);
}
#define PROC_SNMP "/proc/net/snmp"
#define PROC_BUF_LEN 256
#define PROC_BUF_LEN2 128
#define NETSTAT "netstat"
#if defined(linux)
#define RETRANS "segments retransmitted"
#define NETSTAT_DIR "/bin/"
#define NRETRANS_BEFORE
#elif defined(__FreeBSD__)
#define RETRANS "retransmitted"
#define NETSTAT_DIR "/usr/bin/"
#define NRETRANS_BEFORE
#elif defined(__APPLE__) && defined(__MACH__)
#define RETRANS "retransmitted"
#define NETSTAT_DIR "/usr/sbin/"
#define NRETRANS_BEFORE
#elif defined(sparc)
#define RETRANS "tcpRetransSegs"
#define NETSTAT_DIR "/usr/bin/"
#elif defined(sgi)
#define RETRANS "retransmitted"
#define NETSTAT_DIR "/usr/etc/"
#define NRETRANS_BEFORE
#elif defined(__CYGWIN__) || defined(_WIN32)
#define RETRANS "Segments Retransmitted"
#define NETSTAT_DIR ""
#else
#define RETRANS "retransmitted"
#define NETSTAT_DIR "/usr/bin/"
#define NRETRANS_BEFORE
#endif
char proc_buf[PROC_BUF_LEN];
char proc_buf2[PROC_BUF_LEN2];
int get_retrans( int sockfd, struct STRUCT_TCPINFO *tcpinfo )
{
FILE *proc_snmp;
char *cp, *cp2;
int num_retrans;
int pipefd[2];
int pidstat;
pid_t pid = 0;
pid_t wait_pid;
if (retransinfo < 0)
return(0);
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
if ((retransinfo <= 1) && (sockfd >= 0)) {
optlen = sizeof(*tcpinfo);
if (getsockopt(sockfd, SOL_TCP, TCP_INFO, (void *)tcpinfo,
&optlen) == 0) {
if (optlen >= SIZEOF_TCP_INFO_RETRANS) {
retransinfo = 1;
cwndinfo = 1;
b_flag = 1;
return(tcpinfo->tcpi_total_retrans);
}
}
if (retransinfo == 1) {
retransinfo = -1;
cwndinfo = 0;
return(0);
}
retransinfo = 2;
cwndinfo = 0;
}
#else
retransinfo = 2;
cwndinfo = 0;
#endif
if ((retransinfo == 3) || (!(proc_snmp = fopen(PROC_SNMP, "r")))) {
retransinfo = 3;
cwndinfo = 0;
if (pipe(pipefd) != 0) {
retransinfo = -1;
cwndinfo = 0;
return(0);
}
if ((pid = fork()) == (pid_t)-1) {
perror("can't fork");
close(pipefd[0]);
close(pipefd[1]);
retransinfo = -1;
cwndinfo = 0;
return(0);
}
if (pid == 0) {
signal(SIGINT, SIG_DFL);
close(1);
close(2);
dup(pipefd[1]);
dup(pipefd[1]);
close(pipefd[0]);
close(pipefd[1]);
execl(NETSTAT_DIR NETSTAT, NETSTAT, "-s", NULL);
perror("execl failed");
fprintf(stderr, "failed to execute %s%s -s\n",
NETSTAT_DIR, NETSTAT);
fflush(stdout);
fflush(stderr);
exit(0);
}
close(pipefd[1]);
if (!(proc_snmp = fdopen(pipefd[0], "r"))) {
close(pipefd[0]);
retransinfo = -1;
cwndinfo = 0;
return(0);
}
}
errno = 0;
num_retrans = -1;
while (fgets(proc_buf, sizeof(proc_buf), proc_snmp)) {
if (retransinfo == 2) {
if (strncmp(proc_buf, "Tcp:", 4) != 0)
continue;
if ((!fgets(proc_buf2, sizeof(proc_buf2), proc_snmp))
|| (strncmp(proc_buf2, "Tcp:", 4) != 0))
break;
cp = proc_buf;
cp2 = proc_buf2;
while ((cp = strchr(cp, ' '))) {
while (*++cp == ' ')
;
if (!(*cp))
goto close;
if (!(cp2 = strchr(cp2, ' ')))
goto close;
while (*++cp2 == ' ')
;
if (!(*cp2))
goto close;
if (strncmp(cp, "RetransSegs", 11) == 0) {
if (!isdigit((int)(*cp2)))
goto close;
num_retrans = atoi(cp2);
goto close;
}
else
continue;
}
}
else {
if ((cp = strstr(proc_buf, RETRANS))) {
#ifdef NRETRANS_BEFORE
num_retrans = atoi(proc_buf);
#else
cp2 = strchr(cp, '=');
cp2++;
num_retrans = atoi(cp2);
#endif
break;
}
}
}
close:
fclose(proc_snmp);
if (retransinfo == 3) {
while ((wait_pid = wait(&pidstat)) != pid) {
if (wait_pid == (pid_t)-1) {
if (errno == ECHILD)
break;
err("wait failed");
}
}
}
if (num_retrans < 0) {
retransinfo = -1;
cwndinfo = 0;
return(0);
}
return(num_retrans);
}
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
void
print_tcpinfo()
{
fprintf(stdout, "state = %d, ca_state = %d, retransmits = %d, "
"unacked = %d, sacked = %d\n",
tcpinf.tcpinfo_state, tcpinf.tcpinfo_ca_state,
tcpinf.tcpinfo_retransmits, tcpinf.tcpinfo_unacked,
tcpinf.tcpinfo_sacked);
fprintf(stdout, " lost = %d, retrans = %d, fackets = %d, "
"rtt = %d, rttvar = %d\n",
tcpinf.tcpinfo_lost, tcpinf.tcpinfo_retrans,
tcpinf.tcpinfo_fackets, tcpinf.tcpinfo_rtt,
tcpinf.tcpinfo_rttvar);
fprintf(stdout, " snd_ssthresh = %d, snd_cwnd = %d, "
"total_retrans = %d\n",
tcpinf.tcpinfo_snd_ssthresh, tcpinf.tcpinfo_snd_cwnd,
tcpinf.tcpi_total_retrans);
return;
}
#endif
|