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
|
/******************************************************************************
* ldns_packet.i: LDNS packet class
*
* Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
* Karel Slany (slany AT fit.vutbr.cz)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the organization nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
/* ========================================================================= */
/* SWIG setting and definitions. */
/* ========================================================================= */
/* Creates a temporary instance of (ldns_pkt *). */
%typemap(in,numinputs=0,noblock=1) (ldns_pkt **)
{
ldns_pkt *$1_pkt;
$1 = &$1_pkt;
}
/* Result generation, appends (ldns_pkt *) after the result. */
%typemap(argout,noblock=1) (ldns_pkt **)
{
$result = SWIG_AppendOutput($result,
SWIG_NewPointerObj(SWIG_as_voidptr($1_pkt),
SWIGTYPE_p_ldns_struct_pkt, SWIG_POINTER_OWN | 0 ));
}
%newobject ldns_pkt_new;
%newobject ldns_pkt_clone;
%newobject ldns_pkt_rr_list_by_type;
%newobject ldns_pkt_rr_list_by_name_and_type;
%newobject ldns_pkt_rr_list_by_name;
%newobject ldns_update_pkt_new;
%nodefaultctor ldns_struct_pkt; /* No default constructor. */
%nodefaultdtor ldns_struct_pkt; /* No default destructor. */
%rename(ldns_pkt) ldns_struct_pkt;
%newobject ldns_pkt2str;
%newobject ldns_pkt_opcode2str;
%newobject ldns_pkt_rcode2str;
%newobject ldns_pkt_algorithm2str;
%newobject ldns_pkt_cert_algorithm2str;
%newobject ldns_pkt_get_section_clone;
/* Clone data on pull. */
%newobject _ldns_pkt_additional;
%rename(__ldns_pkt_additional) ldns_pkt_additional;
%inline
%{
ldns_rr_list * _ldns_pkt_additional(ldns_pkt *p)
{
return ldns_rr_list_clone(ldns_pkt_additional(p));
}
%}
%newobject _ldns_pkt_answer;
%rename(__ldns_pkt_answer) ldns_pkt_answer;
%inline
%{
ldns_rr_list * _ldns_pkt_answer(ldns_pkt *p)
{
return ldns_rr_list_clone(ldns_pkt_answer(p));
}
%}
%newobject _ldns_pkt_answerfrom;
%rename(__ldns_pkt_answerfrom) ldns_pkt_answerfrom;
%inline
%{
ldns_rdf * _ldns_pkt_answerfrom(ldns_pkt *p)
{
ldns_rdf *rdf;
rdf = ldns_pkt_answerfrom(p);
if (rdf != NULL) {
rdf = ldns_rdf_clone(rdf);
}
return rdf;
}
%}
%newobject _ldns_pkt_authority;
%rename(__ldns_pkt_authority) ldns_pkt_authority;
%inline
%{
ldns_rr_list * _ldns_pkt_authority(ldns_pkt *p)
{
return ldns_rr_list_clone(ldns_pkt_authority(p));
}
%}
%newobject _ldns_pkt_edns_data;
%rename(__ldns_pkt_edns_data) ldns_pkt_edns_data;
%inline
%{
ldns_rdf * _ldns_pkt_edns_data(ldns_pkt *p)
{
ldns_rdf *rdf;
rdf = ldns_pkt_edns_data(p);
if (rdf != NULL) {
rdf = ldns_rdf_clone(rdf);
}
return rdf;
}
%}
%newobject _ldns_pkt_tsig;
%rename(__ldns_pkt_tsig) ldns_pkt_tsig;
%inline
%{
ldns_rr * _ldns_pkt_tsig(const ldns_pkt *pkt)
{
return ldns_rr_clone(ldns_pkt_tsig(pkt));
}
%}
%newobject _ldns_pkt_question;
%rename(__ldns_pkt_question) ldns_pkt_question;
%inline
%{
ldns_rr_list * _ldns_pkt_question(ldns_pkt *p)
{
return ldns_rr_list_clone(ldns_pkt_question(p));
}
%}
/* End of pull cloning. */
/* Clone data on push. */
%newobject _ldns_pkt_query_new;
%rename(__ldns_pkt_query_new) ldns_pkt_query_new;
%inline
%{
ldns_pkt * _ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type,
ldns_rr_class rr_class, uint16_t flags)
{
return ldns_pkt_query_new(ldns_rdf_clone(rr_name), rr_type, rr_class,
flags);
}
%}
%rename(__ldns_pkt_push_rr) ldns_pkt_push_rr;
%inline
%{
bool _ldns_pkt_push_rr(ldns_pkt *p, ldns_pkt_section sec, ldns_rr *rr)
{
return ldns_pkt_push_rr(p, sec, ldns_rr_clone(rr));
}
%}
%rename(__ldns_pkt_safe_push_rr) ldns_pkt_safe_push_rr;
%inline
%{
bool _ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec,
ldns_rr *rr)
{
/* Prevents memory leaks when fails. */
ldns_rr *rr_clone = NULL;
bool ret;
if (rr != NULL) {
rr_clone = ldns_rr_clone(rr);
}
ret = ldns_pkt_safe_push_rr(pkt, sec, rr_clone);
if (!ret) {
ldns_rr_free(rr_clone);
}
return ret;
}
%}
%rename(__ldns_pkt_push_rr_list) ldns_pkt_push_rr_list;
%inline
%{
bool _ldns_pkt_push_rr_list(ldns_pkt *p, ldns_pkt_section sec,
ldns_rr_list *rrl)
{
return ldns_pkt_push_rr_list(p, sec, ldns_rr_list_clone(rrl));
}
%}
%rename(__ldns_pkt_safe_push_rr_list) ldns_pkt_safe_push_rr_list;
%inline
%{
bool _ldns_pkt_safe_push_rr_list(ldns_pkt *p, ldns_pkt_section s,
ldns_rr_list *rrl)
{
/* Prevents memory leaks when fails. */
ldns_rr_list *rrl_clone = NULL;
bool ret;
if (rrl != NULL) {
rrl_clone = ldns_rr_list_clone(rrl);
}
ret = ldns_pkt_safe_push_rr_list(p, s, rrl_clone);
if (!ret) {
ldns_rr_list_free(rrl_clone);
}
return ret;
}
%}
%rename(__ldns_pkt_set_additional) ldns_pkt_set_additional;
%inline
%{
void _ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rrl)
{
ldns_rr_list *rrl_clone = NULL;
if (rrl != NULL) {
rrl_clone = ldns_rr_list_clone(rrl);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_additional(p, rrl_clone);
}
%}
%rename(__ldns_pkt_set_answer) ldns_pkt_set_answer;
%inline
%{
void _ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rrl)
{
ldns_rr_list *rrl_clone = NULL;
if (rrl != NULL) {
rrl_clone = ldns_rr_list_clone(rrl);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_answer(p, rrl_clone);
}
%}
%rename (__ldns_pkt_set_answerfrom) ldns_pkt_set_answerfrom;
%inline
%{
void _ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *rdf)
{
ldns_rdf *rdf_clone = NULL;
if (rdf != NULL) {
rdf_clone = ldns_rdf_clone(rdf);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_answerfrom(packet, rdf_clone);
}
%}
%rename(__ldns_pkt_set_authority) ldns_pkt_set_authority;
%inline
%{
void _ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rrl)
{
ldns_rr_list *rrl_clone = NULL;
if (rrl != NULL) {
rrl_clone = ldns_rr_list_clone(rrl);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_authority(p, rrl_clone);
}
%}
%rename(__ldns_pkt_set_edns_data) ldns_pkt_set_edns_data;
%inline
%{
void _ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *rdf)
{
ldns_rdf *rdf_clone = NULL;
if (rdf != NULL) {
rdf_clone = ldns_rdf_clone(rdf);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_edns_data(packet, rdf_clone);
}
%}
%rename(__ldns_pkt_set_question) ldns_pkt_set_question;
%inline
%{
void _ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rrl)
{
ldns_rr_list *rrl_clone = NULL;
if (rrl != NULL) {
rrl_clone = ldns_rr_list_clone(rrl);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_question(p, rrl_clone);
}
%}
%rename(__ldns_pkt_set_tsig) ldns_pkt_set_tsig;
%inline
%{
void _ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
{
ldns_rr *rr_clone = NULL;
if (rr != NULL) {
rr_clone = ldns_rr_clone(rr);
}
/* May leak memory, when overwriting pointer value. */
ldns_pkt_set_tsig(pkt, rr_clone);
}
%}
/* End of push cloning. */
/* ========================================================================= */
/* Debugging related code. */
/* ========================================================================= */
#ifdef LDNS_DEBUG
%rename(__ldns_pkt_free) ldns_pkt_free;
%inline
%{
/*!
* @brief Prints information about deallocated pkt and deallocates.
*/
void _ldns_pkt_free (ldns_pkt* p) {
printf("******** LDNS_PKT free 0x%lX ************\n",
(long unsigned int) p);
ldns_pkt_free(p);
}
%}
#else /* !LDNS_DEBUG */
%rename(_ldns_pkt_free) ldns_pkt_free;
#endif /* LDNS_DEBUG */
/* ========================================================================= */
/* Added C code. */
/* ========================================================================= */
/* None. */
/* ========================================================================= */
/* Encapsulating Python code. */
/* ========================================================================= */
%feature("docstring") ldns_struct_pkt "LDNS packet object.
The :class:`ldns_pkt` object contains DNS packed (either a query or an answer).
It is the complete representation of what you actually send to a name server,
and what you get back (see :class:`ldns.ldns_resolver`).
**Usage**
>>> import ldns
>>> resolver = ldns.ldns_resolver.new_frm_file(\"/etc/resolv.conf\")
>>> pkt = resolver.query(\"nic.cz\", ldns.LDNS_RR_TYPE_NS,ldns.LDNS_RR_CLASS_IN)
>>> print pkt
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 63004
;; flags: qr rd ra ; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; nic.cz. IN NS
;; ANSWER SECTION:
nic.cz. 758 IN NS a.ns.nic.cz.
nic.cz. 758 IN NS c.ns.nic.cz.
nic.cz. 758 IN NS e.ns.nic.cz.
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; Query time: 8 msec
;; SERVER: 82.100.38.2
;; WHEN: Thu Jan 11 12:54:33 2009
;; MSG SIZE rcvd: 75
This simple example instances a resolver in order to resolve NS for nic.cz."
%extend ldns_struct_pkt {
%pythoncode
%{
def __init__(self):
"""
Cannot be created directly from Python.
"""
raise Exception("This class can't be created directly. " +
"Please use: ldns_pkt_new, ldns_pkt_query_new " +
"or ldns_pkt_query_new_frm_str")
__swig_destroy__ = _ldns._ldns_pkt_free
#
# LDNS_PKT_CONSTRUCTORS_
#
@staticmethod
def new():
"""
Creates new empty packet structure.
:return: (:class:`ldns_pkt` ) New empty packet.
"""
return _ldns.ldns_pkt_new()
@staticmethod
def new_query(rr_name, rr_type, rr_class, flags):
"""
Creates a packet with a query in it for the given name,
type and class.
:param rr_name: The name to query for.
:type rr_name: :class:`ldns_dname`
:param rr_type: The type to query for.
:type rr_type: ldns_rr_type
:param rr_class: The class to query for.
:type rr_class: ldns_rr_class
:param flags: Packet flags.
:type flags: uint16_t
:throws TypeError: When arguments of inappropriate types.
:return: (:class:`ldns_pkt`) New object.
.. note::
The type checking of parameter `rr_name` is benevolent.
It allows also to pass a dname :class:`ldns_rdf` object.
This will probably change in future.
"""
if (not isinstance(rr_name, ldns_dname)) and \
isinstance(rr_name, ldns_rdf) and \
rr_name.get_type() == _ldns.LDNS_RDF_TYPE_DNAME:
warnings.warn("The ldns_pkt.new_query() method will" +
" drop the possibility to accept ldns_rdf." +
" Convert argument to ldns_dname.",
PendingDeprecationWarning, stacklevel=2)
if not isinstance(rr_name, ldns_rdf):
raise TypeError("Parameter must be derived from ldns_rdf.")
if (rr_name.get_type() != _ldns.LDNS_RDF_TYPE_DNAME):
raise Exception("Operands must be ldns_dname.")
return _ldns._ldns_pkt_query_new(rr_name, rr_type, rr_class, flags)
@staticmethod
def new_query_frm_str(rr_name, rr_type, rr_class, flags, raiseException = True):
"""
Creates a query packet for the given name, type, class.
:param rr_name: The name to query for.
:type rr_name: str
:param rr_type: The type to query for.
:type rr_type: ldns_rr_type
:param rr_class: The class to query for.
:type rr_class: ldns_rr_class
:param flags: Packet flags.
:type flags: uint16_t
:param raiseException: If True, an exception occurs in case a
packet object can't be created.
:throws TypeError: When arguments of inappropriate types.
:throws Exception: When raiseException set and packet couldn't
be created.
:return: (:class:`ldns_pkt`) Query packet object or None.
If the object can't be created and raiseException is True,
an exception occurs.
**Usage**
>>> pkt = ldns.ldns_pkt.new_query_frm_str("test.nic.cz",ldns.LDNS_RR_TYPE_ANY, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_QR | ldns.LDNS_AA)
>>> rra = ldns.ldns_rr.new_frm_str("test.nic.cz. IN A 192.168.1.1",300)
>>> list = ldns.ldns_rr_list()
>>> if (rra): list.push_rr(rra)
>>> pkt.push_rr_list(ldns.LDNS_SECTION_ANSWER, list)
>>> print pkt
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 0
;; flags: qr aa ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; test.nic.cz. IN ANY
;; ANSWER SECTION:
test.nic.cz. 300 IN A 192.168.1.1
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; Query time: 0 msec
;; WHEN: Thu Jan 1 01:00:00 1970
;; MSG SIZE rcvd: 0
"""
status, pkt = _ldns.ldns_pkt_query_new_frm_str(rr_name, rr_type, rr_class, flags)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create query packet, error: %d" % status)
return None
return pkt
#
# _LDNS_PKT_CONSTRUCTORS
#
def __str__(self):
"""
Converts the data in the DNS packet to presentation format.
:return: (str)
"""
return _ldns.ldns_pkt2str(self)
def opcode2str(self):
"""
Converts a packet opcode to its mnemonic and returns that as an
allocated null-terminated string.
:return: (str)
"""
return _ldns.ldns_pkt_opcode2str(self.get_opcode())
def rcode2str(self):
"""
Converts a packet rcode to its mnemonic and returns that as an
allocated null-terminated string.
:return: (str)
"""
return _ldns.ldns_pkt_rcode2str(self.get_rcode())
def print_to_file(self, output):
"""
Prints the data in the DNS packet to the given file stream
(in presentation format).
:param output: Opened file to write to.
:type output: file
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_print(output, self)
#parameters: FILE *,const ldns_pkt *,
def write_to_buffer(self, buffer):
"""
Copies the packet data to the buffer in wire format.
:param buffer: Buffer to append the result to.
:type buffer: :class:`ldns_buffer`
:throws TypeError: When arguments of inappropriate types.
:return: (ldns_status) ldns_status
"""
return _ldns.ldns_pkt2buffer_wire(buffer, self)
#parameters: ldns_buffer *,const ldns_pkt *,
#retvals: ldns_status
@staticmethod
def algorithm2str(alg):
"""
Converts a signing algorithms to its mnemonic and returns that
as an allocated null-terminated string.
:param alg: The algorithm to convert to text.
:type alg: ldns_algorithm
:return: (str)
"""
return _ldns.ldns_pkt_algorithm2str(alg)
#parameters: ldns_algorithm,
@staticmethod
def cert_algorithm2str(alg):
"""
Converts a cert algorithm to its mnemonic and returns that as an
allocated null-terminated string.
:param alg: Cert algorithm to convert to text.
:type alg: ldns_cert_algorithm
:return: (str)
"""
return _ldns.ldns_pkt_cert_algorithm2str(alg)
#parameters: ldns_algorithm,
#
# LDNS_PKT_METHODS_
#
def aa(self):
"""
Read the packet's aa bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_aa(self)
#parameters: const ldns_pkt *,
#retvals: bool
def ad(self):
"""
Read the packet's ad bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_ad(self)
#parameters: const ldns_pkt *,
#retvals: bool
def additional(self):
"""
Return the packet's additional section.
:return: (:class:`ldns_rr_list`) The additional section.
"""
return _ldns._ldns_pkt_additional(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def all(self):
"""
Return the packet's question, answer, authority and additional
sections concatenated.
:return: (:class:`ldns_rr_list`) Concatenated sections.
"""
return _ldns.ldns_pkt_all(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def all_noquestion(self):
"""
Return the packet's answer, authority and additional sections
concatenated.
Like :meth:`all` but without the questions.
:return: (:class:`ldns_rr_list`) Concatenated sections except
questions.
"""
return _ldns.ldns_pkt_all_noquestion(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def ancount(self):
"""
Return the packet's an count.
:return: (int) The an count.
"""
return _ldns.ldns_pkt_ancount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def answer(self):
"""
Return the packet's answer section.
:return: (:class:`ldns_rr_list`) The answer section.
"""
return _ldns._ldns_pkt_answer(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def answerfrom(self):
"""
Return the packet's answerfrom.
:return: (:class:`ldns_rdf`) The name of the server.
"""
return _ldns._ldns_pkt_answerfrom(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rdf *
def arcount(self):
"""
Return the packet's ar count.
:return: (int) The ar count.
"""
return _ldns.ldns_pkt_arcount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def authority(self):
"""
Return the packet's authority section.
:return: (:class:`ldns_rr_list`) The authority section.
"""
return _ldns._ldns_pkt_authority(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def cd(self):
"""
Read the packet's cd bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_cd(self)
#parameters: const ldns_pkt *,
#retvals: bool
def clone(self):
"""
Clones the packet, creating a fully allocated copy.
:return: (:class:`ldns_pkt`) New packet clone.
"""
return _ldns.ldns_pkt_clone(self)
#parameters: ldns_pkt *,
#retvals: ldns_pkt *
def edns(self):
"""
Returns True if this packet needs and EDNS rr to be sent.
At the moment the only reason is an expected packet size larger
than 512 bytes, but for instance DNSSEC would be a good reason
too.
:return: (bool) True if packet needs EDNS rr.
"""
return _ldns.ldns_pkt_edns(self)
#parameters: const ldns_pkt *,
#retvals: bool
def edns_data(self):
"""
Return the packet's edns data.
:return: (:class:`ldns_rdf`) The edns data.
"""
return _ldns._ldns_pkt_edns_data(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rdf *
def edns_do(self):
"""
Return the packet's edns do bit
:return: (bool) The bit's value.
"""
return _ldns.ldns_pkt_edns_do(self)
#parameters: const ldns_pkt *,
#retvals: bool
def edns_extended_rcode(self):
"""
Return the packet's edns extended rcode.
:return: (uint8_t) The rcode.
"""
return _ldns.ldns_pkt_edns_extended_rcode(self)
#parameters: const ldns_pkt *,
#retvals: uint8_t
def edns_udp_size(self):
"""
Return the packet's edns udp size.
:return: (uint16_t) The udp size.
"""
return _ldns.ldns_pkt_edns_udp_size(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def edns_version(self):
"""
Return the packet's edns version.
:return: (uint8_t) The edns version.
"""
return _ldns.ldns_pkt_edns_version(self)
#parameters: const ldns_pkt *,
#retvals: uint8_t
def edns_z(self):
"""
Return the packet's edns z value.
:return: (uint16_t) The z value.
"""
return _ldns.ldns_pkt_edns_z(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def empty(self):
"""
Check if a packet is empty.
:return: (bool) True: empty, False: not empty
"""
return _ldns.ldns_pkt_empty(self)
#parameters: ldns_pkt *,
#retvals: bool
def get_opcode(self):
"""
Read the packet's code.
:return: (ldns_pkt_opcode) the opcode
"""
return _ldns.ldns_pkt_get_opcode(self)
#parameters: const ldns_pkt *,
#retvals: ldns_pkt_opcode
def get_rcode(self):
"""
Return the packet's response code.
:return: (ldns_pkt_rcode) The response code.
"""
return _ldns.ldns_pkt_get_rcode(self)
#parameters: const ldns_pkt *,
#retvals: ldns_pkt_rcode
def get_section_clone(self, s):
"""
Return the selected rr_list's in the packet.
:param s: What section(s) to return.
:type s: ldns_pkt_section
:throws TypeError: When arguments of inappropriate types.
:return: (:class:`ldns_rr_list`) RR list with the rr's or None
if none were found.
"""
return _ldns.ldns_pkt_get_section_clone(self, s)
#parameters: const ldns_pkt *,ldns_pkt_section,
#retvals: ldns_rr_list *
def id(self):
"""
Read the packet id.
:return: (uint16_t) The packet id.
"""
return _ldns.ldns_pkt_id(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def nscount(self):
"""
Return the packet's ns count.
:return: (uint16_t) The ns count.
"""
return _ldns.ldns_pkt_nscount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def push_rr(self, section, rr):
"""
Push an rr on a packet.
:param section: Where to put it.
:type section: ldns_pkt_section
:param rr: RR to push.
:type rr: :class:`ldns_rr`
:throws TypeError: When arguments of inappropriate types.
:return: (bool) A boolean which is True when the rr was added.
"""
return _ldns._ldns_pkt_push_rr(self,section,rr)
#parameters: ldns_pkt *,ldns_pkt_section,ldns_rr *,
#retvals: bool
def push_rr_list(self, section, list):
"""
Push a rr_list on a packet.
:param section: Where to put it.
:type section: ldns_pkt_section
:param list: The rr_list to push.
:type list: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
:return: (bool) A boolean which is True when the rr was added.
"""
return _ldns._ldns_pkt_push_rr_list(self,section,list)
#parameters: ldns_pkt *,ldns_pkt_section,ldns_rr_list *,
#retvals: bool
def qdcount(self):
"""
Return the packet's qd count.
:return: (uint16_t) The qd count.
"""
return _ldns.ldns_pkt_qdcount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def qr(self):
"""
Read the packet's qr bit.
:return: (bool) value of the bit
"""
return _ldns.ldns_pkt_qr(self)
#parameters: const ldns_pkt *,
#retvals: bool
def querytime(self):
"""
Return the packet's query time.
:return: (uint32_t) The query time.
"""
return _ldns.ldns_pkt_querytime(self)
#parameters: const ldns_pkt *,
#retvals: uint32_t
def question(self):
"""
Return the packet's question section.
:return: (:class:`ldns_rr_list`) The question section.
"""
return _ldns._ldns_pkt_question(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr_list *
def ra(self):
"""
Read the packet's ra bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_ra(self)
#parameters: const ldns_pkt *,
#retvals: bool
def rd(self):
"""
Read the packet's rd bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_rd(self)
#parameters: const ldns_pkt *,
#retvals: bool
def reply_type(self):
"""
Looks inside the packet to determine what kind of packet it is,
AUTH, NXDOMAIN, REFERRAL, etc.
:return: (ldns_pkt_type) The type of packet.
"""
return _ldns.ldns_pkt_reply_type(self)
#parameters: ldns_pkt *,
#retvals: ldns_pkt_type
def rr(self, sec, rr):
"""
Check to see if an rr exist in the packet.
:param sec: In which section to look.
:type sec: ldns_pkt_section
:param rr: The rr to look for.
:type rr: :class:`ldns_rr`
:throws TypeError: When arguments of inappropriate types.
:return: (bool) Return True is exists.
"""
return _ldns.ldns_pkt_rr(self, sec, rr)
#parameters: ldns_pkt *,ldns_pkt_section,ldns_rr *,
#retvals: bool
def rr_list_by_name(self, r, s):
"""
Return all the rr with a specific name from a packet.
:param r: The name.
:type r: :class:`ldns_rdf`
:param s: The packet's section.
:type s: ldns_pkt_section
:throws TypeError: When arguments of inappropriate types.
:return: (:class:`ldns_rr_list`) A list with the rr's or None
if none were found.
"""
return _ldns.ldns_pkt_rr_list_by_name(self,r,s)
#parameters: ldns_pkt *,ldns_rdf *,ldns_pkt_section,
#retvals: ldns_rr_list *
def rr_list_by_name_and_type(self, ownername, atype, sec):
"""
Return all the rr with a specific type and type from a packet.
:param ownername: The name.
:type ownername: :class:`ldns_rdf`
:param atype: The type.
:type atype: ldns_rr_type
:param sec: The packet's section.
:type sec: ldns_pkt_section
:throws TypeError: When arguments of inappropriate types.
:return: (:class:`ldns_rr_list`) A list with the rr's or None
if none were found.
"""
return _ldns.ldns_pkt_rr_list_by_name_and_type(self, ownername, atype, sec)
#parameters: const ldns_pkt *,const ldns_rdf *,ldns_rr_type,ldns_pkt_section,
#retvals: ldns_rr_list *
def rr_list_by_type(self, t, s):
"""
Return all the rr with a specific type from a packet.
:param t: The type.
:type t: ldns_rr_type
:param s: The packet's section.
:type s: ldns_pkt_section
:throws TypeError: When arguments of inappropriate types.
:return: (:class:`ldns_rr_list`) A list with the rr's or None
if none were found.
"""
return _ldns.ldns_pkt_rr_list_by_type(self, t, s)
#parameters: const ldns_pkt *,ldns_rr_type,ldns_pkt_section,
#retvals: ldns_rr_list *
def safe_push_rr(self, sec, rr):
"""
Push an rr on a packet, provided the RR is not there.
:param sec: Where to put it.
:type sec: ldns_pkt_section
:param rr: RR to push.
:type rr: :class:`ldns_rr`
:throws TypeError: When arguments of inappropriate types.
:return: (bool) A boolean which is True when the rr was added.
"""
return _ldns._ldns_pkt_safe_push_rr(self,sec,rr)
#parameters: ldns_pkt *,ldns_pkt_section,ldns_rr *,
#retvals: bool
def safe_push_rr_list(self, sec, list):
"""
Push an rr_list to a packet, provided the RRs are not already
there.
:param sec: Where to put it.
:type sec: ldns_pkt_section
:param list: The rr_list to push.
:type list: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
:return: (bool) A boolean which is True when the list was added.
"""
return _ldns._ldns_pkt_safe_push_rr_list(self, sec, list)
#parameters: ldns_pkt *,ldns_pkt_section,ldns_rr_list *,
#retvals: bool
def set_aa(self, b):
"""
Set the packet's aa bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_aa(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_ad(self, b):
"""
Set the packet's ad bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_ad(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_additional(self, rr):
"""
Directly set the additional section.
:param rr: The rr list to set.
:type rr: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_additional(self, rr)
#parameters: ldns_pkt *,ldns_rr_list *,
#retvals:
def set_ancount(self, c):
"""
Set the packet's an count.
:param c: The count.
:type c: int
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_ancount(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_answer(self, rr):
"""
Directly set the answer section.
:param rr: The rr list to set.
:type rr: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_answer(self, rr)
#parameters: ldns_pkt *,ldns_rr_list *,
#retvals:
def set_answerfrom(self, r):
"""
Set the packet's answering server.
:param r: The address.
:type r: :class:`ldns_rdf`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_answerfrom(self, r)
#parameters: ldns_pkt *,ldns_rdf *,
#retvals:
def set_arcount(self, c):
"""
Set the packet's arcount.
:param c: The count.
:type c: int
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_arcount(self,c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_authority(self, rr):
"""
Directly set the authority section.
:param rr: The rr list to set.
:type rr: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_authority(self, rr)
#parameters: ldns_pkt *,ldns_rr_list *,
#retvals:
def set_cd(self, b):
"""
Set the packet's cd bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_cd(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_edns_data(self, data):
"""
Set the packet's edns data.
:param data: The data.
:type data: :class:`ldns_rdf`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_edns_data(self, data)
#parameters: ldns_pkt *,ldns_rdf *,
#retvals:
def set_edns_do(self, value):
"""
Set the packet's edns do bit.
:param value: The bit's new value.
:type value: bool
"""
_ldns.ldns_pkt_set_edns_do(self, value)
#parameters: ldns_pkt *,bool,
#retvals:
def set_edns_extended_rcode(self, c):
"""
Set the packet's edns extended rcode.
:param c: The code.
:type c: uint8_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_edns_extended_rcode(self, c)
#parameters: ldns_pkt *,uint8_t,
#retvals:
def set_edns_udp_size(self, s):
"""
Set the packet's edns udp size.
:param s: The size.
:type s: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_edns_udp_size(self, s)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_edns_version(self, v):
"""
Set the packet's edns version.
:param v: The version.
:type v: uint8_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_edns_version(self, v)
#parameters: ldns_pkt *,uint8_t,
#retvals:
def set_edns_z(self, z):
"""
Set the packet's edns z value.
:param z: The value.
:type z: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_edns_z(self, z)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_flags(self, flags):
"""
Sets the flags in a packet.
:param flags: ORed values: LDNS_QR| LDNS_AR for instance.
:type flags: int
:throws TypeError: When arguments of inappropriate types.
:return: (bool) True on success, False otherwise.
"""
return _ldns.ldns_pkt_set_flags(self, flags)
#parameters: ldns_pkt *,uint16_t,
#retvals: bool
def set_id(self, id):
"""
Set the packet's id.
:param id: The id to set.
:type id: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_id(self, id)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_nscount(self, c):
"""
Set the packet's ns count.
:param c: The count.
:type c: int
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_nscount(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_opcode(self, c):
"""
Set the packet's opcode.
:param c: The opcode.
:type c: ldns_pkt_opcode
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_opcode(self, c)
#parameters: ldns_pkt *,ldns_pkt_opcode,
#retvals:
def set_qdcount(self, c):
"""
Set the packet's qd count.
:param c: The count.
:type c: int
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_qdcount(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def set_qr(self, b):
"""
Set the packet's qr bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_qr(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_querytime(self, t):
"""
Set the packet's query time.
:param t: The query time in msec.
:type t: uint32_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_querytime(self, t)
#parameters: ldns_pkt *,uint32_t,
#retvals:
def set_question(self, rr):
"""
Directly set the question section.
:param rr: The rr list to set.
:type rr: :class:`ldns_rr_list`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_question(self, rr)
#parameters: ldns_pkt *,ldns_rr_list *,
#retvals:
def set_ra(self, b):
"""
Set the packet's ra bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_ra(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_random_id(self):
"""
Set the packet's id to a random value.
"""
_ldns.ldns_pkt_set_random_id(self)
#parameters: ldns_pkt *,
#retvals:
def set_rcode(self, c):
"""
Set the packet's response code.
:param c: The rcode.
:type c: uint8_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_rcode(self, c)
#parameters: ldns_pkt *,uint8_t,
#retvals:
def set_rd(self, b):
"""
Set the packet's rd bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_rd(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_section_count(self, s, x):
"""
Set a packet's section count to x.
:param s: The section.
:type s: ldns_pkt_section
:param x: The section count.
:type x: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_section_count(self, s, x)
#parameters: ldns_pkt *,ldns_pkt_section,uint16_t,
#retvals:
def set_size(self, s):
"""
Set the packet's size.
:param s: The size.
:type s: int
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_size(self,s)
#parameters: ldns_pkt *,size_t,
#retvals:
def set_tc(self, b):
"""
Set the packet's tc bit.
:param b: The value to set.
:type b: bool
"""
_ldns.ldns_pkt_set_tc(self, b)
#parameters: ldns_pkt *,bool,
#retvals:
def set_timestamp(self, timeval):
"""
Set the packet's time stamp.
:param timestamp: The time stamp.
:type timestamp: struct timeval
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_pkt_set_timestamp(self, timeval)
#parameters: ldns_pkt *,struct timeval,
#retvals:
def set_tsig(self, t):
"""
Set the packet's tsig rr.
:param t: The tsig rr.
:type t: :class:`ldns_rr`
:throws TypeError: When arguments of inappropriate types.
"""
_ldns._ldns_pkt_set_tsig(self, t)
#parameters: ldns_pkt *,ldns_rr *,
#retvals:
def size(self):
"""
Return the packet's size in bytes.
:return: (size_t) The size.
"""
return _ldns.ldns_pkt_size(self)
#parameters: const ldns_pkt *,
#retvals: size_t
def tc(self):
"""
Read the packet's tc bit.
:return: (bool) Value of the bit.
"""
return _ldns.ldns_pkt_tc(self)
#parameters: const ldns_pkt *,
#retvals: bool
def timestamp(self):
"""
Return the packet's time stamp.
:return: (struct timeval) The time stamp.
"""
return _ldns.ldns_pkt_timestamp(self)
#parameters: const ldns_pkt *,
#retvals: struct timeval
def tsig(self):
"""
Return the packet's tsig pseudo rr's.
:return: (:class:`ldns_rr`) The tsig rr.
"""
return _ldns._ldns_pkt_tsig(self)
#parameters: const ldns_pkt *,
#retvals: ldns_rr *
#
# _LDNS_PKT_METHODS#
#
#
# LDNS update methods
#
#
# LDNS_METHODS_
#
def update_ad(self):
"""
Get the ad count.
:return: (uint16_t) The ad count.
"""
return _ldns.ldns_update_ad(self)
#parameters: ldns_pkt *
#retvals: uint16_t
def update_pkt_tsig_add(self, r):
"""
Add tsig credentials to a packet from a resolver.
:param r: Resolver to copy from.
:type r: :class:`ldns_resolver`
:throws TypeError: When arguments of inappropriate types.
:return: (ldns_status) Status whether successful or not.
"""
return _ldns.ldns_update_pkt_tsig_add(self, r)
#parameters: ldns_pkt *,ldns_resolver *,
#retvals: ldns_status
def update_prcount(self):
"""
Get the pr count.
:return: (uint16_t) The pr count.
"""
return _ldns.ldns_update_prcount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def update_set_adcount(self, c):
"""
Set the ad count.
:param c: The ad count to set.
:type c: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_update_set_adcount(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def update_set_prcount(self, c):
"""
Set the pr count.
:param c: The pr count to set.
:type c: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_update_set_prcount(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def update_set_upcount(self, c):
"""
Set the up count.
:param c: The up count to set.
:type c: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_update_set_upcount(self,c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def update_set_zo(self, c):
"""
Set the zo count.
:param c: The zo count to set.
:type c: uint16_t
:throws TypeError: When arguments of inappropriate types.
"""
_ldns.ldns_update_set_zo(self, c)
#parameters: ldns_pkt *,uint16_t,
#retvals:
def update_upcount(self):
"""
Get the up count.
:return: (uint16_t) The up count.
"""
return _ldns.ldns_update_upcount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
def update_zocount(self):
"""
Get the zo count.
:return: (uint16_t) The zo count.
"""
return _ldns.ldns_update_zocount(self)
#parameters: const ldns_pkt *,
#retvals: uint16_t
#
# _LDNS_METHODS
#
%}
}
|