ReactOS 0.4.16-dev-297-gc569aee
address.c File Reference
#include "precomp.h"
Include dependency graph for address.c:

Go to the source code of this file.

Functions

int sprintf (char *out, const char *fmt,...)
 
PCHAR A2S (PIP_ADDRESS Address)
 
ULONG IPv4NToHl (ULONG Address)
 
UINT AddrCountPrefixBits (PIP_ADDRESS Netmask)
 
VOID AddrWidenAddress (PIP_ADDRESS Network, PIP_ADDRESS Source, PIP_ADDRESS Netmask)
 
VOID IPAddressFree (PVOID Object)
 
BOOLEAN AddrIsUnspecified (PIP_ADDRESS Address)
 
NTSTATUS AddrGetAddress (PTRANSPORT_ADDRESS AddrList, PIP_ADDRESS Address, PUSHORT Port)
 
NTSTATUS AddrBuildAddress (PTRANSPORT_ADDRESS TaAddress, 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)
 
unsigned long NTAPI inet_addr (const char *AddrString)
 

Variables

CHAR A2SStr [128]
 

Function Documentation

◆ A2S()

PCHAR A2S ( PIP_ADDRESS  Address)

Definition at line 17 of file address.c.

26{
27 ULONG ip;
28 PCHAR p;
29
30 p = A2SStr;
31
32 if (!Address) {
33 TI_DbgPrint(MIN_TRACE, ("NULL address given.\n"));
34 strcpy(p, "(NULL)");
35 return p;
36 }
37
38 switch (Address->Type) {
39 case IP_ADDRESS_V4:
40 ip = DN2H(Address->Address.IPv4Address);
41 sprintf(p, "%d.%d.%d.%d",
42 (INT)((ip >> 24) & 0xFF),
43 (INT)((ip >> 16) & 0xFF),
44 (INT)((ip >> 8) & 0xFF),
45 (INT)(ip & 0xFF));
46 break;
47
48 case IP_ADDRESS_V6:
49 /* FIXME: IPv6 is not supported */
50 strcpy(p, "(IPv6 address not supported)");
51 break;
52 }
53 return p;
54}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define DN2H(dw)
Definition: addrconv.c:21
#define MIN_TRACE
Definition: debug.h:14
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
#define IP_ADDRESS_V6
Definition: ip.h:33
#define IP_ADDRESS_V4
Definition: ip.h:32
CHAR A2SStr[128]
Definition: address.c:15
GLfloat GLfloat p
Definition: glext.h:8902
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static WCHAR Address[46]
Definition: ping.c:68
Definition: dhcpd.h:62
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51

Referenced by AddrSearchNext(), BuildRawIpPacket(), BuildUDPPacket(), FileOpenAddress(), FindOnLinkInterface(), HasPrefix(), InfoTdiSetRoute(), IPRemoveInterfaceRoute(), LogActiveObjects(), NBFindOrCreateNeighbor(), NBResetNeighborTimeout(), RouteGetRouteToDestination(), RouterAddRoute(), RouterCreateRoute(), RouterDumpRoutes(), RouterGetRoute(), and RouterRemoveRoute().

◆ AddrBuildAddress()

NTSTATUS AddrBuildAddress ( PTRANSPORT_ADDRESS  TaAddress,
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
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 FALSE
Definition: types.h:117
UCHAR Type
Definition: ip.h:24
union IP_ADDRESS::@1014 Address
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26

◆ 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:1647

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

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().

◆ 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().

◆ sprintf()

int sprintf ( char out,
const char fmt,
  ... 
)

Definition at line 768 of file utprint.c.

772{
774 int Length;
775
776
779 va_end (Args);
780
781 return (Length);
782}
char ** Args
Definition: acdebug.h:353
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define ACPI_UINT32_MAX
Definition: actypes.h:66
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define vsnprintf
Definition: tif_win32.c:406
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Variable Documentation

◆ A2SStr

CHAR A2SStr[128]

Definition at line 15 of file address.c.

Referenced by A2S().