require '_h2ph_pre.ph';

unless(defined(&M_WAITOK)) {
    require 'sys/malloc.ph';
}
unless(defined(&MLEN)) {
    sub MLEN () {	( &MSIZE - $sizeof{'struct m_hdr'});}
}
unless(defined(&MHLEN)) {
    sub MHLEN () {	( &MLEN - $sizeof{'struct pkthdr'});}
}
unless(defined(&MINCLSIZE)) {
    sub MINCLSIZE () {	( &MHLEN+ &MLEN+1);}
}
unless(defined(&M_MAXCOMPRESS)) {
    sub M_MAXCOMPRESS () {	( &MHLEN / 2);}
}
unless(defined(&mtod)) {
    sub mtod {
	local($m,$t) = @_;
	eval q(((($m)-> &m_data)));
    }
}
unless(defined(&dtom)) {
    sub dtom {
	local($x) = @_;
	eval q(((($x) & ~( &MSIZE-1))));
    }
}
unless(defined(&mtocl)) {
    sub mtocl {
	local($x) = @_;
	eval q((( -  &mbutl) >>  &MCLSHIFT));
    }
}
unless(defined(&cltom)) {
    sub cltom {
	local($x) = @_;
	eval q((( &mbutl + (($x) <<  &MCLSHIFT))));
    }
}
unless(defined(&m_next)) {
    sub m_next () {	 ($m_hdr->{mh_next});}
}
unless(defined(&m_len)) {
    sub m_len () {	 ($m_hdr->{mh_len});}
}
unless(defined(&m_data)) {
    sub m_data () {	 ($m_hdr->{mh_data});}
}
unless(defined(&m_type)) {
    sub m_type () {	 ($m_hdr->{mh_type});}
}
unless(defined(&m_flags)) {
    sub m_flags () {	 ($m_hdr->{mh_flags});}
}
unless(defined(&m_nextpkt)) {
    sub m_nextpkt () {	 ($m_hdr->{mh_nextpkt});}
}
unless(defined(&m_act)) {
    sub m_act () {	 &m_nextpkt;}
}
unless(defined(&m_pkthdr)) {
    sub m_pkthdr () {	 ($M_dat->{MH}->{MH_pkthdr});}
}
unless(defined(&m_ext)) {
    sub m_ext () {	 ($M_dat->{MH}->{MH_dat}->{MH_ext});}
}
unless(defined(&m_pktdat)) {
    sub m_pktdat () {	 ($M_dat->{MH}->{MH_dat}->{MH_databuf});}
}
unless(defined(&m_dat)) {
    sub m_dat () {	 ($M_dat->{M_databuf});}
}
unless(defined(&M_EXT)) {
    sub M_EXT () {	0x0001;}
}
unless(defined(&M_PKTHDR)) {
    sub M_PKTHDR () {	0x0002;}
}
unless(defined(&M_EOR)) {
    sub M_EOR () {	0x0004;}
}
unless(defined(&M_BCAST)) {
    sub M_BCAST () {	0x0100;}
}
unless(defined(&M_MCAST)) {
    sub M_MCAST () {	0x0200;}
}
unless(defined(&M_CONF)) {
    sub M_CONF () {	0x0400;}
}
unless(defined(&M_AUTH)) {
    sub M_AUTH () {	0x0800;}
}
unless(defined(&M_TUNNEL)) {
    sub M_TUNNEL () {	0x1000;}
}
unless(defined(&M_DAD)) {
    sub M_DAD () {	0x2000;}
}
unless(defined(&M_COPYFLAGS)) {
    sub M_COPYFLAGS () {	( &M_PKTHDR| &M_EOR| &M_BCAST| &M_MCAST| &M_CONF| &M_AUTH| &M_TUNNEL| &M_DAD);}
}
unless(defined(&MT_FREE)) {
    sub MT_FREE () {	0;}
}
unless(defined(&MT_DATA)) {
    sub MT_DATA () {	1;}
}
unless(defined(&MT_HEADER)) {
    sub MT_HEADER () {	2;}
}
unless(defined(&MT_SOCKET)) {
    sub MT_SOCKET () {	3;}
}
unless(defined(&MT_PCB)) {
    sub MT_PCB () {	4;}
}
unless(defined(&MT_RTABLE)) {
    sub MT_RTABLE () {	5;}
}
unless(defined(&MT_HTABLE)) {
    sub MT_HTABLE () {	6;}
}
unless(defined(&MT_ATABLE)) {
    sub MT_ATABLE () {	7;}
}
unless(defined(&MT_SONAME)) {
    sub MT_SONAME () {	8;}
}
unless(defined(&MT_SOOPTS)) {
    sub MT_SOOPTS () {	10;}
}
unless(defined(&MT_FTABLE)) {
    sub MT_FTABLE () {	11;}
}
unless(defined(&MT_RIGHTS)) {
    sub MT_RIGHTS () {	12;}
}
unless(defined(&MT_IFADDR)) {
    sub MT_IFADDR () {	13;}
}
unless(defined(&MT_CONTROL)) {
    sub MT_CONTROL () {	14;}
}
unless(defined(&MT_OOBDATA)) {
    sub MT_OOBDATA () {	15;}
}
unless(defined(&M_DONTWAIT)) {
    sub M_DONTWAIT () {	 &M_NOWAIT;}
}
unless(defined(&M_WAIT)) {
    sub M_WAIT () {	 &M_WAITOK;}
}
unless(defined(&MBUFLOCK)) {
    sub MBUFLOCK {
	local($code) = @_;
	eval q({ 'int'  &ms =  &splimp(); { $code }  &splx( &ms); });
    }
}
unless(defined(&MGET)) {
    sub MGET {
	local($m, $how, $type) = @_;
	eval q({  &MALLOC(, 'struct mbuf' *,  &MSIZE,  $mbtypes[$type], );  &if { -> &m_type = ;  &MBUFLOCK( ($mbstat->{m_mtypes[$type]})++;) -> &m_next =  &NULL; -> &m_nextpkt =  &NULL; ($m)-> &m_data = ($m)-> &m_dat; ($m)-> &m_flags = 0; }  &else ($m) =  &m_retry(($how), ($type)); });
    }
}
unless(defined(&MGETHDR)) {
    sub MGETHDR {
	local($m, $how, $type) = @_;
	eval q({  &MALLOC(, 'struct mbuf' *,  &MSIZE,  $mbtypes[$type], );  &if { -> &m_type = ;  &MBUFLOCK( ($mbstat->{m_mtypes[$type]})++;) -> &m_next =  &NULL; -> &m_nextpkt =  &NULL; ($m)-> &m_data = ($m)-> &m_pktdat; ($m)-> &m_flags =  &M_PKTHDR; }  &else ($m) =  &m_retryhdr(($how), ($type)); });
    }
}
unless(defined(&MCLALLOC)) {
    sub MCLALLOC {
	local($p, $how) = @_;
	eval q( &MBUFLOCK(  &if ( &mclfree == 0)  &m_clalloc(1, );  &if (( =  &mclfree) != 0) { ++ $mclrefcnt[ &mtocl];  ($mbstat->{m_clfree})--;  &mclfree = (($p))-> &mcl_next; } ));
    }
}
unless(defined(&MCLGET)) {
    sub MCLGET {
	local($m, $how) = @_;
	eval q({  &MCLALLOC(($m)-> ($m_ext->{ext_buf}), ($how));  &if (($m)-> ($m_ext->{ext_buf}) !=  &NULL) { ($m)-> &m_data = ($m)-> ($m_ext->{ext_buf}); ($m)-> &m_flags |=  &M_EXT; ($m)-> ($m_ext->{ext_size}) =  &MCLBYTES; ($m)-> ($m_ext->{ext_free}) =  &NULL; ($m)-> ($m_ext->{ext_ref}) =  &NULL; ($m)-> ($m_ext->{ext_handle}) =  &NULL; } });
    }
}
unless(defined(&MCLFREE)) {
    sub MCLFREE {
	local($p) = @_;
	eval q( &MBUFLOCK (  &if (-- $mclrefcnt[ &mtocl] == 0) { ()-> &mcl_next =  &mclfree;  &mclfree = ($p);  ($mbstat->{m_clfree})++; } ));
    }
}
unless(defined(&MCL_ALIGN)) {
    sub MCL_ALIGN {
	local($m, $len) = @_;
	eval q({ ($m)-> &m_data += ( &MCLBYTES - ($len)) &~ ($sizeof{'long'} -1); });
    }
}
unless(defined(&MFREE)) {
    sub MFREE {
	local($m, $n) = @_;
	eval q({  &MBUFLOCK( ($mbstat->{m_mtypes[&(m)}->{m_type]})--;)  &if (($m)-> &m_flags &  &M_EXT) {  &if (($m)-> ($m_ext->{ext_free})) (*(($m)-> ($m_ext->{ext_free})))($m);  &else  &MCLFREE(($m)-> ($m_ext->{ext_buf})); } ($n) = ($m)-> &m_next;  &FREE(($m),  $mbtypes[($m)-> &m_type]); });
    }
}
unless(defined(&M_COPY_PKTHDR)) {
    sub M_COPY_PKTHDR {
	local($to, $from) = @_;
	eval q({ ($to)-> &m_pkthdr = ($from)-> &m_pkthdr; ($to)-> &m_flags = ($from)-> &m_flags &  &M_COPYFLAGS; ($to)-> &m_data = ($to)-> &m_pktdat; });
    }
}
unless(defined(&M_ALIGN)) {
    sub M_ALIGN {
	local($m, $len) = @_;
	eval q({ ($m)-> &m_data += ( &MLEN - ($len)) &~ ($sizeof{'long'} - 1); });
    }
}
unless(defined(&MH_ALIGN)) {
    sub MH_ALIGN {
	local($m, $len) = @_;
	eval q({ ($m)-> &m_data += ( &MHLEN - ($len)) &~ ($sizeof{'long'} - 1); });
    }
}
unless(defined(&M_LEADINGSPACE)) {
    sub M_LEADINGSPACE {
	local($m) = @_;
	eval q((($m)-> &m_flags &  &M_EXT ? 0: ($m)-> &m_flags &  &M_PKTHDR ? ($m)-> &m_data - ($m)-> &m_pktdat : ($m)-> &m_data - ($m)-> &m_dat));
    }
}
unless(defined(&M_TRAILINGSPACE)) {
    sub M_TRAILINGSPACE {
	local($m) = @_;
	eval q((($m)-> &m_flags &  &M_EXT ? ($m)-> ($m_ext->{ext_buf}) + ($m)-> ($m_ext->{ext_size}) - (($m)-> &m_data + ($m)-> &m_len) : ($m)-> $m_dat[ &MLEN] - (($m)-> &m_data + ($m)-> &m_len)));
    }
}
unless(defined(&M_PREPEND)) {
    sub M_PREPEND {
	local($m, $plen, $how) = @_;
	eval q({  &if ( &M_LEADINGSPACE($m) >= ($plen)) { ($m)-> &m_data -= ($plen); ($m)-> &m_len += ($plen); }  &else ($m) =  &m_prepend(($m), ($plen), ($how));  &if (($m)  && ($m)-> &m_flags &  &M_PKTHDR) ($m)-> ($m_pkthdr->{len}) += ($plen); });
    }
}
unless(defined(&MCHTYPE)) {
    sub MCHTYPE {
	local($m, $t) = @_;
	eval q({  &MBUFLOCK( ($mbstat->{m_mtypes[&(m)}->{m_type]})--;  ($mbstat->{m_mtypes[$t]})++;) ($m)-> &m_type = $t;});
    }
}
unless(defined(&M_COPYALL)) {
    sub M_COPYALL () {	1000000000;}
}
unless(defined(&m_copy)) {
    sub m_copy {
	local($m, $o, $l) = @_;
	eval q( &m_copym(($m), ($o), ($l),  &M_DONTWAIT));
    }
}
if(defined(&_KERNEL)) {
    if(defined(&MBTYPES)) {
	if(defined(&DATAKIT)) {
	}
    }
}
1;
