< prev index next >

src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c

Print this page




 179     /* fd is an int field on fdObj */
 180     int fd;
 181     int len = 0;
 182     SOCKETADDRESS sa;
 183     socklen_t slen = sizeof(SOCKETADDRESS);
 184 
 185     if (IS_NULL(fdObj)) {
 186         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
 187                         "Socket closed");
 188         return;
 189     } else {
 190         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
 191     }
 192 
 193     if (IS_NULL(iaObj)) {
 194         JNU_ThrowNullPointerException(env, "iaObj is null.");
 195         return;
 196     }
 197 
 198     /* bind */
 199     if (NET_InetAddressToSockaddr(env, iaObj, localport, &sa, &len,
 200                                   JNI_TRUE) != 0) {
 201       return;
 202     }
 203     setDefaultScopeID(env, &sa.sa);
 204 
 205     if (NET_Bind(fd, &sa, len) < 0)  {
 206         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
 207             errno == EPERM || errno == EACCES) {
 208             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
 209                             "Bind failed");
 210         } else {
 211             JNU_ThrowByNameWithMessageAndLastError
 212                 (env, JNU_JAVANETPKG "SocketException", "Bind failed");
 213         }
 214         return;
 215     }
 216 
 217     /* initialize the local port */
 218     if (localport == 0) {
 219         /* Now that we're a connected socket, let's extract the port number
 220          * that the system chose for us and store it in the Socket object.




 179     /* fd is an int field on fdObj */
 180     int fd;
 181     int len = 0;
 182     SOCKETADDRESS sa;
 183     socklen_t slen = sizeof(SOCKETADDRESS);
 184 
 185     if (IS_NULL(fdObj)) {
 186         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
 187                         "Socket closed");
 188         return;
 189     } else {
 190         fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
 191     }
 192 
 193     if (IS_NULL(iaObj)) {
 194         JNU_ThrowNullPointerException(env, "iaObj is null.");
 195         return;
 196     }
 197 
 198     /* bind */
 199     if (NET_InetAddressToSockaddr0(env, iaObj, localport, &sa, &len,
 200                                    JNI_TRUE, JNI_TRUE) != 0) {
 201       return;
 202     }
 203     setDefaultScopeID(env, &sa.sa);
 204 
 205     if (NET_Bind(fd, &sa, len) < 0)  {
 206         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
 207             errno == EPERM || errno == EACCES) {
 208             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
 209                             "Bind failed");
 210         } else {
 211             JNU_ThrowByNameWithMessageAndLastError
 212                 (env, JNU_JAVANETPKG "SocketException", "Bind failed");
 213         }
 214         return;
 215     }
 216 
 217     /* initialize the local port */
 218     if (localport == 0) {
 219         /* Now that we're a connected socket, let's extract the port number
 220          * that the system chose for us and store it in the Socket object.


< prev index next >