require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_SOCKET_H_)) {
    eval 'sub _SYS_SOCKET_H_ () {1;}' unless defined(&_SYS_SOCKET_H_);
    require 'sys/featuretest.ph';
    require 'sys/ansi.ph';
    unless(defined(&sa_family_t)) {
	eval 'sub sa_family_t () { &__sa_family_t;}' unless defined(&sa_family_t);
    }
    unless(defined(&socklen_t)) {
	eval 'sub socklen_t () { &__socklen_t;}' unless defined(&socklen_t);
    }
    require 'machine/ansi.ph';
    if(defined(&_BSD_SIZE_T_)) {
	undef(&_BSD_SIZE_T_) if defined(&_BSD_SIZE_T_);
    }
    if(defined(&_BSD_SSIZE_T_)) {
	undef(&_BSD_SSIZE_T_) if defined(&_BSD_SSIZE_T_);
    }
    require 'sys/uio.ph';
    require 'sys/sigtypes.ph';
    eval 'sub SOCK_STREAM () {1;}' unless defined(&SOCK_STREAM);
    eval 'sub SOCK_DGRAM () {2;}' unless defined(&SOCK_DGRAM);
    eval 'sub SOCK_RAW () {3;}' unless defined(&SOCK_RAW);
    eval 'sub SOCK_RDM () {4;}' unless defined(&SOCK_RDM);
    eval 'sub SOCK_SEQPACKET () {5;}' unless defined(&SOCK_SEQPACKET);
    eval 'sub SOCK_CONN_DGRAM () {6;}' unless defined(&SOCK_CONN_DGRAM);
    eval 'sub SOCK_DCCP () { &SOCK_CONN_DGRAM;}' unless defined(&SOCK_DCCP);
    eval 'sub SOCK_CLOEXEC () {0x10000000;}' unless defined(&SOCK_CLOEXEC);
    eval 'sub SOCK_NONBLOCK () {0x20000000;}' unless defined(&SOCK_NONBLOCK);
    eval 'sub SOCK_NOSIGPIPE () {0x40000000;}' unless defined(&SOCK_NOSIGPIPE);
    eval 'sub SOCK_FLAGS_MASK () {0xf0000000;}' unless defined(&SOCK_FLAGS_MASK);
    eval 'sub SO_DEBUG () {0x1;}' unless defined(&SO_DEBUG);
    eval 'sub SO_ACCEPTCONN () {0x2;}' unless defined(&SO_ACCEPTCONN);
    eval 'sub SO_REUSEADDR () {0x4;}' unless defined(&SO_REUSEADDR);
    eval 'sub SO_KEEPALIVE () {0x8;}' unless defined(&SO_KEEPALIVE);
    eval 'sub SO_DONTROUTE () {0x10;}' unless defined(&SO_DONTROUTE);
    eval 'sub SO_BROADCAST () {0x20;}' unless defined(&SO_BROADCAST);
    eval 'sub SO_USELOOPBACK () {0x40;}' unless defined(&SO_USELOOPBACK);
    eval 'sub SO_LINGER () {0x80;}' unless defined(&SO_LINGER);
    eval 'sub SO_OOBINLINE () {0x100;}' unless defined(&SO_OOBINLINE);
    eval 'sub SO_REUSEPORT () {0x200;}' unless defined(&SO_REUSEPORT);
    eval 'sub SO_NOSIGPIPE () {0x800;}' unless defined(&SO_NOSIGPIPE);
    eval 'sub SO_ACCEPTFILTER () {0x1000;}' unless defined(&SO_ACCEPTFILTER);
    eval 'sub SO_TIMESTAMP () {0x2000;}' unless defined(&SO_TIMESTAMP);
    eval 'sub SO_RERROR () {0x4000;}' unless defined(&SO_RERROR);
    eval 'sub SO_DEFOPTS () {( &SO_DEBUG| &SO_REUSEADDR| &SO_KEEPALIVE| &SO_DONTROUTE|  &SO_BROADCAST| &SO_USELOOPBACK| &SO_LINGER| &SO_OOBINLINE| &SO_REUSEPORT|  &SO_NOSIGPIPE| &SO_TIMESTAMP| &SO_RERROR);}' unless defined(&SO_DEFOPTS);
    eval 'sub __SO_OPTION_BITS () {"\\20" "\\1SO_DEBUG" "\\2SO_ACCEPTCONN" "\\3SO_REUSEADDR" "\\4SO_KEEPALIVE" "\\5SO_DONTROUTE" "\\6SO_BROADCAST" "\\7SO_USELOOPBACK" "\\10SO_LINGER" "\\11SO_OOBINLINE" "\\12SO_REUSEPORT" "\\13SO_OTIMESTAMP" "\\14SO_NOSIGPIPE" "\\15SO_ACCEPTFILTER" "\\16SO_TIMESTAMP" "\\17SO_RERROR";}' unless defined(&__SO_OPTION_BITS);
    eval 'sub SO_SNDBUF () {0x1001;}' unless defined(&SO_SNDBUF);
    eval 'sub SO_RCVBUF () {0x1002;}' unless defined(&SO_RCVBUF);
    eval 'sub SO_SNDLOWAT () {0x1003;}' unless defined(&SO_SNDLOWAT);
    eval 'sub SO_RCVLOWAT () {0x1004;}' unless defined(&SO_RCVLOWAT);
    eval 'sub SO_ERROR () {0x1007;}' unless defined(&SO_ERROR);
    eval 'sub SO_TYPE () {0x1008;}' unless defined(&SO_TYPE);
    eval 'sub SO_OVERFLOWED () {0x1009;}' unless defined(&SO_OVERFLOWED);
    eval 'sub SO_NOHEADER () {0x100a;}' unless defined(&SO_NOHEADER);
    eval 'sub SO_SNDTIMEO () {0x100b;}' unless defined(&SO_SNDTIMEO);
    eval 'sub SO_RCVTIMEO () {0x100c;}' unless defined(&SO_RCVTIMEO);
    eval 'sub SOL_SOCKET () {0xffff;}' unless defined(&SOL_SOCKET);
    eval 'sub AF_UNSPEC () {0;}' unless defined(&AF_UNSPEC);
    eval 'sub AF_LOCAL () {1;}' unless defined(&AF_LOCAL);
    eval 'sub AF_UNIX () { &AF_LOCAL;}' unless defined(&AF_UNIX);
    eval 'sub AF_INET () {2;}' unless defined(&AF_INET);
    eval 'sub AF_IMPLINK () {3;}' unless defined(&AF_IMPLINK);
    eval 'sub AF_PUP () {4;}' unless defined(&AF_PUP);
    eval 'sub AF_CHAOS () {5;}' unless defined(&AF_CHAOS);
    eval 'sub AF_NS () {6;}' unless defined(&AF_NS);
    eval 'sub AF_ISO () {7;}' unless defined(&AF_ISO);
    eval 'sub AF_OSI () { &AF_ISO;}' unless defined(&AF_OSI);
    eval 'sub AF_ECMA () {8;}' unless defined(&AF_ECMA);
    eval 'sub AF_DATAKIT () {9;}' unless defined(&AF_DATAKIT);
    eval 'sub AF_CCITT () {10;}' unless defined(&AF_CCITT);
    eval 'sub AF_SNA () {11;}' unless defined(&AF_SNA);
    eval 'sub AF_DECnet () {12;}' unless defined(&AF_DECnet);
    eval 'sub AF_DLI () {13;}' unless defined(&AF_DLI);
    eval 'sub AF_LAT () {14;}' unless defined(&AF_LAT);
    eval 'sub AF_HYLINK () {15;}' unless defined(&AF_HYLINK);
    eval 'sub AF_APPLETALK () {16;}' unless defined(&AF_APPLETALK);
    eval 'sub AF_OROUTE () {17;}' unless defined(&AF_OROUTE);
    eval 'sub AF_LINK () {18;}' unless defined(&AF_LINK);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub pseudo_AF_XTP () {19;}' unless defined(&pseudo_AF_XTP);
    }
    eval 'sub AF_COIP () {20;}' unless defined(&AF_COIP);
    eval 'sub AF_CNT () {21;}' unless defined(&AF_CNT);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub pseudo_AF_RTIP () {22;}' unless defined(&pseudo_AF_RTIP);
    }
    eval 'sub AF_IPX () {23;}' unless defined(&AF_IPX);
    eval 'sub AF_INET6 () {24;}' unless defined(&AF_INET6);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub pseudo_AF_PIP () {25;}' unless defined(&pseudo_AF_PIP);
    }
    eval 'sub AF_ISDN () {26;}' unless defined(&AF_ISDN);
    eval 'sub AF_E164 () { &AF_ISDN;}' unless defined(&AF_E164);
    eval 'sub AF_NATM () {27;}' unless defined(&AF_NATM);
    eval 'sub AF_ARP () {28;}' unless defined(&AF_ARP);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub pseudo_AF_KEY () {29;}' unless defined(&pseudo_AF_KEY);
	eval 'sub pseudo_AF_HDRCMPLT () {30;}' unless defined(&pseudo_AF_HDRCMPLT);
    }
    eval 'sub AF_BLUETOOTH () {31;}' unless defined(&AF_BLUETOOTH);
    eval 'sub AF_IEEE80211 () {32;}' unless defined(&AF_IEEE80211);
    eval 'sub AF_MPLS () {33;}' unless defined(&AF_MPLS);
    eval 'sub AF_ROUTE () {34;}' unless defined(&AF_ROUTE);
    eval 'sub AF_CAN () {35;}' unless defined(&AF_CAN);
    eval 'sub AF_ETHER () {36;}' unless defined(&AF_ETHER);
    eval 'sub AF_MAX () {37;}' unless defined(&AF_MAX);
    if(defined(&_KERNEL)) {
	eval 'sub _SB_DATASIZE () {254;}' unless defined(&_SB_DATASIZE);
    }
    eval 'sub _SS_MAXSIZE () {128;}' unless defined(&_SS_MAXSIZE);
    eval 'sub _SS_ALIGNSIZE () {($sizeof{ &__int64_t});}' unless defined(&_SS_ALIGNSIZE);
    eval 'sub _SS_PAD1SIZE () {( &_SS_ALIGNSIZE - 2);}' unless defined(&_SS_PAD1SIZE);
    eval 'sub _SS_PAD2SIZE () {( &_SS_MAXSIZE - 2-  &_SS_PAD1SIZE -  &_SS_ALIGNSIZE);}' unless defined(&_SS_PAD2SIZE);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub sstosa {
	    my($__ss) = @_;
    	    eval q((($__ss)));
	}' unless defined(&sstosa);
	eval 'sub sstocsa {
	    my($__ss) = @_;
    	    eval q((( &const \'struct sockaddr\' *)($__ss)));
	}' unless defined(&sstocsa);
    }
    eval 'sub PF_UNSPEC () { &AF_UNSPEC;}' unless defined(&PF_UNSPEC);
    eval 'sub PF_LOCAL () { &AF_LOCAL;}' unless defined(&PF_LOCAL);
    eval 'sub PF_UNIX () { &PF_LOCAL;}' unless defined(&PF_UNIX);
    eval 'sub PF_INET () { &AF_INET;}' unless defined(&PF_INET);
    eval 'sub PF_IMPLINK () { &AF_IMPLINK;}' unless defined(&PF_IMPLINK);
    eval 'sub PF_PUP () { &AF_PUP;}' unless defined(&PF_PUP);
    eval 'sub PF_CHAOS () { &AF_CHAOS;}' unless defined(&PF_CHAOS);
    eval 'sub PF_NS () { &AF_NS;}' unless defined(&PF_NS);
    eval 'sub PF_ISO () { &AF_ISO;}' unless defined(&PF_ISO);
    eval 'sub PF_OSI () { &AF_ISO;}' unless defined(&PF_OSI);
    eval 'sub PF_ECMA () { &AF_ECMA;}' unless defined(&PF_ECMA);
    eval 'sub PF_DATAKIT () { &AF_DATAKIT;}' unless defined(&PF_DATAKIT);
    eval 'sub PF_CCITT () { &AF_CCITT;}' unless defined(&PF_CCITT);
    eval 'sub PF_SNA () { &AF_SNA;}' unless defined(&PF_SNA);
    eval 'sub PF_DECnet () { &AF_DECnet;}' unless defined(&PF_DECnet);
    eval 'sub PF_DLI () { &AF_DLI;}' unless defined(&PF_DLI);
    eval 'sub PF_LAT () { &AF_LAT;}' unless defined(&PF_LAT);
    eval 'sub PF_HYLINK () { &AF_HYLINK;}' unless defined(&PF_HYLINK);
    eval 'sub PF_APPLETALK () { &AF_APPLETALK;}' unless defined(&PF_APPLETALK);
    eval 'sub PF_OROUTE () { &AF_OROUTE;}' unless defined(&PF_OROUTE);
    eval 'sub PF_LINK () { &AF_LINK;}' unless defined(&PF_LINK);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub PF_XTP () { &pseudo_AF_XTP;}' unless defined(&PF_XTP);
    }
    eval 'sub PF_COIP () { &AF_COIP;}' unless defined(&PF_COIP);
    eval 'sub PF_CNT () { &AF_CNT;}' unless defined(&PF_CNT);
    eval 'sub PF_INET6 () { &AF_INET6;}' unless defined(&PF_INET6);
    eval 'sub PF_IPX () { &AF_IPX;}' unless defined(&PF_IPX);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub PF_RTIP () { &pseudo_AF_RTIP;}' unless defined(&PF_RTIP);
	eval 'sub PF_PIP () { &pseudo_AF_PIP;}' unless defined(&PF_PIP);
    }
    eval 'sub PF_ISDN () { &AF_ISDN;}' unless defined(&PF_ISDN);
    eval 'sub PF_E164 () { &AF_E164;}' unless defined(&PF_E164);
    eval 'sub PF_NATM () { &AF_NATM;}' unless defined(&PF_NATM);
    eval 'sub PF_ARP () { &AF_ARP;}' unless defined(&PF_ARP);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub PF_KEY () { &pseudo_AF_KEY;}' unless defined(&PF_KEY);
    }
    eval 'sub PF_BLUETOOTH () { &AF_BLUETOOTH;}' unless defined(&PF_BLUETOOTH);
    eval 'sub PF_MPLS () { &AF_MPLS;}' unless defined(&PF_MPLS);
    eval 'sub PF_ROUTE () { &AF_ROUTE;}' unless defined(&PF_ROUTE);
    eval 'sub PF_CAN () { &AF_CAN;}' unless defined(&PF_CAN);
    eval 'sub PF_ETHER () { &AF_ETHER;}' unless defined(&PF_ETHER);
    eval 'sub PF_MAX () { &AF_MAX;}' unless defined(&PF_MAX);
    if(defined(&_NETBSD_SOURCE)) {
	unless(defined(&pid_t)) {
	    eval 'sub pid_t () { &__pid_t;}' unless defined(&pid_t);
	}
	unless(defined(&gid_t)) {
	    eval 'sub gid_t () { &__gid_t;}' unless defined(&gid_t);
	}
	unless(defined(&uid_t)) {
	    eval 'sub uid_t () { &__uid_t;}' unless defined(&uid_t);
	}
	eval 'sub SOCKCREDSIZE {
	    my($ngrps) = @_;
    	    eval q(( $sizeof{\'struct sockcred\'} + ($sizeof{ &gid_t} * (($ngrps) - 1))));
	}' unless defined(&SOCKCREDSIZE);
    }
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub ki_src () { ($ki_s->{_kis_src});}' unless defined(&ki_src);
	eval 'sub ki_dst () { ($ki_d->{_kid_dst});}' unless defined(&ki_dst);
	eval 'sub ki_spad () { ($ki_s->{_kis_pad});}' unless defined(&ki_spad);
	eval 'sub ki_dpad () { ($ki_d->{_kid_pad});}' unless defined(&ki_dpad);
	eval 'sub PCB_SLOP () {20;}' unless defined(&PCB_SLOP);
	eval 'sub PCB_ALL () {0;}' unless defined(&PCB_ALL);
    }
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub NET_RT_DUMP () {1;}' unless defined(&NET_RT_DUMP);
	eval 'sub NET_RT_FLAGS () {2;}' unless defined(&NET_RT_FLAGS);
	eval 'sub NET_RT_OOOIFLIST () {3;}' unless defined(&NET_RT_OOOIFLIST);
	eval 'sub NET_RT_OOIFLIST () {4;}' unless defined(&NET_RT_OOIFLIST);
	eval 'sub NET_RT_OIFLIST () {5;}' unless defined(&NET_RT_OIFLIST);
	eval 'sub NET_RT_IFLIST () {6;}' unless defined(&NET_RT_IFLIST);
    }
    unless(defined(&SOMAXCONN)) {
	eval 'sub SOMAXCONN () {128;}' unless defined(&SOMAXCONN);
    }
    require 'sys/cdefs.ph';
    eval 'sub MSG_OOB () {0x1;}' unless defined(&MSG_OOB);
    eval 'sub MSG_PEEK () {0x2;}' unless defined(&MSG_PEEK);
    eval 'sub MSG_DONTROUTE () {0x4;}' unless defined(&MSG_DONTROUTE);
    eval 'sub MSG_EOR () {0x8;}' unless defined(&MSG_EOR);
    eval 'sub MSG_TRUNC () {0x10;}' unless defined(&MSG_TRUNC);
    eval 'sub MSG_CTRUNC () {0x20;}' unless defined(&MSG_CTRUNC);
    eval 'sub MSG_WAITALL () {0x40;}' unless defined(&MSG_WAITALL);
    eval 'sub MSG_DONTWAIT () {0x80;}' unless defined(&MSG_DONTWAIT);
    eval 'sub MSG_BCAST () {0x100;}' unless defined(&MSG_BCAST);
    eval 'sub MSG_MCAST () {0x200;}' unless defined(&MSG_MCAST);
    eval 'sub MSG_NOSIGNAL () {0x400;}' unless defined(&MSG_NOSIGNAL);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub MSG_CMSG_CLOEXEC () {0x800;}' unless defined(&MSG_CMSG_CLOEXEC);
	eval 'sub MSG_NBIO () {0x1000;}' unless defined(&MSG_NBIO);
	eval 'sub MSG_WAITFORONE () {0x2000;}' unless defined(&MSG_WAITFORONE);
	eval 'sub MSG_NOTIFICATION () {0x4000;}' unless defined(&MSG_NOTIFICATION);
    }
    eval 'sub MSG_USERFLAGS () {0xffffff;}' unless defined(&MSG_USERFLAGS);
    eval 'sub MSG_NAMEMBUF () {0x1000000;}' unless defined(&MSG_NAMEMBUF);
    eval 'sub MSG_CONTROLMBUF () {0x2000000;}' unless defined(&MSG_CONTROLMBUF);
    eval 'sub MSG_IOVUSRSPACE () {0x4000000;}' unless defined(&MSG_IOVUSRSPACE);
    eval 'sub MSG_LENUSRSPACE () {0x8000000;}' unless defined(&MSG_LENUSRSPACE);
    eval 'sub __CMSG_ALIGN {
        my($n) = @_;
	    eval q(((($n) +  &__ALIGNBYTES) & ~ &__ALIGNBYTES));
    }' unless defined(&__CMSG_ALIGN);
    if(defined(&_KERNEL)) {
	eval 'sub CMSG_ALIGN {
	    my($n) = @_;
    	    eval q( &__CMSG_ALIGN($n));
	}' unless defined(&CMSG_ALIGN);
    }
    eval 'sub __CMSG_ASIZE () { &__CMSG_ALIGN($sizeof{\'struct cmsghdr\'});}' unless defined(&__CMSG_ASIZE);
    eval 'sub __CMSG_MSGNEXT {
        my($cmsg) = @_;
	    eval q(( &__CASTV(\'char\' *, $cmsg) +  &__CMSG_ALIGN(($cmsg)-> &cmsg_len)));
    }' unless defined(&__CMSG_MSGNEXT);
    eval 'sub __CMSG_MSGEND {
        my($mhdr) = @_;
	    eval q(( &__CASTV(\'char\' *, ($mhdr)-> &msg_control) + ($mhdr)-> &msg_controllen));
    }' unless defined(&__CMSG_MSGEND);
    eval 'sub CMSG_DATA {
        my($cmsg) = @_;
	    eval q(( &__CASTV(\'unsigned char\' *, $cmsg) +  &__CMSG_ASIZE));
    }' unless defined(&CMSG_DATA);
    eval 'sub CCMSG_DATA {
        my($cmsg) = @_;
	    eval q(( &__CASTCV( &const \'unsigned char\' *, $cmsg) +  &__CMSG_ASIZE));
    }' unless defined(&CCMSG_DATA);
    eval 'sub CMSG_NXTHDR {
        my($mhdr, $cmsg) = @_;
	    eval q( &__CASTV(\'struct cmsghdr\' *,  &__CMSG_MSGNEXT($cmsg) +  &__CMSG_ASIZE >  &__CMSG_MSGEND($mhdr) ? 0:  &__CMSG_MSGNEXT($cmsg)));
    }' unless defined(&CMSG_NXTHDR);
    eval 'sub CMSG_FIRSTHDR {
        my($mhdr) = @_;
	    eval q( &__CASTV(\'struct cmsghdr\' *, ($mhdr)-> &msg_controllen < $sizeof{\'struct cmsghdr\'} ? 0: ($mhdr)-> &msg_control));
    }' unless defined(&CMSG_FIRSTHDR);
    eval 'sub CMSG_SPACE {
        my($l) = @_;
	    eval q(( &__CMSG_ASIZE +  &__CMSG_ALIGN($l)));
    }' unless defined(&CMSG_SPACE);
    eval 'sub CMSG_LEN {
        my($l) = @_;
	    eval q(( &__CMSG_ASIZE + ($l)));
    }' unless defined(&CMSG_LEN);
    eval 'sub SCM_RIGHTS () {0x1;}' unless defined(&SCM_RIGHTS);
    if(defined(&_NETBSD_SOURCE)) {
	eval 'sub SCM_TIMESTAMP () {0x8;}' unless defined(&SCM_TIMESTAMP);
	eval 'sub SCM_CREDS () {0x10;}' unless defined(&SCM_CREDS);
    }
    eval 'sub SHUT_RD () {0;}' unless defined(&SHUT_RD);
    eval 'sub SHUT_WR () {1;}' unless defined(&SHUT_WR);
    eval 'sub SHUT_RDWR () {2;}' unless defined(&SHUT_RDWR);
    if(defined(&_KERNEL)) {
	eval 'sub sockaddr_getlen {
	    my($sa) = @_;
    	    eval q({  ($sa->{sa_len}); });
	}' unless defined(&sockaddr_getlen);
    }
    unless(defined(&_KERNEL)) {
	if(!defined(&__LIBC12_SOURCE__)  && !defined(&_STANDALONE)) {
	}
	if(defined(&_NETBSD_SOURCE)) {
	}
    }
}
1;
