2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
10 #include <SupportDefs.h>
13 // NOTE: We support the standard FS address space as well as the alternative
14 // internal address space Linux features (sun_path[0] is 0, followed by 5 hex
15 // digits, without null-termination). The latter one is nice to have, because
16 // the address lookup is quick (hash table lookup, instead of asking the VFS to
17 // resolve the path), and we don't have to pollute the FS when auto-binding
18 // sockets (e.g. on connect()).
21 #define INTERNAL_UNIX_ADDRESS_LEN (2 + 1 + 5)
22 // sun_len + sun_family + null byte + 5 hex digits
35 UnixAddress(const UnixAddress
& other
)
40 UnixAddress(int32 internalID
)
45 UnixAddress(dev_t volumeID
, ino_t nodeID
, struct vnode
* vnode
)
47 SetTo(volumeID
, nodeID
, vnode
);
50 void SetTo(int32 internalID
)
52 fInternalID
= internalID
;
58 void SetTo(dev_t volumeID
, ino_t nodeID
, struct vnode
* vnode
)
76 return fInternalID
>= 0 || fVolumeID
>= 0;
79 bool IsInternalAddress() const
81 return fInternalID
>= 0;
84 int32
InternalID() const
89 int32
VolumeID() const
99 struct vnode
* Vnode() const
104 uint32
HashCode() const
106 return fInternalID
>= 0
108 : uint32(fVolumeID
) ^ uint32(fNodeID
);
111 char* ToString(char *buffer
, size_t bufferSize
) const;
113 UnixAddress
& operator=(const UnixAddress
& other
)
115 fInternalID
= other
.fInternalID
;
116 fVolumeID
= other
.fVolumeID
;
117 fNodeID
= other
.fNodeID
;
118 fVnode
= other
.fVnode
;
122 bool operator==(const UnixAddress
& other
) const
124 return fInternalID
>= 0
125 ? fInternalID
== other
.fInternalID
126 : fVolumeID
== other
.fVolumeID
127 && fNodeID
== other
.fNodeID
;
130 bool operator!=(const UnixAddress
& other
) const
132 return !(*this == other
);
135 static bool IsEmptyAddress(const sockaddr_un
& address
)
137 return address
.sun_len
== sizeof(sockaddr
)
138 && address
.sun_path
[0] == '\0' && address
.sun_path
[1] == '\0';
141 static int32
InternalID(const sockaddr_un
& address
)
143 if (address
.sun_len
< INTERNAL_UNIX_ADDRESS_LEN
144 || address
.sun_path
[0] != '\0') {
151 for (int32 i
= 0; i
< 5; i
++) {
152 char c
= address
.sun_path
[i
+ 1];
153 if (c
>= '0' && c
<= '9')
154 id
= (id
<< 4) + (c
- '0');
155 else if (c
>= 'a' && c
<= 'f')
156 id
= (id
<< 4) + 10 + (c
- 'a');
165 // fat interface: If fInternalID is >= 0, it's an address in the internal
166 // namespace, otherwise a FS address.
170 struct vnode
* fVnode
;
174 #endif // UNIX_ADDRESS_H