ReactOS 0.4.15-dev-8119-g4fb2fdb
address.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AddrInitIPv4(IPAddress, RawAddress)
 

Functions

VOID IPAddressFree (PVOID Object)
 
BOOLEAN AddrIsUnspecified (PIP_ADDRESS Address)
 
NTSTATUS AddrGetAddress (PTRANSPORT_ADDRESS AddrList, PIP_ADDRESS Address, PUSHORT Port)
 
NTSTATUS AddrBuildAddress (PTRANSPORT_ADDRESS TdiAddress, PIP_ADDRESS Address, PUSHORT Port)
 
BOOLEAN AddrIsEqual (PIP_ADDRESS Address1, PIP_ADDRESS Address2)
 
INT AddrCompare (PIP_ADDRESS Address1, PIP_ADDRESS Address2)
 
BOOLEAN AddrIsEqualIPv4 (PIP_ADDRESS Address1, IPv4_RAW_ADDRESS Address2)
 
PIP_INTERFACE AddrLocateInterface (PIP_ADDRESS MatchAddress)
 
PADDRESS_FILE AddrSearchFirst (PIP_ADDRESS Address, USHORT Port, USHORT Protocol, PAF_SEARCH SearchContext)
 
PADDRESS_FILE AddrSearchNext (PAF_SEARCH SearchContext)
 
unsigned long NTAPI inet_addr (const char *)
 
ULONG IPv4NToHl (ULONG Address)
 
UINT AddrCountPrefixBits (PIP_ADDRESS Netmask)
 
VOID AddrWidenAddress (PIP_ADDRESS Network, PIP_ADDRESS Source, PIP_ADDRESS Netmask)
 

Macro Definition Documentation

◆ AddrInitIPv4

#define AddrInitIPv4 (   IPAddress,
  RawAddress 
)
Value:
{ \
(IPAddress)->Type = IP_ADDRESS_V4; \
(IPAddress)->Address.IPv4Address = (RawAddress); \
}
Type
Definition: Type.h:7
#define IP_ADDRESS_V4
Definition: ip.h:32
static WCHAR Address[46]
Definition: ping.c:68

Definition at line 16 of file address.h.

Function Documentation

◆ AddrBuildAddress()

NTSTATUS AddrBuildAddress ( PTRANSPORT_ADDRESS  TdiAddress,
PIP_ADDRESS  Address,
PUSHORT  Port 
)

Definition at line 184 of file address.c.

188{
189 PTDI_ADDRESS_IP ValidAddr;
190 PTA_ADDRESS TdiAddress = &TaAddress->Address[0];
191
192 if (TdiAddress->AddressType != TDI_ADDRESS_TYPE_IP) {
194 (MID_TRACE,("AddressType %x, Not valid\n", TdiAddress->AddressType));
196 }
197 if (TdiAddress->AddressLength < TDI_ADDRESS_LENGTH_IP) {
199 (MID_TRACE,("AddressLength %x, Not valid (expected %x)\n",
202 }
203
204
205 ValidAddr = (PTDI_ADDRESS_IP)TdiAddress->Address;
206
207 AddrInitIPv4(Address, ValidAddr->in_addr);
208 *Port = ValidAddr->sin_port;
209
210 return STATUS_SUCCESS;
211}
#define AddrInitIPv4(IPAddress, RawAddress)
Definition: address.h:16
#define MID_TRACE
Definition: debug.h:15
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
CPPORT Port[4]
Definition: headless.c:35
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:557
#define STATUS_SUCCESS
Definition: shellext.h:65
UCHAR Address[1]
Definition: tdi.h:340
USHORT AddressLength
Definition: tdi.h:338
USHORT AddressType
Definition: tdi.h:339
ULONG in_addr
Definition: tdi.h:409
USHORT sin_port
Definition: tdi.h:408
TA_ADDRESS Address[1]
Definition: tdi.h:377
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345

Referenced by TCPConnect().

◆ AddrCompare()

INT AddrCompare ( PIP_ADDRESS  Address1,
PIP_ADDRESS  Address2 
)

Definition at line 257 of file address.c.

260{
261 switch (Address1->Type) {
262 case IP_ADDRESS_V4: {
263 ULONG Addr1, Addr2;
264 if (Address2->Type == IP_ADDRESS_V4) {
265 Addr1 = DN2H(Address1->Address.IPv4Address);
266 Addr2 = DN2H(Address2->Address.IPv4Address);
267 if (Addr1 < Addr2)
268 return -1;
269 else
270 if (Addr1 == Addr2)
271 return 0;
272 else
273 return 1;
274 } else
275 /* FIXME: Support IPv6 */
276 return -1;
277
278 case IP_ADDRESS_V6:
279 /* FIXME: Support IPv6 */
280 break;
281 }
282 }
283
284 return FALSE;
285}
#define DN2H(dw)
Definition: addrconv.c:21
#define FALSE
Definition: types.h:117
#define IP_ADDRESS_V6
Definition: ip.h:33
UCHAR Type
Definition: ip.h:24
union IP_ADDRESS::@1009 Address
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
uint32_t ULONG
Definition: typedefs.h:59

◆ AddrCountPrefixBits()

UINT AddrCountPrefixBits ( PIP_ADDRESS  Netmask)

Definition at line 64 of file address.c.

64 {
65 UINT Prefix = 0;
66 if( Netmask->Type == IP_ADDRESS_V4 ) {
67 ULONG BitTest = 0x80000000;
68
69 /* The mask has been read in network order. Put it in host order
70 * in order to scan it. */
71
72 ULONG TestMask = IPv4NToHl(Netmask->Address.IPv4Address);
73
74 while ((BitTest & TestMask) != 0) {
75 Prefix++;
76 BitTest >>= 1;
77 }
78 return Prefix;
79 } else {
80 TI_DbgPrint(DEBUG_DATALINK, ("Don't know address type %d\n",
81 Netmask->Type));
82 return 0;
83 }
84}
#define DEBUG_DATALINK
Definition: debug.h:24
ULONG IPv4NToHl(ULONG Address)
Definition: address.c:56
#define BitTest
Definition: interlocked.h:7
unsigned int UINT
Definition: ndis.h:50
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1630

Referenced by FindOnLinkInterface(), and RouterGetRoute().

◆ AddrGetAddress()

NTSTATUS AddrGetAddress ( PTRANSPORT_ADDRESS  AddrList,
PIP_ADDRESS  Address,
PUSHORT  Port 
)

Definition at line 146 of file address.c.

150{
151 PTA_ADDRESS CurAddr;
152 INT i;
153
154 /* We can only use IP addresses. Search the list until we find one */
155 CurAddr = AddrList->Address;
156
157 for (i = 0; i < AddrList->TAAddressCount; i++) {
158 switch (CurAddr->AddressType) {
160 if (CurAddr->AddressLength >= TDI_ADDRESS_LENGTH_IP) {
161 /* This is an IPv4 address */
162 PTDI_ADDRESS_IP ValidAddr = (PTDI_ADDRESS_IP)CurAddr->Address;
163 *Port = ValidAddr->sin_port;
164 Address->Type = CurAddr->AddressType;
165 ValidAddr = (PTDI_ADDRESS_IP)CurAddr->Address;
166 AddrInitIPv4(Address, ValidAddr->in_addr);
167 return STATUS_SUCCESS;
168 }
169 }
170 }
171
173}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG TAAddressCount
Definition: tdi.h:376
int32_t INT
Definition: typedefs.h:58

Referenced by DGReceiveDatagram().

◆ AddrIsEqual()

BOOLEAN AddrIsEqual ( PIP_ADDRESS  Address1,
PIP_ADDRESS  Address2 
)

Definition at line 221 of file address.c.

224{
225 if (Address1->Type != Address2->Type) {
226 DbgPrint("AddrIsEqual: Unequal Address Types\n");
227 return FALSE;
228 }
229
230 switch (Address1->Type) {
231 case IP_ADDRESS_V4:
232 return (Address1->Address.IPv4Address == Address2->Address.IPv4Address);
233
234 case IP_ADDRESS_V6:
235 return (RtlCompareMemory(&Address1->Address, &Address2->Address,
236 sizeof(IPv6_RAW_ADDRESS)) == sizeof(IPv6_RAW_ADDRESS));
237 break;
238
239 default:
240 DbgPrint("AddrIsEqual: Bad address type\n");
241 break;
242 }
243
244 return FALSE;
245}
USHORT IPv6_RAW_ADDRESS[8]
Definition: ip.h:19
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define DbgPrint
Definition: hal.h:12

Referenced by AddrIsBroadcastMatch(), AddrLocateInterface(), AddrReceiveMatch(), ARPReceive(), DGDeliverData(), GetReassemblyInfo(), NBCopyNeighbors(), NBFindOrCreateNeighbor(), NBLocateNeighbor(), NBResetNeighborTimeout(), RouterCreateRoute(), and RouterRemoveRoute().

◆ AddrIsEqualIPv4()

BOOLEAN AddrIsEqualIPv4 ( PIP_ADDRESS  Address1,
IPv4_RAW_ADDRESS  Address2 
)

Definition at line 296 of file address.c.

299{
300 if (Address1->Type == IP_ADDRESS_V4)
301 return (Address1->Address.IPv4Address == Address2);
302
303 return FALSE;
304}

◆ AddrIsUnspecified()

BOOLEAN AddrIsUnspecified ( PIP_ADDRESS  Address)

Definition at line 113 of file address.c.

122{
123 switch (Address->Type) {
124 case IP_ADDRESS_V4:
125 return (Address->Address.IPv4Address == 0 ||
126 Address->Address.IPv4Address == 0xFFFFFFFF);
127
128 case IP_ADDRESS_V6:
129 /* FIXME: IPv6 is not supported */
130 default:
131 return FALSE;
132 }
133}

Referenced by AddrIsBroadcastMatch(), AddrReceiveMatch(), DGDeliverData(), DispTdiQueryIpHwAddress(), FileOpenAddress(), FindOnLinkInterface(), GetDefaultInterface(), NBFindOrCreateNeighbor(), RawIPSendDatagram(), ReadIpConfiguration(), TCPConnect(), and UDPSendDatagram().

◆ AddrLocateInterface()

PIP_INTERFACE AddrLocateInterface ( PIP_ADDRESS  MatchAddress)

Definition at line 89 of file interface.c.

91{
93 PIP_INTERFACE RetIF = NULL;
94 IF_LIST_ITER(CurrentIF);
95
97
98 ForEachInterface(CurrentIF) {
99 if( AddrIsEqual( &CurrentIF->Unicast, MatchAddress ) ||
100 AddrIsEqual( &CurrentIF->Broadcast, MatchAddress ) ) {
101 RetIF = CurrentIF;
102 break;
103 }
104 } EndFor(CurrentIF);
105
107
108 return RetIF;
109}
BOOLEAN AddrIsEqual(PIP_ADDRESS Address1, PIP_ADDRESS Address2)
Definition: address.c:221
#define NULL
Definition: types.h:112
KSPIN_LOCK InterfaceListLock
Definition: ip.c:18
VOID TcpipReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL Irql)
Definition: lock.c:26
VOID TcpipAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL Irql)
Definition: lock.c:18
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define ForEachInterface(n)
Definition: tilists.h:9
#define EndFor(n)
Definition: tilists.h:20
#define IF_LIST_ITER(n)
Definition: tilists.h:5
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by DispTdiQueryIpHwAddress(), and FileOpenAddress().

◆ AddrSearchFirst()

PADDRESS_FILE AddrSearchFirst ( PIP_ADDRESS  Address,
USHORT  Port,
USHORT  Protocol,
PAF_SEARCH  SearchContext 
)

Definition at line 38 of file fileobjs.c.

43{
45
46 SearchContext->Address = Address;
47 SearchContext->Port = Port;
48 SearchContext->Protocol = Protocol;
49
51
52 SearchContext->Next = AddressFileListHead.Flink;
53
55 ReferenceObject(CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry));
56
58
59 return AddrSearchNext(SearchContext);
60}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
KSPIN_LOCK AddressFileListLock
Definition: fileobjs.c:22
PADDRESS_FILE AddrSearchNext(PAF_SEARCH SearchContext)
Definition: fileobjs.c:231
LIST_ENTRY AddressFileListHead
Definition: fileobjs.c:21
PLIST_ENTRY Next
Definition: titypes.h:184
USHORT Port
Definition: titypes.h:186
PIP_ADDRESS Address
Definition: titypes.h:185
USHORT Protocol
Definition: titypes.h:187
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ReferenceObject(Object)
Definition: titypes.h:14
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by RawIpReceive(), and UDPReceive().

◆ AddrSearchNext()

PADDRESS_FILE AddrSearchNext ( PAF_SEARCH  SearchContext)

Definition at line 231 of file fileobjs.c.

233{
234 PLIST_ENTRY CurrentEntry;
235 PIP_ADDRESS IPAddress;
237 PADDRESS_FILE Current = NULL;
239 PADDRESS_FILE StartingAddrFile;
240
242
243 if (SearchContext->Next == &AddressFileListHead)
244 {
246 return NULL;
247 }
248
249 /* Save this pointer so we can dereference it later */
250 StartingAddrFile = CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry);
251
252 CurrentEntry = SearchContext->Next;
253
254 while (CurrentEntry != &AddressFileListHead) {
255 Current = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry);
256
257 IPAddress = &Current->Address;
258
259 TI_DbgPrint(DEBUG_ADDRFILE, ("Comparing: ((%d, %d, %s), (%d, %d, %s)).\n",
260 WN2H(Current->Port),
261 Current->Protocol,
262 A2S(IPAddress),
263 WN2H(SearchContext->Port),
264 SearchContext->Protocol,
265 A2S(SearchContext->Address)));
266
267 /* See if this address matches the search criteria */
268 if ((Current->Port == SearchContext->Port) &&
269 (Current->Protocol == SearchContext->Protocol) &&
270 (AddrReceiveMatch(IPAddress, SearchContext->Address))) {
271 /* We've found a match */
272 Found = TRUE;
273 break;
274 }
275 CurrentEntry = CurrentEntry->Flink;
276 }
277
278 if (Found)
279 {
280 SearchContext->Next = CurrentEntry->Flink;
281
282 if (SearchContext->Next != &AddressFileListHead)
283 {
284 /* Reference the next address file to prevent the link from disappearing behind our back */
285 ReferenceObject(CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry));
286 }
287
288 /* Reference the returned address file before dereferencing the starting
289 * address file because it may be that Current == StartingAddrFile */
290 ReferenceObject(Current);
291 }
292 else
293 Current = NULL;
294
295 DereferenceObject(StartingAddrFile);
296
298
299 return Current;
300}
unsigned char BOOLEAN
#define WN2H(w)
Definition: addrconv.c:35
return Found
Definition: dirsup.c:1270
#define TRUE
Definition: types.h:120
#define DEBUG_ADDRFILE
Definition: debug.h:23
PCHAR A2S(PIP_ADDRESS Address)
Definition: address.c:17
BOOLEAN AddrReceiveMatch(PIP_ADDRESS LocalAddress, PIP_ADDRESS RemoteAddress)
Definition: fileobjs.c:77
Definition: ip.h:23
USHORT Port
Definition: titypes.h:120
IP_ADDRESS Address
Definition: titypes.h:117
USHORT Protocol
Definition: titypes.h:119
Definition: typedefs.h:120
#define DereferenceObject(Object)
Definition: titypes.h:24

Referenced by AddrSearchFirst(), RawIpReceive(), and UDPReceive().

◆ AddrWidenAddress()

VOID AddrWidenAddress ( PIP_ADDRESS  Network,
PIP_ADDRESS  Source,
PIP_ADDRESS  Netmask 
)

Definition at line 86 of file address.c.

87 {
88 if( Netmask->Type == IP_ADDRESS_V4 ) {
89 Network->Type = Netmask->Type;
90 Network->Address.IPv4Address =
91 Source->Address.IPv4Address & Netmask->Address.IPv4Address;
92 } else {
93 TI_DbgPrint(DEBUG_DATALINK, ("Don't know address type %d\n",
94 Netmask->Type));
95 *Network = *Source;
96 }
97}
@ Network
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169

Referenced by IPAddInterfaceRoute(), and IPRemoveInterfaceRoute().

◆ inet_addr()

unsigned long NTAPI inet_addr ( const char AddrString)

Definition at line 307 of file address.c.

315{
316 ULONG Octets[4] = {0,0,0,0};
317 ULONG i = 0;
318
319 if(!AddrString)
320 return -1;
321
322 while(*AddrString)
323 {
324 CHAR c = *AddrString;
325 AddrString++;
326
327 if(c == '.')
328 {
329 i++;
330 continue;
331 }
332
333 if(c < '0' || c > '9')
334 return -1;
335
336 Octets[i] *= 10;
337 Octets[i] += (c - '0');
338
339 if(Octets[i] > 255)
340 return -1;
341 }
342
343 return (Octets[3] << 24) + (Octets[2] << 16) + (Octets[1] << 8) + Octets[0];
344}
const GLubyte * c
Definition: glext.h:8905
char CHAR
Definition: xmlstorage.h:175

◆ IPAddressFree()

VOID IPAddressFree ( PVOID  Object)

Definition at line 99 of file address.c.

108{
110}
#define IP_ADDRESS_TAG
Definition: tags.h:18
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object

◆ IPv4NToHl()

ULONG IPv4NToHl ( ULONG  Address)

Definition at line 56 of file address.c.

56 {
57 return
58 ((Address & 0xff) << 24) |
59 ((Address & 0xff00) << 8) |
60 ((Address >> 8) & 0xff00) |
61 ((Address >> 24) & 0xff);
62}

Referenced by AddrCountPrefixBits().