Introducing mIP - A 100% Managed TCP/IP Stack for .NET MF

Yes, that’s right.

None. You need to set it yourself with something like:


...
static byte[] myMAC = new byte[] { 0x00, 0x30, 0xFD, 0xE5, 0xD7, 0x7C };
...
networkInterface.PhysicalAddress = myMAC;
/code]

I’m playing catch-up on connecting FEZ boards to the internet. So, excuse me if I’ve missed something (and I hope I have). But, this is what I’ve found so far…

The ENC28 module product description says…

Since the ENC28 module is the only ethernet module available for Cerberus & Hydra then my assumption is that something is unfinished - either the ethernet version of the firmware or the ENC28 driver. Sorry, I don’t know enough about what the difference in the ethernet vs. non-ethernet versions of the firmware. All I know is that there appears to be no plug & play solution for ethernet on the OSHW boards. mIP appears to work fairly well, but it does not appear to be a drop-in replacement for the NETMF/Gadgeteer networking libraries since I cannot seem to take examples based on pure NETMF code and quickly make it work using mIP.

So, if I have to use mIP then I’m left with the question of what is gained by having the ethernet version of the firmware?

EDIT: After reading my own post, I see that I may have read the product description wrong for the ENC28. It seems that the “secondary firmware” is probably the ethernet version of the firmware and not the 3rd party software (mIP) that I read it as last night… Now to find a working example of using the ethernet firmware… :frowning:

@ ianlee74 - I would recommend that you use the ethernet firmware. Not that mIP isn’t great, but the LWIP in the Ethernet firmware is a proper stack and in many cases is the best choice. I personally, found it lacking, so I wrote mIP. There are certainly pros and cons to both.

Maybe I should ask, what do you intend to do with Networking? Web server, FTP, SSL, UDP messages (multacast or broadcast)?

@ Valkyrie-MT Yea… Once I realized that I had misread the notes on the ENC28, I went back to trying to make the ethernet firmware work since it is definitely the preferred route. I’m just needing to post some data to a web service (ThingSpeak). I started a new thread…

http://www.tinyclr.com/forum/topic?id=10140

Hi,
I wanted to use mIP because I need it on a G120 for a 2nd NW interface.
Because I need FTP on this one I thought ‘how hard could it be to modify the NETMF FtpListener to use mIP’.

After playing around half a day I got it to nearly to allow a login, but it seams to be very tricky.
I think mIP currently has some trouble in beeing a TCP Server.

Since we would need this for a commercial product I would like to extend mIP so it works as TCP Server with FTP.
To do so I would like extend the Connection class to be even more like a socket (adding Read, Poll, Avialable, Send, … and an Accept method)
By this the OnTcpPacketReceived event would not be needed anmore. Instead I would write the data internally inta a buffer hosted by the Connection object.
Also the ListenToPort would be obsolete for TCP. But I’m not sure if this would need to much change in the internal structure of mIP.

Finally, do you have any problems if I extend mIP like this?

I currently use mIP as a web server and it works well for that. It’s become very reliable. As long as requests to mIP are 1 packet or less, it should work well. If you are planning on uploading files to an FTP server running on mIP, that is going to be a real challenge requiring some low level TCP changes I expect.

I welcome the contribution as long as it does not break the samples. Also, make sure you work from the current Beta release from codeplex (released December 2012).

-Valkyrie-MT

@ Valkyrie-MT - OK, I’ll try to do so. In fact I already had problems with the 1st FTP telegrams which are really short.
If I have to do breaking changes: Would it be ok for you if I make my own spin off.

What is the state of play on mIP, is Valkyrie-MT still maintaining this, does anyone use this in anger, my goal is to do simple http post to cosm et al using a Cerberus,
I guess that using WebRequest classes is incompatible with mIP tho

The state of mIP is stable for me and I fix bugs if they come up, but I haven’t had any in a while. I personally use it all the time. If you’re trying to do an HTTP GET, it should work great for that. Can you tell me exactly what’s happening and what url you are requesting from?

hey Valkyrie, great job, I was just curious if it was just rusty, but sounds like your saying no need to fix anything if it aint broke.

At the moment I have it running on a Cerberus, (coz Im having dhcp issues with built in) and the dhcp works ;-), but Im getting an exception when performing a dns lookup.

Im tempted to debug the code on a desktop, using an ndis packet driver to inject and snoop the packets (replace the adapter), might make debugging easier, have you tried that

Interesting. If you can sniff the packets and capture the relevant DNS traffic, it would be an easy fix if it’s doing something wrong.

I pass the networking through my desktop PC (through a second NIC) where I run wireshark to snoop on the packet traffic. That lets me see all the packets to do debugging work.

What DNS server are you using and what DNS name are you attempting to resolve. I assume the nslookup command works on a PC connected to the same router?

this is on the work network so probably some Linux or windows server box.
nslookup works ok.

Im a bit stumped why the dns fails but ill try to get some more info.

actually im just using the built in internet checker ConnectedToInternet (networking.cs)
I see the packet go out but it times out, there are a lot of packets flying around tho, so difficult to see

ps Is mip_v0.3 still the latest, that’s what im using

So what you should see on the wire for the ConnectedToInternet call is a DNS lookup query for www.msftncsi.com. Then a response from the DNS server should contain the answer with the IP address. Then it should send an http GET for ncsi.txt file. This is the method Windows 7 (and older versions) use to test the internet connectivity, so I figured this service will be around for a while :). The web service should respond then with a standard HTTP 200 OK. Once that response is received, the ConnectedToInternet method will return the true/false result.

That idea is based on a post here: http://blog.superuser.com/2011/05/16/windows-7-network-awareness

Alternatively, this method could ping google or something that will never go away… but I followed Microsoft’s lead here.

But that DNS lookup should not fail. If it is sending a DNS request, but is not getting a response, it must be a malformed request. I would compare the request to that sent with nslookup. If you can send me a wireshark trace of the whole exchange, I’d be happy to review it.

Yes, v0.3 is the latest.

wilco, back to you shortly

ok ive got a small wireshark file not sure how to interpret it tho.

truncated to show the problem packet


No.     Time                       Source                Destination           Protocol Length Info
     10 8.146369                   172.16.46.36          172.16.45.1           UDP      77     SecretLa_00:00:dd

Frame 10: 77 bytes on wire (616 bits), 77 bytes captured (616 bits)
Ethernet II, Src: SecretLa_00:00:dd (5c:86:4a:00:00:dd), Dst: HewlettP_10:2a:d0 (e4:11:5b:10:2a:d0)
Internet Protocol Version 4, Src: 172.16.46.36 (172.16.46.36), Dst: 172.16.45.1 (172.16.45.1)
User Datagram Protocol, Src Port: 44048 (44048), Dst Port: 11538 (11538)
Data (35 bytes)

0000  7c a4 01 00 00 01 00 00 00 00 00 00 03 77 77 77   |............www
0010  09 6d 69 63 72 6f 73 6f 66 74 03 63 6f 6d 00 00   .microsoft.com..
0020  01 00 01                                          ...

No.     Time                       Source                Destination           Protocol Length Info
     11 12.003813                  SecretLa_00:00:dd     Broadcast             ARP      60     SecretLa_00:00:dd

Frame 11: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: SecretLa_00:00:dd (5c:86:4a:00:00:dd), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Address Resolution Protocol (request/gratuitous ARP)


I thought DNS was UDP on port number 53, looking at log it is using 11538 ??
It looks like something is overwriting the scratch byte[] somewhere, mmm suspicious

the problem is with this line

            scratch.Overwrite(30, (useSecondaryDnsServer && Adapter.DomainNameServer2 != null) ? Adapter.DomainNameServer2 : Adapter.DomainNameServer);   // Destiantion IP Address

on my system Adapter.DomainNameServer is 8 bytes long!!

and is set with this line (in DHCP.cs)
nb options[“6”] contains 8 bytes


if (options.Contains("6")) Adapter.DomainNameServer = (byte[])options["6"];  // DNS Server

OK Put in a hack to guard against this case and it works SO… there is a bug in the DHCP when assigning the DnsAddress from options[6] in that this is sometimes two addresses, have to check the rfc to see if this is legal

and the following is OK :wink:


Debug.Print("Try an http request");
var r = new HttpRequest("http://www.msftncsi.com/ncsi.txt");
r.Headers.Add("Accept", "*/*");  // Add custom properties to the Request eader
var response = r.Send();

According to this option 6 is multiples of 4 octets

btw a couple of observations… I hope this doesn’t sound picky :wink:

I don’t think you need the MultiSpii class any more, don’t know what the problem is but the sdk release notes says there is a bug fix around this issue

Get a couple of warnings

1>NetworkingService\DNS.cs(294,20,294,29): warning CS0659: ‘Networking.DnsAnswer’ overrides Object.Equals(object o) but does not override Object.GetHashCode()

NetworkingService\TCP.cs(539,25,539,33): warning CS0649: field ‘Networking.HttpRequest._content’ is never assigned to, and will always have its default value null

Fantastic. It does appear that you found a bug here. I’m wondering how this ever worked at all. I will go and test this myself this weekend. But, this is exactly what is great about a managed TCP/IP stack… people can easily debug it. If this kind of problem was in the LWIP stack, debugging and fixing would take a lot longer.

As for the nitpicking, I actually hate having to use that MultiSPI. I needed to add it to allow the SPI bus to be used for other devices. You think it isn’t necessary anymore? I will try removing it…

Yeah, I remember those warnings about the missing GetHashcode implementation… I remember thinking they were not necessary. I am always looking to trim code because I want to keep things minimal. But I don’t remember what my justification was. I’d probably have to look at where I am testing equality for those objects. Looks important though from this post: c# - Why is it important to override GetHashCode when Equals method is overridden? - Stack Overflow