mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-04-18 05:38:36 +01:00
Clean up networking code. Fix missing DCDel in Stars wallpaper.
This commit is contained in:
parent
f5d80414c4
commit
51efddc954
11 changed files with 14 additions and 97 deletions
Binary file not shown.
|
@ -32,6 +32,8 @@ U0 WallPaperStars(CTask *task)
|
|||
}
|
||||
}
|
||||
|
||||
DCDel(dc);
|
||||
|
||||
//Uncomment the following if you wish. Will draw the old wallpaper over this one.
|
||||
//old_wall_paper(task);
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
//#include "PCNet"
|
||||
//#include "Ethernet"
|
||||
|
||||
#define ARP_HASHTABLE_SIZE 1024
|
||||
|
||||
#define HTT_ARP 0x00100 //identical to HTT_DICT_WORD
|
||||
|
@ -27,7 +24,7 @@ class CARPHeader
|
|||
};
|
||||
|
||||
class CARPHash:CHash
|
||||
{ //store U32 ip_address as CHash->str U8*, MStrPrint("%d")
|
||||
{ //store U32 ip_address as CHash->str U8*, MStrPrint("%X")
|
||||
// U32 ip_address;
|
||||
U8 mac_address[MAC_ADDRESS_LENGTH];
|
||||
};
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//www.networksorcery.com/enp/protocol/dhcp.htm
|
||||
|
||||
//#include "DNS";
|
||||
|
||||
#define DHCP_OPCODE_BOOTREQUEST 0x01
|
||||
|
||||
#define DHCP_OPTION_SUBNET_MASK 1
|
||||
|
@ -114,8 +112,6 @@ I64 DHCPSendDiscover(U32 xid)
|
|||
dhcp->server_ip = 0;
|
||||
dhcp->gateway_ip = 0;
|
||||
MemCopy(dhcp->client_hw_addr, EthernetGetMAC(), MAC_ADDRESS_LENGTH);
|
||||
// "DHCP Send Discover\n";
|
||||
// ClassRep(dhcp);
|
||||
|
||||
opts = ethernet_frame + sizeof(CDHCPHeader);
|
||||
|
||||
|
@ -130,7 +126,6 @@ I64 DHCPSendDiscover(U32 xid)
|
|||
opts->param_req_list[2] = DHCP_OPTION_DNS;
|
||||
opts->param_req_list[3] = DHCP_OPTION_DOMAIN_NAME;
|
||||
opts->end = 0xFF; // ??
|
||||
// ClassRep(opts);
|
||||
|
||||
UDPPacketFinish(de_index);
|
||||
return de_index;
|
||||
|
@ -184,7 +179,6 @@ I64 DHCPSendRequest(U32 xid, U32 requested_ip, U32 server_ip)
|
|||
opts->server_id = EndianU32(server_ip);
|
||||
opts->end = 0xFF;
|
||||
|
||||
// ClassRep(opts);
|
||||
UDPPacketFinish(de_index);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//#include "UDP";
|
||||
|
||||
// https://www2.cs.duke.edu/courses/fall16/compsci356/DNS/DNS-primer.pdf
|
||||
// https://en.wikipedia.org/wiki/Domain_Name_System
|
||||
|
||||
|
@ -678,10 +676,4 @@ U0 DNSRep()
|
|||
"\n";
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
U0 DNSInit()
|
||||
|
||||
*/
|
||||
|
||||
DNSCacheInit;
|
|
@ -1,5 +1,3 @@
|
|||
//#include "IPV4"
|
||||
|
||||
#define ICMP_TYPE_ECHO_REPLY 0
|
||||
#define ICMP_TYPE_ECHO_REQUEST 8
|
||||
|
||||
|
@ -14,7 +12,7 @@ class CICMPHeader // Shrine's use of id and seq indicate this header is for Addr
|
|||
};
|
||||
|
||||
|
||||
I64 ICMPSendReply(U32 destination_ip_address,
|
||||
U0 ICMPSendReply(U32 destination_ip_address,
|
||||
U16 identifier,
|
||||
U16 sequence_number,
|
||||
U16 request_checksum,
|
||||
|
@ -33,7 +31,7 @@ I64 ICMPSendReply(U32 destination_ip_address,
|
|||
if (de_index < 0)
|
||||
{
|
||||
NetErr("ICMP SEND REPLY: Failed to allocate IPV4 packet.");
|
||||
return de_index;
|
||||
return;
|
||||
}
|
||||
|
||||
header = frame;
|
||||
|
@ -48,7 +46,6 @@ I64 ICMPSendReply(U32 destination_ip_address,
|
|||
MemCopy(frame + sizeof(CICMPHeader), payload, length);
|
||||
|
||||
IPV4PacketFinish(de_index);
|
||||
//return IPV4PacketFinish
|
||||
}
|
||||
|
||||
I64 ICMPHandler(CIPV4Packet *packet)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
//#include "ARP"
|
||||
|
||||
#define IPV4_ERR_ADDR_INVALID -200001
|
||||
#define IPV4_ERR_HOST_UNREACHABLE -200002
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
CTask *net_log_task = NULL;
|
||||
|
||||
U0 NetLogTask(I64)
|
||||
|
|
|
@ -13,9 +13,6 @@
|
|||
- Clear documentation.
|
||||
*/
|
||||
|
||||
//#include "Net.HH"
|
||||
//#include "NetQueue"
|
||||
|
||||
#define PCNET_DEVICE_ID 0x2000
|
||||
#define PCNET_VENDOR_ID 0x1022
|
||||
|
||||
|
@ -76,7 +73,6 @@
|
|||
#define PCNET_DESCRIPTORf_ENP 24
|
||||
#define PCNET_DESCRIPTORf_STP 25
|
||||
#define PCNET_DESCRIPTORf_OWN 31 // AMD PCNet datasheet p.1-992, 1-994
|
||||
//#define PCNET_DESCRIPTORF_OWN (1 << PCNET_DESCRIPTORf_OWN)
|
||||
|
||||
class CPCNet
|
||||
{
|
||||
|
@ -678,20 +674,13 @@ U0 PCNetInit()
|
|||
NetLog("PCNET INIT UPLOAD: what is STOP ?: %d", Bt(&csr, PCNET_CTRL_STOP));
|
||||
NetLog("PCNET INIT UPLOAD: what is RINT ?: %d", Bt(&csr, PCNET_CTRL_RINT));
|
||||
|
||||
while (!(PCNetReadCSR(0) & (1<<8)))
|
||||
while (!(PCNetReadCSR(0) & (1 << 8)))
|
||||
Yield;
|
||||
|
||||
PCNetExitConfigMode;
|
||||
|
||||
Sleep(100); //? necessary?
|
||||
|
||||
/* ClassRep(&pcnet);
|
||||
|
||||
"pcnet->rx_de_buffer: %X\n", pcnet.rx_de_buffer;
|
||||
"pcnet->tx_de_buffer: %X\n", pcnet.tx_de_buffer;
|
||||
"pcnet->rx_de_buffer_phys: %X\n", pcnet.rx_de_buffer_phys;
|
||||
"pcnet->rx_de_buffer_phys: %X\n", pcnet.tx_de_buffer_phys;
|
||||
*/
|
||||
csr = PCNetReadCSR(PCNET_CSR_CTRLSTATUS);
|
||||
NetLog("PCNET INIT END: what is INIT ?: %d", Bt(&csr, PCNET_CTRL_INIT));
|
||||
NetLog("PCNET INIT END: what is STRT ?: %d", Bt(&csr, PCNET_CTRL_STRT));
|
||||
|
@ -721,7 +710,6 @@ I64 EthernetFrameAllocate(U8 **packet_buffer_out,
|
|||
parameter has the value at its pointer set to the
|
||||
payload of the Ethernet Frame. */
|
||||
|
||||
//todo: un magic number the rest of this
|
||||
U8 *ethernet_frame;
|
||||
I64 de_index;
|
||||
|
||||
|
@ -743,7 +731,7 @@ I64 EthernetFrameAllocate(U8 **packet_buffer_out,
|
|||
MemCopy(ethernet_frame, destination_address, MAC_ADDRESS_LENGTH);
|
||||
MemCopy(ethernet_frame + MAC_ADDRESS_LENGTH, source_address, MAC_ADDRESS_LENGTH);
|
||||
|
||||
ethernet_frame[ETHERNET_ETHERTYPE_OFFSET] = ethertype >> 8; // << or >> ? Shrine has >>
|
||||
ethernet_frame[ETHERNET_ETHERTYPE_OFFSET] = ethertype >> 8;
|
||||
ethernet_frame[ETHERNET_ETHERTYPE_OFFSET + 1] = ethertype & 0xFF;
|
||||
|
||||
*packet_buffer_out = ethernet_frame + ETHERNET_MAC_HEADER_LENGTH;
|
||||
|
|
|
@ -47,14 +47,6 @@
|
|||
#define IP_PARSE_STATE_NUM 0
|
||||
#define IP_PARSE_STATE_DOT 1
|
||||
|
||||
/*
|
||||
class CSocketAddress
|
||||
{
|
||||
U16 family; // 'address family, AF_xxx'
|
||||
|
||||
U8 data[14]; // '14 bytes of protocol address'
|
||||
};
|
||||
*/
|
||||
class CIPV4Address
|
||||
{
|
||||
U32 address; // 'in Network Byte order' ... Big Endian
|
||||
|
@ -72,7 +64,6 @@ class CIPAddressStorage
|
|||
|
||||
class CSocketAddressIPV4
|
||||
{
|
||||
// I16 family; // 'AF_INET'
|
||||
U16 family; // 'AF_INET'
|
||||
U16 port; // 'in Network Byte order' ... Big Endian
|
||||
CIPV4Address address;
|
||||
|
@ -94,7 +85,6 @@ class CSocketAddressStorage
|
|||
|
||||
U16 family;
|
||||
U8 padding[26];
|
||||
|
||||
};
|
||||
|
||||
class CAddressInfo
|
||||
|
@ -151,10 +141,8 @@ U0 AddressInfoFree(CAddressInfo *info)
|
|||
|
||||
Bool IPV4AddressParse(U8 *string, U32 *destination)
|
||||
{
|
||||
// U8* lexable_string;
|
||||
// lexable_string = StrReplace(string, ",", ","); // swap any commas with an unexpected value
|
||||
|
||||
U8 *lexable_string = StrNew(string);
|
||||
|
||||
lexable_string = StrReplace(lexable_string, ".", ","); // swap dots with commas since Lex is easier with them.
|
||||
|
||||
CCompCtrl *cc = CompCtrlNew(lexable_string);
|
||||
|
@ -220,23 +208,17 @@ Bool IPV4AddressParse(U8 *string, U32 *destination)
|
|||
|
||||
temp_destination = EndianU32(temp_destination); // store the address in Network Byte Order (Big-Endian)
|
||||
*destination = temp_destination;
|
||||
"\n\n%X\n\n", temp_destination;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
I64 PresentationToNetwork(I64 address_family, U8 *string, CIPAddressStorage *destination)
|
||||
{/* Converts IP string to internet address class, our inet_pton().
|
||||
{
|
||||
/* Converts IP string to internet address class, our inet_pton().
|
||||
Destination written as CIPV4Address or CIPV6Address depending
|
||||
on value of address_family.
|
||||
The destination address is the generic class, functions
|
||||
calling this method must cast their classes in the params.
|
||||
|
||||
TODO: test it more... clarify above comment? is casting shit needed if we do it like this?..
|
||||
if we declare the possible address classes, then just set them to where the
|
||||
destination is from param, wouldn't that suffice fully? I noticed that it wrote fine to
|
||||
a pointer to CIPV4Address without any complaints that it wasn't CIPAddressStorage .. */
|
||||
|
||||
//CCompCtrl *cc = CompCtrlNew(string);
|
||||
calling this method must cast their classes in the params. */
|
||||
|
||||
CIPV4Address *ipv4_address;
|
||||
CIPV6Address *ipv6_address;
|
||||
|
@ -277,7 +259,6 @@ I64 PresentationToNetwork(I64 address_family, U8 *string, CIPAddressStorage *des
|
|||
return -1;
|
||||
}
|
||||
|
||||
//CompCtrlDel(cc);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -285,10 +266,8 @@ I64 PresentationToNetwork(I64 address_family, U8 *string, CIPAddressStorage *des
|
|||
U8 *NetworkToPresentation(I64 address_family, CIPAddressStorage *source)
|
||||
{ // converts socket address to IP string, our inet_ntop. Taking Shrine approach of function returns U8* .
|
||||
|
||||
// I64 i;
|
||||
|
||||
U8 *ip_string;
|
||||
// U8* ip_string[INET_ADDRSTRLEN];
|
||||
U8 *ip_string;
|
||||
CIPV4Address *ipv4_source;
|
||||
CIPV4Address *ipv6_source;
|
||||
|
||||
|
@ -298,12 +277,6 @@ U8 *NetworkToPresentation(I64 address_family, CIPAddressStorage *source)
|
|||
|
||||
ipv4_source = source;
|
||||
|
||||
/* StrPrint(ip_string, "%d.%d.%d.%d",
|
||||
ipv4_source->address.u8[3],
|
||||
ipv4_source->address.u8[2],
|
||||
ipv4_source->address.u8[1],
|
||||
ipv4_source->address.u8[0]);*/
|
||||
|
||||
StrPrint(ip_string, "%d.%d.%d.%d",
|
||||
ipv4_source->address.u8[0],
|
||||
ipv4_source->address.u8[1],
|
||||
|
@ -395,22 +368,6 @@ U0 SocketClose(CSocket *socket)
|
|||
request state before destroying the socket at
|
||||
the protocol level. */
|
||||
socket->state = SOCKET_STATE_CLOSE_REQ;
|
||||
|
||||
/*
|
||||
switch (socket->state)
|
||||
{
|
||||
case SOCKET_STATE_LISTENING:
|
||||
case SOCKET_STATE_OPEN:
|
||||
/* Sockets can only be closed if
|
||||
they were opened or listening
|
||||
to incoming connections. */
|
||||
socket->state = SOCKET_STATE_CLOSE_REQ;
|
||||
break;
|
||||
|
||||
default:
|
||||
SocketStateErr("CLOSE", socket->state);
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
|
||||
U0 SocketBind(CSocket *socket)
|
||||
|
|
|
@ -165,7 +165,7 @@ CUDPTreeNode *UDPTreeNodePop(I64 port, CUDPTreeNode *tree)
|
|||
CUDPTreeNode *UDPTreeNodeSinglePop(I64 port, CUDPTreeNode *tree)
|
||||
{ // pop a tree off, then add back in its sub-trees to main tree.
|
||||
// original node sub-trees are cleared.
|
||||
// TODO: double check this logic ensure it's sound.
|
||||
|
||||
CUDPTreeNode *node = UDPTreeNodePop(port, tree);
|
||||
CUDPTreeNode *left = node->left;
|
||||
CUDPTreeNode *right = node->right;
|
||||
|
@ -196,7 +196,6 @@ U0 UDPTreeNodeQueueAdd(CUDPSocket *socket, CUDPTreeNode *node)
|
|||
QueueInsert(new_entry, node->queue->last);
|
||||
}
|
||||
|
||||
// refactored to UDPTreeNodeQueueSocketFind for Socket-call level functions
|
||||
CUDPTreeQueue *UDPTreeNodeQueueSocketFind(CUDPSocket *socket, CUDPTreeNode *node)
|
||||
{
|
||||
CUDPTreeQueue *temp_queue;
|
||||
|
@ -245,8 +244,6 @@ CUDPTreeQueue *UDPTreeNodeQueueIPV4Find(U32 address, CUDPTreeNode *node)
|
|||
CUDPTreeQueue *UDPTreeNodeQueueSocketSinglePop(CUDPSocket *socket, CUDPTreeNode *node)
|
||||
{ // search by socket, pop a single UDPTreeQueue off the node, return popped queue.
|
||||
CUDPTreeQueue *temp_queue = UDPTreeNodeQueueSocketFind(socket, node);
|
||||
CUDPTreeQueue *temp_next;
|
||||
CUDPTreeQueue *temp_last;
|
||||
|
||||
if (temp_queue)
|
||||
{
|
||||
|
@ -334,7 +331,6 @@ I64 UDPParsePacket(U16 *source_port_out,
|
|||
|
||||
}
|
||||
|
||||
//CUDPSocket *UDPSocket(U16 domain, U16 type) // should this even be allowed? why not just UDPSocket; ? it could just know its domain and type.
|
||||
CUDPSocket *UDPSocket(U16 domain=AF_UNSPEC)
|
||||
{
|
||||
U16 type = SOCKET_DATAGRAM;
|
||||
|
@ -593,7 +589,6 @@ I64 UDPSocketReceiveFrom(CUDPSocket *udp_socket, U8 *buffer, I64 len, CSocketAdd
|
|||
|
||||
while (message == message->next)
|
||||
{ // wait for a message to be added to queue. head is non-message.
|
||||
// if (udp_socket->receive_timeout_ms != 0 && counts.jiffies > udp_socket->receive_max_timeout)
|
||||
if (udp_socket->receive_timeout_ms == 0)
|
||||
return -1; // if no timeout set and didn't see message, bail early
|
||||
|
||||
|
@ -724,7 +719,6 @@ I64 UDPHandler(CIPV4Packet *packet)
|
|||
CUDPMessageQueue *message;
|
||||
CUDPSocket *udp_socket;
|
||||
CSocketAddressIPV4 *ipv4_addr;
|
||||
// I64 num_receive;
|
||||
|
||||
NetLog("UDP HANDLER: Beginning handling UDP Packet.");
|
||||
|
||||
|
@ -741,7 +735,6 @@ I64 UDPHandler(CIPV4Packet *packet)
|
|||
node = UDPTreeNodeFind(destination_port, head);
|
||||
if (node)
|
||||
{
|
||||
// queue = UDPTreeNodeQueueIPV4Find(packet->destination_ip_address, node); // TODO: make sure bit order is correct here!!
|
||||
queue = UDPTreeNodeQueueIPV4Find(packet->source_ip_address, node); // TODO: make sure bit order is correct here!!
|
||||
if (queue)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue