FreeNOS
ARPSocket.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/API/ProcessID.h>
19 #include "Ethernet.h"
20 #include "IPV4.h"
21 #include "ARP.h"
22 #include "ARPSocket.h"
23 
25  ARP *arp)
26  : NetworkSocket(inode, arp->getMaximumPacketSize(), ANY)
27 {
28  m_arp = arp;
29  m_ipAddr = 0;
31 }
32 
34 {
35 }
36 
38  Size & size,
39  const Size offset)
40 {
41  DEBUG("");
42 
43  if (size != sizeof(Ethernet::Address))
44  {
46  }
47 
48  if (offset >= sizeof(Ethernet::Address))
49  {
50  size = 0;
51  return FileSystem::Success;
52  }
53 
55  if (result != FileSystem::Success)
56  {
57  return result;
58  }
59 
60  buffer.write(&m_ethAddr, sizeof(Ethernet::Address));
61  size = sizeof(Ethernet::Address);
62  return FileSystem::Success;
63 }
64 
66  Size & size,
67  const Size offset)
68 {
69  DEBUG("");
70 
71  // Save the request address
72  buffer.read(&m_ipAddr, sizeof(IPV4::Address));
73 
74  // Send request
76  if (result != FileSystem::Success)
77  {
78  return result;
79  }
80 
81  size = sizeof(IPV4::Address);
82  return FileSystem::Success;
83 }
84 
86 {
87  DEBUG("");
88 
89  return FileSystem::Success;
90 }
ARP::lookupAddress
FileSystem::Result lookupAddress(const IPV4::Address *ipAddr, Ethernet::Address *ethAddr)
Lookup Ethernet address for an IP.
Definition: ARP.cpp:86
ARPSocket::~ARPSocket
virtual ~ARPSocket()
Destructor.
Definition: ARPSocket.cpp:33
ARPSocket::process
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt)
Process incoming network packet.
Definition: ARPSocket.cpp:85
MemoryBlock::set
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Definition: MemoryBlock.cpp:25
Ethernet.h
FileSystem::InvalidArgument
@ InvalidArgument
Definition: FileSystem.h:55
FileSystem::Success
@ Success
Definition: FileSystem.h:54
ARPSocket::m_ethAddr
Ethernet::Address m_ethAddr
Ethernet address for reply.
Definition: ARPSocket.h:104
DEBUG
#define DEBUG(msg)
Output a debug message to standard output.
Definition: Log.h:89
Ethernet::Address
Ethernet network address.
Definition: Ethernet.h:52
ARPSocket::m_ipAddr
IPV4::Address m_ipAddr
IPV4 address for request.
Definition: ARPSocket.h:101
IOBuffer
Abstract Input/Output buffer.
Definition: IOBuffer.h:37
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
IPV4::Address
u32 Address
IP-address.
Definition: IPV4.h:47
IPV4.h
NetworkSocket
Network socket represents a single logical connection on a protocol.
Definition: NetworkSocket.h:37
ARP.h
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
ARPSocket::write
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Send ARP request.
Definition: ARPSocket.cpp:65
ARPSocket::m_arp
ARP * m_arp
ARP protocol instance.
Definition: ARPSocket.h:98
ANY
#define ANY
Definition: ProcessID.h:34
IOBuffer::read
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
Definition: IOBuffer.cpp:156
IOBuffer::write
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition: IOBuffer.cpp:180
ARPSocket.h
Ethernet::Address
struct Ethernet::Address Address
Ethernet network address.
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
ARP
Address Resolution Protocol.
Definition: ARP.h:42
ARPSocket::read
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Receive ARP response.
Definition: ARPSocket.cpp:37
ARPSocket::ARPSocket
ARPSocket(const u32 inode, ARP *arp)
Constructor.
Definition: ARPSocket.cpp:24