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
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 97">
<meta name="GENERATOR" content="Mozilla/4.6 [en] (Win98; I) [Netscape]">
<title>Introduction</title>
</head>
<body text="#000000" bgcolor="#CCCCCC" link="#0000FF" vlink="#800080" alink="#FF0000">
<a href="6.html">Next</a> <a href="4.html">Previous</a> <a href="lrm.html">Top</a>
<p>
<hr ALIGN="LEFT">
<br><b><font size=+2>5. Library Internals</font></b>
<p><font size=-1>This section is devoted to the internals of the library.
First covered are all the user-accessible functions, then constants, macros
and finally libnet-specific data structures.</font>
<p><font size=-1>Proceeding each function prototype is a small table listing
the return values of the function, whether or not the function is reentrant
(a function is considered reentrant if it may be called repeatedly, or
may be called before previous invocations have completed, and each invocation
is independent of all other invocations) and a brief description of the
function's arguments.</font>
<p><a NAME="s5_1"></a><b><font size=+2>5.1 Memory Management Functions</font></b>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_init_packet(u_short packet_size, u_char **buf);</b>
<br>
<br>
<table BORDER WIDTH="498" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - desired packet size</font>
<br><font size=-1>2 - address of a u_char pointer</font></td>
</tr>
</table>
<p><font size=-1>libnet_init_packet() creates memory for a packet (it doesn't
so much create memory as it requests it from the underlying operating system
via malloc()). Upon success the memory is zero-filled. The
function accepts two arguments, the packet size and the address of the
pointer to the packet. The packet size parameter may be 0, in which
case the library will attempt to guess a packet size for you. Passing
in the pointer to a pointer (passing by address) is necessary as we are
allocating memory locally. If we instead passed in just a pointer
(passing by value) the allocated memory would be lost.</font>
<p><font size=-1>This function is a good example of interface hiding.
This function is essentially a malloc() wrapper. By using this function
the details of what's really happening are abstracted so that you, the
programmer, can worry about your task at hand.</font>
<br>
<hr ALIGN="LEFT">
<br><b>void libnet_destroy_packet(u_char **buf);</b>
<br>
<br>
<table BORDER WIDTH="486" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - address of a u_char pointer </font></td>
</tr>
</table>
<p><font size=-1>libnet_destroy_packet() is the free() analog to libnet_init_packet.
It destroys the packet referenced by 'buf'. In reality, it is of
course a simple free() wrapper. It frees the heap memory and points
`buf` to NULL to dispel the dangling pointer. The function does make
the assertion that `buf` is not NULL. A pointer to a pointer is passed
to maintain interface consistency.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_init_packet_arena(struct libnet_arena **arena, u_short
packet_size, u_short packet_size);</b>
<br>
<br>
<table BORDER WIDTH="566" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to an arena structure pointer</font>
<br><font size=-1>2 - number of packets</font>
<br><font size=-1>3 - packet size</font></td>
</tr>
</table>
<p><font size=-1>libnet_init_packet_arena() allocates and initializes a
memory pool. If you plan on building and sending several different
packets, this is a good choice. It allocates a pool of memory from
which you can grab chunks to build packets (see next_packet_from_arena()).
It takes the address to an arena structure pointer, and hints on
the possible packet size and number of packets. The last two arguments
are used to compute the size of the memory pool. As before, they
can be set to 0 and the library will attempt to choose a decent value.
The function returns -1 if the malloc fails or 1 if everything goes ok.</font>
<br>
<hr ALIGN="LEFT">
<br><b>u_char *libnet_next_packet_from_arena(struct libnet_arena **arena,
u_short packet_size);</b>
<br>
<br>
<table BORDER WIDTH="517" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>pointer to the request packet memory</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NULL</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to the arena</font>
<br><font size=-1>2 - requested packet size</font></td>
</tr>
</table>
<p><font size=-1>libnet_next_packet_from_arena() returns a chunk of memory
from the specified arena of the requested size and decrements the arenas
available byte counter. If the requested memory is not available
from the arena, the function returns NULL. Note that there is nothing
preventing a poorly coded application from using more memory than requested
and causing all kinds of problems. Take heed.</font>
<br>
<hr ALIGN="LEFT">
<br><b>void libnet_destroy_packet_arena(struct libnet_arena **arena);</b>
<br>
<br>
<table BORDER WIDTH="436" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to the arena</font></td>
</tr>
</table>
<p><font size=-1>libnet_destroy_packet_arena() frees the memory associated
with the specified arena.</font>
<br>
<hr ALIGN="LEFT">
<br><a NAME="s5_2"></a><b><font size=+2>5.2 Address Resolution Functions</font></b>
<br>
<hr ALIGN="LEFT">
<br><b>u_char *libnet_host_lookup(u_long ip, u_short use_name);</b>
<br>
<br>
<br>
<table BORDER WIDTH="521" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>pointer to the converted IP address</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NULL</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>no</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - network-byte ordered IP address</font>
<br><font size=-1>2 - use_name flag</font></td>
</tr>
</table>
<p><font size=-1>libnet_host_lookup() converts the supplied network-ordered
(big-endian) IP address into its human-readable counterpart. If the
usename flag is LIBNET_RESOLVE, the function will attempt to resolve the
IP address (possibly incurring DNS network traffic) and return a canonical
hostname, otherwise if it is LIBNET_DONT_RESOLVE (or if the lookup fails),
the function returns a dotted-decimal ASCII string. This function
is hopelessly non reentrant as it uses static data.</font>
<br>
<hr ALIGN="LEFT">
<br><b>void libnet_host_lookup_r(u_long ip, u_short use_name, u_char *buf);</b>
<br>
<br>
<table BORDER WIDTH="579" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>depends on architecture</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - network-byte ordered IP address</font>
<br><font size=-1>2 - use_name flag</font>
<br><font size=-1>3 - buffer to contain the converted IP address</font></td>
</tr>
</table>
<p><font size=-1>libnet_host_lookup_r() is the planned reentrant version
of the above function. If reentrant network resolver libraries become
available, this function will likewise be reentrant. An additional
argument of a buffer to store the converted (or resolved) IP address is
supplied by the user.</font>
<br>
<hr ALIGN="LEFT">
<br><b>u_long libnet_name_resolve(u_char *ip, u_short use_name);</b>
<br>
<br>
<table BORDER WIDTH="578" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>network-byte ordered IP address</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - human readable IP address or FQDN</font>
<br><font size=-1>2 - use_name flag</font></td>
</tr>
</table>
<p><font size=-1>libnet_name_resolve() takes a NULL terminated ASCII string
representation of an IP address (dots and decimals or, if the usename flag
is LIBNET_RESOLVE, a canonical hostname) and converts it into a network-ordered
(big-endian) unsigned long value.</font>
<hr ALIGN="LEFT">
<br><b>u_long libnet_get_ipaddr(struct libnet_link_int *l, const u_char
*device, const u_char *ebuf);</b>
<br>
<br>
<table BORDER WIDTH="729" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>requested IP address</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a link interface structure</font>
<br><font size=-1>2 - pointer to the device to query</font>
<br><font size=-1>3 - pointer to a buffer to contain a possible error message</font></td>
</tr>
</table>
<p><font size=-1>libnet_get_ipaddr() returns the IP address of a specified
network device. The function takes a pointer to a link layer interface
structure, a pointer to the network device name, and an empty buffer to
be used in case of error. Upon success the function returns the IP
address of the specified interface in network-byte order or 0 upon error
(and errbuf will contain a reason).</font>
<br>
<hr ALIGN="LEFT">
<br><b>struct ether_addr *libnet_get_hwaddr(struct libnet_link_int *l,
const u_char *device, const u_char *ebuf);</b>
<br>
<br>
<table BORDER WIDTH="720" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>pointer to the requested ethernet address</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NULL</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>depends on architecture</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a link interface structure</font>
<br><font size=-1>2 - pointer to the device to query</font>
<br><font size=-1>3 - pointer to a buffer to contain a possible error message</font></td>
</tr>
</table>
<p><font size=-1>libnet_get_hwaddr() returns the hardware address of a
specified network device. At the time of this writing, only ethernet
is supported. The function takes a pointer to a link layer interface
structure, a pointer to the network device name, and an empty buffer to
be used in case of error. The function returns the MAC address of
the specified interface upon success or NULL upon error (and errbuf will
contain a reason).</font>
<br>
<hr ALIGN="LEFT">
<br><a NAME="s5_3"></a><b><font size=+2>5.3 Packet Injection Support Functions</font></b>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_open_raw_sock(int protocol);</b>
<br>
<br>
<table BORDER WIDTH="601" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>opened socket</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - protocol number of desired socket type</font></td>
</tr>
</table>
<p><font size=-1>libnet_open_raw_sock() opens a raw IP socket of the specified
protocol type (supported types vary from system to system, but usually
you'll want to open an IPPROTO_RAW socket). The function also sets
the IP_HDRINCL socket option. Returned is the socket file descriptor
or -1 on error. The function can fail if either of the underlying
calls to socket or setsockopt fails. Checking errno will reveal the
reason for the error.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_close_raw_sock(int socket);</b>
<br>
<br>
<table BORDER WIDTH="436" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - socket to be closed</font></td>
</tr>
</table>
<p><font size=-1>libnet_close_raw_sock() will close the referenced raw
socket.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_select_device(struct sockaddr_in *sin, u_char **device,
u_char *ebuf);</b>
<br>
<br>
<table BORDER WIDTH="693" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>no</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a sockaddr_in structure
pointer</font>
<br><font size=-1>2 - pointer to the device to query</font>
<br><font size=-1>3 - pointer to a buffer to contain a possible error message</font></td>
</tr>
</table>
<p><font size=-1>libnet_select_device() will run through the list of interfaces
and select one for use (ignoring the loopback device). If the device
argument points to NULL (don't pass in a NULL pointer, the function expects
a pointer to a pointer, and C can't derefrence a NULL pointer) it will
try to fill it in with the first non-loopback device it finds, otherwise,
it will try to open the specified device. If successful, 1 is returned
(and if device was NULL, it will now contain the device name which can
be used in libnet_*link*() type calls). The function can fail for
a variety of reasons, including socket system call failures, ioctl failures,
if no interfaces are found, etc.. If such an error occurs, -1 is
returned and errbuf will contain a reason.</font>
<br>
<hr ALIGN="LEFT">
<br><b>struct libnet_link_int *libnet_open_link_interface(char *device,
char *ebuf);</b>
<br>
<br>
<table BORDER WIDTH="733" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>pointer to a link interface structure</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NULL</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a device</font>
<br><font size=-1>2 - pointer to a buffer to contain a possible error message</font></td>
</tr>
</table>
<p><font size=-1>libnet_open_link_interface() opens a low-level packet
interface. This is required in order to be able inject link layer
frames. Supplied is a u_char pointer to the interface device name
and a u_char pointer to an error buffer. Returned is a filled-in
link_int structure or NULL on error (with the error buffer containing the
reason). The function can fail for a variety of reasons due to the
fact that it is architecture specific.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_close_link_interface(struct libnet_link_int *l);</b>
<br>
<br>
<table BORDER WIDTH="712" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a link interface structure</font></td>
</tr>
</table>
<p><font size=-1>libnet_close_link_interface() closes an opened low-level
packet interface.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_write_ip(int socket, u_char *packet, int packet_size);</b>
<br>
<br>
<table BORDER WIDTH="436" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>packet size</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - socket</font>
<br><font size=-1>2 - pointer to the packet</font>
<br><font size=-1>3 - packet size</font></td>
</tr>
</table>
<p><font size=-1>libnet_write_ip() writes an IP packet to the network.
The first argument is the socket created with a previous call to libnet_open_raw_sock,
the second is a pointer to a buffer containing a complete IP datagram,
and the third argument is the total packet size. The function returns
the number of bytes written upon success or -1 on error (with errno containing
the reason).</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_write_link_layer(struct libnet_link_int *l, const u_char
*device, u_char *packet, int packet_size);</b>
<br>
<br>
<table BORDER WIDTH="666" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>packet size</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>depends on architecture</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a link interface structure</font>
<br><font size=-1>2 - pointer to the network device</font>
<br><font size=-1>3 - pointer to the packet</font>
<br><font size=-1>4 - packet size</font></td>
</tr>
</table>
<p><font size=-1>libnet_write_link_layer() writes a link-layer frame to
the network. The first argument is a pointer to a filled-in libnet_link_int
structure, the next is a pointer to the network device, the third is the
raw packet and the last is the packet size. Returned is the number
of bytes written or -1 on error.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_do_checksum(u_char *packet, int protocol, int packet_size);</b>
<br>
<br>
<table BORDER WIDTH="659" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a packet</font>
<br><font size=-1>2 - protocol number of packet type</font>
<br><font size=-1>3 - packet size</font></td>
</tr>
</table>
<p><font size=-1>libnet_do_checksum() calculates the checksum for a packet.
The first argument is a pointer to a fully built IP packet. The second
is the transport protocol of the packet and the third is the packet length
(not including the IP header). The function calculates the checksum
for the transport protocol and fills it in at the appropriate header location
(this function should be called only after a complete packet has been built).</font>
<p><font size=-1>Note that when using raw sockets the IP checksum is always
computed by the kernel and does not need to done by the user. When
using the link layer interface the IP checksum must be explicitly computed
(in this case, the protocol would be of type IPPROTO_IP and the size would
include IP_H). The function returns 1 upon success or -1 if the protocol
is of an unsupported type. Currently supported are:</font>
<br>
<br>
<table BORDER WIDTH="366" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>PROTOCOL</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_TCP</font></td>
<td VALIGN=CENTER><font size=-1>TCP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_UDP</font></td>
<td VALIGN=CENTER><font size=-1>UDP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_ICMP</font></td>
<td VALIGN=CENTER><font size=-1>ICMP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_IGMP</font></td>
<td VALIGN=CENTER><font size=-1>IGMP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_IP</font></td>
<td VALIGN=CENTER><font size=-1>IP (for the link-layer api)</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_OSPF</font></td>
<td VALIGN=CENTER><font size=-1>OSPF</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IPPROTO_OSPF</font></td>
<td VALIGN=CENTER><font size=-1>OSPF_LSA</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><a NAME="s5_4"></a><b><font size=+2>5.4 Packet Construction Functions</font></b>
<br>
<hr ALIGN="LEFT">
<br><font size=-1>All libnet packet creation functions contain the same
three terminal arguments: a pointer to an optional payload (or NULL if
no payload is to be included), the length of the payload in bytes (or 0
if no payload is included) and most importantly, a pointer to a pre-allocated
block of memory (which must be large enough to accommodate the entire packet
and payload).</font>
<p><font size=-1>The only way for any libnet packet construction function
will return an error is if the memory which is supposed to be pre-allocated
points to NULL.</font>
<p><b>libnet_build_arp(u_short hrdw, u_short prot, u_short h_len, u_short
p_len, u_short op, u_char *s_ha, u_char *s_pa, u_char *t_ha, u_char *t_pa,
const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="656" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - hardware address format (ARPHRD_ETHER)</font>
<br><font size=-1>2 - protocol address format</font>
<br><font size=-1>3 - length of the hardware address</font>
<br><font size=-1>4 - length of the protocol address</font>
<br><font size=-1>5 - ARP operation type</font>
<br><font size=-1>6 - sender's hardware address</font>
<br><font size=-1>7 - sender's protocol address</font>
<br><font size=-1>8 - target's hardware address</font>
<br><font size=-1>9 - target's protocol address</font>
<br><font size=-1>10 - pointer to packet payload</font>
<br><font size=-1>11 - packet payload length</font>
<br><font size=-1>12 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_arp() constructs an ARP (RARP) packet.
At this point in the library, the function only builds ethernet/ARP packets,
but this will be easy enough to change (whenever I get around to it).
The first nine arguments are standard ARP header arguments, with the last
three being standard libnet packet creation arguments. The ARP operation
type should be one of the following symbolic types:</font>
<br>
<table BORDER WIDTH="472" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_REQUEST</font></td>
<td VALIGN=CENTER><font size=-1>ARP request</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_REPLY</font></td>
<td VALIGN=CENTER><font size=-1>ARP reply</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_REVREQUEST</font></td>
<td VALIGN=CENTER><font size=-1>RARP request</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_REVREPLY</font></td>
<td VALIGN=CENTER><font size=-1>RARP reply</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_INVREQUEST </font></td>
<td VALIGN=CENTER><font size=-1>request to identify peer</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ARPOP_INVREPLY</font></td>
<td VALIGN=CENTER><font size=-1>reply identifying peer</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_dns(u_short id, u_short flags, u_short num_q, u_short
num_answ_rr, u_short num_auth_rr, u_short num_add_rr, const u_char * payload,
int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="658" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet id</font>
<br><font size=-1>2 - control flags</font>
<br><font size=-1>3 - number of questions</font>
<br><font size=-1>4 - number of answer resource records</font>
<br><font size=-1>5 - number of authority resource records</font>
<br><font size=-1>6 - number of additional resource records</font>
<br><font size=-1>7 - pointer to packet payload</font>
<br><font size=-1>8 - packet payload length</font>
<br><font size=-1>9 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_dns() constructs a DNS packet. The
static DNS fields are included as the first six arguments, but the optional
variable length fields must be included with the payload interface.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ethernet(u_char *daddr, u_char *saddr, u_short
id, const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="574" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to the destination address</font>
<br><font size=-1>2 - pointer to the source address</font>
<br><font size=-1>3 - ethernet packet type</font>
<br><font size=-1>4 - pointer to packet payload</font>
<br><font size=-1>5 - packet payload size</font>
<br><font size=-1>6 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ethernet() constructs an ethernet packet.
The destination address and source address arguments are expected to be
arrays of unsigned character bytes. The packet type should be one
of the following:</font>
<br>
<table BORDER WIDTH="469" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>PROTOCOL</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_PUP</font></td>
<td VALIGN=CENTER><font size=-1>PUP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_IP</font></td>
<td VALIGN=CENTER><font size=-1>IP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_ARP</font></td>
<td VALIGN=CENTER><font size=-1>ARP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_REVARP</font></td>
<td VALIGN=CENTER><font size=-1>RARP</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_VLAN</font></td>
<td VALIGN=CENTER><font size=-1>IEEE VLAN tagging</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ETHERTYPE_LOOPBACK</font></td>
<td VALIGN=CENTER><font size=-1>loopback test</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_echo(u_char type, u_char code, u_short id,
u_short seq, const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="557" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1- packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - packet id</font>
<br><font size=-1>4 - packet sequence number</font>
<br><font size=-1>5 - pointer to packet payload</font>
<br><font size=-1>6 - packet payload size</font>
<br><font size=-1>7 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_echo() constructs an ICMP_ECHO / ICMP_ECHOREPLY
packet. The packet type should be ICMP_ECHOREPLY or ICMP_ECHO and
the code should be 0.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_mask(u_char type, u_char code, u_short id,
u_short seq, u_long mask, const u_char *payload, int payload_len, u_char
*packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="596" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - packet id</font>
<br><font size=-1>4 - packet sequence number</font>
<br><font size=-1>5 - IP netmask</font>
<br><font size=-1>6 - pointer to packet payload</font>
<br><font size=-1>7 - packet payload length</font>
<br><font size=-1>8 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_mask() constructs an ICMP_MASKREQ /
ICMP_MASKREPLY packet. The packet type should be either ICMP_MASKREQ
or ICMP_MASKREPLY and the code should be 0. The IP netmask argument
should be a 32-bit network-byte ordered subnet mask.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_unreach(u_char type, u_char code, u_short
orig_len, u_char orig_tos, u_short orig_id, u_short orig_frag, u_char orig_ttl,
u_char orig_prot, u_long orig_saddr, u_long orig_daddr, const u_char *payload,
int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="592" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - original IP length</font>
<br><font size=-1>4 - original IP TOS</font>
<br><font size=-1>5 - original IP id</font>
<br><font size=-1>6 - original IP fragmentation bits</font>
<br><font size=-1>7 - original IP time to live</font>
<br><font size=-1>8 - original IP protocol</font>
<br><font size=-1>9 - original IP source address</font>
<br><font size=-1>10 - original IP destination address</font>
<br><font size=-1>11 - pointer to original IP payload</font>
<br><font size=-1>12 - original IP payload size</font>
<br><font size=-1>13 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_unreach() constructs an ICMP_UNREACH
packet. The 3rd through the 12th arguments are used to build the
IP header of the original packet that caused the error message (the ICMP
unreachable). The packet type should be ICMP_UNREACH and the code
should be one of the following:</font>
<br>
<table BORDER WIDTH="699" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_NET</font></td>
<td VALIGN=CENTER><font size=-1>network is unreachable</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_HOST</font></td>
<td VALIGN=CENTER><font size=-1>host is unreachable</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_PROTOCOL</font></td>
<td VALIGN=CENTER><font size=-1>protocol is unreachable</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_PORT</font></td>
<td VALIGN=CENTER><font size=-1>port is unreachable</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_NEEDFRAG</font></td>
<td VALIGN=CENTER><font size=-1>fragmentation required but DF bit set</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_SRCFAIL</font></td>
<td VALIGN=CENTER><font size=-1>source routing failed</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_NET_UNKOWN</font></td>
<td VALIGN=CENTER><font size=-1>network is unknown</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_HOST_PROHIB</font></td>
<td VALIGN=CENTER><font size=-1>host is prohibited</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_TOSNET</font></td>
<td VALIGN=CENTER><font size=-1>IP TOS and network</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_TOSHOST</font></td>
<td VALIGN=CENTER><font size=-1>IP TOS and host</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_FILTER_PROHIB</font></td>
<td VALIGN=CENTER><font size=-1>prohibitive filtering</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_HOST_PRECEDENCE</font></td>
<td VALIGN=CENTER><font size=-1>host precedence</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_PRECEDENCE_CUTOFF</font></td>
<td VALIGN=CENTER><font size=-1>host precedence cut-off</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_timeexceed(u_char, u_char, u_short, u_char,
u_short, u_short, u_char, u_char, u_long, u_long, const u_char *, int,
u_char *);</b>
<br>
<br>
<table BORDER WIDTH="637" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - original IP length</font>
<br><font size=-1>4 - original IP TOS</font>
<br><font size=-1>5 - original IP id</font>
<br><font size=-1>6 - original IP fragmentation bits</font>
<br><font size=-1>7 - original IP time to live</font>
<br><font size=-1>8 - original IP protocol</font>
<br><font size=-1>9 - original IP source address</font>
<br><font size=-1>10 - original IP destination address</font>
<br><font size=-1>11 - pointer to original IP payload</font>
<br><font size=-1>12 - original IP payload size</font>
<br><font size=-1>13 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_timeexceed() constructs an ICMP_TIMEXCEED
packet. This function is identical to libnet_build_icmp_unreach with
the exception of the packet type and code. The packet type should
be either ICMP_TIMXCEED_INTRANS for packets that expired in transit (TTL
expired) or ICMP_TIMXCEED_REASS for packets that expired in the fragmentation
reassembly queue.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_redirect(u_char type, u_char code, u_long
gateway, u_short orig_len, u_char orig_tos, u_short orig_id, u_short orig_frag,
u_char orig_ttl, u_char orig_prot, u_long orig_saddr, u_long orig_daddr,
const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="590" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - IP address of the gateway</font>
<br><font size=-1>4 - original IP length</font>
<br><font size=-1>5 - original IP TOS</font>
<br><font size=-1>6 - original IP id</font>
<br><font size=-1>7 - original IP fragmentation bits</font>
<br><font size=-1>8 - original IP time to live</font>
<br><font size=-1>9 - original IP protocol</font>
<br><font size=-1>10 - original IP source address</font>
<br><font size=-1>11 - original IP destination address</font>
<br><font size=-1>12 - pointer to original IP payload</font>
<br><font size=-1>13 - original IP payload size</font>
<br><font size=-1>14 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_redirect() constructs an ICMP_REDIRECT
packet. This function is similar to libnet_build_icmp_unreach, the
differences being the type and code and the addition of an argument to
hold the IP address of the gateway that should be used (hence the redirect).
The packet type should be ICMP_REDIRECT and the code should be one of the
following:</font>
<br>
<table BORDER WIDTH="545" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_NET</font></td>
<td VALIGN=CENTER><font size=-1>redirect for network</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_HOST</font></td>
<td VALIGN=CENTER><font size=-1>redirect for host</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_PROTOCOL</font></td>
<td VALIGN=CENTER><font size=-1>redirect for TOS and network</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>ICMP_UNREACH_PORT</font></td>
<td VALIGN=CENTER><font size=-1>redirect for TOS and host</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_icmp_timestamp(u_char type, u_char code, u_short
id, u_short seq, n_time otime, n_time rtime, n_time ttime, const u_char
*payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="566" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - packet id</font>
<br><font size=-1>4 - packet sequence number</font>
<br><font size=-1>5 - originate timestamp</font>
<br><font size=-1>6 - receive timestamp</font>
<br><font size=-1>7 - transmit timestamp</font>
<br><font size=-1>8 - pointer to packet payload</font>
<br><font size=-1>9 - packet payload size</font>
<br><font size=-1>10 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_icmp_timestamp() constructs an ICMP_TSTAMP
/ ICMP_TSTAMPREPLY packet. The packet type should be ICMP_TSTAMP
or ICMP_TSTAMPREPLY and the code should be 0.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_igmp(u_char type, u_char code, u_long ip, const
u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<table BORDER WIDTH="607" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet type</font>
<br><font size=-1>2 - packet code</font>
<br><font size=-1>3 - IP address</font>
<br><font size=-1>4 - pointer to packet payload</font>
<br><font size=-1>5 - packet payload size</font>
<br><font size=-1>6 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_igmp() constructs an IGMP packet. The
packet type should be one of the following:</font>
<br>
<table BORDER WIDTH="597" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IGMP_MEMBERSHIP_QUERY</font></td>
<td VALIGN=CENTER><font size=-1>membership query</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IGMP_V1_MEMBERSHIP_REPORT</font></td>
<td VALIGN=CENTER><font size=-1>version 1 membership report</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IGMP_V2_MEMBERSHIP_REPORT</font></td>
<td VALIGN=CENTER><font size=-1>version 2 membership report</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IGMP_LEAVE_GROUP</font></td>
<td VALIGN=CENTER><font size=-1>leave-group message</font></td>
</tr>
</table>
<p><font size=-1>The code, which is a routing sub-message, should probably
be left to 0, unless you know what you're doing.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ip(u_short len, u_char tos, u_short ip_id, u_short
frag, u_char ttl, u_char protocol, u_long saddr, u_long daddr, const u_char
*payload, int payload_len, u_char *packet_buf);</b>
<br>
<br>
<table BORDER WIDTH="622" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet length (not including the IP
header)</font>
<br><font size=-1>2 - type of service</font>
<br><font size=-1>3 - packet id</font>
<br><font size=-1>4 - fragmentation bits / offset</font>
<br><font size=-1>5 - time to live</font>
<br><font size=-1>6 - protocol</font>
<br><font size=-1>7 - source address</font>
<br><font size=-1>8 - destination address</font>
<br><font size=-1>9 - pointer to packet payload</font>
<br><font size=-1>10 - packet payload length</font>
<br><font size=-1>11 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ip() constructs the mighty IP packet.
The fragmentation field may be 0 or contain some combination of the following:</font>
<br>
<table BORDER WIDTH="654" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IP_DF</font></td>
<td VALIGN=CENTER><font size=-1>don't fragment this datagram (only valid
when alone)</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>IP_MF</font></td>
<td VALIGN=CENTER><font size=-1>more fragments on the way (OR'd together
with an offset value)</font></td>
</tr>
</table>
<p><font size=-1>The IP_OFFMASK is used to retrieve the offset from the
fragmentation field. IP packets may be no larger than IP_MAXPACKET
bytes. The source and destination addresses need to be in network-byte
order. The payload interface should only be used to construct an
arbitrary or non-supported type IP datagram. To construct a TCP,
UDP, or similar type packet, use the relevant libnet_build function.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf(u_short len, u_char type, u_long router_id,
u_long area_id, u_short auth_type, const char *payload, int payload_s,
u_char *buf);</b>
<br>
<table BORDER WIDTH="651" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet length (not including the OSPF
header)</font>
<br><font size=-1>2 - packet type</font>
<br><font size=-1>3 - router ID</font>
<br><font size=-1>4 - area ID</font>
<br><font size=-1>5 - authentication type</font>
<br><font size=-1>6 - pointer to packet payload</font>
<br><font size=-1>7 - packet payload length</font>
<br><font size=-1>8 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf() builds a OSPF packet. You pass
the packet length (not including the OSPF header), the packet type, 32-bit
router ID, 32-bit area ID, the authentication type, a pointer to an optional
data payload, the payload length, and a pointer to a pre-allocated block
of memory for the packet. The payload should not be used to build
the Hello, LSA, LSU, LSR, or DBD packets as there are specific construction
functions for those packet types. The following variables are to
be used for the OSPF packet type:</font>
<br>
<table BORDER WIDTH="435" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_UMD</font></td>
<td VALIGN=CENTER><font size=-1>UMD monitoring packet</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_HELLO</font></td>
<td VALIGN=CENTER><font size=-1>Hello packet</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_DBD</font></td>
<td VALIGN=CENTER><font size=-1>Database description packet</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_LSR</font></td>
<td VALIGN=CENTER><font size=-1>Link state request packet</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_LSU</font></td>
<td VALIGN=CENTER><font size=-1>Link state update packet</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_LSA</font></td>
<td VALIGN=CENTER><font size=-1>Link state acknowledgement packet</font></td>
</tr>
</table>
<p><font size=-1>The following are the possible authentication types:</font>
<br>
<table BORDER WIDTH="513" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_AUTH_NULL</font></td>
<td VALIGN=CENTER><font size=-1>NULL password</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_AUTH_SIMPLE</font></td>
<td VALIGN=CENTER><font size=-1>plaintext, 8 character password</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>OSPF_AUTH_MD5</font></td>
<td VALIGN=CENTER><font size=-1>MD5</font></td>
</tr>
</table>
<p><font size=-1>The following is the structure used for the 64 bit field
when using MD5:</font>
<p><tt> struct auth {</tt>
<br><tt> u_short ospf_auth_null;
/* NULL 16 bits */</tt>
<br><tt> u_char ospf_auth_keyid;
/* Key ID */</tt>
<br><tt> u_char ospf_auth_len;
/* Auth data len */</tt>
<br><tt> u_int ospf_auth_seq;
/* Sequence num */</tt>
<br><tt> };</tt>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_hello(u_long netmask, u_short interval, u_char
options, u_char priority, u_int dead_interval, u_long des_router, u_long
backup, u_long neighbor, const char *payload, int payload_s, u_char *buf);</b>
<br>
<br>
<table BORDER WIDTH="609" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - netmask for interface</font>
<br><font size=-1>2 - num of seconds since last packet was sent</font>
<br><font size=-1>3 - options</font>
<br><font size=-1>4 - priority</font>
<br><font size=-1>5 - num of seconds until router is deemed dead</font>
<br><font size=-1>6 - designated router</font>
<br><font size=-1>7 - backup router</font>
<br><font size=-1>8 - neighbor</font>
<br><font size=-1>9 - packet payload</font>
<br><font size=-1>10 - payload length</font>
<br><font size=-1>11 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_hello() builds an OSPF Hello packet.
You pass the netmask for the interface, the number of seconds since the
last packet was sent, possible options, the router's priority (if 0, it
can't be a backup router), the time (in seconds) until a router is deemed
down, the networks designated router, the networks backup router, a neighbor,
a pointer to an optional data payload, the payload length, and a pointer
to a pre-allocated block of memory used for the packet. If there
is more than one neighbor that is to be included in the packet, just allocate
enough space for the packet buf, and pass the neighbors as the "optional
data payload."</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_dbd(u_short len, u_char options, u_char type,
u_int sequence_num, const char *payload, int payload_s, u_char *buf);</b>
<br>
<br>
<table BORDER WIDTH="603" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - length</font>
<br><font size=-1>2 - options</font>
<br><font size=-1>3 - type</font>
<br><font size=-1>4 - sequence number</font>
<br><font size=-1>5 - packet payload</font>
<br><font size=-1>6 - payload length</font>
<br><font size=-1>7 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_dbd() builds an OSPF DataBase Description
(DBD) packet. You pass the maximum length of an IP packet the interface
can use, packet options, the type of exchange occurring, a sequence number,
a pointer to an optional data payload, the payload length, and a pointer
to a pre-allocated block of memory for the packet. The following
can be used for the type variable:</font>
<br>
<table BORDER WIDTH="382" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>DBD_IBIT</font></td>
<td VALIGN=CENTER><font size=-1>Initialization bit</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>DBD_MBIT</font></td>
<td VALIGN=CENTER><font size=-1>More DBD packets en route</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>DBD_MSBIT</font></td>
<td VALIGN=CENTER><font size=-1>Sender is the master</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsr(u_int type, u_int ls_id, u_long adv_router,
const char *payload, int payload_s, u_char *buf);</b>
<br>
<br>
<table BORDER WIDTH="594" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - type</font>
<br><font size=-1>2 - ID</font>
<br><font size=-1>3 - advertising router</font>
<br><font size=-1>4 - packet payload</font>
<br><font size=-1>5 - payload length</font>
<br><font size=-1>6 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsr() builds an OSPF Link State Request
(LSR) packet. You pass the type of link state packet being requested, the
link state ID, the advertising router, a pointer to an optional data payload,
the payload length, and a pointer to a pre-allocated block of memory for
the packet. See the libnet_build_ospf_lsa() section for more information
regarding variables.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsu(u_int num, const char *payload, int payload_s,
u_char *buf);</b>
<br>
<table BORDER WIDTH="611" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - number of LSA packets inside</font>
<br><font size=-1>2 - packet payload</font>
<br><font size=-1>3 - payload length</font>
<br><font size=-1>4 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsu() builds an OSPF Link State Update
(LSU) packet. You pass the number of Link State Acknowledgment (LSA)
packets that will be in the packet, a pointer to an optional data payload,
the payload length, and a pointer to a pre-allocated block of memory for
the packet.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsa(u_short age, u_char options, u_char type,
u_int ls_id, u_long adv_router, u_int sequence_num, u_short len, const
char *payload, int payload_s, u_char *buf);</b>
<br>
<table BORDER WIDTH="597" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - link state age</font>
<br><font size=-1>2 - options</font>
<br><font size=-1>3 - type</font>
<br><font size=-1>4 - link state ID</font>
<br><font size=-1>5 - advertising router</font>
<br><font size=-1>6 - sequence number</font>
<br><font size=-1>7 - length not including LSA header</font>
<br><font size=-1>8 - packet payload</font>
<br><font size=-1>9 - payload length</font>
<br><font size=-1>10 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsa() builds an OSPF Link State Acknowledgement
(LSA) packet. You pass the link state age, packet options, type of
LSA, the link state ID, the advertising router, the packet's sequence number,
the length of the packet (_not_ including the LSA header length), a pointer
to an optional data payload, the payload length, and a pointer to a pre-allocated
block of memory for the packet. The following variables can be used
for the type of LSA:</font>
<br>
<table BORDER WIDTH="469" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LS_TYPE_RTR</font></td>
<td VALIGN=CENTER><font size=-1>Router LSA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LS_TYPE_NET</font></td>
<td VALIGN=CENTER><font size=-1>Network LSA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LS_TYPE_IP</font></td>
<td VALIGN=CENTER><font size=-1>Summary LSA (IP network)</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LS_TYPE_ASBR</font></td>
<td VALIGN=CENTER><font size=-1>Summary LSA (ASBR)</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LS_TYPE_ASEXT</font></td>
<td VALIGN=CENTER><font size=-1>AS-External LSA</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsa_rtr(u_short flags, u_short num, u_int
id, u_int data, u_char type, u_char tos, u_short metric, const char *payload,
int payload_s, u_char *buf);</b>
<br>
<table BORDER WIDTH="605" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - flags</font>
<br><font size=-1>2 - number of links</font>
<br><font size=-1>3 - link ID</font>
<br><font size=-1>4 - info for link ID</font>
<br><font size=-1>5 - router link type</font>
<br><font size=-1>6 - TOS metrics</font>
<br><font size=-1>7 - packet payload</font>
<br><font size=-1>8 - payload length</font>
<br><font size=-1>9 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsa_rtr() builds an OSPF Link State
Router packet. You pass the optional packet flags, the number of
links within that packet, the link ID (helps describe the next variable),
the info for the specified link ID, the type of router link, the number
of TOS metrics for this link, the metric (the cost of using the link),
a pointer to an optional data payload, the payload length, and a pointer
to a pre-allocated block of memory for the packet. The possible flags
(not including 0x00) are as follows:</font>
<br>
<table BORDER WIDTH="255" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_FLAGS_W</font></td>
<td VALIGN=CENTER><font size=-1>W bit</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_FLAGS_E</font></td>
<td VALIGN=CENTER><font size=-1>E bit</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_FLAGS_B</font></td>
<td VALIGN=CENTER><font size=-1>B bit</font></td>
</tr>
</table>
<p><font size=-1>The possible link ID's are as follows:</font>
<br>
<table BORDER WIDTH="255" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LINK_ID_NBR_ID</font></td>
<td VALIGN=CENTER><font size=-1>Neighbors router ID</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LINK_ID_IP_DES</font></td>
<td VALIGN=CENTER><font size=-1>IP address of router</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LINK_ID_SUB</font></td>
<td VALIGN=CENTER><font size=-1>IP subnet number</font></td>
</tr>
</table>
<p><font size=-1>The possible values for the router type are as follows:</font>
<br>
<table BORDER WIDTH="255" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_TYPE_PTP</font></td>
<td VALIGN=CENTER><font size=-1>Point to point</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_TYPE_TRANS</font></td>
<td VALIGN=CENTER><font size=-1>Connection to a `transit network`</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_TYPE_STUB</font></td>
<td VALIGN=CENTER><font size=-1>Connection to a `stub network`</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RTR_TYPE_VRTL</font></td>
<td VALIGN=CENTER><font size=-1>Connection to a `virtual link`</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsa_net(u_long netmask, u_int router_id, const
char *payload, int payload_s, u_char *buf);</b>
<br>
<table BORDER WIDTH="573" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - netmask</font>
<br><font size=-1>2 - router ID</font>
<br><font size=-1>3 - packet payload</font>
<br><font size=-1>4 - packet payload length</font>
<br><font size=-1>5 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsa_net() builds an OSPF Link Sate Network
packet. You pass the interface's netmask, the router ID, a pointer
to an optional data payload, the payload length, and a pointer to a pre-allocated
block of memory for the packet.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsa_sum(u_long netmask, u_int metric, u_int
tos, const char *payload, int payload_s, u_char *buf);</b>
<br>
<br>
<table BORDER WIDTH="622" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - netmask</font>
<br><font size=-1>2 - metric</font>
<br><font size=-1>3 - TOS</font>
<br><font size=-1>4 - packet payload</font>
<br><font size=-1>5 - packet payload length</font>
<br><font size=-1>6 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_ospf_lsa_sum() builds an OSPF Link State
Summary packet. You pass the interface's netmask, the cost of using
the link (metric), the TOS, which is passed as a unsigned integer but the
first 8 bits are the TOS and the last 24 bits are the TOS metric, a pointer
to an optional data payload, the payload length, and a pointer to a pre-allocated
block of memory for the packet.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_ospf_lsa_as(u_long netmask, u_int metric, u_long
fwd_addr, u_int tag, const char *payload, int payload_s, u_char *buf);</b>
<br>
<table BORDER WIDTH="578" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - netmask</font>
<br><font size=-1>2 - metric</font>
<br><font size=-1>3 - forwarding address</font>
<br><font size=-1>4 - external route tag</font>
<br><font size=-1>6 - packet payload</font>
<br><font size=-1>7 - packet payload length</font>
<br><font size=-1>8 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_buils_ospf_lsa_as() builds an OSPF Link State AS
External packet. You pass the interface's netmask, the cost of using the
link (metric), the forwarding address, the external route tag, a pointer
to an optional data payload, the payload length, and a pointer to a pre-allocated
block of memory for the packet. In reality, the metric only uses
the last 24 bits of the unsigned int. The first 8bits are reserved
for a possible bit to be set (the E bit, see above for more info).
The variable AS_E_BIT_ON can be used logically to set the E bit on.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_build_rip(u_char cmd, u_char ver, u_short domain, u_short
addr_fam, u_short route_tag, u_long ip, u_long mask, u_long next_hop, u_long
metric, const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<table BORDER WIDTH="604" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - command</font>
<br><font size=-1>2 - version</font>
<br><font size=-1>3 - routing domain (or zero)</font>
<br><font size=-1>4 - address family</font>
<br><font size=-1>5 - route tag (or zero)</font>
<br><font size=-1>6 - IP address</font>
<br><font size=-1>7 - netmask (or zero)</font>
<br><font size=-1>8 - next hop IP address (or zero)</font>
<br><font size=-1>9 - metric</font>
<br><font size=-1>10 - pointer to packet payload</font>
<br><font size=-1>11 - packet payload length</font>
<br><font size=-1>12 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_rip() constructs a RIP packet. Depending
on the version of RIP you are using, packet fields are slightly different.
The following chart highlights these differences:</font>
<br>
<table BORDER WIDTH="457" >
<tr>
<td VALIGN=CENTER><b>ARGUMENT</b></td>
<td VALIGN=CENTER><b>VERSION 1</b></td>
<td VALIGN=CENTER><b>VERSION 2</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>1</font></td>
<td VALIGN=CENTER><font size=-1>command</font></td>
<td VALIGN=CENTER><font size=-1>command</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>2</font></td>
<td VALIGN=CENTER><font size=-1>RIPVER_1</font></td>
<td VALIGN=CENTER><font size=-1>RIPVER_2</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>3</font></td>
<td VALIGN=CENTER><font size=-1>zero</font></td>
<td VALIGN=CENTER><font size=-1>routing domain</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>4</font></td>
<td VALIGN=CENTER><font size=-1>address family</font></td>
<td VALIGN=CENTER><font size=-1>address family</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>5</font></td>
<td VALIGN=CENTER><font size=-1>zero</font></td>
<td VALIGN=CENTER><font size=-1>subnet mask</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>6</font></td>
<td VALIGN=CENTER><font size=-1>IP address</font></td>
<td VALIGN=CENTER><font size=-1>IP address</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>7</font></td>
<td VALIGN=CENTER><font size=-1>zero</font></td>
<td VALIGN=CENTER><font size=-1>subnet mask</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>8</font></td>
<td VALIGN=CENTER><font size=-1>zero</font></td>
<td VALIGN=CENTER><font size=-1>next hop ip</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>9</font></td>
<td VALIGN=CENTER><font size=-1>metric</font></td>
<td VALIGN=CENTER><font size=-1>metric</font></td>
</tr>
</table>
<p><font size=-1>The RIP commands should be one of the following:</font>
<br>
<table BORDER WIDTH="255" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_REQUEST</font></td>
<td VALIGN=CENTER><font size=-1>RIP request</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_RESPONSE</font></td>
<td VALIGN=CENTER><font size=-1>RIP response</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_TRACEON</font></td>
<td VALIGN=CENTER><font size=-1>RIP tracing on</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_TRACEOFF</font></td>
<td VALIGN=CENTER><font size=-1>RIP tracing off</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_POLL</font></td>
<td VALIGN=CENTER><font size=-1>RIP polling</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_POLLENTRY</font></td>
<td VALIGN=CENTER><font size=-1>RIP poll entry</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>RIPCMD_MAX</font></td>
<td VALIGN=CENTER> </td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_tcp(u_short th_sport, u_short th_dport, u_long
th_seq, u_long th_ack, u_char th_flags, u_short th_win, u_short th_urg,
const u_char *payload, int payload_len, u_char *packet_buf);</b>
<br>
<table BORDER WIDTH="565" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - source port</font>
<br><font size=-1>2 - destination port</font>
<br><font size=-1>3 - sequence number</font>
<br><font size=-1>4 - acknowledgement number</font>
<br><font size=-1>5 - control flags </font>
<br><font size=-1>6 - window size</font>
<br><font size=-1>7 - urgent pointer</font>
<br><font size=-1>8 - pointer to packet payload</font>
<br><font size=-1>9 - packet payload size</font>
<br><font size=-1>10 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_tcp() constructs a TCP packet. The
control flags should be one or more of the following (OR'd together if
need be):</font>
<br>
<table BORDER WIDTH="517" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_URG</font></td>
<td VALIGN=CENTER><font size=-1>urgent data is present</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_ACK</font></td>
<td VALIGN=CENTER><font size=-1>acknowledgement number field should be
checked</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_PSH</font></td>
<td VALIGN=CENTER><font size=-1>push this data to the application</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_RST</font></td>
<td VALIGN=CENTER><font size=-1>reset the referenced connection</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_SYN</font></td>
<td VALIGN=CENTER><font size=-1>synchronize connection sequence numbers</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>TH_FIN</font></td>
<td VALIGN=CENTER><font size=-1>sender is finished sending data</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<br><b>int libnet_build_udp(u_short sport, u_short dport, const u_char
*payload, int payload_len, u_char *packet_buf);</b>
<br>
<table BORDER WIDTH="560" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - source port</font>
<br><font size=-1>2 - destination port</font>
<br><font size=-1>3 - pointer to packet payload</font>
<br><font size=-1>4 - packet payload size</font>
<br><font size=-1>5 - pointer to pre-allocated packet memory</font></td>
</tr>
</table>
<p><font size=-1>libnet_build_udp() constructs a UDP packet. Please
remember that UDP checksums are considered mandatory by the host requirements
RFC.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_insert_ipo(struct ipoption *opt, u_char opt_len, u_char
*packet_buf);</b>
<br>
<table BORDER WIDTH="632" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a IP options structure (filled
in)</font>
<br><font size=-1>2 - options length</font>
<br><font size=-1>3 - pointer to a complete IP packet</font></td>
</tr>
</table>
<p><font size=-1>libnet_insert_ipo() inserts IP options into a pre-built
IP packet. Supplied is a pointer to an ip options structure, the
size of this options list, and a pointer the pre-built packet. The
options list should be constructed as they will appear on the wire, as
they are simply inserted into the packet at the appropriate location.</font>
<p><font size=-1>The function returns -1 if the options would result in
packet too large (greater then 65535 bytes), or if the packet buffer is
NULL. It is an unchecked runtime error for the user to have not allocated
enough heap memory for the IP packet plus the IP options.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_insert_tcpo(struct tcpoption *opt, u_char opt_len, u_char
*packet_buf);</b>
<br>
<table BORDER WIDTH="615" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a TCP options structure
(filled in)</font>
<br><font size=-1>2 - options length</font>
<br><font size=-1>3 - pointer to a complete IP/TCP packet</font></td>
</tr>
</table>
<p><font size=-1>libnet_insert_tcpo() inserts TCP options into a pre-built
IP/TCP packet. Supplied is a pointer to a tcp options structure, the size
of this options list, and a pointer the pre-built packet. The options
list should be constructed as they will appear on the wire, as they are
simply inserted into the packet at the appropriate location.</font>
<p><font size=-1>The function returns -1 if the options would result in
packet too large (greater then 65535 bytes), if the packet isn't an IP/TCP
packet, if the options list if longer than 20 bytes, or if the packet buffer
is NULL. It is an unchecked runtime error for the user to have not
allocated enough heap memory for the IP/TCP packet plus the IP options.</font>
<br>
<hr ALIGN="LEFT">
<br><a NAME="s5_5"></a><b><font size=+2>5.5 Support Functions</font></b>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_seed_prand();</b>
<br>
<table BORDER WIDTH="436" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
</table>
<p><font size=-1>libnet_seed_prand() seeds the pseudo-random number generator.
The function is basically a wrapper to srandom. It makes a call to
gettimeofday to get entropy. It can return -1 if the call to gettimeofday
fails (check errno). It otherwise returns 1.</font>
<br>
<hr ALIGN="LEFT">
<br><b>u_long libnet_get_prand(int modulus);</b>
<br>
<br>
<table BORDER WIDTH="690" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - maximum size of pseudo-random number
desired</font></td>
</tr>
</table>
<p><font size=-1>libnet_get_prand() generates a psuedo-random number.
The range of the returned number is controlled by the function's only argument:</font>
<br>
<table BORDER WIDTH="255" >
<tr>
<td VALIGN=CENTER><b>VALUE</b></td>
<td VALIGN=CENTER><b>DESCSRIPTION</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR2</font></td>
<td VALIGN=CENTER><font size=-1>0 - 1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR8</font></td>
<td VALIGN=CENTER><font size=-1>0 - 255</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR16</font></td>
<td VALIGN=CENTER><font size=-1>0 - 32767</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRu16</font></td>
<td VALIGN=CENTER><font size=-1>0 - 65535</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR32</font></td>
<td VALIGN=CENTER><font size=-1>0 - 2147483647</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRu32</font></td>
<td VALIGN=CENTER><font size=-1>0 - 4294967295</font></td>
</tr>
</table>
<p><font size=-1>The function does not fail.</font>
<br>
<hr ALIGN="LEFT">
<br><b>void libnet_hex_dump(u_char * buf, int len, int swap, FILE *stream);</b>
<br>
<table BORDER WIDTH="699" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - packet to dump</font>
<br><font size=-1>2 - packet length</font>
<br><font size=-1>3 - byte swap flag</font>
<br><font size=-1>4 - previously opened stream in which to dump packet</font></td>
</tr>
</table>
<p><font size=-1>libnet_hex_dump() prints out a packet in hexadecimal.
It will print the packet as it appears in memory, or as it will appear
on the wire, depending on the value of the byte-swap flag. The function
prints the packet to a previously opened stream (such as stdout).
Note that on big-endian architectures such as Solaris, the packet will
appear the same in memory as it will on the wire.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_plist_chain_new(struct libnet_plist_chain **plist, char
*token_list);</b>
<br>
<table BORDER WIDTH="558" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a libnet_plist_chain pointer</font>
<br><font size=-1>2 - pointer to token list</font></td>
</tr>
</table>
<p><font size=-1>libnet_plist_chain_new() constructs a new libnet port-list
chain. A libnet port-list chain is a fast and simple way of implementing
port-list ranges (useful for applications that employ a list of ports -
like a port scanner). You'll see naive implementations that allocate
an entire array of 65535 bytes and fill in the desired ports one by one.
However, we only really need to store the beginning port and the ending
port, and we can efficiently store multiple port ranges (delimited by commas)
by using a linked list chain with each node holding the beginning and ending
port for a particular range. For example, The port range `1-1024`
would occupy one node with the beginning port being 1 and the ending port
being 1024. The port range `25,110-161,6000` would result in 3 nodes
being allocated. Single ports are taken as single ranges (port 25
ends up being 25-25). A port list range without a terminating port
(port_num - ) is considered shorthand for (port_num - 65535).</font>
<p><font size=-1>The arguments are a pointer to libnet_plist_chain pointer
(which will end up being the head of the linked list) which needs to deference
an allocated libnet_plist_chain structure and pointer to the port-list
(token-list) itself.</font>
<p><font size=-1>The function checks this character port list for valid
tokens (1234567890,- ) and returns an error if an unrecognized token is
found.</font>
<p><font size=-1>Upon success the function returns 1, and head points to
the newly formed port-list (and also contains the number of nodes in the
list. If an error occurs (an unrecognized token is found or malloc
fails) -1 is returned and head is set to NULL.</font>
<p><font size=-1>libnet_plist_chain_next_pair() should be used to extract
port list pairs.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_plist_chain_next_pair(struct libnet_plist_chain *plist,
u_short *bport, u_short *eport);</b>
<br>
<table BORDER WIDTH="603" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1, 0</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a libnet_plist_chain pointer</font>
<br><font size=-1>2 - pointer to the beginning port (to be filled in)</font>
<br><font size=-1>3 - pointer to the ending port (to be filled in)</font></td>
</tr>
</table>
<p><font size=-1>libnet_plist_chain_next_pair() fetches the next pair of
ports from the list. The function takes a pointer to the head of
the prebuilt list and a pointer to a u_short that will contain the beginning
port and a pointer to a u_short that will contain the ending port.</font>
<p><font size=-1>The function returns 1 and fills in these values if there
are nodes remaining, or if the port list chain is exhausted, it returns
0. If an error occurs (the libnet_plist_chain pointer is NULL) the
function</font>
<br><font size=-1>returns -1.</font>
<br>
<hr ALIGN="LEFT">
<br><b>int libnet_plist_chain_dump(struct libnet_plist_chain *plist);</b>
<br>
<br>
<table BORDER WIDTH="539" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>-1</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a libnet_plist_chain pointer</font></td>
</tr>
</table>
<p><font size=-1>libnet_plist_chain_dump() dumps the port-list chain referenced
by the argument. The function prints the list to stdout (it's mainly
meant as a debugging tool). It returns 1 upon success or if an error
occurs (the libnet_plist_chain pointer is NULL) the function returns -1.</font>
<br>
<hr ALIGN="LEFT">
<br><b>u_char *libnet_plist_chain_dump_string(struct libnet_plist_chain
*plist);</b>
<br>
<table BORDER WIDTH="557" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>pointer to the token list</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NULL</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>no</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a libnet_plist_chain pointer</font></td>
</tr>
</table>
<p><font size=-1>libnet_plist_chain_dump_string() returns the port-list
chain referenced by the argument as a string. It returns the port
list string upon success or if an error occurs (the libnet_plist_chain
pointer is NULL) the function returns NULL.</font>
<br>
<hr ALIGN="LEFT">
<br><b>void libnet_plist_chain_free(struct libnet_plist_chain *plist);</b>
<br>
<table BORDER WIDTH="559" >
<tr>
<td VALIGN=CENTER><font size=-1>return value upon success</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>return value upon failure</font></td>
<td VALIGN=CENTER><font size=-1>NA</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>re-entrant</font></td>
<td VALIGN=CENTER><font size=-1>yes</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>arguments</font></td>
<td VALIGN=CENTER><font size=-1>1 - pointer to a libnet_plist_chain pointer</font></td>
</tr>
</table>
<p><font size=-1>libnet_plist_chain_free() frees the memory associated
with the libnet port list chain.</font>
<br>
<hr ALIGN="LEFT">
<br><a NAME="s5_6"></a><b><font size=+2>5.6 Symbolic Constants</font></b>
<br>
<hr ALIGN="LEFT">
<br><font size=-1>Libnet conveniently defines standard packet header sizes,
for use with many packet manipulation functions, as per the following chart:</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>SYMBOLIC CONSTANT </b></td>
<td VALIGN=CENTER><b>SIZE IN BYTES</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ARP_H</font></td>
<td VALIGN=CENTER><font size=-1>28</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_DNS_H</font></td>
<td VALIGN=CENTER><font size=-1>12</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ETH_H</font></td>
<td VALIGN=CENTER><font size=-1>14</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_H (deprecated)</font></td>
<td VALIGN=CENTER><font size=-1>4</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_ECHO_H</font></td>
<td VALIGN=CENTER><font size=-1>8</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_MASK_H </font></td>
<td VALIGN=CENTER><font size=-1>12</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_UNREACH_H </font></td>
<td VALIGN=CENTER><font size=-1>8</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_TIMXCEED_H</font></td>
<td VALIGN=CENTER><font size=-1>8 </font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_REDIRECT_H</font></td>
<td VALIGN=CENTER><font size=-1>8 </font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ICMP_TS_H </font></td>
<td VALIGN=CENTER><font size=-1>20</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_IGMP_H</font></td>
<td VALIGN=CENTER><font size=-1>8</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_IP_H</font></td>
<td VALIGN=CENTER><font size=-1>20</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_RIP_H</font></td>
<td VALIGN=CENTER><font size=-1>24</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_TCP_H</font></td>
<td VALIGN=CENTER><font size=-1>20</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_UDP_H</font></td>
<td VALIGN=CENTER><font size=-1>8</font></td>
</tr>
</table>
<p><font size=-1>More packet memory constants:</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>SYMBOLIC CONSTANT</b></td>
<td VALIGN=CENTER><b>MEANING</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PACKET</font></td>
<td VALIGN=CENTER><font size=-1>enough memory for a TCP or UDP header and
an IP header</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_OPTS</font></td>
<td VALIGN=CENTER><font size=-1>enough memory for IP or TCP options (40
bytes)</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_MAX_PACKET</font></td>
<td VALIGN=CENTER><font size=-1>enough memory for IP_MAXPACKET (65535 bytes)</font></td>
</tr>
</table>
<p><font size=-1>The following are used for psuedo random number generation,
with libnet_get_prand():</font>
<br>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>SYMBOLIC CONSTANT </b></td>
<td VALIGN=CENTER><b>RANGE</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRAND_MAX</font></td>
<td VALIGN=CENTER><font size=-1>65535</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR2</font></td>
<td VALIGN=CENTER><font size=-1>0 - 2</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR8</font></td>
<td VALIGN=CENTER><font size=-1>0 - 255</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR16</font></td>
<td VALIGN=CENTER><font size=-1>0 - 32767</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRu16</font></td>
<td VALIGN=CENTER><font size=-1>0 - 65535</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PR32</font></td>
<td VALIGN=CENTER><font size=-1>0 - 2147483647</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRu32</font></td>
<td VALIGN=CENTER><font size=-1>0 - 4294967295</font></td>
</tr>
</table>
<p><font size=-1>For error messaging, used in conjunction with libnet_error():</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>SYMBOLIC CONSTANT</b></td>
<td VALIGN=CENTER><b>MEANING</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ERR_WARNING</font></td>
<td VALIGN=CENTER>warning error message</td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ERR_CRITICAL</font></td>
<td VALIGN=CENTER>critical error message</td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_ERR_FATAL</font></td>
<td VALIGN=CENTER>fatal error message (program will exit)</td>
</tr>
</table>
<p><font size=-1>For use with libnet_host_lookup(), libnet_host_lookup_r(),
and libnet_name_resolve():</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>SYMBOLIC CONSTANT </b></td>
<td VALIGN=CENTER><b>MEANING</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_DONT_RESOLVE </font></td>
<td VALIGN=CENTER><font size=-1>do not resolve IP addresses into FQDNs</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_RESOLVE </font></td>
<td VALIGN=CENTER><font size=-1>attempt to resolve IP addresses into FQDNs</font></td>
</tr>
</table>
<p>
<hr ALIGN="LEFT">
<br><a NAME="s5_7"></a><b><font size=+2>5.7 Macros</font></b>
<br>
<hr ALIGN="LEFT">
<p><font size=-1>The arena interface defines the following macros:</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>MACRO</b></td>
<td VALIGN=CENTER><b>MEANING</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_GET_ARENA_SIZE(</font><tt>arena</tt><font size=-1>)</font></td>
<td VALIGN=CENTER><font size=-1>returns the size of the arena</font></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_GET_ARENA_REMAINING_BYTES(</font><tt>arena</tt><font size=-1>)</font></td>
<td VALIGN=CENTER><font size=-1>returns the number of bytes left in the
arena</font></td>
</tr>
</table>
<p><font size=-1>To print the ethernet address from an ether_addr struct
use the following macro:</font>
<br>
<table BORDER CELLSPACING=3 CELLPADDING=3 >
<tr>
<td VALIGN=CENTER><b>MACRO</b></td>
<td VALIGN=CENTER><b>MEANING</b></td>
</tr>
<tr>
<td VALIGN=CENTER><font size=-1>LIBNET_PRINT_ETH_ADDR(</font><tt>e</tt><font size=-1>)</font></td>
<td VALIGN=CENTER><font size=-1>Prints the ethernet address of the ether_addr
struct</font></td>
</tr>
</table>
<hr ALIGN="LEFT">
<p><b><font size=-1><a href="6.html">Next</a> <a href="4.html">Previous</a><a href="lrm.html">Top</a></font></b>
</body>
</html>
|