FreeNOS
ICMPSocket.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 <MemoryBlock.h>
19#include "Ethernet.h"
20#include "IPV4.h"
21#include "ICMP.h"
22#include "ICMPSocket.h"
23#include "NetworkClient.h"
24
26 ICMP *icmp,
27 const ProcessID pid)
28 : NetworkSocket(inode, icmp->getMaximumPacketSize(), pid)
29{
30 m_icmp = icmp;
31 m_gotReply = false;
32 MemoryBlock::set(&m_info, 0, sizeof(m_info));
33}
34
38
40{
41 return m_info.address;
42}
43
45 Size & size,
46 const Size offset)
47{
48 DEBUG("");
49
50 if (!m_gotReply)
51 {
53 }
54
55 m_gotReply = false;
56 buffer.write(&m_reply, sizeof(m_reply));
57 size = sizeof(m_reply);
59}
60
62 Size & size,
63 const Size offset)
64{
65 DEBUG("");
66
67 // Receive socket information first?
68 if (!m_info.address)
69 {
70 buffer.read(&m_info, sizeof(m_info));
72 }
73 else
74 {
76 buffer.read(&header, sizeof(header));
77
79 }
80}
81
88
90{
91 DEBUG("");
92
93 if (!m_gotReply)
94 {
96 m_gotReply = true;
97 }
98}
SystemDescriptorHeader header
Definition IntelACPI.h:0
ICMPSocket(const u32 inode, ICMP *icmp, const ProcessID pid)
Constructor.
virtual ~ICMPSocket()
Destructor.
bool m_gotReply
Definition ICMPSocket.h:120
const IPV4::Address getAddress() const
Get associated IP host.
virtual FileSystem::Result process(const NetworkQueue::Packet *pkt)
Process incoming network packet.
virtual FileSystem::Result read(IOBuffer &buffer, Size &size, const Size offset)
Read ICMP response.
virtual FileSystem::Result write(IOBuffer &buffer, Size &size, const Size offset)
Send ICMP request.
void setReply(const ICMP::Header *reply)
Set ICMP reply.
ICMP::Header m_reply
Reply.
Definition ICMPSocket.h:119
ICMP * m_icmp
ICMP protocol instance.
Definition ICMPSocket.h:116
Internet Control Message Protocol (ICMP)
Definition ICMP.h:43
FileSystem::Result sendPacket(const IPV4::Address ip, const Header *header, const void *payload, const Size payloadSize)
Send packet.
Definition ICMP.cpp:148
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.
static Size copy(void *dest, const void *src, Size count)
Copy memory from one place to another.
Network socket represents a single logical connection on a protocol.
NetworkClient::SocketInfo m_info
Socket connection.
u32 ProcessID
Process Identification Number.
Definition Types.h:140
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 ZERO
Zero value.
Definition Macros.h:43
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
Packet header format.
Definition ICMP.h:65
Represents a network packet.