FreeNOS
NetworkClient.h
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 #ifndef __LIB_LIBNET_NETWORKCLIENT_H
19 #define __LIB_LIBNET_NETWORKCLIENT_H
20 
21 #include <Types.h>
22 #include "IPV4.h"
23 #include "Ethernet.h"
24 
45 {
46  public:
47 
52  {
57  };
58 
65  typedef struct SocketInfo
66  {
70  }
71  SocketInfo;
72 
79  struct PacketInfo
80  {
83  };
84 
89  {
90  ARP,
92  TCP,
94  };
95 
99  enum Result
100  {
106  };
107 
108  public:
109 
115  NetworkClient(const char *networkDevice);
116 
120  virtual ~NetworkClient();
121 
127  Result initialize();
128 
138  int *socket);
139 
149  Result connectSocket(const int sock,
150  const IPV4::Address addr,
151  const u16 port = 0);
152 
162  Result bindSocket(const int sock,
163  const IPV4::Address addr = 0,
164  const u16 port = 0);
165 
176  const int sock,
177  const Size msecTimeout);
178 
186  Result close(const int sock);
187 
188  private:
189 
193  Result writeSocketInfo(const int sock,
194  const IPV4::Address addr,
195  const u16 port,
196  const SocketAction action);
197 
198  private:
199 
202 };
203 
209 #endif /* __LIB_LIBNET_NETWORKCLIENT_H */
NetworkClient::m_deviceName
String m_deviceName
Network device name.
Definition: NetworkClient.h:201
NetworkClient::Result
Result
Result codes.
Definition: NetworkClient.h:99
NetworkClient::Success
@ Success
Definition: NetworkClient.h:101
NetworkClient::PacketInfo
Describes a single packet.
Definition: NetworkClient.h:79
NetworkClient::SocketAction
SocketAction
Socket actions.
Definition: NetworkClient.h:51
NetworkClient::Connect
@ Connect
Definition: NetworkClient.h:53
NetworkClient::TimedOut
@ TimedOut
Definition: NetworkClient.h:105
NetworkClient::initialize
Result initialize()
Perform initialization.
Definition: NetworkClient.cpp:35
NetworkClient::createSocket
Result createSocket(const SocketType type, int *socket)
Create new socket.
Definition: NetworkClient.cpp:80
Types.h
NetworkClient::close
Result close(const int sock)
Close the socket.
Definition: NetworkClient.cpp:239
NetworkClient::SocketInfo
struct NetworkClient::SocketInfo SocketInfo
Socket information.
NetworkClient::NotFound
@ NotFound
Definition: NetworkClient.h:103
NetworkClient::SocketInfo::address
IPV4::Address address
Definition: NetworkClient.h:67
String
Abstraction of strings.
Definition: String.h:41
Ethernet.h
UDP
User Datagram Protocol (UDP)
Definition: UDP.h:41
Address
unsigned long Address
A memory address.
Definition: Types.h:131
NetworkClient::PacketInfo::address
Address address
Definition: NetworkClient.h:81
NetworkClient::SocketInfo::port
u16 port
Definition: NetworkClient.h:68
NetworkClient::connectSocket
Result connectSocket(const int sock, const IPV4::Address addr, const u16 port=0)
Connect socket to address/port.
Definition: NetworkClient.cpp:115
NetworkClient::~NetworkClient
virtual ~NetworkClient()
Destructor.
Definition: NetworkClient.cpp:31
NetworkClient::TCP
@ TCP
Definition: NetworkClient.h:92
u16
unsigned short u16
Unsigned 16-bit number.
Definition: Types.h:56
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
NetworkClient
Networking Client implementation.
Definition: NetworkClient.h:44
NetworkClient::SocketType
SocketType
Socket types.
Definition: NetworkClient.h:88
NetworkClient::SendSingle
@ SendSingle
Definition: NetworkClient.h:55
IPV4.h
NetworkClient::bindSocket
Result bindSocket(const int sock, const IPV4::Address addr=0, const u16 port=0)
Bind socket to address/port.
Definition: NetworkClient.cpp:123
NetworkClient::IOError
@ IOError
Definition: NetworkClient.h:102
NetworkClient::ARP
@ ARP
Definition: NetworkClient.h:90
NetworkClient::SocketInfo
Socket information.
Definition: NetworkClient.h:65
NetworkClient::NetworkClient
NetworkClient(const char *networkDevice)
Constructor.
Definition: NetworkClient.cpp:26
NetworkClient::ICMP
@ ICMP
Definition: NetworkClient.h:91
NetworkClient::writeSocketInfo
Result writeSocketInfo(const int sock, const IPV4::Address addr, const u16 port, const SocketAction action)
Set socket to new state.
Definition: NetworkClient.cpp:180
NetworkClient::waitSocket
Result waitSocket(const NetworkClient::SocketType type, const int sock, const Size msecTimeout)
Wait until the given socket has data to receive.
Definition: NetworkClient.cpp:131
type
u8 type
Definition: IntelACPI.h:63
NetworkClient::NotSupported
@ NotSupported
Definition: NetworkClient.h:104
NetworkClient::SocketInfo::action
u16 action
Definition: NetworkClient.h:69
NetworkClient::SendMultiple
@ SendMultiple
Definition: NetworkClient.h:56
NetworkClient::PacketInfo::size
Size size
Definition: NetworkClient.h:82
NetworkClient::Listen
@ Listen
Definition: NetworkClient.h:54