commit 0e1456a374bcd2d4ae6dc1681999910d81490e78 from: Stefan Sperling date: Mon Mar 11 09:49:08 2024 UTC fix connection commit - 28a5a7c15fff13abd7c9b06a742c70309db37b03 commit + 0e1456a374bcd2d4ae6dc1681999910d81490e78 blob - 13eb7042ee3ae10f0021d9550dc9b67d662373c2 blob + bc6f702e1ea25327f3545179d493446d81da8948 --- gotd/libexec/got-notify-email/Makefile +++ gotd/libexec/got-notify-email/Makefile @@ -4,7 +4,7 @@ .include "../../../got-version.mk" PROG= got-notify-email -SRCS= got-notify-email.c sockaddr.c pollfd.c error.c hash.c +SRCS= got-notify-email.c pollfd.c error.c hash.c CPPFLAGS = -I${.CURDIR}/../../../include -I${.CURDIR}/../../../lib blob - 220116ff58e9f3497055341a85904ca3b58e1847 blob + ab206e0678b79a050d007298939bedaa0ca687aa --- gotd/libexec/got-notify-email/got-notify-email.c +++ gotd/libexec/got-notify-email/got-notify-email.c @@ -14,9 +14,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include -#include -#include #include #include @@ -25,11 +24,11 @@ #include #include #include +#include #include #include #include "got_error.h" -#include "got_sockaddr.h" #include "got_lib_poll.h" @@ -185,9 +184,8 @@ send_email(const char *myfromaddr, const char *fromadd char *line = NULL; size_t linesize = 0; ssize_t linelen; - struct in_addr in_addr; - struct sockaddr_in sa_in; - int s = -1; + struct addrinfo hints, *res = NULL; + int s = -1, ret; time_t now; char datebuf[26]; char *datestr; @@ -195,16 +193,19 @@ send_email(const char *myfromaddr, const char *fromadd now = time(NULL); datestr = get_datestr(&now, datebuf); - if (inet_aton("127.0.0.1", &in_addr) == 0) - err(1, "inet_aton"); - - got_sockaddr_inet_init(&sa_in, &in_addr); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; - s = socket(AF_INET, SOCK_STREAM, 0); + ret = getaddrinfo("127.0.0.1", "25", &hints, &res); + if (ret) + errx(1, "getaddrinfo: %s", gai_strerror(ret)); + + s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s == -1) err(1, "socket"); - if (connect(s, (struct sockaddr *)&sa_in, sizeof(sa_in)) == -1) + if (connect(s, res->ai_addr, res->ai_addrlen) == -1) err(1, "connect 127.0.0.1:25"); if (read_smtp_code(s, "220")) @@ -285,6 +286,8 @@ send_email(const char *myfromaddr, const char *fromadd close(s); free(line); + if (res) + freeaddrinfo(res); } int