From 2943526cf5ccaf90b2befff6aa1649464e9d223d Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 14:39:47 +0100 Subject: [PATCH 1/9] win32/sendmail.c/TSendMail(): use bool type instead of int --- win32/sendmail.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index 394676f30316..c9c4aeb2a945 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -219,7 +219,7 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message, if (INI_STR("sendmail_from")) { RPath = estrdup(INI_STR("sendmail_from")); } else if (headers_lc) { - int found = 0; + bool found = false; const char *lookup = ZSTR_VAL(headers_lc); while (lookup) { @@ -236,7 +236,7 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message, } } - found = 1; + found = true; /* Real offset is memaddress from the original headers + difference of * string found in the lowercase headers + 5 characters to jump over From ccf8e3f57bd1abc5223707b74dddcea3f5b3aadb Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 11:59:05 +0100 Subject: [PATCH 2/9] win32/sendmail.c/GetAddr(): use standard char* type And make it const too while at it. --- win32/sendmail.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index c9c4aeb2a945..453b3c5cf137 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -118,7 +118,7 @@ static int MailConnect(); static bool PostHeader(char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); static bool Post(LPCSTR msg); static int Ack(char **server_response); -static unsigned long GetAddr(LPSTR szHost); +static unsigned long GetAddr(const char *szHost); static int FormatEmailAddress(char* Buf, char* EmailAddress, char* FormatString); /* This function is meant to unify the headers passed to to mail() @@ -904,7 +904,7 @@ static int Ack(char **server_response) //********************************************************************* -// Name: unsigned long GetAddr (LPSTR szHost) +// Name: unsigned long GetAddr (const char *szHost) // Input: // Output: // Description: Given a string, it will return an IP address. @@ -915,7 +915,7 @@ static int Ack(char **server_response) // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static unsigned long GetAddr(LPSTR szHost) +static unsigned long GetAddr(const char *szHost) { LPHOSTENT lpstHost; u_long lAddr = INADDR_ANY; From 28fa7b63cc83d639ba8a62d5e3f1f574e674c86b Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 12:04:42 +0100 Subject: [PATCH 3/9] win32/sendmail.c: add const qualifiers --- win32/sendmail.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index 453b3c5cf137..ad1dc151bc9d 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -112,14 +112,14 @@ static const char *ErrorMessages[] = #define PHP_WIN32_MAIL_DOT_PATTERN "\n." #define PHP_WIN32_MAIL_DOT_REPLACE "\n.." -static int SendText(char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message); static int MailConnect(); -static bool PostHeader(char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); +static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); static bool Post(LPCSTR msg); static int Ack(char **server_response); static unsigned long GetAddr(const char *szHost); -static int FormatEmailAddress(char* Buf, char* EmailAddress, char* FormatString); +static int FormatEmailAddress(char* Buf, const char* EmailAddress, const char* FormatString); /* This function is meant to unify the headers passed to to mail() * This means, use PCRE to transform single occurrences of \n or \r in \r\n @@ -387,7 +387,7 @@ static char *find_address(char *list, char **state) // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static int SendText(char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message) { int res; @@ -658,7 +658,7 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, const // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static bool PostHeader(char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders) +static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders) { /* Print message header according to RFC 822 */ /* Return-path, Received, Date, From, Subject, Sender, To, cc */ @@ -941,10 +941,10 @@ static unsigned long GetAddr(const char *szHost) } /* end GetAddr() */ /* returns the contents of an angle-addr (caller needs to efree) or NULL */ -static char *get_angle_addr(char *address) +static char *get_angle_addr(const char *address) { bool in_quotes = 0; - char *p1 = address, *p2; + const char *p1 = address, *p2; while ((p1 = strpbrk(p1, "<\"\\")) != NULL) { if (*p1 == '\\' && in_quotes) { @@ -994,7 +994,7 @@ static char *get_angle_addr(char *address) // Author/Date: garretts 08/18/2009 // History: //********************************************************************* -static int FormatEmailAddress(char* Buf, char* EmailAddress, char* FormatString) { +static int FormatEmailAddress(char* Buf, const char* EmailAddress, const char* FormatString) { char *tmpAddress; int result; From 04c96dec6f0d9fe86bd326643fd5369aca05ff34 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 13:05:14 +0100 Subject: [PATCH 4/9] win32/sendmail.c/MailConnect(): remove outdated comment --- win32/sendmail.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index ad1dc151bc9d..52af2b6c22d6 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -782,12 +782,7 @@ return 0; } /* Resolve the servers IP */ - /* - if (!isdigit(PW32G(mail_host)[0])||!gethostbyname(PW32G(mail_host))) - { - return (FAILED_TO_RESOLVE_HOST); - } - */ + unsigned long server_addr = GetAddr(PW32G(mail_host)); portnum = (short) INI_INT("smtp_port"); if (!portnum) { @@ -797,7 +792,7 @@ return 0; /* Connect to server */ sock_in.sin_family = AF_INET; sock_in.sin_port = htons(portnum); - sock_in.sin_addr.S_un.S_addr = GetAddr(PW32G(mail_host)); + sock_in.sin_addr.S_un.S_addr = server_addr; if (connect(PW32G(mail_socket), (LPSOCKADDR) & sock_in, sizeof(sock_in))) { closesocket(PW32G(mail_socket)); From aab2c2b0973e33fb2e24bd90a94079c434d13691 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 14:42:38 +0100 Subject: [PATCH 5/9] win32/sendmail.c/MailConnect(): move socket creation --- win32/sendmail.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index 52af2b6c22d6..2c2542507196 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -738,21 +738,14 @@ static int MailConnect() return 0; #endif - /* Create Socket */ - if ((PW32G(mail_socket) = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { - return (FAILED_TO_OBTAIN_SOCKET_HANDLE); - } - /* Get our own host name */ if (gethostname(PW32G(mail_local_host), HOST_NAME_LEN)) { - closesocket(PW32G(mail_socket)); return (FAILED_TO_GET_HOSTNAME); } ent = gethostbyname(PW32G(mail_local_host)); if (!ent) { - closesocket(PW32G(mail_socket)); return (FAILED_TO_GET_HOSTNAME); } @@ -765,7 +758,6 @@ return 0; #endif { if (namelen + 2 >= HOST_NAME_LEN) { - closesocket(PW32G(mail_socket)); return (FAILED_TO_GET_HOSTNAME); } @@ -774,13 +766,17 @@ return 0; strcpy(PW32G(mail_local_host) + namelen + 1, "]"); } else { if (namelen >= HOST_NAME_LEN) { - closesocket(PW32G(mail_socket)); return (FAILED_TO_GET_HOSTNAME); } strcpy(PW32G(mail_local_host), ent->h_name); } + /* Create Socket */ + if ((PW32G(mail_socket) = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { + return (FAILED_TO_OBTAIN_SOCKET_HANDLE); + } + /* Resolve the servers IP */ unsigned long server_addr = GetAddr(PW32G(mail_host)); From 708144b67c8269dc965418e2d2a19d6835271e71 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 14:28:41 +0100 Subject: [PATCH 6/9] win32/sendmail.c: move initial MailConnect() into SendText() As we don't do anything with it prior to it and we already try to reconect in SendText() --- win32/sendmail.c | 82 ++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index 2c2542507196..f3515f8f1803 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -112,7 +112,7 @@ static const char *ErrorMessages[] = #define PHP_WIN32_MAIL_DOT_PATTERN "\n." #define PHP_WIN32_MAIL_DOT_REPLACE "\n.." -static int SendText(const char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(_In_ const char *host, const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message); static int MailConnect(); static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); @@ -196,11 +196,6 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message, if (host == NULL) { *error = BAD_MAIL_HOST; return FAILURE; - } else if (strlen(host) >= HOST_NAME_LEN) { - *error = BAD_MAIL_HOST; - return FAILURE; - } else { - strcpy(PW32G(mail_host), host); } if (headers) { @@ -261,39 +256,20 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message, } } - /* attempt to connect with mail host */ - *error = MailConnect(); - if (*error != 0) { - if (RPath) { - efree(RPath); - } - if (headers) { - zend_string_release(headers_trim); - zend_string_release(headers_lc); - } - /* 128 is safe here, the specifier in snprintf isn't longer than that */ - *error_message = ecalloc(1, HOST_NAME_LEN + 128); - snprintf(*error_message, HOST_NAME_LEN + 128, - "Failed to connect to mailserver at \"%s\" port " ZEND_ULONG_FMT ", verify your \"SMTP\" " - "and \"smtp_port\" setting in php.ini or use ini_set()", - PW32G(mail_host), !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port")); + ret = SendText(host, RPath, Subject, mailTo, data, headers_trim, headers_lc, error_message); + TSMClose(); + if (RPath) { + efree(RPath); + } + if (headers) { + zend_string_release(headers_trim); + zend_string_release(headers_lc); + } + if (ret != SUCCESS) { + *error = ret; return FAILURE; - } else { - ret = SendText(RPath, Subject, mailTo, data, headers_trim, headers_lc, error_message); - TSMClose(); - if (RPath) { - efree(RPath); - } - if (headers) { - zend_string_release(headers_trim); - zend_string_release(headers_lc); - } - if (ret != SUCCESS) { - *error = ret; - return FAILURE; - } - return SUCCESS; } + return SUCCESS; } //********************************************************************* @@ -387,7 +363,7 @@ static char *find_address(char *list, char **state) // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static int SendText(const char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(_In_ const char *host, const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message) { int res; @@ -415,19 +391,29 @@ static int SendText(const char *RPath, const char *Subject, const char *mailTo, return (BAD_MSG_DESTINATION); */ + if (strlen(host) >= HOST_NAME_LEN) { + *error = BAD_MAIL_HOST; + return FAILURE; + } else { + strcpy(PW32G(mail_host), host); + } + + /* attempt to connect with mail host */ + res = MailConnect(); + if (res != 0) { + /* 128 is safe here, the specifier in snprintf isn't longer than that */ + *error_message = ecalloc(1, HOST_NAME_LEN + 128); + snprintf(*error_message, HOST_NAME_LEN + 128, + "Failed to connect to mailserver at \"%s\" port " ZEND_ULONG_FMT ", verify your \"SMTP\" " + "and \"smtp_port\" setting in php.ini or use ini_set()", + host, !INI_INT("smtp_port") ? 25 : INI_INT("smtp_port")); + return res; + } + snprintf(PW32G(mail_buffer), sizeof(PW32G(mail_buffer)), "HELO %s\r\n", PW32G(mail_local_host)); - /* in the beginning of the dialog */ - /* attempt reconnect if the first Post fail */ if (!Post(PW32G(mail_buffer))) { - int err = MailConnect(); - if (0 != err) { - return (FAILED_TO_SEND); - } - - if (!Post(PW32G(mail_buffer))) { - return (FAILED_TO_SEND); - } + return (FAILED_TO_SEND); } if ((res = Ack(&server_response)) != SUCCESS) { SMTP_ERROR_RESPONSE(server_response); From b51c2cdba5eb3b0022a4754123016d5b6b0f888a Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 14:32:41 +0100 Subject: [PATCH 7/9] win32/sendmail.c/MailConnect(): pass host as param This removes the usage of a global --- win32/php_win32_globals.h | 1 - win32/sendmail.c | 15 ++++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/win32/php_win32_globals.h b/win32/php_win32_globals.h index 733c32c1c93d..19c10d976076 100644 --- a/win32/php_win32_globals.h +++ b/win32/php_win32_globals.h @@ -42,7 +42,6 @@ struct _php_win32_core_globals { char mail_buffer[MAIL_BUFFER_SIZE]; SOCKET mail_socket; - char mail_host[HOST_NAME_LEN]; char mail_local_host[HOST_NAME_LEN]; }; diff --git a/win32/sendmail.c b/win32/sendmail.c index f3515f8f1803..d0ffbae1751f 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -114,7 +114,7 @@ static const char *ErrorMessages[] = static int SendText(_In_ const char *host, const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message); -static int MailConnect(); +static int MailConnect(_In_ const char *host); static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); static bool Post(LPCSTR msg); static int Ack(char **server_response); @@ -391,15 +391,8 @@ static int SendText(_In_ const char *host, const char *RPath, const char *Subjec return (BAD_MSG_DESTINATION); */ - if (strlen(host) >= HOST_NAME_LEN) { - *error = BAD_MAIL_HOST; - return FAILURE; - } else { - strcpy(PW32G(mail_host), host); - } - /* attempt to connect with mail host */ - res = MailConnect(); + res = MailConnect(host); if (res != 0) { /* 128 is safe here, the specifier in snprintf isn't longer than that */ *error_message = ecalloc(1, HOST_NAME_LEN + 128); @@ -708,7 +701,7 @@ static bool PostHeader(const char *RPath, const char *Subject, const char *mailT // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static int MailConnect() +static int MailConnect(_In_ const char *host) { int res, namelen; @@ -764,7 +757,7 @@ return 0; } /* Resolve the servers IP */ - unsigned long server_addr = GetAddr(PW32G(mail_host)); + unsigned long server_addr = GetAddr(host); portnum = (short) INI_INT("smtp_port"); if (!portnum) { From 8cff2256aaf14a22717a97e7e1058651f9ebb4f9 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 14:39:04 +0100 Subject: [PATCH 8/9] win32/sendmail.c/SendText(): mark RPath argument as _In_ As we always pass it a non-NULL char* pointer. Also remove conditional check that is always true --- win32/sendmail.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/win32/sendmail.c b/win32/sendmail.c index d0ffbae1751f..a24a32936cf1 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -112,7 +112,7 @@ static const char *ErrorMessages[] = #define PHP_WIN32_MAIL_DOT_PATTERN "\n." #define PHP_WIN32_MAIL_DOT_REPLACE "\n.." -static int SendText(_In_ const char *host, const char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(_In_ const char *host, _In_ const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message); static int MailConnect(_In_ const char *host); static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); @@ -258,9 +258,8 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message, ret = SendText(host, RPath, Subject, mailTo, data, headers_trim, headers_lc, error_message); TSMClose(); - if (RPath) { - efree(RPath); - } + efree(RPath); + if (headers) { zend_string_release(headers_trim); zend_string_release(headers_lc); @@ -363,7 +362,7 @@ static char *find_address(char *list, char **state) // Author/Date: jcar 20/9/96 // History: //********************************************************************* -static int SendText(_In_ const char *host, const char *RPath, const char *Subject, const char *mailTo, const char *data, +static int SendText(_In_ const char *host, _In_ const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message) { int res; @@ -379,8 +378,6 @@ static int SendText(_In_ const char *host, const char *RPath, const char *Subjec return (BAD_MSG_CONTENTS); if (mailTo == NULL) return (BAD_MSG_DESTINATION); - if (RPath == NULL) - return (BAD_MSG_RPATH); /* simple checks for the mailto address */ /* have ampersand ? */ From 70eb9f589598cd43276095d325c23b169a5bb56f Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Sat, 27 Dec 2025 15:13:41 +0100 Subject: [PATCH 9/9] win32/sendmail.c: create function for SMTP HELO command This allows moving out from MailConnect() the logic to determine the local host name and remove a global --- win32/php_win32_globals.h | 1 - win32/sendmail.c | 120 +++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 53 deletions(-) diff --git a/win32/php_win32_globals.h b/win32/php_win32_globals.h index 19c10d976076..be688f6c4e3c 100644 --- a/win32/php_win32_globals.h +++ b/win32/php_win32_globals.h @@ -42,7 +42,6 @@ struct _php_win32_core_globals { char mail_buffer[MAIL_BUFFER_SIZE]; SOCKET mail_socket; - char mail_local_host[HOST_NAME_LEN]; }; void php_win32_core_globals_ctor(void *vg); diff --git a/win32/sendmail.c b/win32/sendmail.c index a24a32936cf1..c3c59e6820e6 100644 --- a/win32/sendmail.c +++ b/win32/sendmail.c @@ -115,6 +115,7 @@ static const char *ErrorMessages[] = static int SendText(_In_ const char *host, _In_ const char *RPath, const char *Subject, const char *mailTo, const char *data, zend_string *headers, zend_string *headers_lc, char **error_message); static int MailConnect(_In_ const char *host); +static int PostHelo(char **error_message); static bool PostHeader(const char *RPath, const char *Subject, const char *mailTo, zend_string *xheaders); static bool Post(LPCSTR msg); static int Ack(char **server_response); @@ -400,14 +401,9 @@ static int SendText(_In_ const char *host, _In_ const char *RPath, const char *S return res; } - snprintf(PW32G(mail_buffer), sizeof(PW32G(mail_buffer)), "HELO %s\r\n", PW32G(mail_local_host)); - - if (!Post(PW32G(mail_buffer))) { - return (FAILED_TO_SEND); - } - if ((res = Ack(&server_response)) != SUCCESS) { - SMTP_ERROR_RESPONSE(server_response); - return (res); + res = PostHelo(error_message); + if (res != SUCCESS) { + return res; } SMTP_SKIP_SPACE(RPath); @@ -623,6 +619,69 @@ static int SendText(_In_ const char *host, _In_ const char *RPath, const char *S return (SUCCESS); } +static int PostHelo(char **error_message) +{ + size_t namelen; + struct hostent *ent; + IN_ADDR addr; +#ifdef HAVE_IPV6 + IN6_ADDR addr6; +#endif + char mail_local_host[HOST_NAME_LEN]; + +#if SENDMAIL_DEBUG + return 0; +#endif + + /* Get our own host name */ + if (gethostname(mail_local_host, HOST_NAME_LEN)) { + return (FAILED_TO_GET_HOSTNAME); + } + + ent = gethostbyname(mail_local_host); + + 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(mail_local_host, "["); + strcpy(mail_local_host + 1, ent->h_name); + strcpy(mail_local_host + namelen + 1, "]"); + } else { + if (namelen >= HOST_NAME_LEN) { + return (FAILED_TO_GET_HOSTNAME); + } + + strcpy(mail_local_host, ent->h_name); + } + + snprintf(PW32G(mail_buffer), sizeof(PW32G(mail_buffer)), "HELO %s\r\n", mail_local_host); + + if (!Post(PW32G(mail_buffer))) { + return (FAILED_TO_SEND); + } + + char *server_response = NULL; + int res = Ack(&server_response); + if (res != SUCCESS) { + SMTP_ERROR_RESPONSE(server_response); + return (res); + } + return SUCCESS; +} + //********************************************************************* // Name: PostHeader // Input: 1) return path @@ -701,53 +760,10 @@ static bool PostHeader(const char *RPath, const char *Subject, const char *mailT static int MailConnect(_In_ const char *host) { - int res, namelen; + int res; short portnum; - struct hostent *ent; - IN_ADDR addr; -#ifdef HAVE_IPV6 - IN6_ADDR addr6; -#endif SOCKADDR_IN sock_in; -#if SENDMAIL_DEBUG -return 0; -#endif - - /* Get our own host name */ - if (gethostname(PW32G(mail_local_host), HOST_NAME_LEN)) { - return (FAILED_TO_GET_HOSTNAME); - } - - ent = gethostbyname(PW32G(mail_local_host)); - - if (!ent) { - return (FAILED_TO_GET_HOSTNAME); - } - - namelen = (int)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(PW32G(mail_local_host), "["); - strcpy(PW32G(mail_local_host) + 1, ent->h_name); - strcpy(PW32G(mail_local_host) + namelen + 1, "]"); - } else { - if (namelen >= HOST_NAME_LEN) { - return (FAILED_TO_GET_HOSTNAME); - } - - strcpy(PW32G(mail_local_host), ent->h_name); - } - /* Create Socket */ if ((PW32G(mail_socket) = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { return (FAILED_TO_OBTAIN_SOCKET_HANDLE);