#include <netinet/in.h>

#if defined(COMPILE_DL) || defined(COMPILE_DL_QLIB)
#include "dl/phpdl.h"
#endif

#include "php.h"
#include "php_globals.h"
#include "php_qlib.h"

#if HAVE_QLIB

function_entry qlib_functions[] = {
    PHP_FE(ntohl,           NULL)
    {NULL, NULL, NULL}
};

zend_module_entry qlib_module_entry = {
    "qlib",
    qlib_functions,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    STANDARD_MODULE_PROPERTIES
};

PHP_FUNCTION(ntohl)
{
    unsigned long res, num;
    zval **yynum;

    if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &yynum) == FAILURE) {
        WRONG_PARAM_COUNT;
    }
    convert_to_long_ex(yynum);
    num = (*yynum)->value.lval;

    php_error(E_WARNING, "value: %lu\n", num);
    
    res = ntohl(num);

    return_value->value.lval = res;
    return_value->type = IS_LONG;
}

#endif
