Hi, I am testing an ethernet device on a development board, I programmed a ping echo program based on the ethernet driver, not using any IP protocol stack, but I have a hard time using the program to echo the ping from my Windows 2000 PC. From some network traffic tool I can see the ethernet frame coming to the PC and I believe the ethernet header and ICMP header are correct, but Windows ping can not receive my echo. I suspect I miss some tricks, so I am wondering if there are ping source code for Windows to reference. From web searching, I see someone mentioned Windows SDK has a sample ICMP application, but I do not have access of that and I think that application should be based on socket programming, while I am looking for no protocol stack source file. Could you help here? Thanks.
ask for sample ping source code without IP protocal stack
Started by ●March 5, 2004
Reply by ●March 5, 20042004-03-05
On Fri, 05 Mar 2004 16:26:22 -0700, John Black wrote:> I am testing an ethernet device on a development board, I programmed >a ping echo program based on the ethernet driver, not using any IP >protocol stackStart with straight Ethernet. Understand the difference between DIX and IEEE formats, and how to cope with both. Now implement ARP. Once you have ARP, try simple IP datagrams. Once you can send/receive IP, try ICMP echo. Now write the tricky bits :o) Don't even *think* of trying to get this working without an Ethernet packet sniffer, btw. -- Max
Reply by ●March 6, 20042004-03-06
John Black wrote:> I am testing an ethernet device on a development > board, I programmed a ping echo program [...]You are trying to run before you can crawl. First do ping, then ARP, then ping replies. ICMP Echo Replies need to match the signature of the Echo or they will be ignored by the pinging station, so you cannot hard-code an Echo Reply string. Also, you need to implement ARP or install static entries in the PC side (sounds like you must have done this already) so the ping will reach you at all. And, you need to calculate the IP checksums on-the-fly for replies, since the content varies. None of these obstacles exist if your device is the one pinging instead of replying. 1) Goto http://www.ethereal.com and get their packet sniffer. It's free, and it's invaluable. 2) Sniff PC A sending an ICMP ping to PC B on the same subnet. 3) Copy the packet hex *exactly* into your program. Don't change the MAC addresses or any values in the packet. 4) Run your program to send pings. On PC B, run Ethereal and see the incoming pings and outgoing replies. Yes, the replies will go to PC A's MAC address instead of back to your device, but you've succeeded in transmitting a working IP packet. 5) Then, work on varying the source MAC and IP, while updating the IP checksums. 6) Implement an ARP responder on your device so it can be pinged 7) Listen for incoming pings and generate replies with the right payload and checksum. Then you'd be at the point you're trying to start from.> I suspect I miss some tricks, so I am wondering > if there are ping source code for Windows to > reference. From web searching, I see someone > mentioned Windows SDK has a sample ICMP > application [...]You're wasting your time with this search. Most sample ICMP programs are going to make calls into an IP stack, which will actually format the packet and handle transmission. If you don't have 2 PCs, use PC A and a DSL router, or any other device that will answer a ping. Run the Ethereal on PC A instead; if you use a hub, it'll see all the traffic anyway. Good luck, Richard
Reply by ●March 6, 20042004-03-06
John Black <black@eed.com> wrote in message news:<40490C9E.74D5732A@eed.com>...> Hi, > I am testing an ethernet device on a development board, I programmed > a ping echo program based on the ethernet driver, not using any IP > protocol stack, but I have a hard time using the program to echo the > ping from my Windows 2000 PC. From some network traffic tool I can see > the ethernet frame coming to the PC and I believe the ethernet header > and ICMP header are correct, but Windows ping can not receive my echo. > I suspect I miss some tricks, so I am wondering if there are ping > source code for Windows to reference. From web searching, I see someone > mentioned Windows SDK has a sample ICMP application, but I do not have > access of that and I think that application should be based on socket > programming, while I am looking for no protocol stack source file. > Could you help here?There's not really much to question here: ICMP echo-request/reply are pretty solidly spec'd in the RFCs. Can you post the network monitor trace of the echo request from the Windows box and the reply from your device? Be sure to include everything out to the MAC frame. Also, let us know what the MAC and IP addresses are for the two boxes, and be sure to include any ARP traffic. My suspicion is that you are either not putting the correct MAC or IP address into the reply, or you're not copying over the identifier and sequence number fields from the request.
Reply by ●March 6, 20042004-03-06
John, you can find a lot of ideas and hands on information in Jeremy Bentham's book: "TCP/IP lean". It helps a lot to understand the different protocols of TCP/IP. ICMP is one of them. grtnx /jan John Black <black@eed.com> schrieb in im Newsbeitrag: 40490C9E.74D5732A@eed.com...> Hi, > I am testing an ethernet device on a development board, I programmed > a ping echo program based on the ethernet driver, not using any IP > protocol stack, but I have a hard time using the program to echo the > ping from my Windows 2000 PC. From some network traffic tool I can see > the ethernet frame coming to the PC and I believe the ethernet header > and ICMP header are correct, but Windows ping can not receive my echo. > I suspect I miss some tricks, so I am wondering if there are ping > source code for Windows to reference. From web searching, I see someone > mentioned Windows SDK has a sample ICMP application, but I do not have > access of that and I think that application should be based on socket > programming, while I am looking for no protocol stack source file. > Could you help here? > > Thanks. >
Reply by ●March 6, 20042004-03-06
John Black wrote:> Hi, > I am testing an ethernet device on a development board, I programmed > a ping echo program based on the ethernet driver, not using any IP > protocol stack, but I have a hard time using the program to echo the > ping from my Windows 2000 PC. From some network traffic tool I can see > the ethernet frame coming to the PC and I believe the ethernet header > and ICMP header are correct, but Windows ping can not receive my echo. > I suspect I miss some tricks, so I am wondering if there are ping > source code for Windows to reference. From web searching, I see someone > mentioned Windows SDK has a sample ICMP application, but I do not have > access of that and I think that application should be based on socket > programming, while I am looking for no protocol stack source file. > Could you help here? >There is no such thing. Ping (as used on PC's and other Internet devices) is a part of the ICMP (Internet Control Message Protocol). ICMP runs using the IP (Internet Protocol) to transfer the packets. For Ethernet, IP needs also ARP (Address Resolution Protocol) to translate from IP addresses to Ethernet addresses. So, for a working ping, you'll need at least in stripped form the protocol handlers for ICMP, IP and ARP in addition to the Ethernet packet driver. Been there - done that. Tauno Voipio tauno voipio @ iki fi
Reply by ●March 6, 20042004-03-06
On Sat, 6 Mar 2004 09:29:38 +0100, Jan Homuth wrote:>you can find a lot of ideas and hands on information in Jeremy Bentham's >book: >"TCP/IP lean". >It helps a lot to understand the different protocols of TCP/IP. >ICMP is one of them.There are quite a lot of errors in the published code though (at least in the 1st edition). It's very patchy in it's pacing, as well. I wouldn't recommend it to someone inexperienced in networking. I'd suggest the "TCP/IP Illustrated" series by Richard Stevens, published by Addison-Wesley. -- Max
Reply by ●March 6, 20042004-03-06
Max wrote:> I'd suggest the "TCP/IP Illustrated" series by Richard Stevens, > published by Addison-Wesley.I'd agree. Volume I is an excellent book for IP packet reference. It's a little dated (a couple newer ICMP codes and IPsec aren't covered, IIRC), but it's the best one available. Hopefully someone will pick up the torch from the late author and release a new edition. However, I don't recommend trying to craft a packet from scratch using specs from the book, since there are a couple different Ethernet frame types to deal with. (Been there, done that.) Better to start with a known-working packet from a Sniffer trace, then modify it using the book as reference. Cheers, Richard
Reply by ●March 6, 20042004-03-06
On Fri, 05 Mar 2004 21:08:40 -0700, Richard wrote:>If you don't have 2 PCs, use PC A and a DSL router, or any other device >that will answer a ping. Run the Ethereal on PC A instead; if you use a >hub, it'll see all the traffic anyway.Good post, and I agree with most of it, but that's not quite true nowadays. Most devices sold as "hubs" are actually store&forward switches, which only retransmit frames on the output port with the addressed MAC device attached. -- Max
Reply by ●March 6, 20042004-03-06
Max wrote:> Good post, and I agree with most of it, but that's > not quite true nowadays. Most devices sold as "hubs" > are actually store&forward switchesYes, I should have left my draft wording of "if you use a hub (not a switch)", since fewer people know the difference these days. These days you can still buy a 10Mb hub (or even 100 or 10/100 hubs), and many products like DSL routers have them integrated - but equally, the cost of switches has dropped to nearly completely displace hubs. Especially since switches are technically superior for all but this kind of application. Vendors are still fairly explicit in hub vs. switch labelling for marketing value, but one must know to look for it.