The Pedigree Project  0.1
system/include/pedigree/kernel/machine/Network.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef MACHINE_NETWORK_H
21 #define MACHINE_NETWORK_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/machine/Device.h"
25 #include "pedigree/kernel/network/IpAddress.h"
26 #include "pedigree/kernel/network/MacAddress.h"
27 #include "pedigree/kernel/processor/types.h"
28 
29 class String;
30 
33 {
34  public:
35  // Broadcast address defaults to 255.255.255.255, as we may need to
36  // broadcast without a known IPv4 address (and therefore no known network
37  // or broadcast address).
38  StationInfo();
39  StationInfo(const StationInfo &info);
40  virtual ~StationInfo();
41 
42  IpAddress ipv4;
43  IpAddress *ipv6; // Not compulsory
44  size_t nIpv6Addresses;
45 
46  IpAddress subnetMask;
47  IpAddress broadcast;
49  IpAddress gatewayIpv6;
50 
51  IpAddress *dnsServers;
52  size_t nDnsServers;
53 
54  MacAddress mac; // MAC address
55 
56  size_t nPackets;
57  size_t nDropped;
58  size_t nBad;
59 
60  StationInfo &operator=(const StationInfo &info) = delete;
61 };
62 
67 {
68  public:
69  Network();
70  Network(Network *pDev);
71  virtual ~Network();
72 
73  virtual Type getType();
74 
75  virtual void getName(String &str);
76 
77  virtual void dump(String &str);
78 
82  virtual bool send(size_t nBytes, uintptr_t buffer) = 0;
83 
86  virtual bool setStationInfo(const StationInfo &info);
87 
89  virtual const StationInfo &getStationInfo();
90 
92  virtual bool isConnected();
93 
95  EXPORTED_PUBLIC static uint32_t
96  convertToIpv4(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
97 
99  EXPORTED_PUBLIC static IpAddress convertToIpv6(
100  uint8_t a, uint8_t b = 0, uint8_t c = 0, uint8_t d = 0, uint8_t e = 0,
101  uint8_t f = 0, uint8_t g = 0, uint8_t h = 0, uint8_t i = 0,
102  uint8_t j = 0, uint8_t k = 0, uint8_t l = 0, uint8_t m = 0,
103  uint8_t n = 0, uint8_t o = 0, uint8_t p = 0);
104 
106  EXPORTED_PUBLIC static uint16_t
107  calculateChecksum(uintptr_t buffer, size_t nBytes);
108 
111  virtual void gotPacket();
114 
116  virtual void droppedPacket();
117 
120  virtual void badPacket();
121 
122  protected:
123  StationInfo m_StationInfo;
124 };
125 
126 #endif
virtual void dump(String &str)
Definition: Device.h:250
virtual void getName(String &str)
Definition: Device.cc:121
A communication device.
Definition: Device.h:59
size_t nBad
Number of packets dropped by the filter.
Definition: String.h:49
IpAddress gateway
Automatically calculated?
Definition: Device.h:43
size_t nDnsServers
Can contain IPv6 addresses.
size_t nDropped
Number of packets passed through the interface.
virtual Type getType()
Definition: Device.h:163
Type
Definition: Device.h:50