moved address selection logic to a new 'get_buffer_route'.
- IPv4 now assumes the addresses it is supplied in send_routed_data are already the appropriate ones. - made the Data(), operator* and operator-> methods in NetBufferFieldReader const so we can use them in the same expression as the constructor. - fixed an issue with UDP where the wrong source address could be used in the calculating the checksum. - changed ipv4_print_address to use the more common 0.0.0.0 format. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20660 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,56 +22,49 @@ class NetBufferFieldReader {
|
||||
public:
|
||||
NetBufferFieldReader(net_buffer *buffer)
|
||||
:
|
||||
fBuffer(buffer),
|
||||
fStatus(B_BAD_VALUE)
|
||||
fBuffer(buffer)
|
||||
{
|
||||
if ((Offset + sizeof(Type)) <= buffer->size) {
|
||||
fStatus = Module::Get()->direct_access(fBuffer, Offset,
|
||||
sizeof(Type), (void **)&fData);
|
||||
if (fStatus != B_OK) {
|
||||
fData = NULL;
|
||||
fStatus = Module::Get()->read(fBuffer, Offset,
|
||||
&fDataBuffer, sizeof(Type));
|
||||
}
|
||||
fStatus = Module::Get()->direct_access(fBuffer, Offset,
|
||||
sizeof(Type), (void **)&fData);
|
||||
if (fStatus != B_OK) {
|
||||
fStatus = Module::Get()->read(fBuffer, Offset,
|
||||
&fDataBuffer, sizeof(Type));
|
||||
fData = &fDataBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
status_t
|
||||
Status()
|
||||
Status() const
|
||||
{
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
Type &
|
||||
Data()
|
||||
Data() const
|
||||
{
|
||||
if (fData != NULL)
|
||||
return *fData;
|
||||
|
||||
return fDataBuffer;
|
||||
return *fData;
|
||||
}
|
||||
|
||||
Type *
|
||||
operator->()
|
||||
operator->() const
|
||||
{
|
||||
return &Data();
|
||||
return fData;
|
||||
}
|
||||
|
||||
Type &
|
||||
operator*()
|
||||
operator*() const
|
||||
{
|
||||
return Data();
|
||||
return *fData;
|
||||
}
|
||||
|
||||
void
|
||||
Sync()
|
||||
{
|
||||
if (fBuffer == NULL)
|
||||
if (fBuffer == NULL || fStatus < B_OK)
|
||||
return;
|
||||
|
||||
if (fData == NULL)
|
||||
Module::Get()->write(fBuffer, Offset, &fDataBuffer,
|
||||
sizeof(Type));
|
||||
if (fData == &fDataBuffer)
|
||||
Module::Get()->write(fBuffer, Offset, fData, sizeof(Type));
|
||||
|
||||
fBuffer = NULL;
|
||||
}
|
||||
@@ -138,15 +131,14 @@ class NetBufferHeaderRemover : public NetBufferHeaderReader<Type, Module> {
|
||||
template<typename Type, typename Module = NetBufferModuleGetter>
|
||||
class NetBufferPrepend : public NetBufferFieldReader<Type, 0, Module> {
|
||||
public:
|
||||
NetBufferPrepend(net_buffer *buffer, size_t size = 0)
|
||||
NetBufferPrepend(net_buffer *buffer, size_t size = sizeof(Type))
|
||||
{
|
||||
fBuffer = buffer;
|
||||
fData = NULL;
|
||||
|
||||
if (size == 0)
|
||||
size = sizeof(Type);
|
||||
|
||||
fStatus = Module::Get()->prepend_size(buffer, size, (void **)&fData);
|
||||
fStatus = Module::Get()->prepend_size(buffer, size,
|
||||
(void **)&fData);
|
||||
if (fStatus == B_OK && fData == NULL)
|
||||
fData = &fDataBuffer;
|
||||
}
|
||||
|
||||
~NetBufferPrepend()
|
||||
|
||||
@@ -79,6 +79,8 @@ struct net_datalink_module_info {
|
||||
const struct net_route *route);
|
||||
struct net_route *(*get_route)(struct net_domain *domain,
|
||||
const struct sockaddr *address);
|
||||
status_t (*get_buffer_route)(struct net_domain *domain,
|
||||
struct net_buffer *buffer, struct net_route **_route);
|
||||
void (*put_route)(struct net_domain *domain, struct net_route *route);
|
||||
|
||||
status_t (*register_route_info)(struct net_domain *domain,
|
||||
@@ -118,6 +120,8 @@ struct net_address_module_info {
|
||||
status_t (*set_to)(sockaddr *address, const sockaddr *from);
|
||||
status_t (*set_to_empty_address)(sockaddr *address);
|
||||
|
||||
status_t (*update_to)(sockaddr *address, const sockaddr *from);
|
||||
|
||||
uint32 (*hash_address_pair)(const sockaddr *ourAddress,
|
||||
const sockaddr *peerAddress);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user