X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FSocket%2FSocket.xs;h=1c541d7cef2650ffecfae4551a3f691c58d1ecdb;hb=5b8dae3fb0c7cd61d5a928efa0f69f243928e61b;hp=d2f3d9e10da7b472768eb98126c07023cf5d39c8;hpb=fcdb74fc457a967c0dbbf004893e223481b9f9ae;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs index d2f3d9e..1c541d7 100644 --- a/ext/Socket/Socket.xs +++ b/ext/Socket/Socket.xs @@ -7,6 +7,11 @@ # include # endif #include +#ifdef MPE +# define PF_INET AF_INET +# define PF_UNIX AF_UNIX +# define SOCK_RAW 3 +#endif #ifdef I_SYS_UN #include #endif @@ -14,7 +19,9 @@ # include # endif #include -#include +#ifdef I_ARPA_INET +# include +#endif #else #include "sockadapt.h" #endif @@ -78,9 +85,9 @@ my_inet_aton(register const char *cp, struct in_addr *addr) cp++; continue; } - if (base == 16 && (s=strchr(hexdigit,c))) { + if (base == 16 && (s=strchr(PL_hexdigit,c))) { val = (val << 4) + - ((s - hexdigit) & 15); + ((s - PL_hexdigit) & 15); cp++; continue; } @@ -323,30 +330,114 @@ constant(char *name, int arg) case 'L': break; case 'M': + if (strEQ(name, "MSG_CTLFLAGS")) +#ifdef MSG_CTLFLAGS + return MSG_CTLFLAGS; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_CTLIGNORE")) +#ifdef MSG_CTLIGNORE + return MSG_CTLIGNORE; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_CTRUNC")) +#if defined(MSG_TRUNC) || defined(HAS_MSG_CTRUNC) /* might be an enum */ + return MSG_CTRUNC; +#else + goto not_there; +#endif if (strEQ(name, "MSG_DONTROUTE")) -#ifdef MSG_DONTROUTE +#if defined(MSG_DONTROUTE) || defined(HAS_MSG_DONTROUTE) /* might be an enum */ return MSG_DONTROUTE; #else goto not_there; #endif + if (strEQ(name, "MSG_DONTWAIT")) +#ifdef MSG_DONTWAIT + return MSG_DONTWAIT; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_EOF")) +#ifdef MSG_EOF + return MSG_EOF; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_EOR")) +#ifdef MSG_EOR + return MSG_EOR; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_ERRQUEUE")) +#ifdef MSG_ERRQUEUE + return MSG_ERRQUEUE; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_FIN")) +#ifdef MSG_FIN + return MSG_FIN; +#else + goto not_there; +#endif if (strEQ(name, "MSG_MAXIOVLEN")) #ifdef MSG_MAXIOVLEN return MSG_MAXIOVLEN; #else goto not_there; #endif + if (strEQ(name, "MSG_NOSIGNAL")) +#ifdef MSG_NOSIGNAL + return MSG_NOSIGNAL; +#else + goto not_there; +#endif if (strEQ(name, "MSG_OOB")) -#ifdef MSG_OOB +#if defined(MSG_OOB) || defined(HAS_MSG_OOB) /* might be an enum */ return MSG_OOB; #else goto not_there; #endif if (strEQ(name, "MSG_PEEK")) -#ifdef MSG_PEEK +#if defined(MSG_PEEK) || defined(HAS_MSG_PEEK) /* might be an enum */ return MSG_PEEK; #else goto not_there; #endif + if (strEQ(name, "MSG_PROXY")) +#if defined(MSG_PROXY) || defined(HAS_MSG_PROXY) /* might be an enum */ + return MSG_PROXY; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_RST")) +#ifdef MSG_RST + return MSG_RST; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_SYN")) +#ifdef MSG_SYN + return MSG_SYN; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_TRUNC")) +#ifdef MSG_TRUNC + return MSG_TRUNC; +#else + goto not_there; +#endif + if (strEQ(name, "MSG_WAITALL")) +#ifdef MSG_WAITALL + return MSG_WAITALL; +#else + goto not_there; +#endif break; case 'N': break; @@ -503,6 +594,36 @@ constant(char *name, int arg) case 'R': break; case 'S': + if (strEQ(name, "SCM_CONNECT")) +#ifdef SCM_CONNECT + return SCM_CONNECT; +#else + goto not_there; +#endif + if (strEQ(name, "SCM_CREDENTIALS")) +#ifdef SCM_CREDENTIALS + return SCM_CREDENTIALSS; +#else + goto not_there; +#endif + if (strEQ(name, "SCM_CREDS")) +#ifdef SCM_CREDS + return SCM_CREDS; +#else + goto not_there; +#endif + if (strEQ(name, "SCM_RIGHTS")) +#if defined(SCM_RIGHTS) || defined(HAS_SCM_RIGHTS) /* might be an enum */ + return SCM_RIGHTS; +#else + goto not_there; +#endif + if (strEQ(name, "SCM_TIMESTAMP")) +#ifdef SCM_TIMESTAMP + return SCM_TIMESTAMP; +#else + goto not_there; +#endif if (strEQ(name, "SOCK_DGRAM")) #ifdef SOCK_DGRAM return SOCK_DGRAM; @@ -699,13 +820,11 @@ inet_aton(host) { struct in_addr ip_address; struct hostent * phe; - int ok; + int ok = inet_aton(host, &ip_address); - if (phe = gethostbyname(host)) { + if (!ok && (phe = gethostbyname(host))) { Copy( phe->h_addr, &ip_address, phe->h_length, char ); ok = 1; - } else { - ok = inet_aton(host, &ip_address); } ST(0) = sv_newmortal(); @@ -745,7 +864,10 @@ pack_sockaddr_un(pathname) STRLEN len; Zero( &sun_ad, sizeof sun_ad, char ); sun_ad.sun_family = AF_UNIX; - strncpy(sun_ad.sun_path, pathname, sizeof sun_ad.sun_path); + len = strlen(pathname); + if (len > sizeof(sun_ad.sun_path)) + len = sizeof(sun_ad.sun_path); + Copy( pathname, sun_ad.sun_path, len, char ); ST(0) = sv_2mortal(newSVpv((char *)&sun_ad, sizeof sun_ad)); #else ST(0) = (SV *) not_here("pack_sockaddr_un"); @@ -781,7 +903,7 @@ unpack_sockaddr_un(sun_sv) e = addr.sun_path; while (*e && e < addr.sun_path + sizeof addr.sun_path) ++e; - ST(0) = sv_2mortal(newSVpvn(addr.sun_path, e - addr.sun_path)); + ST(0) = sv_2mortal(newSVpv(addr.sun_path, e - addr.sun_path)); #else ST(0) = (SV *) not_here("unpack_sockaddr_un"); #endif @@ -828,7 +950,7 @@ unpack_sockaddr_in(sin_sv) port = ntohs(addr.sin_port); ip_address = addr.sin_addr; - EXTEND(sp, 2); + EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV) port))); PUSHs(sv_2mortal(newSVpv((char *)&ip_address,sizeof ip_address))); }