OpenBSD: Use Darwin version of afsi_SetServerIPRank() for OpenBSD 4.7 and above.
[openafs.git] / src / afs / afs_server.c
index cf3db57..6043425 100644 (file)
@@ -505,6 +505,7 @@ ForceAllNewConnections(void)
     }
 
     addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
+    osi_Assert(addrs != NULL);
     j = 0;
     for (i = 0; i < NSERVERS; i++) {
        for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
@@ -571,6 +572,7 @@ afs_CheckServers(int adown, struct cell *acellp)
     }
 
     addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
+    osi_Assert(addrs != NULL);
     j = 0;
     for (i = 0; i < NSERVERS; i++) {
        for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
@@ -583,13 +585,19 @@ afs_CheckServers(int adown, struct cell *acellp)
     ReleaseReadLock(&afs_xsrvAddr);
     ReleaseReadLock(&afs_xserver);
 
-    conns = (struct afs_conn **)afs_osi_Alloc(j * sizeof(struct afs_conn *));
-    rxconns = (struct rx_connection **)afs_osi_Alloc(j * sizeof(struct rx_connection *));
-    conntimer = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
-    deltas = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
-    results = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
-
-    caps = (Capabilities *)afs_osi_Alloc(j * sizeof (Capabilities));
+    conns = afs_osi_Alloc(j * sizeof(struct afs_conn *));
+    osi_Assert(conns != NULL);
+    rxconns = afs_osi_Alloc(j * sizeof(struct rx_connection *));
+    osi_Assert(rxconns != NULL);
+    conntimer = afs_osi_Alloc(j * sizeof (afs_int32));
+    osi_Assert(conntimer != NULL);
+    deltas = afs_osi_Alloc(j * sizeof (afs_int32));
+    osi_Assert(deltas != NULL);
+    results = afs_osi_Alloc(j * sizeof (afs_int32));
+    osi_Assert(results != NULL);
+
+    caps = afs_osi_Alloc(j * sizeof (Capabilities));
+    osi_Assert(caps != NULL);
     memset(caps, 0, j * sizeof(Capabilities));
 
     for (i = 0; i < j; i++) {
@@ -1191,7 +1199,7 @@ afsi_SetServerIPRank(struct srvAddr *sa, afs_int32 addr,
     return;
 }
 #else /* AFS_USERSPACE_IP_ADDR */
-#if (! defined(AFS_SUN5_ENV)) && !defined(AFS_DARWIN_ENV) && defined(USEIFADDR)
+#if (! defined(AFS_SUN5_ENV)) && (! defined(AFS_DARWIN_ENV)) && (! defined(AFS_OBSD47_ENV)) && defined(USEIFADDR)
 void
 afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa)
 {
@@ -1228,7 +1236,7 @@ afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa)
 #endif /* IFF_POINTTOPOINT */
 }
 #endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR) */
-#if defined(AFS_DARWIN_ENV) && defined(USEIFADDR)
+#if (defined(AFS_DARWIN_ENV) || defined(AFS_OBSD47_ENV)) && defined(USEIFADDR)
 #ifndef afs_min
 #define afs_min(A,B) ((A)<(B)) ? (A) : (B)
 #endif
@@ -1245,7 +1253,7 @@ afsi_SetServerIPRank(struct srvAddr *sa, rx_ifaddr_t ifa)
     if (rx_ifaddr_address_family(ifa) != AF_INET)
        return;
     t = rx_ifaddr_address(ifa, &sout, sizeof(sout));
-    if (t == 0) {
+    if (t != 0) {
        sin = (struct sockaddr_in *)&sout;
        myAddr = ntohl(sin->sin_addr.s_addr);   /* one of my IP addr in host order */
     } else {
@@ -1253,16 +1261,16 @@ afsi_SetServerIPRank(struct srvAddr *sa, rx_ifaddr_t ifa)
     }
     serverAddr = ntohl(sa->sa_ip);     /* server's IP addr in host order */
     t = rx_ifaddr_netmask(ifa, &sout, sizeof(sout));
-    if (t == 0) {
+    if (t != 0) {
        sin = (struct sockaddr_in *)&sout;
        subnetmask = ntohl(sin->sin_addr.s_addr);       /* subnet mask in host order */
     } else {
        subnetmask = 0;
     }
     t = rx_ifaddr_dstaddress(ifa, &sout, sizeof(sout));
-    if (t == 0) {
+    if (t != 0) {
        sin = (struct sockaddr_in *)&sout;
-       myDstaddr = sin->sin_addr.s_addr;
+       myDstaddr = ntohl(sin->sin_addr.s_addr);
     } else {
        myDstaddr = 0;
     }
@@ -1792,7 +1800,7 @@ afs_GetServer(afs_uint32 * aserverp, afs_int32 nservers, afs_int32 acell,
     if (oldts) {
        newts = oldts;
     } else {
-       newts = (struct server *)afs_osi_Alloc(sizeof(struct server));
+       newts = afs_osi_Alloc(sizeof(struct server));
        if (!newts)
            panic("malloc of server struct");
        afs_totalServers++;
@@ -1837,7 +1845,7 @@ afs_GetServer(afs_uint32 * aserverp, afs_int32 nservers, afs_int32 acell,
        if (oldsa) {
            newsa = oldsa;
        } else {
-           newsa = (struct srvAddr *)afs_osi_Alloc(sizeof(struct srvAddr));
+           newsa = afs_osi_Alloc(sizeof(struct srvAddr));
            if (!newsa)
                panic("malloc of srvAddr struct");
            afs_totalSrvAddrs++;
@@ -1887,8 +1895,7 @@ afs_GetServer(afs_uint32 * aserverp, afs_int32 nservers, afs_int32 acell,
 
            /* Have a srvAddr struct. Now get a server struct (if not already) */
            if (!orphts) {
-               orphts =
-                   (struct server *)afs_osi_Alloc(sizeof(struct server));
+               orphts = afs_osi_Alloc(sizeof(struct server));
                if (!orphts)
                    panic("malloc of lo server struct");
                memset(orphts, 0, sizeof(struct server));