Java Code Examples for io.netty.util.internal.PlatformDependent#maybeSuperUser()

The following examples show how to use io.netty.util.internal.PlatformDependent#maybeSuperUser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDatagramChannelConfig.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public DatagramChannelConfig setBroadcast(boolean broadcast) {
    try {
        // See: https://github.com/netty/netty/issues/576
        if (broadcast &&
            !javaSocket.getLocalAddress().isAnyLocalAddress() &&
            !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) {
            // Warn a user about the fact that a non-root user can't receive a
            // broadcast packet on *nix if the socket is bound on non-wildcard address.
            logger.warn(
                    "A non-root user can't receive a broadcast packet if the socket " +
                    "is not bound to a wildcard address; setting the SO_BROADCAST flag " +
                    "anyway as requested on the socket which is bound to " +
                    javaSocket.getLocalSocketAddress() + '.');
        }

        javaSocket.setBroadcast(broadcast);
    } catch (SocketException e) {
        throw new ChannelException(e);
    }
    return this;
}
 
Example 2
Source File: BGPPeerAcceptorImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public BGPPeerAcceptorImpl(final IpAddressNoZone bindingAddress, final PortNumber portNumber,
        final BGPDispatcher bgpDispatcher) {
    this.bgpDispatcher = requireNonNull(bgpDispatcher);
    this.address = getAddress(requireNonNull(bindingAddress), requireNonNull(portNumber));
    if (!PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()
            && portNumber.getValue().toJava() < PRIVILEGED_PORTS) {
        throw new AccessControlException("Unable to bind port " + portNumber.getValue()
                + " while running as non-root user.");
    }
}
 
Example 3
Source File: Controller.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the BGP controller.
 */
public void start() {
    log.info("Started");
    if (!PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) {
        portNumber = BGP_PRIVILEGED_PORT;
    } else {
        portNumber = BGP_PORT_NUM;
    }
    this.init();
    this.run();
}
 
Example 4
Source File: AbstractChannel.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
        public final void bind(final SocketAddress localAddress, final ChannelPromise promise) {
            assertEventLoop();

            if (!promise.setUncancellable() || !ensureOpen(promise)) {
                return;
            }

            // See: https://github.com/netty/netty/issues/576
            if (Boolean.TRUE.equals(config().getOption(ChannelOption.SO_BROADCAST)) &&
                localAddress instanceof InetSocketAddress &&
                !((InetSocketAddress) localAddress).getAddress().isAnyLocalAddress() &&
                !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) {
                // Warn a user about the fact that a non-root user can't receive a
                // broadcast packet on *nix if the socket is bound on non-wildcard address.
                logger.warn(
                        "A non-root user can't receive a broadcast packet if the socket " +
                        "is not bound to a wildcard address; binding to a non-wildcard " +
                        "address (" + localAddress + ") anyway as requested.");
            }

            boolean wasActive = isActive();
            try {
//                调用java底层bind操作
                doBind(localAddress);
            } catch (Throwable t) {
//                发布bind失败事件
                safeSetFailure(promise, t);
//                channel如果是打开的就关闭
                closeIfClosed();
                return;
            }

            if (!wasActive && isActive()) {
                invokeLater(new Runnable() {
                    @Override
                    public void run() {
//                        触发pipeline的激活事件
                        pipeline.fireChannelActive();
                    }
                });
            }

//            发布bind成功事件
            safeSetSuccess(promise);
        }