Пример #1
0
        /// <summary> Send an outgoing multicast DNS message.</summary>
        internal async Task Send(DNSOutgoing out_Renamed)
        {
            out_Renamed.Finish();
            if (!out_Renamed.Empty)
            {
                SupportClass.PacketSupport packet = new SupportClass.PacketSupport(SupportClass.ToByteArray(out_Renamed.data), out_Renamed.off, new IPEndPoint(group, DNSConstants.MDNS_PORT));

                try
                {
                    DNSIncoming msg = new DNSIncoming(packet);
                    logger.Debug("send() JmDNS out:" + msg.Print(true));
                }
                catch (IOException e)
                {
                    logger.Error("send(DNSOutgoing) - JmDNS can not parse what it sends!!!", e);
                }
                await SupportClass.UdpClientSupport.Send(socket, packet);
            }
        }
Пример #2
0
 internal Address(string name, int type, int clazz, int ttl, sbyte[] rawAddress) : base(name, type, clazz, ttl)
 {
     try
     {
         byte[] rawAddressUnsigned = SupportClass.ToByteArray(rawAddress);
         // HACK: why doesn't the other constructor work?
         string dottedQuad = rawAddressUnsigned[0] + "." +
                             rawAddressUnsigned[1] + "." +
                             rawAddressUnsigned[2] + "." +
                             rawAddressUnsigned[3];
         this.addr = IPAddress.Parse(dottedQuad);
         //this.addr = new IPAddress(rawAddressUnsigned);
         //this.addr = new IPAddress(rawAddress);
     }
     catch (Exception exception)
     {
         logger.Warn("Address() exception ", exception);
     }
 }
Пример #3
0
 /// <summary> Construct a service description for registrating with JmDNS. The properties hashtable must
 /// map property names to either Strings or byte arrays describing the property values.
 /// </summary>
 /// <param name="type">fully qualified service type name, such as <code>_http._tcp.local.</code>.
 /// </param>
 /// <param name="name">unqualified service instance name, such as <code>foobar</code>
 /// </param>
 /// <param name="port">the local port on which the service runs
 /// </param>
 /// <param name="weight">weight of the service
 /// </param>
 /// <param name="priority">priority of the service
 /// </param>
 /// <param name="props">properties describing the service
 /// </param>
 public ServiceInfo(string type, string name, int port, int weight, int priority, Hashtable props) : this(type, name, port, weight, priority, new sbyte[0])
 {
     if (props != null)
     {
         try
         {
             MemoryStream out_Renamed = new MemoryStream(256);
             foreach (string key in props.Keys)
             {
                 object       val  = props[key];
                 MemoryStream out2 = new MemoryStream(100);
                 WriteUTF(out2, key);
                 if (val is string)
                 {
                     out2.WriteByte((byte)'=');
                     WriteUTF(out2, (string)val);
                 }
                 else if (val is sbyte[])
                 {
                     out2.WriteByte((byte)'=');
                     sbyte[] bval = (sbyte[])val;
                     out2.Write(SupportClass.ToByteArray(bval), 0, bval.Length);
                 }
                 else if (val != NO_VALUE)
                 {
                     throw new ArgumentException("invalid property value: " + val);
                 }
                 sbyte[] data = SupportClass.ToSByteArray(out2.ToArray());
                 out_Renamed.WriteByte((byte)data.Length);
                 out_Renamed.Write(SupportClass.ToByteArray(data), 0, data.Length);
             }
             this.text = SupportClass.ToSByteArray(out_Renamed.ToArray());
         }
         catch (IOException e)
         {
             throw new Exception("unexpected exception: " + e);
         }
     }
 }
Пример #4
0
 private sbyte[] toByteArray()
 {
     try
     {
         // TODO: check this
         MemoryStream bout = new MemoryStream();
         BinaryWriter dout = new BinaryWriter(bout);
         dout.Write(SupportClass.ToByteArray(SupportClass.ToSByteArray(Encoding.GetEncoding("UTF8").GetBytes(name))));
         dout.Write((Int16)type);
         dout.Write((Int16)clazz);
         //dout.writeInt(len);
         dout.Write((Int16)priority);
         dout.Write((Int16)weight);
         dout.Write((Int16)port);
         dout.Write(SupportClass.ToByteArray(SupportClass.ToSByteArray(Encoding.GetEncoding("UTF8").GetBytes(server))));
         dout.Dispose();
         return(SupportClass.ToSByteArray(bout.ToArray()));
     }
     catch
     {
         throw new Exception();
     }
 }
Пример #5
0
 /// <summary> Creates a byte array representation of this record.
 /// This is needed for tie-break tests according to
 /// draft-cheshire-dnsext-multicastdns-04.txt chapter 9.2.
 /// </summary>
 private sbyte[] toByteArray()
 {
     try
     {
         // TODO: check this
         MemoryStream bout = new MemoryStream();
         BinaryWriter dout = new BinaryWriter(bout);
         dout.Write(SupportClass.ToByteArray(SupportClass.ToSByteArray(Encoding.UTF8.GetBytes(name))));
         dout.Write((Int16)type);
         dout.Write((Int16)clazz);
         //dout.writeInt(len);
         sbyte[] buffer = SupportClass.ToSByteArray(addr.GetAddressBytes());
         for (int i = 0; i < buffer.Length; i++)
         {
             dout.Write((byte)buffer[i]);
         }
         dout.Dispose();
         return(SupportClass.ToSByteArray(bout.ToArray()));
     }
     catch
     {
         throw new Exception();
     }
 }