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
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;
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);
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);
83}
84
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt)
Process incoming network packet.
Definition ARPSocket.cpp:85
Ethernet::Address m_ethAddr
Ethernet address for reply.
Definition ARPSocket.h:104
ARP * m_arp
ARP protocol instance.
Definition ARPSocket.h:98
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Receive ARP response.
Definition ARPSocket.cpp:37
virtual ~ARPSocket()
Destructor.
Definition ARPSocket.cpp:33
IPV4::Address m_ipAddr
IPV4 address for request.
Definition ARPSocket.h:101
ARPSocket(const u32 inode, ARP *arp)
Constructor.
Definition ARPSocket.cpp:24
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Send ARP request.
Definition ARPSocket.cpp:65
Address Resolution Protocol.
Definition ARP.h:43
FileSystem::Result lookupAddress(const IPV4::Address *ipAddr, Ethernet::Address *ethAddr)
Lookup Ethernet address for an IP.
Definition ARP.cpp:86
Abstract Input/Output buffer.
Definition IOBuffer.h:38
FileSystem::Result read(void *buffer, const Size size, const Size offset=ZERO)
Read bytes from the I/O buffer.
Definition IOBuffer.cpp:156
FileSystem::Result write(const void *buffer, const Size size, const Size offset=ZERO)
Write bytes to the I/O buffer.
Definition IOBuffer.cpp:180
u32 Address
IP-address.
Definition IPV4.h:47
static void * set(void *dest, int ch, unsigned count)
Fill memory with a constant byte.
Network socket represents a single logical connection on a protocol.
#define ANY
Definition ProcessID.h:34
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
@ InvalidArgument
Definition FileSystem.h:55
Ethernet network address.
Definition Ethernet.h:53
Represents a network packet.