<p>How do you get the maximum number of bytes that can be passed to a <code>sendto(..)</code> call for a socket opened as a UDP port?</p>

[{'answer_id': 25853, 'author': 'Kristof Provost', 'author_id': 1466, 'author_profile': 'https://Stackoverflow.com/users/1466', 'pm_score': 2, 'selected': False, 'text': "<p>As UDP is not connection oriented there's no way to indicate that two packets belong together. As a result you're limited by the maximum size of a single IP packet (65535). The data you can send is somewhat less that that, because the IP packet size also includes the IP header (usually 20 bytes) and the UDP header (8 bytes). </p>\n\n<p>Note that this IP packet can be fragmented to fit in smaller packets (eg. ~1500 bytes for ethernet).</p>\n\n<p>I'm not aware of any OS restricting this further.</p>\n\n<h2>Bonus</h2>\n\n<p><code>SO_MAX_MSG_SIZE</code> of UDP packet</p>\n\n<ul>\n<li>IPv4: 65,507 bytes</li>\n<li>IPv6: 65,527 bytes</li>\n</ul>\n"}, {'answer_id': 25855, 'author': 'Steve M', 'author_id': 1693, 'author_profile': 'https://Stackoverflow.com/users/1693', 'pm_score': 4, 'selected': False, 'text': '<p>Use getsockopt(). <a href="http://www.mkssoftware.com/docs/man3/getsockopt.3.asp" rel="noreferrer">This site</a> has a good breakdown of the usage and options you can retrieve.</p>\n\n<p>In Windows, you can do:</p>\n\n<pre>\nint optlen = sizeof(int);\nint optval;\ngetsockopt(socket, SOL_SOCKET, SO_MAX_MSG_SIZE, (int *)&optval, &optlen);\n</pre>\n\n<p>For Linux, according to the UDP man page, the kernel will use MTU discovery (it will check what the maximum UDP packet size is between here and the destination, and pick that), or if MTU discovery is off, it\'ll set the maximum size to the interface MTU and fragment anything larger. If you\'re sending over Ethernet, the typical MTU is 1500 bytes.</p>\n'}, {'answer_id': 25976, 'author': 'diciu', 'author_id': 2811, 'author_profile': 'https://Stackoverflow.com/users/2811', 'pm_score': 3, 'selected': False, 'text': '<p>On Mac OS X there are different values for sending (SO_SNDBUF) and receiving (SO_RCVBUF).\nThis is the size of the send buffer (man getsockopt):</p>\n\n<pre><code>getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (int *)&amp;optval, &amp;optlen);\n</code></pre>\n\n<p>Trying to send a bigger message (on Leopard 9216 octets on UDP sent via the local loopback) will result in "Message too long / EMSGSIZE".</p>\n'}]
['https://Stackoverflow.com/questions/25841', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/842/']