Fixes to improve portability (especially to OS X, Solaris, OpenBSD).
[ircu2.10.12-pk.git] / ircd / ircd_auth.c
index e3629d0e6a43af5cc0f197b3b3bb3869c3b3aa59..23a90700bc3e1dc19ae6d3e7391734a63c5ffc62 100644 (file)
@@ -47,6 +47,9 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
 
 struct IAuthRequest {
   struct IAuthRequest *iar_prev;        /* previous request struct */
@@ -86,7 +89,7 @@ struct IAuth {
   char i_buffer[BUFSIZE+1];             /* partial unprocessed line from server */
   char i_passwd[PASSWDLEN+1];           /* password for connection */
   char i_host[HOSTLEN+1];               /* iauth server hostname */
-  in_addr_t i_addr;                     /* iauth server ip address */
+  uint32_t i_addr;                      /* iauth server ip address */
   unsigned short i_port;                /* iauth server port */
   struct IAuth *i_next;                 /* next connection in list */
 };
@@ -140,14 +143,20 @@ struct IAuthCmd {
 
 struct IAuth *iauth_active;
 
-static const struct IAuthCmd iauth_cmdtab[];
-
 static void iauth_write(struct IAuth *iauth);
 static void iauth_reconnect(struct IAuth *iauth);
 static void iauth_disconnect(struct IAuth *iauth);
 static void iauth_sock_callback(struct Event *ev);
 static void iauth_send_request(struct IAuth *iauth, struct IAuthRequest *iar);
 static void iauth_dispose_request(struct IAuth *iauth, struct IAuthRequest *iar);
+static void iauth_cmd_doneauth(struct IAuth *iauth, int argc, char *argv[]);
+static void iauth_cmd_badauth(struct IAuth *iauth, int argc, char *argv[]);
+
+static const struct IAuthCmd iauth_cmdtab[] = {
+  { "DoneAuth", iauth_cmd_doneauth },
+  { "BadAuth", iauth_cmd_badauth },
+  { NULL, NULL }
+};
 
 struct IAuth *iauth_connect(char *host, unsigned short port, char *passwd, time_t reconnect, time_t timeout)
 {
@@ -314,7 +323,7 @@ static void iauth_disconnect(struct IAuth *iauth)
   s_fd(&i_socket(iauth)) = -1;
 }
 
-static void iauth_dns_callback(void *vptr, struct hostent *he)
+static void iauth_dns_callback(void *vptr, struct DNSReply *he)
 {
   struct IAuth *iauth = vptr;
   if (!he) {
@@ -322,8 +331,8 @@ static void iauth_dns_callback(void *vptr, struct hostent *he)
   } else if (he->h_addrtype != AF_INET) {
     sendto_opmask_butone(0, SNO_OLDSNO, "IAuth connection to %s failed: bad host type %d", i_host(iauth), he->h_addrtype);
   } else {
-    assert(he->h_addrtype == sizeof(i_addr(iauth)));
-    memcpy(&i_addr(iauth), he->h_addr_list[0], sizeof(i_addr(iauth)));
+    struct sockaddr_in *sin = (struct sockaddr_in*)&he->addr;
+    i_addr(iauth) = sin->sin_addr.s_addr;
     if (INADDR_NONE == i_addr(iauth)) {
       sendto_opmask_butone(0, SNO_OLDSNO, "IAuth connection to %s failed: host came back as INADDR_NONE", i_host(iauth));
       return;
@@ -688,9 +697,3 @@ static void iauth_cmd_badauth(struct IAuth *iauth, int argc, char *argv[])
   iauth_dispose_request(iauth, iar);
   exit_client(client, client, &me, reason);
 }
-
-static const struct IAuthCmd iauth_cmdtab[] = {
-  { "DoneAuth", iauth_cmd_doneauth },
-  { "BadAuth", iauth_cmd_badauth },
-  { NULL, NULL }
-};