aboutsummaryrefslogtreecommitdiff
path: root/thing.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-01-13 17:06:40 +0000
committerubq323 <ubq323@ubq323.website>2022-01-13 17:06:40 +0000
commit894e7d9aa5e9d50a2c714ad3eb38dc0056d0f6ae (patch)
treeb34ee42151d99c9be57943a0a160f9c7a4e214c7 /thing.c
parent354b5a61baf739cff5da916e9cfbd597478e890a (diff)
walk the list returned by getaddrinfo like you are meant to
Diffstat (limited to 'thing.c')
-rw-r--r--thing.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/thing.c b/thing.c
index 11c095e..e7c0f53 100644
--- a/thing.c
+++ b/thing.c
@@ -1,9 +1,11 @@
#ifdef LOCAL
#define HOST "0.0.0.0"
#define PORT "6971"
+#define SOCKETNAME "bees.sock"
#else
#define HOST "ubq323.website"
#define PORT "6667"
+#define SOCKETNAME "/srv/apiobot/bees.sock"
#endif
#ifdef DEBUG
@@ -17,7 +19,6 @@
#define REALNAME ",flappy fly bird man?"
#define CHANNEL "#a"
-#define SOCKETNAME "/srv/apiobot/bees.sock"
#include <stdio.h>
#include <stdlib.h>
@@ -67,14 +68,20 @@ int irc_connect() {
return -1;
}
- if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
- perror("socket");
- return -1;
- }
- if (connect(sockfd, res->ai_addr, res->ai_addrlen) != 0) {
- perror("connect");
- return -1;
+ struct addrinfo *cur;
+ for (cur = res; cur != NULL; cur = cur->ai_next) {
+ if ((sockfd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol)) == -1) {
+ perror("socket");
+ continue;
+ }
+ if (connect(sockfd, cur->ai_addr, cur->ai_addrlen) != 0) {
+ perror("connect");
+ continue;
+ }
+ goto success;
}
+ return -1;
+ success:
return sockfd;
}