| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| /* gethostname */ |
| 6 |
|
| #if !defined(_MSC_VER) && !defined(__MINGW32_VERSION) |
| 7 |
|
| # include <unistd.h> |
| 8 |
|
| #endif |
| 9 |
|
| |
| 10 |
|
| /* inet_ntoa -- use definitions from perl Socket.xs instead */ |
| 11 |
|
| #ifndef VMS |
| 12 |
|
| # ifdef I_SYS_TYPES |
| 13 |
|
| # include <sys/types.h> |
| 14 |
|
| # endif |
| 15 |
|
| # if !defined(ultrix) /* Avoid double definition. */ |
| 16 |
|
| # include <sys/socket.h> |
| 17 |
|
| # endif |
| 18 |
|
| # if defined(USE_SOCKS) && defined(I_SOCKS) |
| 19 |
|
| # include <socks.h> |
| 20 |
|
| # endif |
| 21 |
|
| # ifdef MPE |
| 22 |
|
| # define PF_INET AF_INET |
| 23 |
|
| # define PF_UNIX AF_UNIX |
| 24 |
|
| # define SOCK_RAW 3 |
| 25 |
|
| # endif |
| 26 |
|
| # ifdef I_SYS_UN |
| 27 |
|
| # include <sys/un.h> |
| 28 |
|
| # endif |
| 29 |
|
| /* XXX Configure test for <netinet/in_systm.h needed XXX */ |
| 30 |
|
| # if defined(NeXT) || defined(__NeXT__) |
| 31 |
|
| # include <netinet/in_systm.h> |
| 32 |
|
| # endif |
| 33 |
|
| # if defined(__sgi) && !defined(AF_LINK) && defined(PF_LINK) && PF_LINK == AF_LNK |
| 34 |
|
| # undef PF_LINK |
| 35 |
|
| # endif |
| 36 |
|
| # if defined(I_NETINET_IN) || defined(__ultrix__) |
| 37 |
|
| # include <netinet/in.h> |
| 38 |
|
| # endif |
| 39 |
|
| # ifdef I_NETDB |
| 40 |
|
| # if !defined(ultrix) /* Avoid double definition. */ |
| 41 |
|
| # include <netdb.h> |
| 42 |
|
| # endif |
| 43 |
|
| # endif |
| 44 |
|
| # ifdef I_ARPA_INET |
| 45 |
|
| # include <arpa/inet.h> |
| 46 |
|
| # endif |
| 47 |
|
| # ifdef I_NETINET_TCP |
| 48 |
|
| # include <netinet/tcp.h> |
| 49 |
|
| # endif |
| 50 |
|
| #else |
| 51 |
|
| # include "sockadapt.h" |
| 52 |
|
| #endif /* definitions from perl Socket.xs 5.9.3 */ |
| 53 |
|
| |
| 54 |
|
| /* from /usr/include/arpa/nameser.h */ |
| 55 |
|
| #define NS_MAXDNAME 1025 /* maximum domain name */ |
| 56 |
|
| |
| 57 |
|
| #include "c_includes/alt_inet_aton.c" |
| 58 |
|
| |
| 59 |
|
| MODULE = Sys::Hostname::FQDN PACKAGE = Sys::Hostname::FQDN |
| 60 |
|
| |
| 61 |
|
| PROTOTYPES: DISABLE |
| 62 |
|
| |
| 63 |
|
| void |
| 64 |
|
| usually_short() |
| 65 |
|
| PREINIT: |
| 66 |
|
| SV * out; |
| 67 |
|
| char local_name[NS_MAXDNAME]; |
| 68 |
|
| PPCODE: |
| 69 |
3 |
▶ | if (gethostname(local_name,NS_MAXDNAME) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (gethostname(local_name,NS_MAXDNAME) != 0) { |
0 |
3 |
3 |
|
| 70 |
0 |
| ST(0) = &PL_sv_undef; |
| 71 |
|
| } |
| 72 |
|
| else { |
| 73 |
3 |
| out = sv_2mortal(newSVpv(local_name,0)); |
| 74 |
3 |
| ST(0) = out; |
| 75 |
|
| } |
| 76 |
3 |
| XSRETURN(1); |
| 77 |
|
| |
| 78 |
|
| void |
| 79 |
|
| inet_ntoa(netaddr) |
| 80 |
|
| SV * netaddr |
| 81 |
|
| PREINIT: |
| 82 |
|
| STRLEN len; |
| 83 |
|
| SV * out; |
| 84 |
|
| union { |
| 85 |
|
| struct in_addr * inadr; |
| 86 |
|
| char * addr; |
| 87 |
|
| } naddr; |
| 88 |
|
| PPCODE: |
| 89 |
3 |
| naddr.addr = (SvPV(netaddr, len)); |
| 90 |
3 |
| out = sv_2mortal(newSVpv(inet_ntoa(*naddr.inadr),0)); |
| 91 |
3 |
| ST(0) = out; |
| 92 |
3 |
| XSRETURN(1); |
| 93 |
|
| |
| 94 |
|
| void |
| 95 |
|
| inet_aton(dotquad) |
| 96 |
|
| SV * dotquad |
| 97 |
|
| PREINIT: |
| 98 |
|
| SV * out; |
| 99 |
|
| STRLEN len; |
| 100 |
|
| unsigned char * dq; |
| 101 |
|
| union { |
| 102 |
|
| struct in_addr * inadr; |
| 103 |
|
| char * addr; |
| 104 |
|
| } naddr; |
| 105 |
|
| struct in_addr myaddr; |
| 106 |
|
| PPCODE: |
| 107 |
1 |
| dq = (unsigned char *)(SvPV(dotquad, len)); |
| 108 |
1 |
| inet_aton((char *)dq,&myaddr); |
| 109 |
1 |
| out = sv_2mortal(newSVpv((char *)&myaddr.s_addr,4)); |
| 110 |
1 |
| ST(0) = out; |
| 111 |
1 |
| XSRETURN(1); |