rx-provide-binding-version-of-init-20040728
[openafs.git] / src / rx / rx_kcommon.c
index 6563ef8..c1b4872 100644 (file)
@@ -30,6 +30,7 @@ int (*rxk_PacketArrivalProc) (register struct rx_packet * ahandle, register stru
 int (*rxk_GetPacketProc) (char **ahandle, int asize);
 #endif
 
+struct osi_socket *rxk_NewSocketHost(afs_uint32 ahost, short aport);
 extern struct interfaceAddr afs_cb_interface;
 
 rxk_ports_t rxk_ports;
@@ -102,16 +103,21 @@ rxk_shutdownPorts(void)
 }
 
 osi_socket
-rxi_GetUDPSocket(u_short port)
+rxi_GetHostUDPSocket(u_int host, u_short port)
 {
     struct osi_socket *sockp;
-    sockp = (struct osi_socket *)rxk_NewSocket(port);
+    sockp = (struct osi_socket *)rxk_NewSocketHost(host, port);
     if (sockp == (struct osi_socket *)0)
        return OSI_NULLSOCKET;
     rxk_AddPort(port, (char *)sockp);
     return (osi_socket) sockp;
 }
 
+osi_socket
+rxi_GetUDPSocket(u_short port)
+{
+    return rxi_GetHostUDPSocket(htonl(INADDR_ANY), port);
+}
 
 void
 osi_Panic(msg, a1, a2, a3)
@@ -510,6 +516,8 @@ rxi_GetcbiInfo(void)
     memset((void *)mtus, 0, sizeof(mtus));
 
     for (i = 0; i < afs_cb_interface.numberOfInterfaces; i++) {
+        if (!afs_cb_interface.mtu[i]) 
+           afs_cb_interface.mtu[i] = htonl(1500);
        rxmtu = (ntohl(afs_cb_interface.mtu[i]) - RX_IPUDP_SIZE);
        ifinaddr = ntohl(afs_cb_interface.addr_in[i]);
        if (myNetAddrs[i] != ifinaddr)
@@ -754,7 +762,7 @@ rxi_FindIfnet(afs_uint32 addr, afs_uint32 * maskp)
  * in network byte order.
  */
 struct osi_socket *
-rxk_NewSocket(short aport)
+rxk_NewSocketHost(afs_uint32 ahost, short aport)
 {
     register afs_int32 code;
     struct socket *newSocket;
@@ -767,6 +775,8 @@ rxk_NewSocket(short aport)
     extern MBLKP allocb_wait(int, int);
     MBLKP bindnam;
     int addrsize = sizeof(struct sockaddr_in);
+    struct file *fp;
+    extern struct fileops socketops;
 #endif
 #ifdef AFS_SGI65_ENV
     bhv_desc_t bhv;
@@ -776,10 +786,23 @@ rxk_NewSocket(short aport)
 #if (defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)) && defined(KERNEL_FUNNEL)
     thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
 #endif
+    AFS_ASSERT_GLOCK();
+    AFS_GUNLOCK();
 #if    defined(AFS_HPUX102_ENV)
 #if     defined(AFS_HPUX110_ENV)
+    /* we need a file associated with the socket so sosend in NetSend 
+       will not fail */
     /* blocking socket */
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, 0);
+    fp = falloc();
+    if (!fp) goto bad;
+    fp->f_flag = FREAD | FWRITE;
+    fp->f_type = DTYPE_SOCKET;
+    fp->f_ops  = &socketops;
+
+    fp->f_data = (void *) newSocket;
+    newSocket->so_fp = (void *)fp;
+
 #else /* AFS_HPUX110_ENV */
     code = socreate(AF_INET, &newSocket, SOCK_DGRAM, 0, SS_NOWAIT);
 #endif /* else AFS_HPUX110_ENV */
@@ -796,9 +819,10 @@ rxk_NewSocket(short aport)
     if (code)
        goto bad;
 
+    memset(&myaddr, 0, sizeof myaddr);
     myaddr.sin_family = AF_INET;
     myaddr.sin_port = aport;
-    myaddr.sin_addr.s_addr = 0;
+    myaddr.sin_addr.s_addr = ahost;
 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
     myaddr.sin_len = sizeof(myaddr);
 #endif
@@ -841,6 +865,7 @@ rxk_NewSocket(short aport)
     if (code) {
        printf("sobind fails (%d)\n", (int)code);
        soclose(newSocket);
+       AFS_GLOCK();
        goto bad;
     }
 #else /* defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV) */
@@ -875,18 +900,25 @@ rxk_NewSocket(short aport)
 #endif /* else AFS_DARWIN_ENV */
 #endif /* else AFS_HPUX110_ENV */
 
+    AFS_GLOCK();
 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
 #endif
     return (struct osi_socket *)newSocket;
 
   bad:
+    AFS_GLOCK();
 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);
 #endif
     return (struct osi_socket *)0;
 }
 
+struct osi_socket *
+rxk_NewSocket(short aport)
+{
+    return rxk_NewSocketHost(0, aport);
+}
 
 /* free socket allocated by rxk_NewSocket */
 int
@@ -896,6 +928,18 @@ rxk_FreeSocket(register struct socket *asocket)
 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
     thread_funnel_switch(KERNEL_FUNNEL, NETWORK_FUNNEL);
 #endif
+#ifdef AFS_HPUX110_ENV
+    if (asocket->so_fp) {
+       struct file * fp = asocket->so_fp;
+#if !defined(AFS_HPUX1123_ENV)
+       /* 11.23 still has falloc, but not FPENTRYFREE ! 
+          so for now if we shutdown, we will waist a file 
+          structure */
+       FPENTRYFREE(fp);
+       asocket->so_fp = NULL;
+#endif
+    }
+#endif /* AFS_HPUX110_ENV */
     soclose(asocket);
 #if defined(AFS_DARWIN_ENV) && defined(KERNEL_FUNNEL)
     thread_funnel_switch(NETWORK_FUNNEL, KERNEL_FUNNEL);