Skip to content

Commit b362ded

Browse files
committed
Merge branch 'develop'
2 parents a841c58 + 51575d4 commit b362ded

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

examples/client_subnet.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
11
import getdns
2-
import socket, fcntl, sys
32
from struct import pack, unpack
4-
5-
6-
#
7-
# returns a tuple containing the network part of the ip
8-
# address for the interface and the netmask, both encoded
9-
# in strings. Definitely not portable to Windows, probably
10-
# not portable to some Unixes. Unfortunately you have
11-
# to pass in the name of the interface; interface name
12-
# will be discovered in a future version
13-
#
14-
15-
def get_network_info(ifname):
16-
SIOCGIFADDR = 0x8915
17-
SIOCGIFNETMASK = 0x891b
18-
19-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
20-
netmask = fcntl.ioctl(s.fileno(), SIOCGIFNETMASK, pack('256s',ifname))[20:24]
21-
addr = fcntl.ioctl(s.fileno(), SIOCGIFADDR, pack('256s', ifname))[20:24]
22-
return (pack('!I', (unpack('!I', addr)[0] & unpack('!I', netmask)[0])), netmask)
233

244

255
def main():
266
CLIENT_SUBNET_OPCODE = 8
27-
LOCAL_INTERFACE = 'eth0'
7+
8+
address = '192.168.1.0'
289
host = 'getdnsapi.net'
10+
source_len = 12
2911

30-
if len(sys.argv) == 2:
31-
host = sys.argv[1]
3212
family = pack("!H", 1) # start building the edns option fields
33-
source_netmask, address = get_network_info(LOCAL_INTERFACE)
34-
scope_netmask = pack("B", 0)
13+
source_len = pack('!B', source_len)
14+
scope_len = pack('!B', 0)
3515

3616
#
3717
# encoding the binary data in strings makes it really easy
3818
# to build packets by concatenating those strings
3919
#
40-
payload = family + source_netmask + scope_netmask + address
41-
length = pack("!H", len(payload))
20+
address = pack('!BBBB', 192, 168, 1, 0)
21+
payload = family + source_len + scope_len + address
4222
ext = { 'add_opt_parameters': {'options':
4323
[ {'option_code': CLIENT_SUBNET_OPCODE,
44-
'option_data': length+payload} ] }}
24+
'option_data': payload} ] }}
4525

4626
c = getdns.Context()
4727
c.resolution_type = getdns.RESOLUTION_STUB

pygetdns_util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ extensions_to_getdnsdict(PyDictObject *pydict)
329329
} else if (!strncmp(tmpoptionlistkey, "option_data", strlen("option_data"))) {
330330
option_data = (struct getdns_bindata *)malloc(sizeof(struct getdns_bindata));
331331
option_data->size = PyObject_Length(optiondictvalue);
332+
printf("XXX size is %d\n", (int)option_data->size);
332333
#if PY_MAJOR_VERSION >= 3
333-
/* This is almost certainly wrong */
334-
option_data->data = (uint8_t *)PyBytes_AsString(PyObject_Bytes(optiondictvalue));
334+
option_data->data = (uint8_t *)PyBytes_AS_STRING(optiondictvalue);
335335
#else
336-
/* ditto */
337-
option_data->data = (uint8_t *)PyString_AsString(PyObject_Bytes(optiondictvalue));
336+
option_data->data = (uint8_t *)PyString_AS_STRING(optiondictvalue);
338337
#endif
338+
339339
getdns_dict_set_bindata(tmpoptions_list_dict, "option_data", option_data);
340340
} else {
341341
PyErr_SetString(getdns_error, GETDNS_RETURN_EXTENSION_MISFORMAT_TEXT);

0 commit comments

Comments
 (0)