MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SendIPv4

Function SendIPv4

Kernel/src/net/interface.cpp:112–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110 }
111
112 int SendIPv4(void* data, size_t length, IPv4Address& destination, uint8_t protocol){
113 uint8_t buffer[1600]; // The maxmium Ethernet frame size is 1518 so this will do
114
115 if(length > 1518 - sizeof(EthernetFrame) - sizeof(IPv4Header)){
116 return -EMSGSIZE;
117 }
118
119 EthernetFrame* ethFrame = (EthernetFrame*)buffer;
120 ethFrame->etherType = EtherTypeIPv4;
121 ethFrame->src = mainAdapter->mac;
122 ethFrame->dest = IPLookup(destination);
123
124 IPv4Header* ipHeader = (IPv4Header*)ethFrame->data;
125 ipHeader->ihl = 5; // 5 dwords (20 bytes)
126 ipHeader->version = 4; // Internet Protocol version 4
127 ipHeader->length = length + sizeof(IPv4Header);
128 ipHeader->flags = 0;
129 ipHeader->ttl = 64;
130 ipHeader->protocol = protocol;
131 ipHeader->headerChecksum = 0;
132 ipHeader->destIP = destination;
133 ipHeader->sourceIP = gateway;
134
135 ipHeader->headerChecksum = CaclulateChecksum(ipHeader, sizeof(IPv4Header));
136
137 memcpy(ipHeader->data, data, length);
138
139 Send(ethFrame, sizeof(EthernetFrame) + sizeof(IPv4Header) + length);
140
141 return 0;
142 }
143
144 int SendUDP(void* data, size_t length, IPv4Address& destination, BigEndianUInt16 sourcePort, BigEndianUInt16 destinationPort){
145 uint8_t buffer[1600];

Callers 1

SendUDPFunction · 0.85

Calls 4

IPLookupFunction · 0.85
CaclulateChecksumFunction · 0.85
memcpyFunction · 0.85
SendFunction · 0.85

Tested by

no test coverage detected