■ ContentsixOther getaddrinfo( ) Flags ������������������������������������������������������������������������������������������������������������������������������������ 64Primitive Name Service Routines ������������������������������������������������������������������������������������������������������������������������ 65Using getsockaddr( ) in Your Own Code ��������������������������������������������������������������������������������������������������������������� 65The DNS Protocol ������������������������������������������������������������������������������������������������������������������������67
Why Not to Use Raw DNS ������������������������������������������������������������������������������������������������������������������������������������ 69Making a DNS Query from Python ����������������������������������������������������������������������������������������������������������������������� 69Resolving Mail Domains �������������������������������������������������������������������������������������������������������������������������������������� 71Summary ������������������������������������������������������������������������������������������������������������������������������������� 73
■ Chapter 5: Network Data and Network Errors �����������������������������������������������������������������75
Bytes and Strings ������������������������������������������������������������������������������������������������������������������������75
Character Strings ������������������������������������������������������������������������������������������������������������������������������������������������� 76Binary Numbers and Network Byte Order ����������������������������������������������������������������������������������������������������������� 79Framing and Quoting �������������������������������������������������������������������������������������������������������������������81
Pickles and Self-delimiting Formats �������������������������������������������������������������������������������������������86
XML and JSON �����������������������������������������������������������������������������������������������������������������������������86
Compression �������������������������������������������������������������������������������������������������������������������������������87
Network Exceptions ��������������������������������������������������������������������������������������������������������������������88
Raising More Specific Exceptions ����������������������������������������������������������������������������������������������������������������������� 90Catching and Reporting Network Exceptions ������������������������������������������������������������������������������������������������������ 91Summary ������������������������������������������������������������������������������������������������������������������������������������� 92
■ Chapter 6: TLS/SSL ����������������������������������������������������������������������������������������������������������93
What TLS Fails to Protect ������������������������������������������������������������������������������������������������������������93
What Could Possibly Go Wrong? ��������������������������������������������������������������������������������������������������94
Generating Certificates ����������������������������������������������������������������������������������������������������������������95
Offloading TLS �����������������������������������������������������������������������������������������������������������������������������98
Python 3�4 Default Contexts ��������������������������������������������������������������������������������������������������������99
Variations on Socket Wrapping �������������������������������������������������������������������������������������������������������������������������� 103