[Haiku-commits] r31238 - in haiku/trunk: headers/private/net src/add-ons/kernel/network/protocols/ipv4
axeld at BerliOS
axeld at mail.berlios.de
Thu Jun 25 18:01:12 CEST 2009
Author: axeld
Date: 2009-06-25 18:01:11 +0200 (Thu, 25 Jun 2009)
New Revision: 31238
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31238&view=rev
Modified:
haiku/trunk/headers/private/net/ProtocolUtilities.h
haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp
Log:
* DatagramSocket::InitCheck() returned the sem_id instead of a status_t, causing
pings to fail (raw socket initialization) after r31079.
* Further cleanup.
Modified: haiku/trunk/headers/private/net/ProtocolUtilities.h
===================================================================
--- haiku/trunk/headers/private/net/ProtocolUtilities.h 2009-06-25 15:44:17 UTC (rev 31237)
+++ haiku/trunk/headers/private/net/ProtocolUtilities.h 2009-06-25 16:01:11 UTC (rev 31238)
@@ -1,5 +1,5 @@
/*
- * Copyright 2007, Haiku, Inc. All Rights Reserved.
+ * Copyright 2007-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -26,52 +26,58 @@
typedef mutex Type;
typedef MutexLocker AutoLocker;
- static status_t Init(mutex *lock, const char *name)
+ static status_t Init(mutex* lock, const char* name)
{ mutex_init_etc(lock, name, MUTEX_FLAG_CLONE_NAME); return B_OK; }
- static void Destroy(mutex *lock) { mutex_destroy(lock); }
- static status_t Lock(mutex *lock) { return mutex_lock(lock); }
- static status_t Unlock(mutex *lock) { mutex_unlock(lock); return B_OK; }
+ static void Destroy(mutex* lock) { mutex_destroy(lock); }
+ static status_t Lock(mutex* lock) { return mutex_lock(lock); }
+ static status_t Unlock(mutex* lock) { mutex_unlock(lock); return B_OK; }
};
-extern net_buffer_module_info *gBufferModule;
-extern net_stack_module_info *gStackModule;
+extern net_buffer_module_info* gBufferModule;
+extern net_stack_module_info* gStackModule;
class NetModuleBundleGetter {
public:
- static net_stack_module_info *Stack() { return gStackModule; }
- static net_buffer_module_info *Buffer() { return gBufferModule; }
+ static net_stack_module_info* Stack() { return gStackModule; }
+ static net_buffer_module_info* Buffer() { return gBufferModule; }
};
class ProtocolSocket {
public:
- ProtocolSocket(net_socket *socket);
+ ProtocolSocket(net_socket* socket);
status_t Open();
SocketAddress LocalAddress()
{ return SocketAddress(fDomain->address_module, &fSocket->address); }
ConstSocketAddress LocalAddress() const
- { return ConstSocketAddress(fDomain->address_module, &fSocket->address); }
+ { return ConstSocketAddress(fDomain->address_module,
+ &fSocket->address); }
SocketAddress PeerAddress()
{ return SocketAddress(fDomain->address_module, &fSocket->peer); }
ConstSocketAddress PeerAddress() const
{ return ConstSocketAddress(fDomain->address_module, &fSocket->peer); }
- net_domain *Domain() const { return fDomain; }
- net_address_module_info *AddressModule() const
+ net_domain* Domain() const { return fDomain; }
+ net_address_module_info* AddressModule() const
{ return fDomain->address_module; }
protected:
- net_socket *fSocket;
- net_domain *fDomain;
+ net_socket* fSocket;
+ net_domain* fDomain;
};
-inline ProtocolSocket::ProtocolSocket(net_socket *socket)
- : fSocket(socket), fDomain(NULL) {}
+inline
+ProtocolSocket::ProtocolSocket(net_socket* socket)
+ :
+ fSocket(socket),
+ fDomain(NULL)
+{
+}
inline status_t
@@ -91,49 +97,49 @@
typename ModuleBundle = NetModuleBundleGetter>
class DatagramSocket : public ProtocolSocket {
public:
- DatagramSocket(const char *name, net_socket *socket);
- virtual ~DatagramSocket();
+ DatagramSocket(const char* name, net_socket* socket);
+ virtual ~DatagramSocket();
- status_t InitCheck() const;
+ status_t InitCheck() const;
- status_t Enqueue(net_buffer *buffer);
- net_buffer *Dequeue(bool clone);
- status_t BlockingDequeue(bool clone, bigtime_t timeout,
- net_buffer **_buffer);
- void Clear();
+ status_t Enqueue(net_buffer* buffer);
+ net_buffer* Dequeue(bool clone);
+ status_t BlockingDequeue(bool clone, bigtime_t timeout,
+ net_buffer** _buffer);
+ void Clear();
- status_t SocketEnqueue(net_buffer *buffer);
- status_t SocketDequeue(uint32 flags, net_buffer **_buffer);
+ status_t SocketEnqueue(net_buffer* buffer);
+ status_t SocketDequeue(uint32 flags, net_buffer** _buffer);
- ssize_t AvailableData() const;
+ ssize_t AvailableData() const;
- void WakeAll();
+ void WakeAll();
- net_socket *Socket() const { return fSocket; }
+ net_socket* Socket() const { return fSocket; }
protected:
- virtual status_t _SocketStatus() const;
+ virtual status_t _SocketStatus() const;
- status_t _Enqueue(net_buffer *buffer);
- status_t _SocketEnqueue(net_buffer *buffer);
- net_buffer *_Dequeue(bool clone);
- void _Clear();
+ status_t _Enqueue(net_buffer* buffer);
+ status_t _SocketEnqueue(net_buffer* buffer);
+ net_buffer* _Dequeue(bool clone);
+ void _Clear();
- status_t _Wait(bigtime_t timeout);
- void _NotifyOneReader(bool notifySocket);
+ status_t _Wait(bigtime_t timeout);
+ void _NotifyOneReader(bool notifySocket);
- bool _IsEmpty() const { return fBuffers.IsEmpty(); }
- bigtime_t _SocketTimeout(uint32 flags) const;
+ bool _IsEmpty() const { return fBuffers.IsEmpty(); }
+ bigtime_t _SocketTimeout(uint32 flags) const;
typedef typename LockingBase::Type LockType;
typedef typename LockingBase::AutoLocker AutoLocker;
typedef DoublyLinkedListCLink<net_buffer> NetBufferLink;
typedef DoublyLinkedList<net_buffer, NetBufferLink> BufferList;
- sem_id fNotify;
- BufferList fBuffers;
- size_t fCurrentBytes;
- mutable LockType fLock;
+ sem_id fNotify;
+ BufferList fBuffers;
+ size_t fCurrentBytes;
+ mutable LockType fLock;
};
@@ -142,12 +148,12 @@
DatagramSocket<LockingBase, ModuleBundle>
-DECL_DATAGRAM_SOCKET(inline)::DatagramSocket(const char *name,
- net_socket *socket)
+DECL_DATAGRAM_SOCKET(inline)::DatagramSocket(const char* name,
+ net_socket* socket)
: ProtocolSocket(socket), fCurrentBytes(0)
{
status_t status = LockingBase::Init(&fLock, name);
- if (status < B_OK)
+ if (status != B_OK)
fNotify = status;
else
fNotify = create_sem(0, name);
@@ -164,18 +170,18 @@
DECL_DATAGRAM_SOCKET(inline status_t)::InitCheck() const
{
- return fNotify;
+ return fNotify >= 0 ? B_OK : fNotify;
}
-DECL_DATAGRAM_SOCKET(inline status_t)::Enqueue(net_buffer *buffer)
+DECL_DATAGRAM_SOCKET(inline status_t)::Enqueue(net_buffer* buffer)
{
AutoLocker _(fLock);
return _Enqueue(buffer);
}
-DECL_DATAGRAM_SOCKET(inline status_t)::_Enqueue(net_buffer *buffer)
+DECL_DATAGRAM_SOCKET(inline status_t)::_Enqueue(net_buffer* buffer)
{
if (fSocket->receive.buffer_size > 0
&& (fCurrentBytes + buffer->size) > fSocket->receive.buffer_size)
@@ -190,16 +196,16 @@
}
-DECL_DATAGRAM_SOCKET(inline status_t)::SocketEnqueue(net_buffer *_buffer)
+DECL_DATAGRAM_SOCKET(inline status_t)::SocketEnqueue(net_buffer* _buffer)
{
AutoLocker _(fLock);
return _SocketEnqueue(_buffer);
}
-DECL_DATAGRAM_SOCKET(inline status_t)::_SocketEnqueue(net_buffer *_buffer)
+DECL_DATAGRAM_SOCKET(inline status_t)::_SocketEnqueue(net_buffer* _buffer)
{
- net_buffer *buffer = ModuleBundle::Buffer()->clone(_buffer, false);
+ net_buffer* buffer = ModuleBundle::Buffer()->clone(_buffer, false);
if (buffer == NULL)
return B_NO_MEMORY;
@@ -211,14 +217,14 @@
}
-DECL_DATAGRAM_SOCKET(inline net_buffer *)::Dequeue(bool clone)
+DECL_DATAGRAM_SOCKET(inline net_buffer*)::Dequeue(bool clone)
{
AutoLocker _(fLock);
return _Dequeue(clone);
}
-DECL_DATAGRAM_SOCKET(inline net_buffer *)::_Dequeue(bool clone)
+DECL_DATAGRAM_SOCKET(inline net_buffer*)::_Dequeue(bool clone)
{
if (fBuffers.IsEmpty())
return NULL;
@@ -226,7 +232,7 @@
if (clone)
return ModuleBundle::Buffer()->clone(fBuffers.Head(), false);
- net_buffer *buffer = fBuffers.RemoveHead();
+ net_buffer* buffer = fBuffers.RemoveHead();
fCurrentBytes -= buffer->size;
return buffer;
@@ -234,7 +240,7 @@
DECL_DATAGRAM_SOCKET(inline status_t)::BlockingDequeue(bool clone,
- bigtime_t timeout, net_buffer **_buffer)
+ bigtime_t timeout, net_buffer** _buffer)
{
AutoLocker _(fLock);
@@ -265,9 +271,10 @@
DECL_DATAGRAM_SOCKET(inline status_t)::SocketDequeue(uint32 flags,
- net_buffer **_buffer)
+ net_buffer** _buffer)
{
- return BlockingDequeue(flags & MSG_PEEK, _SocketTimeout(flags), _buffer);
+ return BlockingDequeue((flags & MSG_PEEK) != 0, _SocketTimeout(flags),
+ _buffer);
}
@@ -336,7 +343,7 @@
{
bigtime_t timeout = fSocket->receive.timeout;
- if (flags & MSG_DONTWAIT)
+ if ((flags & MSG_DONTWAIT) != 0)
timeout = 0;
else if (timeout != 0 && timeout != B_INFINITE_TIMEOUT)
timeout += system_time();
@@ -349,4 +356,4 @@
return timeout;
}
-#endif
+#endif // PROTOCOL_UTILITIES_H
Modified: haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2009-06-25 15:44:17 UTC (rev 31237)
+++ haiku/trunk/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp 2009-06-25 16:01:11 UTC (rev 31238)
@@ -101,18 +101,18 @@
~FragmentPacket();
status_t AddFragment(uint16 start, uint16 end,
- net_buffer *buffer, bool lastFragment);
- status_t Reassemble(net_buffer *to);
+ net_buffer* buffer, bool lastFragment);
+ status_t Reassemble(net_buffer* to);
bool IsComplete() const
{ return fReceivedLastFragment
&& fBytesLeft == 0; }
- static uint32 Hash(void *_packet, const void *_key, uint32 range);
- static int Compare(void *_packet, const void *_key);
+ static uint32 Hash(void* _packet, const void* _key, uint32 range);
+ static int Compare(void* _packet, const void* _key);
static int32 NextOffset()
{ return offsetof(FragmentPacket, fNext); }
- static void StaleTimer(struct net_timer *timer, void *data);
+ static void StaleTimer(struct net_timer* timer, void* data);
private:
FragmentPacket *fNext;
@@ -127,7 +127,7 @@
class RawSocket
: public DoublyLinkedListLinkImpl<RawSocket>, public DatagramSocket<> {
public:
- RawSocket(net_socket *socket);
+ RawSocket(net_socket* socket);
};
typedef DoublyLinkedList<RawSocket> RawSocketList;
@@ -136,21 +136,21 @@
typedef MulticastFilter<IPv4Multicast> IPv4MulticastFilter;
struct MulticastStateHash {
- typedef std::pair<const in_addr *, uint32> KeyType;
+ typedef std::pair<const in_addr* , uint32> KeyType;
typedef IPv4GroupInterface ValueType;
size_t HashKey(const KeyType &key) const
{ return key.first->s_addr ^ key.second; }
- size_t Hash(ValueType *value) const
+ size_t Hash(ValueType* value) const
{ return HashKey(std::make_pair(&value->Address(),
value->Interface()->index)); }
- bool Compare(const KeyType &key, ValueType *value) const
+ bool Compare(const KeyType &key, ValueType* value) const
{ return value->Interface()->index == key.second
&& value->Address().s_addr == key.first->s_addr; }
- bool CompareValues(ValueType *value1, ValueType *value2) const
+ bool CompareValues(ValueType* value1, ValueType* value2) const
{ return value1->Interface()->index == value2->Interface()->index
&& value1->Address().s_addr == value2->Address().s_addr; }
- HashTableLink<ValueType> *GetLink(ValueType *value) const { return value; }
+ HashTableLink<ValueType>* GetLink(ValueType* value) const { return value; }
};
@@ -181,28 +181,28 @@
extern net_protocol_module_info gIPv4Module;
// we need this in ipv4_std_ops() for registering the AF_INET domain
-net_stack_module_info *gStackModule;
-net_buffer_module_info *gBufferModule;
+net_stack_module_info* gStackModule;
+net_buffer_module_info* gBufferModule;
-static struct net_domain *sDomain;
-static net_datalink_module_info *sDatalinkModule;
-static net_socket_module_info *sSocketModule;
+static struct net_domain* sDomain;
+static net_datalink_module_info* sDatalinkModule;
+static net_socket_module_info* sSocketModule;
static int32 sPacketID;
static RawSocketList sRawSockets;
static mutex sRawSocketsLock;
static mutex sFragmentLock;
-static hash_table *sFragmentHash;
+static hash_table* sFragmentHash;
static mutex sMulticastGroupsLock;
typedef MultiHashTable<MulticastStateHash> MulticastState;
-static MulticastState *sMulticastState;
+static MulticastState* sMulticastState;
-static net_protocol_module_info *sReceivingProtocol[256];
+static net_protocol_module_info* sReceivingProtocol[256];
static mutex sReceivingProtocolLock;
-static const char *
-print_address(const in_addr *address, char *buf, size_t bufLen)
+static const char*
+print_address(const in_addr* address, char* buf, size_t bufLen)
{
unsigned int addr = ntohl(address->s_addr);
@@ -213,7 +213,7 @@
}
-RawSocket::RawSocket(net_socket *socket)
+RawSocket::RawSocket(net_socket* socket)
: DatagramSocket<>("ipv4 raw socket", socket)
{
}
@@ -238,7 +238,7 @@
gStackModule->set_timer(&fTimer, -1);
// delete all fragments
- net_buffer *buffer;
+ net_buffer* buffer;
while ((buffer = fFragments.RemoveHead()) != NULL) {
gBufferModule->free(buffer);
}
@@ -246,7 +246,7 @@
status_t
-FragmentPacket::AddFragment(uint16 start, uint16 end, net_buffer *buffer,
+FragmentPacket::AddFragment(uint16 start, uint16 end, net_buffer* buffer,
bool lastFragment)
{
// restart the timer
@@ -260,8 +260,8 @@
// Search for a position in the list to insert the fragment
FragmentList::ReverseIterator iterator = fFragments.GetReverseIterator();
- net_buffer *previous = NULL;
- net_buffer *next = NULL;
+ net_buffer* previous = NULL;
+ net_buffer* next = NULL;
while ((previous = iterator.Next()) != NULL) {
if (previous->fragment.start <= start) {
// The new fragment can be inserted after this one
@@ -335,11 +335,11 @@
status_t status = gBufferModule->merge(buffer, next, true);
TRACE(" merge next: %s", strerror(status));
if (status != B_OK) {
- fFragments.Insert((net_buffer *)previous->link.next, next);
+ fFragments.Insert((net_buffer*)previous->link.next, next);
return status;
}
- fFragments.Insert((net_buffer *)previous->link.next, buffer);
+ fFragments.Insert((net_buffer*)previous->link.next, buffer);
// cut down existing hole
fBytesLeft -= end - start;
@@ -380,14 +380,14 @@
This buffer must have been added via AddFragment() before.
*/
status_t
-FragmentPacket::Reassemble(net_buffer *to)
+FragmentPacket::Reassemble(net_buffer* to)
{
if (!IsComplete())
return B_ERROR;
- net_buffer *buffer = NULL;
+ net_buffer* buffer = NULL;
- net_buffer *fragment;
+ net_buffer* fragment;
while ((fragment = fFragments.RemoveHead()) != NULL) {
if (buffer != NULL) {
status_t status;
@@ -410,10 +410,10 @@
int
-FragmentPacket::Compare(void *_packet, const void *_key)
+FragmentPacket::Compare(void* _packet, const void* _key)
{
- const ipv4_packet_key *key = (ipv4_packet_key *)_key;
- ipv4_packet_key *packetKey = &((FragmentPacket *)_packet)->fKey;
+ const ipv4_packet_key* key = (ipv4_packet_key*)_key;
+ ipv4_packet_key* packetKey = &((FragmentPacket*)_packet)->fKey;
if (packetKey->id == key->id
&& packetKey->source == key->source
@@ -426,10 +426,10 @@
uint32
-FragmentPacket::Hash(void *_packet, const void *_key, uint32 range)
+FragmentPacket::Hash(void* _packet, const void* _key, uint32 range)
{
- const struct ipv4_packet_key *key = (struct ipv4_packet_key *)_key;
- FragmentPacket *packet = (FragmentPacket *)_packet;
+ const struct ipv4_packet_key* key = (struct ipv4_packet_key*)_key;
+ FragmentPacket* packet = (FragmentPacket*)_packet;
if (packet != NULL)
key = &packet->fKey;
@@ -438,9 +438,9 @@
/*static*/ void
-FragmentPacket::StaleTimer(struct net_timer *timer, void *data)
+FragmentPacket::StaleTimer(struct net_timer* timer, void* data)
{
- FragmentPacket *packet = (FragmentPacket *)data;
+ FragmentPacket* packet = (FragmentPacket*)data;
TRACE("Assembling FragmentPacket %p timed out!", packet);
MutexLocker locker(&sFragmentLock);
@@ -470,8 +470,8 @@
uint8 a;
#endif
};
- struct pretty_ipv4 *src = (struct pretty_ipv4 *)&header.source;
- struct pretty_ipv4 *dst = (struct pretty_ipv4 *)&header.destination;
+ struct pretty_ipv4* src = (struct pretty_ipv4*)&header.source;
+ struct pretty_ipv4* dst = (struct pretty_ipv4*)&header.destination;
dprintf(" version: %d\n", header.version);
dprintf(" header_length: 4 * %d\n", header.header_length);
dprintf(" service_type: %d\n", header.service_type);
@@ -492,12 +492,12 @@
static int
-dump_ipv4_multicast(int argc, char *argv[])
+dump_ipv4_multicast(int argc, char** argv)
{
MulticastState::Iterator it = sMulticastState->GetIterator();
while (it.HasNext()) {
- IPv4GroupInterface *state = it.Next();
+ IPv4GroupInterface* state = it.Next();
char addressBuffer[64];
@@ -529,9 +529,9 @@
\return various error codes if something went wrong (mostly B_NO_MEMORY)
*/
static status_t
-reassemble_fragments(const ipv4_header &header, net_buffer **_buffer)
+reassemble_fragments(const ipv4_header &header, net_buffer** _buffer)
{
- net_buffer *buffer = *_buffer;
+ net_buffer* buffer = *_buffer;
status_t status;
struct ipv4_packet_key key;
@@ -543,7 +543,7 @@
// TODO: Make locking finer grained.
MutexLocker locker(&sFragmentLock);
- FragmentPacket *packet = (FragmentPacket *)hash_lookup(sFragmentHash, &key);
+ FragmentPacket* packet = (FragmentPacket*)hash_lookup(sFragmentHash, &key);
if (packet == NULL) {
// New fragment packet
packet = new (std::nothrow) FragmentPacket(key);
@@ -596,8 +596,8 @@
\a route.
*/
static status_t
-send_fragments(ipv4_protocol *protocol, struct net_route *route,
- net_buffer *buffer, uint32 mtu)
+send_fragments(ipv4_protocol* protocol, struct net_route* route,
+ net_buffer* buffer, uint32 mtu)
{
TRACE_SK(protocol, "SendFragments(%lu bytes, mtu %lu)", buffer->size, mtu);
@@ -610,14 +610,14 @@
uint32 fragmentOffset = 0;
status_t status = B_OK;
- net_buffer *headerBuffer = gBufferModule->split(buffer, headerLength);
+ net_buffer* headerBuffer = gBufferModule->split(buffer, headerLength);
if (headerBuffer == NULL)
return B_NO_MEMORY;
// TODO: we need to make sure ipv4_header is contiguous or
// use another construct.
NetBufferHeaderReader<ipv4_header> bufferHeader(headerBuffer);
- ipv4_header *header = &bufferHeader.Data();
+ ipv4_header* header = &bufferHeader.Data();
// Adapt MTU to be a multiple of 8 (fragment offsets can only be specified
// this way)
@@ -635,13 +635,13 @@
header->fragment_offset = htons((lastFragment ? 0 : IP_MORE_FRAGMENTS)
| (fragmentOffset >> 3));
header->checksum = 0;
- header->checksum = gStackModule->checksum((uint8 *)header,
+ header->checksum = gStackModule->checksum((uint8*)header,
headerLength);
// TODO: compute the checksum only for those parts that changed?
TRACE(" send fragment of %ld bytes (%ld bytes left)\n", fragmentLength, bytesLeft);
- net_buffer *fragmentBuffer;
+ net_buffer* fragmentBuffer;
if (!lastFragment) {
fragmentBuffer = gBufferModule->split(buffer, fragmentLength);
fragmentOffset += fragmentLength;
@@ -677,7 +677,7 @@
static status_t
-deliver_multicast(net_protocol_module_info *module, net_buffer *buffer,
+deliver_multicast(net_protocol_module_info* module, net_buffer* buffer,
bool deliverToRaw)
{
if (module->deliver_data == NULL)
@@ -685,13 +685,13 @@
MutexLocker _(sMulticastGroupsLock);
- sockaddr_in *multicastAddr = (sockaddr_in *)buffer->destination;
+ sockaddr_in* multicastAddr = (sockaddr_in*)buffer->destination;
MulticastState::ValueIterator it = sMulticastState->Lookup(std::make_pair(
&multicastAddr->sin_addr, buffer->interface->index));
while (it.HasNext()) {
- IPv4GroupInterface *state = it.Next();
+ IPv4GroupInterface* state = it.Next();
if (deliverToRaw && state->Parent()->Socket()->raw == NULL)
continue;
@@ -700,7 +700,7 @@
// as Multicast filters are installed with an IPv4 protocol
// reference, we need to go and find the appropriate instance
// related to the 'receiving protocol' with module 'module'.
- net_protocol *proto
+ net_protocol* proto
= state->Parent()->Socket()->socket->first_protocol;
while (proto && proto->module != module)
@@ -716,7 +716,7 @@
static void
-raw_receive_data(net_buffer *buffer)
+raw_receive_data(net_buffer* buffer)
{
MutexLocker locker(sRawSocketsLock);
@@ -736,7 +736,7 @@
RawSocketList::Iterator iterator = sRawSockets.GetIterator();
while (iterator.HasNext()) {
- RawSocket *raw = iterator.Next();
+ RawSocket* raw = iterator.Next();
if (raw->Socket()->protocol == buffer->protocol)
raw->SocketEnqueue(buffer);
@@ -745,25 +745,26 @@
}
-static sockaddr *
-fill_sockaddr_in(sockaddr_in *destination, const in_addr &source)
+static sockaddr*
+fill_sockaddr_in(sockaddr_in* destination, const in_addr &source)
{
memset(destination, 0, sizeof(sockaddr_in));
destination->sin_family = AF_INET;
destination->sin_addr = source;
- return (sockaddr *)destination;
+ return (sockaddr*)destination;
}
status_t
-IPv4Multicast::JoinGroup(IPv4GroupInterface *state)
+IPv4Multicast::JoinGroup(IPv4GroupInterface* state)
{
MutexLocker _(sMulticastGroupsLock);
sockaddr_in groupAddr;
- net_interface *intf = state->Interface();
+ net_interface* interface = state->Interface();
- status_t status = intf->first_info->join_multicast(intf->first_protocol,
+ status_t status = interface->first_info->join_multicast(
+ interface->first_protocol,
fill_sockaddr_in(&groupAddr, state->Address()));
if (status != B_OK)
return status;
@@ -774,24 +775,25 @@
status_t
-IPv4Multicast::LeaveGroup(IPv4GroupInterface *state)
+IPv4Multicast::LeaveGroup(IPv4GroupInterface* state)
{
MutexLocker _(sMulticastGroupsLock);
sMulticastState->Remove(state);
sockaddr_in groupAddr;
- net_interface *intf = state->Interface();
+ net_interface* interface = state->Interface();
- return intf->first_protocol->module->join_multicast(intf->first_protocol,
+ return interface->first_protocol->module->join_multicast(
+ interface->first_protocol,
fill_sockaddr_in(&groupAddr, state->Address()));
}
-static net_protocol_module_info *
+static net_protocol_module_info*
receiving_protocol(uint8 protocol)
{
- net_protocol_module_info *module = sReceivingProtocol[protocol];
+ net_protocol_module_info* module = sReceivingProtocol[protocol];
if (module != NULL)
return module;
@@ -809,20 +811,20 @@
}
-static inline sockaddr *
-fill_sockaddr_in(sockaddr_in *target, in_addr_t address)
+static inline sockaddr*
+fill_sockaddr_in(sockaddr_in* target, in_addr_t address)
{
memset(target, 0, sizeof(sockaddr_in));
target->sin_family = AF_INET;
target->sin_len = sizeof(sockaddr_in);
target->sin_addr.s_addr = address;
- return (sockaddr *)target;
+ return (sockaddr*)target;
}
static status_t
-ipv4_delta_group(IPv4GroupInterface *group, int option,
- net_interface *interface, const in_addr *sourceAddr)
+ipv4_delta_group(IPv4GroupInterface* group, int option,
+ net_interface* interface, const in_addr* sourceAddr)
{
switch (option) {
case IP_ADD_MEMBERSHIP:
@@ -844,12 +846,12 @@
static status_t
-ipv4_delta_membership(ipv4_protocol *protocol, int option,
- net_interface *interface, const in_addr *groupAddr,
- const in_addr *sourceAddr)
+ipv4_delta_membership(ipv4_protocol* protocol, int option,
+ net_interface* interface, const in_addr* groupAddr,
+ const in_addr* sourceAddr)
{
IPv4MulticastFilter &filter = protocol->multicast_filter;
- IPv4GroupInterface *state = NULL;
+ IPv4GroupInterface* state = NULL;
status_t status = B_OK;
switch (option) {
@@ -904,11 +906,11 @@
}
-static net_interface *
-get_multicast_interface(ipv4_protocol *protocol, const in_addr *address)
+static net_interface*
+get_multicast_interface(ipv4_protocol* protocol, const in_addr* address)
{
sockaddr_in groupAddr;
- net_route *route = sDatalinkModule->get_route(sDomain,
+ net_route* route = sDatalinkModule->get_route(sDomain,
fill_sockaddr_in(&groupAddr, address ? address->s_addr : INADDR_ANY));
if (route == NULL)
return NULL;
@@ -918,10 +920,10 @@
static status_t
-ipv4_delta_membership(ipv4_protocol *protocol, int option,
- in_addr *interfaceAddr, in_addr *groupAddr, in_addr *sourceAddr)
+ipv4_delta_membership(ipv4_protocol* protocol, int option,
+ in_addr* interfaceAddr, in_addr* groupAddr, in_addr* sourceAddr)
{
- net_interface *interface = NULL;
+ net_interface* interface = NULL;
if (interfaceAddr->s_addr == INADDR_ANY) {
interface = get_multicast_interface(protocol, groupAddr);
@@ -940,21 +942,19 @@
static status_t
-ipv4_generic_delta_membership(ipv4_protocol *protocol, int option,
- uint32 index, const sockaddr_storage *_groupAddr,
- const sockaddr_storage *_sourceAddr)
+ipv4_generic_delta_membership(ipv4_protocol* protocol, int option,
+ uint32 index, const sockaddr_storage* _groupAddr,
+ const sockaddr_storage* _sourceAddr)
{
if (_groupAddr->ss_family != AF_INET)
- return EINVAL;
+ return B_BAD_VALUE;
if (_sourceAddr && _sourceAddr->ss_family != AF_INET)
- return EINVAL;
+ return B_BAD_VALUE;
- net_interface *interface;
- const in_addr *groupAddr, *sourceAddr = NULL;
+ const in_addr* groupAddr = &((const sockaddr_in*)_groupAddr)->sin_addr;
- groupAddr = &((const sockaddr_in *)_groupAddr)->sin_addr;
-
+ net_interface* interface;
if (index == 0)
interface = get_multicast_interface(protocol, groupAddr);
else
@@ -963,8 +963,9 @@
if (interface == NULL)
return ENODEV;
+ const in_addr* sourceAddr = NULL;
if (_sourceAddr)
- sourceAddr = &((const sockaddr_in *)_sourceAddr)->sin_addr;
+ sourceAddr = &((const sockaddr_in*)_sourceAddr)->sin_addr;
return ipv4_delta_membership(protocol, generic_to_ipv4(option), interface,
groupAddr, sourceAddr);
@@ -972,7 +973,7 @@
static status_t
-get_int_option(void *target, size_t length, int value)
+get_int_option(void* target, size_t length, int value)
{
if (length != sizeof(int))
return B_BAD_VALUE;
@@ -982,7 +983,7 @@
template<typename Type> static status_t
-set_int_option(Type &target, const void *_value, size_t length)
+set_int_option(Type &target, const void* _value, size_t length)
{
int value;
@@ -1000,10 +1001,10 @@
// #pragma mark -
-net_protocol *
-ipv4_init_protocol(net_socket *socket)
+net_protocol*
+ipv4_init_protocol(net_socket* socket)
{
- ipv4_protocol *protocol = new (std::nothrow) ipv4_protocol();
+ ipv4_protocol* protocol = new (std::nothrow) ipv4_protocol();
if (protocol == NULL)
return NULL;
@@ -1017,9 +1018,9 @@
status_t
-ipv4_uninit_protocol(net_protocol *_protocol)
+ipv4_uninit_protocol(net_protocol* _protocol)
{
- ipv4_protocol *protocol = (ipv4_protocol *)_protocol;
+ ipv4_protocol* protocol = (ipv4_protocol*)_protocol;
delete protocol->raw;
delete protocol;
@@ -1031,11 +1032,11 @@
it means we are on a SOCK_RAW socket.
*/
status_t
-ipv4_open(net_protocol *_protocol)
+ipv4_open(net_protocol* _protocol)
{
- ipv4_protocol *protocol = (ipv4_protocol *)_protocol;
+ ipv4_protocol* protocol = (ipv4_protocol*)_protocol;
- RawSocket *raw = new (std::nothrow) RawSocket(protocol->socket);
+ RawSocket* raw = new (std::nothrow) RawSocket(protocol->socket);
if (raw == NULL)
return B_NO_MEMORY;
@@ -1056,10 +1057,10 @@
status_t
-ipv4_close(net_protocol *_protocol)
+ipv4_close(net_protocol* _protocol)
{
- ipv4_protocol *protocol = (ipv4_protocol *)_protocol;
- RawSocket *raw = protocol->raw;
+ ipv4_protocol* protocol = (ipv4_protocol*)_protocol;
+ RawSocket* raw = protocol->raw;
if (raw == NULL)
return B_ERROR;
@@ -1075,29 +1076,29 @@
status_t
-ipv4_free(net_protocol *protocol)
+ipv4_free(net_protocol* protocol)
{
return B_OK;
}
status_t
-ipv4_connect(net_protocol *protocol, const struct sockaddr *address)
+ipv4_connect(net_protocol* protocol, const struct sockaddr* address)
{
return B_ERROR;
}
status_t
-ipv4_accept(net_protocol *protocol, struct net_socket **_acceptedSocket)
+ipv4_accept(net_protocol* protocol, struct net_socket** _acceptedSocket)
{
return EOPNOTSUPP;
}
status_t
-ipv4_control(net_protocol *_protocol, int level, int option, void *value,
- size_t *_length)
+ipv4_control(net_protocol* _protocol, int level, int option, void* value,
+ size_t* _length)
{
if ((level & LEVEL_MASK) != IPPROTO_IP)
return sDatalinkModule->control(sDomain, option, value, _length);
@@ -1107,10 +1108,10 @@
status_t
-ipv4_getsockopt(net_protocol *_protocol, int level, int option, void *value,
- int *_length)
+ipv4_getsockopt(net_protocol* _protocol, int level, int option, void* value,
+ int* _length)
{
- ipv4_protocol *protocol = (ipv4_protocol *)_protocol;
+ ipv4_protocol* protocol = (ipv4_protocol*)_protocol;
if (level == IPPROTO_IP) {
if (option == IP_HDRINCL) {
@@ -1153,10 +1154,10 @@
status_t
-ipv4_setsockopt(net_protocol *_protocol, int level, int option,
- const void *value, int length)
+ipv4_setsockopt(net_protocol* _protocol, int level, int option,
+ const void* value, int length)
{
- ipv4_protocol *protocol = (ipv4_protocol *)_protocol;
+ ipv4_protocol* protocol = (ipv4_protocol*)_protocol;
if (level == IPPROTO_IP) {
if (option == IP_HDRINCL) {
@@ -1239,14 +1240,14 @@
status_t
-ipv4_bind(net_protocol *protocol, const struct sockaddr *address)
+ipv4_bind(net_protocol* protocol, const struct sockaddr* address)
{
if (address->sa_family != AF_INET)
return EAFNOSUPPORT;
// only INADDR_ANY and addresses of local interfaces are accepted:
- if (((sockaddr_in *)address)->sin_addr.s_addr == INADDR_ANY
- || IN_MULTICAST(ntohl(((sockaddr_in *)address)->sin_addr.s_addr))
+ if (((sockaddr_in*)address)->sin_addr.s_addr == INADDR_ANY
+ || IN_MULTICAST(ntohl(((sockaddr_in*)address)->sin_addr.s_addr))
|| sDatalinkModule->is_local_address(sDomain, address, NULL, NULL)) {
memcpy(&protocol->socket->address, address, sizeof(struct sockaddr_in));
protocol->socket->address.ss_len = sizeof(struct sockaddr_in);
@@ -1261,7 +1262,7 @@
status_t
-ipv4_unbind(net_protocol *protocol, struct sockaddr *address)
+ipv4_unbind(net_protocol* protocol, struct sockaddr* address)
{
// nothing to do here
return B_OK;
@@ -1269,35 +1270,35 @@
status_t
-ipv4_listen(net_protocol *protocol, int count)
+ipv4_listen(net_protocol* protocol, int count)
{
return EOPNOTSUPP;
}
status_t
-ipv4_shutdown(net_protocol *protocol, int direction)
+ipv4_shutdown(net_protocol* protocol, int direction)
{
return EOPNOTSUPP;
}
status_t
-ipv4_send_routed_data(net_protocol *_protocol, struct net_route *route,
[... truncated: 203 lines follow ...]
More information about the Haiku-commits
mailing list