title: How much data can I send in one UDP packet and still avoid fragmentation?
body: <p>I have C++ classes that handles sending and receiving UDP packets. So far I used those to send <em>signals</em> (PING, WAKEUP, ...) in other words, very small packets and never had a problem.</p>
  
  <p>Now I'd like to send large blocks of data (i.e. 0.5Mb), but to optimize the possibility of packet losses, I want to be able to do my own fragmentation. First I wrote a function that gives me the MTU size:</p>
  
  <pre><code>int udp_server::get_mtu_size() const
  {
      if(f_mtu_size == 0)
      {
          struct ifreq ifr;
          memset(&amp;ifr, 0, sizeof(ifr));
          strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));
          if(ioctl(f_socket, SIOCGIFMTU, &amp;ifr) == 0)
          {
              f_mtu_size = ifr.ifr_mtu;
          }
          else
          {
              f_mtu_size = -1;
          }
      }
  
      return f_mtu_size;
  }
  </code></pre>
  
  <p><em>Note: I know about PMTUD which this function ignores. As mentioned below, this is to work on a controlled network so the MTU path won't just change on us.</em></p>
  
  <p>This function is likely to return 1500 under Linux.</p>
  
  <p>What is really not clear and seems contradictory between many answers is that this 1,500 bytes size would not be just my payload. It would possibly include some headers over which I have no control (i.e. Ethernet header + footer, IPv4 header, UDP header.)</p>
  
  <p>From some other questions and answers, it feels like I can send 1,500 bytes of data without fragmentation, assuming all my MTUs are 1,500.</p>
  
  <p>So... Which is true?</p>
  
  <ol>
  <li><p>My data buffer can have a size equal to <code>MTU</code></p></li>
  <li><p>My data buffer must be <code>MTU - sizeof(various-headers/footers)</code></p></li>
  </ol>
  
  <p>P.S. The network is a LAN that we control 100%. The packets will travel from one main computer to a set of slave computers using UDP multicast. There is only one 1Gbps switch in between. Nothing more.</p>