Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(90215)

Side by Side Diff: Doc/library/socket.rst

Issue 28332: silent truncations in socket.htons and socket.ntohs
Patch Set: Created 2 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_socket.py » ('j') | Lib/test/test_socket.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`socket` --- Low-level networking interface 1 :mod:`socket` --- Low-level networking interface
2 ================================================ 2 ================================================
3 3
4 .. module:: socket 4 .. module:: socket
5 :synopsis: Low-level networking interface. 5 :synopsis: Low-level networking interface.
6 6
7 **Source code:** :source:`Lib/socket.py` 7 **Source code:** :source:`Lib/socket.py`
8 8
9 -------------- 9 --------------
10 10
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 Convert 32-bit positive integers from network to host byte order. On machine s 656 Convert 32-bit positive integers from network to host byte order. On machine s
657 where the host byte order is the same as network byte order, this is a no-op; 657 where the host byte order is the same as network byte order, this is a no-op;
658 otherwise, it performs a 4-byte swap operation. 658 otherwise, it performs a 4-byte swap operation.
659 659
660 660
661 .. function:: ntohs(x) 661 .. function:: ntohs(x)
662 662
663 Convert 16-bit positive integers from network to host byte order. On machine s 663 Convert 16-bit positive integers from network to host byte order. On machine s
664 where the host byte order is the same as network byte order, this is a no-op; 664 where the host byte order is the same as network byte order, this is a no-op;
665 otherwise, it performs a 2-byte swap operation. 665 otherwise, it performs a 2-byte swap operation.
666
667 Note that in case *x* does not fit in 16-bit unsigned integer, but does fit
storchaka 2016/10/01 21:37:42 Maybe use the "deprecated" directive?
668 in a positive C int, it is silently truncated to 16-bit unsigned integer.
669 However, this silent truncation feature is deprecated, and will raise an
670 exception in future versions of Python.
666 671
667 672
668 .. function:: htonl(x) 673 .. function:: htonl(x)
669 674
670 Convert 32-bit positive integers from host to network byte order. On machine s 675 Convert 32-bit positive integers from host to network byte order. On machine s
671 where the host byte order is the same as network byte order, this is a no-op; 676 where the host byte order is the same as network byte order, this is a no-op;
672 otherwise, it performs a 4-byte swap operation. 677 otherwise, it performs a 4-byte swap operation.
673 678
674 679
675 .. function:: htons(x) 680 .. function:: htons(x)
676 681
677 Convert 16-bit positive integers from host to network byte order. On machine s 682 Convert 16-bit positive integers from host to network byte order. On machine s
678 where the host byte order is the same as network byte order, this is a no-op; 683 where the host byte order is the same as network byte order, this is a no-op;
679 otherwise, it performs a 2-byte swap operation. 684 otherwise, it performs a 2-byte swap operation.
685
686 Note that in case *x* does not fit in 16-bit unsigned integer, but does fit
687 in a positive C int, it is silently truncated to 16-bit unsigned integer.
688 However, this silent truncation feature is deprecated, and will raise an
689 exception in future versions of Python.
680 690
681 691
682 .. function:: inet_aton(ip_string) 692 .. function:: inet_aton(ip_string)
683 693
684 Convert an IPv4 address from dotted-quad string format (for example, 694 Convert an IPv4 address from dotted-quad string format (for example,
685 '123.45.67.89') to 32-bit packed binary format, as a bytes object four charac ters in 695 '123.45.67.89') to 32-bit packed binary format, as a bytes object four charac ters in
686 length. This is useful when conversing with a program that uses the standard C 696 length. This is useful when conversing with a program that uses the standard C
687 library and needs objects of type :c:type:`struct in_addr`, which is the C ty pe 697 library and needs objects of type :c:type:`struct in_addr`, which is the C ty pe
688 for the 32-bit packed binary this function returns. 698 for the 32-bit packed binary this function returns.
689 699
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 1733
1724 - *An Advanced 4.3BSD Interprocess Communication Tutorial*, by Samuel J. Lef fler et 1734 - *An Advanced 4.3BSD Interprocess Communication Tutorial*, by Samuel J. Lef fler et
1725 al, 1735 al,
1726 1736
1727 both in the UNIX Programmer's Manual, Supplementary Documents 1 (sections 1737 both in the UNIX Programmer's Manual, Supplementary Documents 1 (sections
1728 PS1:7 and PS1:8). The platform-specific reference material for the various 1738 PS1:7 and PS1:8). The platform-specific reference material for the various
1729 socket-related system calls are also a valuable source of information on the 1739 socket-related system calls are also a valuable source of information on the
1730 details of socket semantics. For Unix, refer to the manual pages; for Window s, 1740 details of socket semantics. For Unix, refer to the manual pages; for Window s,
1731 see the WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers m ay 1741 see the WinSock (or Winsock 2) specification. For IPv6-ready APIs, readers m ay
1732 want to refer to :rfc:`3493` titled Basic Socket Interface Extensions for IPv 6. 1742 want to refer to :rfc:`3493` titled Basic Socket Interface Extensions for IPv 6.
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_socket.py » ('j') | Lib/test/test_socket.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+