Skip to content

Commit 8e73601

Browse files
committed
Merge branch 'master' into wifly_integration
2 parents 23f09b2 + c1ec5eb commit 8e73601

File tree

16 files changed

+459
-49
lines changed

16 files changed

+459
-49
lines changed

Client.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
#include "string.h"
66
}
77

8-
#include "WProgram.h"
8+
#include "Arduino.h"
99

1010
#include "Ethernet.h"
1111
#include "Client.h"
@@ -70,19 +70,24 @@ int Client::connect(IPAddress ip, uint16_t port) {
7070
return 1;
7171
}
7272

73-
void Client::write(uint8_t b) {
74-
if (_sock != MAX_SOCK_NUM)
75-
send(_sock, &b, 1);
73+
size_t Client::write(uint8_t b) {
74+
return write(&b, 1);
7675
}
7776

78-
void Client::write(const char *str) {
79-
if (_sock != MAX_SOCK_NUM)
80-
send(_sock, (const uint8_t *)str, strlen(str));
77+
size_t Client::write(const char *str) {
78+
return write((const uint8_t *) str, strlen(str));
8179
}
8280

83-
void Client::write(const uint8_t *buf, size_t size) {
84-
if (_sock != MAX_SOCK_NUM)
85-
send(_sock, buf, size);
81+
size_t Client::write(const uint8_t *buf, size_t size) {
82+
if (_sock == MAX_SOCK_NUM) {
83+
setWriteError();
84+
return 0;
85+
}
86+
if (!send(_sock, buf, size)) {
87+
setWriteError();
88+
return 0;
89+
}
90+
return size;
8691
}
8792

8893
int Client::available() {
@@ -156,18 +161,8 @@ uint8_t Client::status() {
156161
return W5100.readSnSR(_sock);
157162
}
158163

159-
// the next three functions are a hack so we can compare the client returned
160-
// by Server::available() to null, or use it as the condition in an
161-
// if-statement. this lets us stay compatible with the Processing network
162-
// library.
163-
164-
uint8_t Client::operator==(int p) {
165-
return _sock == MAX_SOCK_NUM;
166-
}
167-
168-
uint8_t Client::operator!=(int p) {
169-
return _sock != MAX_SOCK_NUM;
170-
}
164+
// the next function allows us to use the client returned by
165+
// Server::available() as the condition in an if-statement.
171166

172167
Client::operator bool() {
173168
return _sock != MAX_SOCK_NUM;

Client.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef client_h
22
#define client_h
3-
#include "WProgram.h"
3+
#include "Arduino.h"
44
#include "Print.h"
55
#include "NetClient.h"
66
#include "IPAddress.h"
@@ -14,9 +14,9 @@ class Client : public NetClient {
1414
uint8_t status();
1515
virtual int connect(IPAddress ip, uint16_t port);
1616
virtual int connect(const char *host, uint16_t port);
17-
virtual void write(uint8_t);
18-
virtual void write(const char *str);
19-
virtual void write(const uint8_t *buf, size_t size);
17+
virtual size_t write(uint8_t);
18+
virtual size_t write(const char *str);
19+
virtual size_t write(const uint8_t *buf, size_t size);
2020
virtual int available();
2121
virtual int read();
2222
virtual int read(uint8_t *buf, size_t size);

Dhcp.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <string.h>
77
#include <stdlib.h>
88
#include "Dhcp.h"
9-
#include "wiring.h"
9+
#include "Arduino.h"
1010
#include "util.h"
1111

1212
int DhcpClass::beginWithDHCP(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
@@ -271,11 +271,19 @@ uint8_t DhcpClass::parseDHCPResponse(unsigned long responseTimeout, uint32_t& tr
271271
case routersOnSubnet :
272272
opt_len = _dhcpUdpSocket.read();
273273
_dhcpUdpSocket.read(_dhcpGatewayIp, 4);
274+
for (int i = 0; i < opt_len-4; i++)
275+
{
276+
_dhcpUdpSocket.read();
277+
}
274278
break;
275279

276280
case dns :
277281
opt_len = _dhcpUdpSocket.read();
278282
_dhcpUdpSocket.read(_dhcpDnsServerIp, 4);
283+
for (int i = 0; i < opt_len-4; i++)
284+
{
285+
_dhcpUdpSocket.read();
286+
}
279287
break;
280288

281289
case dhcpServerIdentifier :

Dns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Dns.h"
1010
#include <string.h>
1111
//#include <stdlib.h>
12-
#include "wiring.h"
12+
#include "Arduino.h"
1313

1414

1515
#define SOCKET_NONE 255

Ethernet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,37 @@ int EthernetClass::begin(uint8_t *mac_address)
3333
}
3434

3535
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
36+
{
37+
// Assume the DNS server will be the machine on the same network as the local IP
38+
// but with last octet being '1'
39+
IPAddress dns_server = local_ip;
40+
dns_server[3] = 1;
41+
begin(mac_address, local_ip, dns_server);
42+
}
43+
44+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
3645
{
3746
// Assume the gateway will be the machine on the same network as the local IP
3847
// but with last octet being '1'
3948
IPAddress gateway = local_ip;
4049
gateway[3] = 1;
41-
begin(mac_address, local_ip, gateway);
50+
begin(mac_address, local_ip, dns_server, gateway);
4251
}
4352

44-
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway)
53+
void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
4554
{
4655
IPAddress subnet(255, 255, 255, 0);
47-
begin(mac_address, local_ip, gateway, subnet);
56+
begin(mac_address, local_ip, dns_server, gateway, subnet);
4857
}
4958

50-
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress gateway, IPAddress subnet)
59+
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
5160
{
5261
W5100.init();
5362
W5100.setMACAddress(mac);
5463
W5100.setIPAddress(local_ip._address);
5564
W5100.setGatewayIp(gateway._address);
5665
W5100.setSubnetMask(subnet._address);
66+
_dnsServerAddress = dns_server;
5767
}
5868

5969
IPAddress EthernetClass::localIP()

Ethernet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class EthernetClass {
2020
// Returns 0 if the DHCP configuration failed, and 1 if it succeeded
2121
int begin(uint8_t *mac_address);
2222
void begin(uint8_t *mac_address, IPAddress local_ip);
23-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway);
24-
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress gateway, IPAddress subnet);
23+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
24+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
25+
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
2526

2627
IPAddress localIP();
2728
IPAddress subnetMask();

Server.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,30 @@ Client Server::available()
6767
return Client(MAX_SOCK_NUM);
6868
}
6969

70-
void Server::write(uint8_t b)
70+
size_t Server::write(uint8_t b)
7171
{
7272
write(&b, 1);
7373
}
7474

75-
void Server::write(const char *str)
75+
size_t Server::write(const char *str)
7676
{
7777
write((const uint8_t *)str, strlen(str));
7878
}
7979

80-
void Server::write(const uint8_t *buffer, size_t size)
80+
size_t Server::write(const uint8_t *buffer, size_t size)
8181
{
82+
size_t n = 0;
83+
8284
accept();
8385

8486
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
8587
Client client(sock);
8688

8789
if (EthernetClass::_server_port[sock] == _port &&
8890
client.status() == SnSR::ESTABLISHED) {
89-
client.write(buffer, size);
91+
n += client.write(buffer, size);
9092
}
9193
}
94+
95+
return n;
9296
}

Server.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public NetServer {
1414
Server(uint16_t);
1515
Client available();
1616
virtual void begin();
17-
virtual void write(uint8_t);
18-
virtual void write(const char *str);
19-
virtual void write(const uint8_t *buf, size_t size);
17+
virtual size_t write(uint8_t);
18+
virtual size_t write(const char *str);
19+
virtual size_t write(const uint8_t *buf, size_t size);
2020
};
2121

2222
#endif

Udp.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,22 @@ int UDP::endPacket()
102102
return sendUDP(_sock);
103103
}
104104

105-
void UDP::write(uint8_t byte)
105+
size_t UDP::write(uint8_t byte)
106106
{
107-
write(&byte, 1);
107+
return write(&byte, 1);
108108
}
109109

110-
void UDP::write(const char *str)
110+
size_t UDP::write(const char *str)
111111
{
112112
size_t len = strlen(str);
113-
write((const uint8_t *)str, len);
113+
return write((const uint8_t *)str, len);
114114
}
115115

116-
void UDP::write(const uint8_t *buffer, size_t size)
116+
size_t UDP::write(const uint8_t *buffer, size_t size)
117117
{
118118
uint16_t bytes_written = bufferData(_sock, _offset, buffer, size);
119119
_offset += bytes_written;
120+
return bytes_written;
120121
}
121122

122123
int UDP::parsePacket()

Udp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class UDP : public Stream {
6767
// Returns 1 if the packet was sent successfully, 0 if there was an error
6868
int endPacket();
6969
// Write a single byte into the packet
70-
virtual void write(uint8_t);
70+
virtual size_t write(uint8_t);
7171
// Write a string of characters into the packet
72-
virtual void write(const char *str);
72+
virtual size_t write(const char *str);
7373
// Write size bytes from buffer into the packet
74-
virtual void write(const uint8_t *buffer, size_t size);
74+
virtual size_t write(const uint8_t *buffer, size_t size);
7575

7676
// Start processing the next available incoming packet
7777
// Returns the size of the packet in bytes, or 0 if no packets are available

0 commit comments

Comments
 (0)