EtherSia
A minimal IPv6 Ethernet library for Arduino.
LinuxSocket.h
Go to the documentation of this file.
1 /**
2  * Header file for using EtherSia with a network Socket on Linux
3  * @file LinuxSocket.h
4  */
5 
6 #ifndef LINUXSOCKET_H
7 #define LINUXSOCKET_H
8 
9 #include <net/if.h>
10 
11 #include "EtherSia.h"
12 
13 /**
14  * Run EtherSia on Linux using a raw socket to Send and receive Ethernet frames
15  * Not intended for use with running EtherSia on Arduino.
16  *
17  * @note this is probably only useful for testing and development of EtherSia.
18  */
20 
21 public:
22  /**
23  * Constructor
24  * @param iface the name of the Ethernet interface to send/receive on
25  */
26  EtherSia_LinuxSocket(const char* iface = NULL);
27 
28  // Tell the compiler we want to use begin() from the base class
29  using EtherSia::begin;
30 
31  /**
32  * Initialise the Ethernet controller
33  * Must be called before sending or receiving Ethernet frames
34  *
35  * @param address the local MAC address for the Ethernet interface
36  * @return Returns true if setting up the Ethernet interface was successful
37  */
38  virtual boolean begin(const MACAddress &address);
39 
40  /**
41  * Send an Ethernet frame
42  * @param data a pointer to the data to send
43  * @param datalen the length of the data in the packet
44  * @return the number of bytes transmitted
45  */
46  virtual uint16_t sendFrame(const uint8_t *data, uint16_t datalen);
47 
48  /**
49  * Read an Ethernet frame
50  * @param buffer a pointer to a buffer to write the packet to
51  * @param bufsize the available space in the buffer
52  * @return the length of the received packet
53  * or 0 if no packet was received
54  */
55  virtual uint16_t readFrame(uint8_t *buffer, uint16_t bufsize);
56 
57  /**
58  * Close the raw ethernet socket
59  */
60  virtual void end();
61 
62 protected:
63 
64  char ifname[IFNAMSIZ];
65  int ifindex;
66  int sockfd;
67 };
68 
69 #endif /* LINUXSOCKET_H */
virtual void end()
Close the raw ethernet socket.
virtual uint16_t sendFrame(const uint8_t *data, uint16_t datalen)
Send an Ethernet frame.
boolean begin()
Configure the Ethernet interface and get things ready.
Definition: EtherSia.cpp:21
Main header file for EtherSia - include this in your project.
EtherSia_LinuxSocket(const char *iface=NULL)
Constructor.
Main class for sending and receiving IPv6 messages using the ENC28J60 Ethernet controller.
Definition: EtherSia.h:52
Class for the storage and manipulation of 48-bit Ethernet addresses.
Definition: MACAddress.h:15
virtual uint16_t readFrame(uint8_t *buffer, uint16_t bufsize)
Read an Ethernet frame.
Run EtherSia on Linux using a raw socket to Send and receive Ethernet frames Not intended for use wit...
Definition: LinuxSocket.h:19