00001 // UDPSocket.h 00002 // 00003 /// Class for managing a UDP socket, using the Ethernet classes 00004 /// This is needed because the recvfrom function in utilitysocket.c in Ethernet does not 00005 /// work very well 00006 // 00007 // Author: Mike McCauley (mikem@open.com.au) 00008 // $Id: UDPSocket.h,v 1.1 2009/10/13 05:07:28 mikem Exp mikem $ 00009 00010 #ifndef _UDPSOCKET_H_ 00011 #define _UDPSOCKET_H_ 00012 00013 #if ARDUINO >= 100 00014 #include <Arduino.h> 00015 #else 00016 #include <wiring.h> 00017 #endif 00018 00019 /// IP4Address 00020 typedef uint8_t IP4Address[4]; 00021 00022 ///////////////////////////////////////////////////////////////////// 00023 /// \class UDPSocket UDPSocket.h <UDPSocket.h> 00024 /// \brief Class to encapsulate a UDP socket 00025 /// 00026 /// This class is used by RadiusMsg to send and receive UDP requests on a LAN through 00027 /// the Arduino Ethernet shield. 00028 /// This is needed because the revfrom function in utilitysocket.c in the Ethernet library does not 00029 /// work properly 00030 class UDPSocket 00031 { 00032 private: 00033 /// The socket number 00034 uint8_t sock; 00035 00036 public: 00037 /// Constructor 00038 UDPSocket(); 00039 00040 /// Initialise the socket 00041 void begin(); 00042 00043 /// Send octets to the given address 00044 /// \param[in] data Data octets to send in a UDP packet 00045 /// \param[in] length Number of octets of data 00046 /// \param[in] address IP4Address of teh destination host 00047 /// \param[in] port Port number of the destination pport 00048 uint16_t sendto(const uint8_t* data, uint16_t length, IP4Address address, uint16_t port); 00049 00050 /// Checks whether a UDP packet is available. 00051 /// \return Returns the number of octets in the next available packet, else 0 00052 uint16_t available(); 00053 00054 /// \param[in] data 00055 /// \param[in] maxLength 00056 /// \param[in] address Pointer to an IP4Address which wil be filled in with the senders IP address 00057 /// \param[in] port Pointer to a port number which will be filled in with the senders port number 00058 uint16_t recvfrom(uint8_t* data, uint16_t maxLength, IP4Address address, uint16_t* port); 00059 }; 00060 00061 #endif