Index: sendmail.c =================================================================== RCS file: /repository/php-src/win32/sendmail.c,v retrieving revision 1.65.2.2.2.1 diff -u -r1.65.2.2.2.1 sendmail.c --- sendmail.c 24 Feb 2007 02:17:28 -0000 1.65.2.2.2.1 +++ sendmail.c 27 Jun 2009 11:21:46 -0000 @@ -38,6 +38,10 @@ #include "sendmail.h" #include "php_ini.h" +#if _MVS_VER < 1500 +#include "inet.h" +#endif + #if HAVE_PCRE || HAVE_BUNDLED_PCRE #include "ext/pcre/php_pcre.h" #endif @@ -765,16 +769,50 @@ static int MailConnect() { - int res; + int res, namelen; short portnum; + struct hostent *ent; + IN_ADDR addr; +#ifdef HAVE_IPV6 + IN6_ADDR addr6; +#endif /* Create Socket */ - if ((sc = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + if ((sc = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { return (FAILED_TO_OBTAIN_SOCKET_HANDLE); + } /* Get our own host name */ - if (gethostname(LocalHost, HOST_NAME_LEN)) + if (gethostname(LocalHost, HOST_NAME_LEN)) { return (FAILED_TO_GET_HOSTNAME); + } + + ent = gethostbyname(LocalHost); + + if (!ent) { + return (FAILED_TO_GET_HOSTNAME); + } + + namelen = strlen(ent->h_name); + +#ifdef HAVE_IPV6 + if (inet_pton(AF_INET, ent->h_name, &addr) == 1 || inet_pton(AF_INET6, ent->h_name, &addr6) == 1) +#else + if (inet_pton(AF_INET, ent->h_name, &addr) == 1) +#endif + { + if (namelen + 2 >= HOST_NAME_LEN) { + return (FAILED_TO_GET_HOSTNAME); + } + strcpy(LocalHost, "["); + strcpy(LocalHost + 1, ent->h_name); + strcpy(LocalHost + namelen + 1, "]"); + } else { + if (namelen >= HOST_NAME_LEN) { + return (FAILED_TO_GET_HOSTNAME); + } + strcpy(LocalHost, ent->h_name); + } /* Resolve the servers IP */ /* @@ -794,8 +832,9 @@ sock_in.sin_port = htons(portnum); sock_in.sin_addr.S_un.S_addr = GetAddr(MailHost); - if (connect(sc, (LPSOCKADDR) & sock_in, sizeof(sock_in))) + if (connect(sc, (LPSOCKADDR) & sock_in, sizeof(sock_in))) { return (FAILED_TO_CONNECT); + } /* receive Server welcome message */ res = Ack(NULL);