EldoS | Feel safer!

Software components for data protection, secure storage and transfer

DNSClient.Lookup example

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#27306
Posted: 11/23/2013 01:13:38
by Lawrence Hughes (Standard support level)
Joined: 11/23/2013
Posts: 8

I keep getting "Invalid parameter" when I try to activate the DNSClient. There do not seem to be any examples of this in the samples or in your online info. Here is the code I'm trying to get work. The address of the node I'm running it on is 172.20.2.1, and there is a MS DNS Server at 172.20.0.13, port 53.

Code
            TSBDNSResourceType dnsResourceCode =
                TSBDNSResourceType.dnsIPv4Address;
            string dnsTarget = "www.sixscape.com";
            TElDNSMessage dnsResponse = new TElDNSMessage();

            TElDNSClient dnsClient = new TElDNSClient();
            dnsClient.Binding.LocalIntfAddress = "172.20.2.1";
            dnsClient.Binding.PortRangeFrom = 40000;
            dnsClient.Binding.PortRangeTo = 60000;

            dnsClient.Address = "172.20.0.13";
            dnsClient.Port = 53;
            dnsClient.UseRecursion = true;
            dnsClient.Timeout = 5000;

            try
            {
                dnsClient.Activate();        // <--- gets exception here
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            try
            {
                dnsClient.Lookup(dnsTarget, dnsResourceCode, ref dnsResponse);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
#27307
Posted: 11/23/2013 03:06:44
by Eugene Mayevski (EldoS Corp.)

DNS client is an internal class used to provide DNSSEC functionality to socket-based components. It was not intended to be used by public.

Please remove local binding - the exception happens during bind'ing a socket and wrong parameters are the most likely reason.


A couple of side notes:
1) please use CODE button to mark the beginning and the end of the code block in your messages.
2) Never put license keys or license ticket to the forum. When you link the license ticket to the account (like you did), we can see licensing information automatically.


Sincerely yours
Eugene Mayevski
#27308
Posted: 11/23/2013 07:48:28
by Lawrence Hughes (Standard support level)
Joined: 11/23/2013
Posts: 8

OK - I have removed the local binding - this is about as simple as I can make it. I still get an exception on the Activate with "An invalid argument was supplied." I must be missing something. I can't use the normal DNS resolve because what I really want to do is to look up SRV records. I'm trying to get it working first with A record. However, I can't seem to get past the Activate() call. This is with Visual Studio 2012 in a Windows Form app.

BTW the real app is a P2P native IPv6 messaging User Agent with embedded PKI. I created the crypto and PKI training for VeriSign many years ago. I will be really testing out the IPv6 aspects of SBB thoroughly. See my website www.sixscape.com.

Code

using SBConstants;
using SBSocket;
using SBDNSSEC;
using SBDNSSECTypes;

// constructor not included

        private void Query_Button_Click(object sender, EventArgs e)
        {
            string dnsServerAddr = "172.20.0.13";
            byte dnsServerPort = 53;

            TElDNSClient dnsClient = new TElDNSClient();
            dnsClient.Address = dnsServerAddr;
            dnsClient.Port = dnsServerPort;
            dnsClient.Timeout = 5000;

            try
            {
                dnsClient.Activate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string dnsTarget = "www.sixscape.com";
            TSBDNSResourceType dnsResourceCode =
                TSBDNSResourceType.dnsIPv4Address;
            TElDNSMessage dnsResponse = new TElDNSMessage();

            try
            {
                dnsClient.Lookup(dnsTarget, dnsResourceCode, ref dnsResponse);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
#27309
Posted: 11/23/2013 09:25:21
by Lawrence Hughes (Standard support level)
Joined: 11/23/2013
Posts: 8

It seems I get an exception every time I call Activate, even if it was successful. If dnsClient.Active is true, looks like I can just ignore the exception. This code appears to be working. The stuff in Answers looks OK. Any comments?

Code
       private void Query_Button_Click(object sender, EventArgs e)
        {
            TElDNSClient dnsClient = new TElDNSClient();
            dnsClient.Address = "172.20.0.13";
            dnsClient.Port = 53;
            dnsClient.Binding.LocalIntfAddress = "172.20.2.1";
            dnsClient.Binding.PortRangeFrom = 10000;
            dnsClient.Binding.PortRangeTo = 30000;
            dnsClient.UseIPv6 = false;
            dnsClient.UseRecursion = true;

            try
            {
                dnsClient.Activate();
            }
            catch (Exception ex)
            {
                if (!dnsClient.Active)
                {
                    MessageBox.Show("Activate failed");
                }

                // if Active is true, ignore exception
            }

            string dnsTarget = "www.sixscape.com";
            TSBDNSResourceType dnsResourceCode =
                TSBDNSResourceType.dnsIPv4Address;
            TElDNSMessage dnsResponse = new TElDNSMessage();

            try
            {
                dnsClient.Lookup(dnsTarget, dnsResourceCode, ref dnsResponse);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            TElDNSResourceRecordSet Answers = dnsResponse.Answers;
            int numAnswers = Answers.Count;

            for (int i = 0; i < numAnswers; i++)
            {
                TElDNSResourceRecord Answer = Answers[i];
                byte[] data = Answer.Data;
                string name = Answer.Name;
                int resourceClass = Answer.ResourceClass;
                int resourceCode = Answer.ResourceCode;
                TSBDNSResourceType resourceType = Answer.ResourceType;
                uint timeToLive = Answer.TimeToLive;
            }
#27345
Posted: 11/25/2013 01:57:42
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Could you post the exception call stack here.
#27358
Posted: 11/25/2013 05:16:45
by Lawrence Hughes (Standard support level)
Joined: 11/23/2013
Posts: 8

I think this is what you want.... and the problem happens whether I am using IPv4 or IPv6. I just happened to notice that "Active" was set, even though I got an exception. I can shoot you the entire code if you want - via email (not posted here).

System.Net.Sockets.SocketException was caught
HResult=-2147467259
Message=An invalid argument was supplied
Source=System
ErrorCode=10022
NativeErrorCode=10022
StackTrace:
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue, Boolean silent)
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)
at System.Net.Sockets.Socket.set_NoDelay(Boolean value)
at SBSocket.TElSocket.DoSetUseNagle(Boolean Value)
at SBSocket.TElSocket.Init(Boolean UseIPv6)
at SBSocket.TElSocket.Bind(Boolean Outgoing, Boolean ReuseAddress)
at SBDNSSEC.TElDNSClient.Activate()
at DNS_Lookup.DNS_Query.GetSRVRecords(String dnsServerAddrStr, String service, String transport, String domain, SRV_Result[]& SRV_Results) in e:\LEH-Dev\DNS_Lookup\DNS_Lookup\DNS_Query.cs:line 115
InnerException:
#27359
Posted: 11/25/2013 05:19:38
by Eugene Mayevski (EldoS Corp.)

Thank you. This exception is suppressed internally in the latest builds of SecureBlackbox. You can ignore it.


Sincerely yours
Eugene Mayevski
#27360
Posted: 11/25/2013 05:21:27
by Vsevolod Ievgiienko (EldoS Corp.)

Do you use the latest version of SecureBlackbox? As far as I remember this problem was fixed recently.
#27364
Posted: 11/25/2013 06:53:02
by Lawrence Hughes (Standard support level)
Joined: 11/23/2013
Posts: 8

I appear to be using "SecureBlackbox - version 10.0.233 - Released February 28, 2013". I think this is the most recent copy of version 10. I just downloaded it recently. I have not upgraded to version 11 yet.
#27365
Posted: 11/25/2013 06:56:23
by Vsevolod Ievgiienko (EldoS Corp.)

In this case just ignore this exception. Its handled internally in the 11th version.
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

Topic viewed 710 times

Number of guests: 2, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!