Problem on Ethernet library

I am using the Ethernet shield (W5100) with arduino-0022.

I am trying to run a very simple TCP server on arduino, but I get a lot of strange/unwanted characters when I use the fucntion

The code is this one:

#include <SPI.h>
#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 220 };

// telnet defaults to port 23
Server server(23);

void setup()
  // initialize the ethernet device
  Ethernet.begin(mac, ip);

  // start listening for clients

void loop()
  Client client = server.available();
  if (client) {

I connect from my computer (gnu/linux) using telnet. As soon as I connect, I see a lot of numbers coming out:

Connected to
Escape character is '^]'.

I made many experiments and it seems that the function continuously read the input buffer, without discarding the read bytes. The sequence of bytes read is cyclical. After a while, it restart to print the same number.

It seems like a bug in the Ethernet library.

Does anybody have the same problem?

It seems like a bug in the Ethernet library.

There's a bug, alright. But, it isn't in the Ethernet library.

Where are you checking that the client actually has something to read? Use client.available() BEFORE calling, or, at the very least, assure that returned something useful before you try to print it.

Actually I also tried using client.available() before, but it does not work.

On arduino-0018, hangs.
On arduino-0022, returns a character, even thou no characters were sent to the server.

Anyway I could finally solve this problem by using the arduino-0018 and the Ethernet2 library:

I attach the Ethernet2 library, ready to be installed and used on arduino-0018.

Ethernet2.tar.gz (31.6 KB)