[Python-modules-commits] [python-getdns] 01/05: Import python-getdns_0.6.1.orig.tar.gz

Scott Kitterman kitterman at moszumanska.debian.org
Thu Apr 7 05:24:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

kitterman pushed a commit to branch master
in repository python-getdns.

commit 64844280ecc464f1d3f89340d7f944dcfb0fd165
Author: Scott Kitterman <scott at kitterman.com>
Date:   Thu Apr 7 01:10:39 2016 -0400

    Import python-getdns_0.6.1.orig.tar.gz
---
 README.md                 |  2 +-
 examples/client_subnet.py | 36 ++++++++----------------------------
 pygetdns_util.c           |  8 ++++----
 3 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/README.md b/README.md
index f67e035..b1fca56 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Built and tested against Python 2.7 and Python 3.4.  You will need to install
 the Python headers and libraries - this is usually a package
 called "python-dev"
 
-Currently building against the getdns 0.3.1 release.
+Currently building against the getdns v0.9.0 release.
 getdns external dependencies include:
 
 * [libldns from NLnet Labs](https://www.nlnetlabs.nl/projects/ldns/) version 1.6.11 or later (ldns requires ope
diff --git a/examples/client_subnet.py b/examples/client_subnet.py
index e3b781b..66ac035 100755
--- a/examples/client_subnet.py
+++ b/examples/client_subnet.py
@@ -1,47 +1,27 @@
 import getdns
-import socket, fcntl, sys
 from struct import pack, unpack
-
-
-#
-#  returns a tuple containing the network part of the ip 
-#  address for the interface and the netmask, both encoded
-#  in strings.  Definitely not portable to Windows, probably
-#  not portable to some Unixes.  Unfortunately you have
-#  to pass in the name of the interface; interface name
-#  will be discovered in a future version
-#
-
-def get_network_info(ifname):
-    SIOCGIFADDR = 0x8915
-    SIOCGIFNETMASK = 0x891b
-
-    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-    netmask = fcntl.ioctl(s.fileno(), SIOCGIFNETMASK, pack('256s',ifname))[20:24]
-    addr = fcntl.ioctl(s.fileno(), SIOCGIFADDR, pack('256s', ifname))[20:24]
-    return (pack('!I', (unpack('!I', addr)[0] & unpack('!I', netmask)[0])), netmask)
     
 
 def main():
     CLIENT_SUBNET_OPCODE = 8
-    LOCAL_INTERFACE = 'eth0'
+        
+    address = '192.168.1.0'
     host = 'getdnsapi.net'
+    source_len = 12
     
-    if len(sys.argv) == 2:
-        host = sys.argv[1]
     family = pack("!H", 1)  # start building the edns option fields
-    source_netmask, address = get_network_info(LOCAL_INTERFACE)
-    scope_netmask = pack("B", 0)
+    source_len = pack('!B', source_len)
+    scope_len = pack('!B', 0)
 
 #
 # encoding the binary data in strings makes it really easy
 # to build packets by concatenating those strings
 #
-    payload = family + source_netmask + scope_netmask + address
-    length = pack("!H", len(payload))
+    address = pack('!BBBB', 192, 168, 1, 0)
+    payload = family + source_len + scope_len + address
     ext = { 'add_opt_parameters': {'options':
                                        [ {'option_code': CLIENT_SUBNET_OPCODE,
-                                          'option_data': length+payload} ] }}
+                                          'option_data': payload} ] }}
 
     c = getdns.Context()
     c.resolution_type = getdns.RESOLUTION_STUB
diff --git a/pygetdns_util.c b/pygetdns_util.c
index 36a0d5a..17b7124 100644
--- a/pygetdns_util.c
+++ b/pygetdns_util.c
@@ -329,13 +329,13 @@ extensions_to_getdnsdict(PyDictObject *pydict)
                             }  else if (!strncmp(tmpoptionlistkey, "option_data", strlen("option_data")))  {
                                 option_data = (struct getdns_bindata *)malloc(sizeof(struct getdns_bindata));
                                 option_data->size = PyObject_Length(optiondictvalue);
+                                printf("XXX size is %d\n", (int)option_data->size);
 #if PY_MAJOR_VERSION >= 3
-/* This is almost certainly wrong */
-                                option_data->data = (uint8_t *)PyBytes_AsString(PyObject_Bytes(optiondictvalue));
+                                option_data->data = (uint8_t *)PyBytes_AS_STRING(optiondictvalue);
 #else
-/* ditto */
-                                option_data->data = (uint8_t *)PyString_AsString(PyObject_Bytes(optiondictvalue)); 
+                                option_data->data = (uint8_t *)PyString_AS_STRING(optiondictvalue); 
 #endif
+
                                 getdns_dict_set_bindata(tmpoptions_list_dict, "option_data", option_data);
                             } else  {
                                 PyErr_SetString(getdns_error, GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-getdns.git



More information about the Python-modules-commits mailing list