dns 编程问题, 怎么把一个域名转成byte[]啊假设www.csdn.net 转成byte[], 怎么转啊
我在java里
String  s = "www.csdn.net"
byte[] b = s.byteValue();
然后把b放到dns信息的问题部分
用upd把包发出去,我用wireshark截包时, 上面显示我的包的问题部分是 unknow我要怎么转成能符合格式啊?

解决方案 »

  1.   

    getBytes() 
              Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
      

  2.   

    String类下没有byteValue()方法...用一楼的方法
      

  3.   

    你用wireshark截包时,还有可能就是你发送的包要符合wireshark能捕获的形式
      

  4.   

    String msg="www.csdn.net""
    int len=s.length();
    byte[] message=new byte[len];
    s.getBytes(0,len,message,0);    不知为何我在eclipse里用getBytes方法的时候,里面总提示说不提倡用getBytes,也不知有没有其他的方法.
      

  5.   

    上面的String msg应为String s
      

  6.   

    void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin) 
              Deprecated. 建议你用byte[] getBytes();方法
      

  7.   

    String s="www.csdn.net"" 
    int len=s.length(); 
    byte[] message=new byte[len]; 
    s.getBytes(0,len,message,0);