3 * Copyright 2005,2007,2008 Free Software Foundation, Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef INCLUDED_USRP2_ETHERNET_H
20 #define INCLUDED_USRP2_ETHERNET_H
24 #include <eth_common.h>
31 * \brief Read and write ethernet frames.
33 * This provides a low level interface to hardware that communicates
34 * via raw (non-IP) ethernet frames.
44 static const int MAX_PKTLEN = 1512;
45 static const int MIN_PKTLEN = 64;
48 * \param ifname ethernet interface name, e.g., "eth0"
49 * \param protocol is the ethertype protocol number in network order.
50 * Use 0 to receive all protocols.
52 bool open (std::string ifname, int protocol);
57 * \brief attach packet filter to socket to restrict which packets read sees.
58 * \param pf the packet filter
60 bool attach_pktfilter (pktfilter *pf);
63 * \brief return 6 byte string containing our MAC address
65 const uint8_t *mac () const { return d_mac; }
68 * \brief Return file descriptor associated with socket.
70 int fd () const { return d_fd; }
73 * \brief Read packet from interface.
75 * \param buf where to put the packet
76 * \param buflen maximum length of packet in bytes (should be >= 1528)
78 * \returns number of bytes read or -1 if trouble.
80 * Returned packet includes 14-byte ethhdr
82 int read_packet (void *buf, int buflen);
85 * \brief Read packet from interface, but don't block waiting
87 * \param buf where to put the packet
88 * \param buflen maximum length of packet in bytes (should be >= 1528)
90 * \returns number of bytes read, -1 if trouble or 0 if nothing available.
92 * Returned packet includes 14-byte ethhdr
94 int read_packet_dont_block (void *buf, int buflen);
97 * \brief Write ethernet packet to interface.
99 * \param buf the packet to write
100 * \param buflen length of packet in bytes
102 * \returns number of bytes written or -1 if trouble.
104 * Packet must begin with 14-byte ethhdr, but does not include the FCS.
106 int write_packet (const void *buf, int buflen);
109 * \brief Write ethernet packet to interface.
111 * \param iov scatter/gather array
112 * \param iovlen number of elements in iov
114 * \returns number of bytes written or -1 if trouble.
116 * Packet must begin with 14-byte ethhdr, but does not include the FCS.
118 int write_packetv (const eth_iovec *iov, size_t iovlen);
124 #endif /* INCLUDED_USRP2_ETHERNET_H */