GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — channel.write(msg, server) | not accepting ipv6 address · Issue #1300 · netty/netty

channel.write(msg, server) | not accepting ipv6 address #1300

New issue
Copy link
New issue
Copy link
Closed
Closed
channel.write(msg, server) | not accepting ipv6 address#1300
Copy link
Assignees
normanmaurer
Labels
defect
Milestone
3.7.0.Final

Description

@Girsh
Girsh
opened on Apr 23, 2013
Issue body actions

I am getting error while writing ChannelFuture future = channel.write(msg, server); . My server ip is ipv6 IP. It works fine when i use ipv4.

Details:

0 [main] INFO TestClient - Waiting total of 20 milliseconds for completion
0 [pool-1-thread-1] DEBUG DhcpMessage - Encoding DhcpMessage for: ff02:0:0:0:0:0:0:1:547
0 [pool-1-thread-1] DEBUG DhcpMessage - DhcpMessage encoded.
16 [New I/O datagram worker #1'-'1] WARN TestClient - Failed to send message id=0
16 [New I/O datagram worker #1'-'1] ERROR TestClient - Exception caught: 
java.net.SocketException: Address family not supported by protocol family: no further information
at sun.nio.ch.DatagramChannelImpl.send0(Native Method)
at sun.nio.ch.DatagramChannelImpl.sendFromNativeBuffer(DatagramChannelImpl.java:304)
at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:269)
at sun.nio.ch.DatagramChannelImpl.send(DatagramChannelImpl.java:254)
at org.jboss.netty.channel.socket.nio.SocketSendBufferPool$PooledSendBuffer.transferTo(SocketSendBufferPool.java:239)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.write0(NioDatagramWorker.java:540)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.writeFromTaskLoop(NioDatagramWorker.java:462)
at org.jboss.netty.channel.socket.nio.NioDatagramChannel$WriteTask.run(NioDatagramChannel.java:317)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.processWriteTaskQueue(NioDatagramWorker.java:330)
at org.jboss.netty.channel.socket.nio.NioDatagramWorker.run(NioDatagramWorker.java:254)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
16 [main] INFO TestClient - Successfully processed 0 of 0 messages in 0 milliseconds
32 [main] INFO TestClient - Shutting down executor...
32 [main] INFO TestClient - Closing channel...
32 [main] INFO TestClient - Done.
BUILD SUCCESSFUL (total time: 2 seconds)

Activity

  1. trustin commented on Apr 27, 2013

    @trustin
    trustin
    on Apr 27, 2013
    Member
    More actions

    Could you please paste the source code of an application/test that reproduces the problem? You'll have to provide both client and server.

  2. Girsh commented on Apr 29, 2013

    @Girsh
    Girsh
    on Apr 29, 2013
    Author
    More actions

    /*

    • Copyright 2009 Jagornet Technologies, LLC. All Rights Reserved.
      *
    • This software is the proprietary information of Jagornet Technologies, LLC.
    • Use is subject to license terms.
      *
      */

    /*

    • This file TestClient.java is part of DHCPv6.
    • DHCPv6 is free software: you can redistribute it and/or modify
    • it under the terms of the GNU General Public License as published by
    • the Free Software Foundation, either version 3 of the License, or
    • (at your option) any later version.
    • DHCPv6 is distributed in the hope that it will be useful,
    • but WITHOUT ANY WARRANTY; without even the implied warranty of
    • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    • GNU General Public License for more details.
    • You should have received a copy of the GNU General Public License
    • along with DHCPv6. If not, see http://www.gnu.org/licenses/.

    */
    package com.jagornet.dhcpv6.client;

    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.NetworkInterface;
    import java.net.SocketException;
    import java.net.UnknownHostException;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;

    import org.apache.commons.cli.BasicParser;
    import org.apache.commons.cli.CommandLine;
    import org.apache.commons.cli.CommandLineParser;
    import org.apache.commons.cli.HelpFormatter;
    import org.apache.commons.cli.Option;
    import org.apache.commons.cli.Options;
    import org.apache.commons.cli.ParseException;
    import org.jboss.netty.channel.ChannelFuture;
    import org.jboss.netty.channel.ChannelFutureListener;
    import org.jboss.netty.channel.ChannelHandler;
    import org.jboss.netty.channel.ChannelHandlerContext;
    import org.jboss.netty.channel.ChannelPipeline;
    import org.jboss.netty.channel.Channels;
    import org.jboss.netty.channel.ExceptionEvent;
    import org.jboss.netty.channel.MessageEvent;
    import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
    import org.jboss.netty.channel.socket.DatagramChannel;
    import org.jboss.netty.channel.socket.DatagramChannelFactory;
    import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
    import org.jboss.netty.channel.socket.oio.OioDatagramChannelFactory;
    import org.jboss.netty.handler.logging.LoggingHandler;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;

    import com.jagornet.dhcpv6.message.DhcpMessage;
    import com.jagornet.dhcpv6.option.DhcpClientIdOption;
    import com.jagornet.dhcpv6.option.DhcpElapsedTimeOption;
    import com.jagornet.dhcpv6.option.DhcpIaNaOption;
    import com.jagornet.dhcpv6.option.DhcpRapidCommitOption;
    import com.jagornet.dhcpv6.option.DhcpUserClassOption;
    import com.jagornet.dhcpv6.server.netty.DhcpChannelDecoder;
    import com.jagornet.dhcpv6.server.netty.DhcpChannelEncoder;
    import com.jagornet.dhcpv6.util.DhcpConstants;

    /**

    • A test client that sends request messages to a DHCPv6 server

    • via either unicast or multicast.

    • @author A. Gregory Rabil
      */
      @ChannelHandler.Sharable
      public class TestClient extends SimpleChannelUpstreamHandler
      {
      private static Logger log = LoggerFactory.getLogger(TestClient.class);

      protected Options options = new Options();
      protected CommandLineParser parser = new BasicParser();
      protected HelpFormatter formatter;

      protected NetworkInterface mcastNetIf = null;
      protected InetAddress serverAddr = DhcpConstants.LOCALHOST_V6;
      protected int serverPort = DhcpConstants.SERVER_PORT;
      protected int clientPort = DhcpConstants.CLIENT_PORT;
      protected boolean rapidCommit = false;
      protected int numRequests = 100;
      protected int requestsSent = 0;
      protected int successCnt = 0;
      protected long startTime = 0;
      protected long endTime = 0;

      protected DatagramChannel channel = null;
      protected ExecutorService executor = Executors.newCachedThreadPool();

      /** The request map. */
      protected Map<Integer, DhcpMessage> requestMap =
      Collections.synchronizedMap(new HashMap<Integer, DhcpMessage>());

      /**

      • Instantiates a new test client.

      • @PARAM args the args
        */
        public TestClient(String[] args)
        {
        setupOptions();

        if(!parseOptions(args)) {
        formatter = new HelpFormatter();
        String cliName = this.getClass().getName();
        formatter.printHelp(cliName, options);
        // PrintWriter stderr = new PrintWriter(System.err, true); // auto-flush=true
        // formatter.printHelp(stderr, 80, cliName, null, options, 2, 2, null);
        System.exit(0);
        }

        try {
        start();

        }
        catch (Exception ex) {
        ex.printStackTrace();
        }
        }

      /**

      • Setup options.
        */
        private void setupOptions()
        {
        Option numOption = new Option("n", "number", true,
        "Number of client requests to send" +
        " [" + numRequests + "]");
        options.addOption(numOption);

        Option addrOption = new Option("a", "address", true,
        "Address of DHCPv6 Server" +
        " [" + serverAddr.getHostAddress() + "]");
        options.addOption(addrOption);

        Option mcastOption = new Option("m", "multicast", true,
        "Multicast interface [none]");
        options.addOption(mcastOption);

        Option cpOption = new Option("cp", "clientport", true,
        "Client Port Number" +
        " [" + clientPort + "]");
        options.addOption(cpOption);

        Option spOption = new Option("sp", "serverport", true,
        "Server Port Number" +
        " [" + serverPort + "]");
        options.addOption(spOption);

        Option rOption = new Option("r", "rapidcommit", false,
        "Send rapid-commit Solicit requests");
        options.addOption(rOption);

        Option helpOption = new Option("?", "help", false, "Show this help page.");

        options.addOption(helpOption);
        }

      /**

      • Parses the options.
      • @PARAM args the args
      • @return true, if successful
        */
        protected boolean parseOptions(String[] args)
        {
        try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("?")) {
        return false;
        }
        if (cmd.hasOption("n")) {
        String n = cmd.getOptionValue("n");
        try {
        numRequests = Integer.parseInt(n);
        }
        catch (NumberFormatException ex) {
        numRequests = 100;
        System.err.println("Invalid number of requests: '" + n +
        "' using default: " + numRequests +
        " Exception=" + ex);
        }
        }
        if (cmd.hasOption("a")) {
        String a = cmd.getOptionValue("a");
        try {
        serverAddr = InetAddress.getByName(a);
        }
        catch (UnknownHostException ex) {
        serverAddr = DhcpConstants.LOCALHOST_V6;
        System.err.println("Invalid address: '" + a +
        "' using default: " + serverAddr +
        " Exception=" + ex);
        }
        }
        if (cmd.hasOption("m")) {
        String m = cmd.getOptionValue("m");
        try {
        mcastNetIf = NetworkInterface.getByName(m);
        }
        catch (SocketException ex) {
        System.err.println("Invalid interface: " + m +
        " - " + ex);
        }
        }
        if (cmd.hasOption("cp")) {
        String p = cmd.getOptionValue("cp");
        try {
        clientPort = Integer.parseInt(p);
        }
        catch (NumberFormatException ex) {
        clientPort = DhcpConstants.CLIENT_PORT;
        System.err.println("Invalid client port number: '" + p +
        "' using default: " + clientPort +
        " Exception=" + ex);
        }
        }
        if (cmd.hasOption("sp")) {
        String p = cmd.getOptionValue("sp");
        try {
        serverPort = Integer.parseInt(p);
        }
        catch (NumberFormatException ex) {
        serverPort = DhcpConstants.SERVER_PORT;
        System.err.println("Invalid server port number: '" + p +
        "' using default: " + serverPort +
        " Exception=" + ex);
        }
        }
        if (cmd.hasOption("r")) {
        rapidCommit = true;
        }
        }
        catch (ParseException pe) {
        System.err.println("Command line option parsing failure: " + pe);
        return false;
        }
        return true;
        }

      /**

      • Start sending DHCPv6 INFORM_REQUESTs.
        */
        public void start()
        {
        DatagramChannelFactory factory = null;
        if (mcastNetIf != null) {
        factory = new OioDatagramChannelFactory(Executors.newCachedThreadPool());
        serverAddr = DhcpConstants.ALL_DHCP_RELAY_AGENTS_AND_SERVERS;
        }
        else {
        factory = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
        }

        InetSocketAddress server = new InetSocketAddress(serverAddr, serverPort);
        InetSocketAddress client = new InetSocketAddress(clientPort);

        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("logger", new LoggingHandler());
        pipeline.addLast("encoder", new DhcpChannelEncoder());
        pipeline.addLast("decoder", new DhcpChannelDecoder(client, false));
        pipeline.addLast("handler", this);

        if (mcastNetIf != null) {
        channel = factory.newChannel(pipeline);
        channel.getConfig().setNetworkInterface(mcastNetIf);
        }
        else {
        channel = factory.newChannel(pipeline);
        }
        channel.bind(client);

        List requestMsgs = buildRequestMessages();

        for (DhcpMessage msg : requestMsgs) {
        executor.execute(new RequestSender(msg, server));
        }

        long ms = 0;
        if (rapidCommit)
        ms = requestMsgs.size()_200;
        else
        ms = requestMsgs.size()_20;

        synchronized (requestMap) {
        try {
        log.info("Waiting total of " + ms + " milliseconds for completion");
        requestMap.wait(ms);
        }
        catch (InterruptedException ex) {
        log.error("Interrupted", ex);
        }
        }

        log.info("Successfully processed " + successCnt +
        " of " + requestsSent + " messages in " +
        (endTime - startTime) + " milliseconds");

        log.info("Shutting down executor...");
        executor.shutdownNow();
        log.info("Closing channel...");
        channel.close();
        log.info("Done.");
        System.exit(0);
        }

      /**

      • The Class RequestSender.
        */
        class RequestSender implements Runnable, ChannelFutureListener
        {

        /** The msg. */
        DhcpMessage msg;

        /** The server. */
        InetSocketAddress server;

        /**

        • Instantiates a new request sender.
          *
        • @PARAM msg the msg
        • @PARAM server the server
          */
          public RequestSender(DhcpMessage msg, InetSocketAddress server)
          {
          this.msg = msg;
          this.server = server;
          }

        /* (non-Javadoc)

        • @see java.lang.Runnable#run()
          */
          @OverRide
          public void run()
          {
          ChannelFuture future = channel.write(msg, server);
          future.addListener(this);
          }

        /* (non-Javadoc)

        • @see org.jboss.netty.channel.ChannelFutureListener#operationComplete(org.jboss.netty.channel.ChannelFuture)
          */
          @OverRide
          public void operationComplete(ChannelFuture future) throws Exception
          {
          int id = msg.getTransactionId();
          if (future.isSuccess()) {
          if (startTime == 0) {
          startTime = System.currentTimeMillis();
          }
          requestsSent++;
          log.info("Succesfully sent message id=" + id);
          requestMap.put(id, msg);
          }
          else {
          log.warn("Failed to send message id=" + msg.getTransactionId());
          }
          }
          }

      /**

      • Builds the request messages.

      • @return the list< dhcp message>
        */
        private List buildRequestMessages()
        {
        List requests = new ArrayList();
        for (int id=0; id<numRequests; id++) {
        DhcpMessage msg =
        new DhcpMessage(null, new InetSocketAddress(serverAddr, serverPort));

        msg.setTransactionId(id);
        String clientId = "clientid-" + id;
        DhcpClientIdOption dhcpClientId = new DhcpClientIdOption();
        dhcpClientId.getOpaqueData().setAscii(clientId);
        
        msg.putDhcpOption(dhcpClientId);
        
        DhcpElapsedTimeOption dhcpElapsedTime = new DhcpElapsedTimeOption();
        dhcpElapsedTime.setUnsignedShort(1);
        msg.putDhcpOption(dhcpElapsedTime);
        
        DhcpUserClassOption dhcpUserClass = new DhcpUserClassOption();
        dhcpUserClass.addOpaqueData("FilterUserClass");
        msg.putDhcpOption(dhcpUserClass);
        
        if (rapidCommit) {
            msg.setMessageType(DhcpConstants.SOLICIT);
            DhcpIaNaOption dhcpIaNa = new DhcpIaNaOption();
            dhcpIaNa.setIaId(1);
            msg.putDhcpOption(dhcpIaNa);
            DhcpRapidCommitOption dhcpRapidCommit = new DhcpRapidCommitOption();
            msg.putDhcpOption(dhcpRapidCommit);
        }
        else {
            msg.setMessageType(DhcpConstants.INFO_REQUEST);
        }            
        requests.add(msg);
        

        }
        return requests;
        }

      /*

      • (non-Javadoc)

      • @see org.jboss.netty.channel.SimpleChannelHandler#messageReceived(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.MessageEvent)
        */
        @OverRide
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
        {
        Object message = e.getMessage();
        if (message instanceof DhcpMessage) {

        DhcpMessage dhcpMessage = (DhcpMessage) message;
        if (log.isDebugEnabled())
            log.debug("Received: " + dhcpMessage.toStringWithOptions());
        else
            log.info("Received: " + dhcpMessage.toString());
        
        DhcpMessage requestMsg = requestMap.remove(dhcpMessage.getTransactionId());
        if (requestMsg != null) {
            successCnt++;
            endTime = System.currentTimeMillis();
            synchronized (requestMap) {
                if (requestMap.isEmpty()) {
                    requestMap.notify();
                }
            }
        }
        

        }
        else {
        // Note: in theory, we can't get here, because the
        // codec would have thrown an exception beforehand
        log.error("Received unknown message object: " + message.getClass());
        }
        }

      /* (non-Javadoc)

      • @see org.jboss.netty.channel.SimpleChannelUpstreamHandler#exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ExceptionEvent)
        */
        @OverRide
        public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
        {
        log.error("Exception caught: ", e.getCause());
        e.getChannel().close();
        }

      /**

      • The main method.
      • @PARAM args the arguments
        */
        public static void main(String[] args) {
        new TestClient(args);
        }

    }

  3. Girsh commented on Apr 29, 2013

    @Girsh
    Girsh
    on Apr 29, 2013
    Author
    More actions

    We can use any Dhcp v6 server. We have requirement to implement Dhcp client for v6

  4. ghost assigned
    normanmaurer
    on May 12, 2013
  5. normanmaurer commented on May 12, 2013

    @normanmaurer
    normanmaurer
    on May 12, 2013
    Member
    More actions

    @Girsh will look into it

  6. normanmaurer commented on May 12, 2013

    @normanmaurer
    normanmaurer
    on May 12, 2013
    Member
    More actions

    @Girsh could you add some more info like os and java version ?

  7. normanmaurer commented on May 15, 2013

    @normanmaurer
    normanmaurer
    on May 15, 2013
    Member
    More actions

    I just tried to reproduce here and everything works as far as I can see. To reproduce I did this:

    Normans-MacBook-Pro% nc -6 -l -u 8080

    Then patched the QuoteOfTheMomentClient and executed it:

    iff --git a/src/main/java/org/jboss/netty/example/qotm/QuoteOfTheMomentClient.java b/src/main/java/org/jboss/netty/example/qotm/QuoteOfTheMomentClient.java
    index 65c56b5..211b2cc 100644
    --- a/src/main/java/org/jboss/netty/example/qotm/QuoteOfTheMomentClient.java
    +++ b/src/main/java/org/jboss/netty/example/qotm/QuoteOfTheMomentClient.java
    @@ -61,7 +61,7 @@ public class QuoteOfTheMomentClient {
             });
    
             // Enable broadcast
    -        b.setOption("broadcast", "true");
    +        //b.setOption("broadcast", "true");
    
             // Allow packets as large as up to 1024 bytes (default is 768).
             // You could increase or decrease this value to avoid truncated packets
    @@ -80,7 +80,7 @@ public class QuoteOfTheMomentClient {
             DatagramChannel c = (DatagramChannel) b.bind(new InetSocketAddress(0));
    
             // Broadcast the QOTM request to port 8080.
    -        c.write("QOTM?", new InetSocketAddress("255.255.255.255", port));
    +        c.write("QOTM?", new InetSocketAddress("fe80::1%lo0", port)).syncUninterruptibly();
    
             // QuoteOfTheMomentClientHandler will close the DatagramChannel when a
             // response is received.  If the channel is not closed within 5 seconds,

    The message was displayed in the shell that runs nc

    QOTM?
    
  8. normanmaurer commented on Jun 21, 2013

    @normanmaurer
    normanmaurer
    on Jun 21, 2013
    Member
    More actions

    Please re-open if you still have the problem and can submit a reproducer

  9. normanmaurer
    closed this as completedon Jun 21, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @normanmaurer
    normanmaurer

Labels

defect

Type

No type

Projects

No projects

    Milestone

    • 3.7.0.Final

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.