function tftpd_send_config($s, $sock, &$db)
{
    /* Read config from database */
    tftpd_db_read_config($db, $data);
    /* Turn read data from a single string into an array of string with
     * TFTP_SEGSIZE length for each array element
     */
    $data = str_split($data, TFTP_SEGSIZE);
    /* Write packets */
    $block = 1;
    $xfer_byte = 0;
    $xfer_time = tftpd_microtime();
    foreach ($data as $chunk) {
        if (!tftpd_send_data($s, $sock, $block, $chunk)) {
            return false;
        }
        $block++;
        $xfer_byte += strlen($chunk);
    }
    /* Log our success */
    $xfer_time = round(tftpd_microtime() - $xfer_time, 3);
    tftpd_log('1', 'sent ' . $xfer_byte . ' bytes in ' . $xfer_time . ' seconds');
}
function tftpd_send_file($s, $sock, $fp)
{
    $block = 1;
    $xfer_byte = 0;
    $xfer_time = tftpd_microtime();
    while (!feof($fp)) {
        $data = fread($fp, TFTP_SEGSIZE);
        if (!tftpd_send_data($s, $sock, $block, $data)) {
            return false;
        }
        $block++;
        if ($block > 65535) {
            $block = 0;
        }
        $xfer_byte += strlen($data);
    }
    /* Log our success */
    $xfer_time = round(tftpd_microtime() - $xfer_time, 3);
    tftpd_log('1', 'sent ' . $xfer_byte . ' bytes in ' . $xfer_time . ' seconds');
}