d561d0ad68
IP, and UDP, as well as a home brewn UDP based protocol, "remote disk", which provides random access to a single remote file/device. The Open Firmware flavored boot loader automatically initializes the net stack, searches for a remote disk, and tries to boot from it, if the boot device is a network device (e.g. when loading the boot loader via TFTP). This is quite nice for developing with a two-machine setup, since one doesn't even need to install Haiku on the test machine anymore, but can serve it directly from the development machine. When the networking support in the kernel is working, this method could even be used to fully boot, not just for loading kernel and initial modules. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15689 a95241bf-73f2-0310-859d-f6bbb57e9c96
108 lines
2.4 KiB
C++
108 lines
2.4 KiB
C++
/*
|
|
* Copyright 2005, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
|
|
* All rights reserved. Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
#ifndef _BOOT_UDP_H
|
|
#define _BOOT_UDP_H
|
|
|
|
#include <boot/net/IP.h>
|
|
|
|
// UDPPacket
|
|
class UDPPacket {
|
|
public:
|
|
UDPPacket();
|
|
~UDPPacket();
|
|
|
|
status_t SetTo(const void *data, size_t size, ip_addr_t sourceAddress,
|
|
uint16 sourcePort, ip_addr_t destinationAddress,
|
|
uint16 destinationPort);
|
|
|
|
UDPPacket *Next() const;
|
|
void SetNext(UDPPacket *next);
|
|
|
|
const void *Data() const;
|
|
size_t DataSize() const;
|
|
|
|
ip_addr_t SourceAddress() const;
|
|
uint16 SourcePort() const;
|
|
ip_addr_t DestinationAddress() const;
|
|
uint16 DestinationPort() const;
|
|
|
|
private:
|
|
UDPPacket *fNext;
|
|
void *fData;
|
|
size_t fSize;
|
|
ip_addr_t fSourceAddress;
|
|
ip_addr_t fDestinationAddress;
|
|
uint16 fSourcePort;
|
|
uint16 fDestinationPort;
|
|
};
|
|
|
|
|
|
class UDPService;
|
|
|
|
// UDPSocket
|
|
class UDPSocket {
|
|
public:
|
|
UDPSocket();
|
|
~UDPSocket();
|
|
|
|
ip_addr_t Address() const { return fAddress; }
|
|
uint16 Port() const { return fPort; }
|
|
|
|
status_t Bind(ip_addr_t address, uint16 port);
|
|
|
|
status_t Send(ip_addr_t destinationAddress, uint16 destinationPort,
|
|
ChainBuffer *buffer);
|
|
status_t Send(ip_addr_t destinationAddress, uint16 destinationPort,
|
|
const void *data, size_t size);
|
|
status_t Receive(UDPPacket **packet, bigtime_t timeout = 0);
|
|
|
|
void PushPacket(UDPPacket *packet);
|
|
UDPPacket *PopPacket();
|
|
|
|
private:
|
|
UDPService *fUDPService;
|
|
UDPPacket *fFirstPacket;
|
|
UDPPacket *fLastPacket;
|
|
ip_addr_t fAddress;
|
|
uint16 fPort;
|
|
};
|
|
|
|
|
|
// UDPService
|
|
class UDPService : public IPSubService {
|
|
public:
|
|
UDPService(IPService *ipService);
|
|
virtual ~UDPService();
|
|
|
|
status_t Init();
|
|
|
|
virtual uint8 IPProtocol() const;
|
|
|
|
virtual void HandleIPPacket(IPService *ipService, ip_addr_t sourceIP,
|
|
ip_addr_t destinationIP, const void *data, size_t size);
|
|
|
|
status_t Send(uint16 sourcePort, ip_addr_t destinationAddress,
|
|
uint16 destinationPort, ChainBuffer *buffer);
|
|
|
|
void ProcessIncomingPackets();
|
|
|
|
status_t BindSocket(UDPSocket *socket, ip_addr_t address, uint16 port);
|
|
void UnbindSocket(UDPSocket *socket);
|
|
|
|
private:
|
|
uint16 _ChecksumBuffer(ChainBuffer *buffer, ip_addr_t source,
|
|
ip_addr_t destination, uint16 length);
|
|
uint16 _ChecksumData(const void *data, uint16 length, ip_addr_t source,
|
|
ip_addr_t destination);
|
|
|
|
UDPSocket *_FindSocket(ip_addr_t address, uint16 port);
|
|
|
|
IPService *fIPService;
|
|
Vector<UDPSocket*> fSockets;
|
|
};
|
|
|
|
#endif // _BOOT_UDP_H
|