commit - 28a5a7c15fff13abd7c9b06a742c70309db37b03
commit + 0e1456a374bcd2d4ae6dc1681999910d81490e78
blob - 13eb7042ee3ae10f0021d9550dc9b67d662373c2
blob + bc6f702e1ea25327f3545179d493446d81da8948
--- gotd/libexec/got-notify-email/Makefile
+++ gotd/libexec/got-notify-email/Makefile
.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
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <err.h>
#include <pwd.h>
+#include <netdb.h>
#include <time.h>
#include <unistd.h>
#include "got_error.h"
-#include "got_sockaddr.h"
#include "got_lib_poll.h"
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;
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"))
close(s);
free(line);
+ if (res)
+ freeaddrinfo(res);
}
int