The Pedigree Project 0.1
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
29class String;
30
32class EXPORTED_PUBLIC StationInfo {
33 public:
34 // Broadcast address defaults to 255.255.255.255, as we may need to
35 // broadcast without a known IPv4 address (and therefore no known network
36 // or broadcast address).
38 StationInfo(const StationInfo& info);
39 virtual ~StationInfo();
40
41 IpAddress ipv4;
42 IpAddress* ipv6; // Not compulsory
43 size_t nIpv6Addresses;
44
45 IpAddress subnetMask;
46 IpAddress broadcast;
48 IpAddress gatewayIpv6;
49
50 IpAddress* dnsServers;
52
53 MacAddress mac; // MAC address
54
55 size_t nPackets;
56 size_t nDropped;
57 size_t nBad;
58
59 StationInfo& operator=(const StationInfo& info) = delete;
60};
61
65class EXPORTED_PUBLIC Network : public Device {
66 friend class NetworkStack;
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 convertToIpv4(uint8_t a, uint8_t b, uint8_t c, uint8_t d);
96
98 EXPORTED_PUBLIC static IpAddress convertToIpv6(uint8_t a, uint8_t b = 0, uint8_t c = 0,
99 uint8_t d = 0, uint8_t e = 0, uint8_t f = 0,
100 uint8_t g = 0, uint8_t h = 0, uint8_t i = 0,
101 uint8_t j = 0, uint8_t k = 0, uint8_t l = 0,
102 uint8_t m = 0, uint8_t n = 0, uint8_t o = 0,
103 uint8_t p = 0);
104
106 EXPORTED_PUBLIC static uint16_t calculateChecksum(uintptr_t buffer, size_t nBytes);
107
112 virtual void gotPacket();
113
115 virtual void droppedPacket();
116
119 virtual void badPacket();
120
121 protected:
122 StationInfo m_StationInfo;
123
124 private:
130};
131
132#endif
size_t m_NetworkStackGeneration
Definition Network.h:129
virtual bool send(size_t nBytes, uintptr_t buffer)=0
size_t nBad
Number of packets dropped by the filter.
Definition Network.h:57
size_t nDnsServers
Can contain IPv6 addresses.
Definition Network.h:51
IpAddress gateway
Automatically calculated?
Definition Network.h:47
StationInfo & operator=(const StationInfo &info)=delete
Number of packets dropped because they were invalid.
size_t nDropped
Number of packets passed through the interface.
Definition Network.h:56