Radius
UDPSocket.h
1 // UDPSocket.h
2 //
3 /// Class for managing a UDP socket, using the Ethernet classes
4 /// This is needed because the recvfrom function in utilitysocket.c in Ethernet does not
5 /// work very well
6 //
7 // Author: Mike McCauley (mikem@airspayce.com)
8 // $Id: UDPSocket.h,v 1.1 2009/10/13 05:07:28 mikem Exp mikem $
9 
10 #ifndef _UDPSOCKET_H_
11 #define _UDPSOCKET_H_
12 
13 #if ARDUINO >= 100
14 #include <Arduino.h>
15 #else
16 #include <wiring.h>
17 #endif
18 
19 /// IP4Address
20 typedef uint8_t IP4Address[4];
21 
22 /////////////////////////////////////////////////////////////////////
23 /// \class UDPSocket UDPSocket.h <UDPSocket.h>
24 /// \brief Class to encapsulate a UDP socket
25 ///
26 /// This class is used by RadiusMsg to send and receive UDP requests on a LAN through
27 /// the Arduino Ethernet shield.
28 /// This is needed because the revfrom function in utilitysocket.c in the Ethernet library does not
29 /// work properly
30 class UDPSocket
31 {
32 private:
33  /// The socket number
34  uint8_t sock;
35 
36 public:
37  /// Constructor
38  UDPSocket();
39 
40  /// Initialise the socket
41  void begin();
42 
43  /// Send octets to the given address
44  /// \param[in] data Data octets to send in a UDP packet
45  /// \param[in] length Number of octets of data
46  /// \param[in] address IP4Address of teh destination host
47  /// \param[in] port Port number of the destination pport
48  uint16_t sendto(const uint8_t* data, uint16_t length, IP4Address address, uint16_t port);
49 
50  /// Checks whether a UDP packet is available.
51  /// \return Returns the number of octets in the next available packet, else 0
52  uint16_t available();
53 
54  /// \param[in] data
55  /// \param[in] maxLength
56  /// \param[in] address Pointer to an IP4Address which wil be filled in with the senders IP address
57  /// \param[in] port Pointer to a port number which will be filled in with the senders port number
58  uint16_t recvfrom(uint8_t* data, uint16_t maxLength, IP4Address address, uint16_t* port);
59 };
60 
61 #endif