aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}