use ExtUtils::MakeMaker;
use ExtUtils::Constant 0.23 'WriteConstants';
use Config;
+
+my @DEFINES;
+unless( $ENV{PERL_CORE} ) {
+ # Building standalone, not as core.
+ require ExtUtils::CChecker;
+ my $cc = ExtUtils::CChecker->new;
+
+ my %defines = (
+ # -Dfoo func() $Config{key}
+ HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ],
+ HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ],
+ HAS_INET_ATON => [ "inet_aton", "d_inetaton" ],
+ HAS_INETNTOP => [ "inet_ntop", "d_inetntop" ],
+ HAS_INETPTON => [ "inet_pton", "d_inetpton" ],
+ );
+
+ foreach my $define ( sort keys %defines ) {
+ my ( $func, $key ) = @{$defines{$define}};
+ next if exists $Config{$key};
+
+ $cc->try_compile_run(
+ define => $define,
+ source => <<"EOF" )
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+int main(int argc, char *argv[]) {
+ void *p = &$func;
+ return 0;
+}
+EOF
+ and print "$func() found\n"
+ or print "$func() not found\n";
+ }
+
+ unless( exists $Config{d_sockaddr_sa_len} ) {
+ $cc->try_compile_run(
+ define => "HAS_SOCKADDR_SA_LEN",
+ source => <<'EOF' )
+#include <sys/types.h>
+#include <sys/socket.h>
+int main(int argc, char *argv[]) {
+ struct sockaddr sa;
+ sa.sa_len = 0;
+ return 0;
+}
+EOF
+ and print "sockaddr has sa_len\n"
+ or print "sockaddr does not have sa_len\n";
+ }
+
+ unless( exists $Config{d_sin6_scope_id} ) {
+ $cc->try_compile_run(
+ define => "HAS_SIN6_SCOPE_ID",
+ source => <<'EOF' )
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+int main(int argc, char *argv[]) {
+ struct sockaddr_in6 sin6;
+ sin6.sin6_scope_id = 0;
+ return 0;
+}
+EOF
+ and print "sockaddr_in6 has sin6_scope_id\n"
+ or print "sockaddr_in6 does not have sin6_scope_id\n";
+ }
+
+ @DEFINES = @{ $cc->extra_compiler_flags };
+}
+
WriteMakefile(
NAME => 'Socket',
VERSION_FROM => 'Socket.pm',
($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()),
XSPROTOARG => '-noprototypes', # XXX remove later?
realclean => {FILES=> 'const-c.inc const-xs.inc'},
+ DEFINE => join( " ", @DEFINES ),
+ CONFIGURE_REQUIRES => {
+ 'ExtUtils::CChecker' => 0,
+ 'ExtUtils::Constant' => '0.23',
+ },
);
my @names = (qw(AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF
AF_DATAKIT AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK
static void xs_getaddrinfo(pTHX_ CV *cv)
{
- dVAR;
dXSARGS;
SV *host;
int n_res;
if(items > 3)
- croak_xs_usage(cv, "host, service, hints");
+ croak("Usage: Socket::getaddrinfo(host, service, hints)");
SP -= items;
#ifdef HAS_GETNAMEINFO
static void xs_getnameinfo(pTHX_ CV *cv)
{
- dVAR;
dXSARGS;
SV *addr;
int err;
if(items < 1 || items > 2)
- croak_xs_usage(cv, "addr, flags=0");
+ croak("Usage: Socket::getnameinfo(addr, flags=0)");
SP -= items;