require '_h2ph_pre.ph';

unless(defined(&__OSDEP_H)) {
    eval 'sub __OSDEP_H () {1;}' unless defined(&__OSDEP_H);
    eval 'sub OSDEP_BSD () {1;}' unless defined(&OSDEP_BSD);
    require 'sys/types.ph';
    require 'sys/param.ph';
    require 'sys/socket.ph';
    if(defined(&KERNEL)) {
	unless(defined(&ATSH_ADD)) {
	    require 'sys/systm.ph';
	}
	unless(defined(&MLEN)) {
	    require 'sys/mbuf.ph';
	}
	require 'sys/kernel.ph';
	require 'sys/malloc.ph';
	unless(defined(&SB_MAX)) {
	    require 'sys/socketvar.ph';
	}
	require 'sys/proc.ph';
	unless(defined(&RTM_RTTUNIT)) {
	    require 'net/route.ph';
	}
    }
    require 'netinet/in.ph';
    if(defined(&KERNEL)) {
	eval 'sub OSDEP_CRITICALDCL () {\'int\'  &__s;;}' unless defined(&OSDEP_CRITICALDCL);
	eval 'sub OSDEP_CRITICALSTART () { &__s =  &splnet();}' unless defined(&OSDEP_CRITICALSTART);
	eval 'sub OSDEP_CRITICALEND () { &splx( &__s);}' unless defined(&OSDEP_CRITICALEND);
	eval 'sub OSDEP_TIMESECONDS () {( ($time->{tv_sec}));}' unless defined(&OSDEP_TIMESECONDS);
	eval 'sub OSDEP_PROCESS () {\'struct proc\';}' unless defined(&OSDEP_PROCESS);
	eval 'sub OSDEP_PROCESSCURRENT () {( &curproc);}' unless defined(&OSDEP_PROCESSCURRENT);
	eval 'sub OSDEP_PROCESSPARENT {
	    local($x) = @_;
    	    eval q((($x)-> &p_pptr));
	}' unless defined(&OSDEP_PROCESSPARENT);
	eval 'sub OSDEP_PROCESSPID {
	    local($x) = @_;
    	    eval q((($x)-> &p_pid));
	}' unless defined(&OSDEP_PROCESSPID);
	if(defined(&SS_PRIV)) {
	    eval 'sub OSDEP_SOCKETPRIVELEGED {
	        local($socket) = @_;
    		eval q(( ($socket->{so_state}) &  &SS_PRIV));
	    }' unless defined(&OSDEP_SOCKETPRIVELEGED);
	} else {
	    eval 'sub OSDEP_SOCKETPRIVELEGED {
	        local($socket) = @_;
    		eval q((! &curproc || ! ($curproc->{p_ucred}) || ! ($curproc->{p_ucred}->{cr_uid})));
	    }' unless defined(&OSDEP_SOCKETPRIVELEGED);
	}
	eval 'sub OSDEP_PCAST {
	    local($x) = @_;
    	    eval q((($x) & 0xffffffff));
	}' unless defined(&OSDEP_PCAST);
	eval 'sub OSDEP_SOCKET () {\'struct socket\';}' unless defined(&OSDEP_SOCKET);
	eval 'sub OSDEP_PACKET () {\'struct mbuf\';}' unless defined(&OSDEP_PACKET);
	eval 'sub OSDEP_REAL_MALLOC {
	    local($n) = @_;
    	    eval q( &malloc(($n),  &M_TEMP,  &M_DONTWAIT));
	}' unless defined(&OSDEP_REAL_MALLOC);
	eval 'sub OSDEP_REAL_FREE {
	    local($p) = @_;
    	    eval q( &free($p,  &M_TEMP));
	}' unless defined(&OSDEP_REAL_FREE);
	eval 'sub OSDEP_FAMILY {
	    local($socket) = @_;
    	    eval q(( ($socket->{so_proto}->{pr_domain}->{dom_family})));
	}' unless defined(&OSDEP_FAMILY);
	eval 'sub OSDEP_PSEUDORANDOM () { &random();}' unless defined(&OSDEP_PSEUDORANDOM);
	eval 'sub OSDEP_DATATOPACKET {
	    local($data, $len, $packet) = @_;
    	    eval q( &__osdep_datatopacket($data, $len, $packet));
	}' unless defined(&OSDEP_DATATOPACKET);
	eval 'sub OSDEP_ZEROPACKET {
	    local($packet) = @_;
    	    eval q( &m_zero($packet));
	}' unless defined(&OSDEP_ZEROPACKET);
	eval 'sub OSDEP_FREEPACKET {
	    local($packet) = @_;
    	    eval q( &m_freem($packet));
	}' unless defined(&OSDEP_FREEPACKET);
	eval 'sub memcpy {
	    local($dst, $src, $len) = @_;
    	    eval q( &bcopy($src, $dst, $len));
	}' unless defined(&memcpy);
	eval 'sub memmove {
	    local($dst, $src, $len) = @_;
    	    eval q( &bcopy($src, $dst, $len));
	}' unless defined(&memmove);
	eval 'sub memset {
	    local($p, $zero, $len) = @_;
    	    eval q( &bzero($p, $len));
	}' unless defined(&memset);
	eval 'sub memcmp {
	    local($p1, $p2, $len) = @_;
    	    eval q( &bcmp($p1, $p2, $len));
	}' unless defined(&memcmp);
	eval 'sub OSDEP_COPYFROMUSER {
	    local($dst, $src, $len) = @_;
    	    eval q( &copyin($src, $dst, $len));
	}' unless defined(&OSDEP_COPYFROMUSER);
	eval 'sub OSDEP_COPYTOUSER {
	    local($dst, $src, $len) = @_;
    	    eval q( &copyout($src, $dst, $len));
	}' unless defined(&OSDEP_COPYTOUSER);
    }
    eval 'sub OSDEP_SALEN () {1;}' unless defined(&OSDEP_SALEN);
    eval 'sub OSDEP_ERROR {
        local($x) = @_;
	    eval q(($x));
    }' unless defined(&OSDEP_ERROR);
    eval 'sub ENETSECURITYPOLICY () {- &ECOMM;}' unless defined(&ENETSECURITYPOLICY);
    if(defined(&DEBUG_MALLOC)) {
	undef(&OSDEP_MALLOC) if defined(&OSDEP_MALLOC);
	undef(&OSDEP_FREE) if defined(&OSDEP_FREE);
	eval 'sub OSDEP_MALLOC {
	    local($n) = @_;
    	    eval q( &debug_malloc_malloc($n,  &DEBUG_STATUS));
	}' unless defined(&OSDEP_MALLOC);
	eval 'sub OSDEP_FREE {
	    local($p) = @_;
    	    eval q( &debug_malloc_free($p));
	}' unless defined(&OSDEP_FREE);
    } else {
	undef(&OSDEP_MALLOC) if defined(&OSDEP_MALLOC);
	eval 'sub OSDEP_MALLOC {
	    local($n) = @_;
    	    eval q( &OSDEP_REAL_MALLOC($n));
	}' unless defined(&OSDEP_MALLOC);
	undef(&OSDEP_FREE) if defined(&OSDEP_FREE);
	eval 'sub OSDEP_FREE {
	    local($p) = @_;
    	    eval q( &OSDEP_REAL_FREE($p));
	}' unless defined(&OSDEP_FREE);
    }
}
1;
