ReactOS  0.4.14-dev-49-gfb4591c
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 }
signed char * PCHAR
Definition: retypes.h:7
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
int sprintf(char *out, const char *fmt,...)
Definition: utprint.c:762
int32_t INT
Definition: typedefs.h:56
#define IP_ADDRESS_V4
Definition: ip.h:32
int ip[4]
Definition: rtl.c:1176
static WCHAR Address[46]
Definition: ping.c:68
#define IP_ADDRESS_V6
Definition: ip.h:33
Definition: dhcpd.h:61
#define DN2H(dw)
Definition: addrconv.c:21
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define MIN_TRACE
Definition: debug.h:14
GLfloat GLfloat p
Definition: glext.h:8902
CHAR A2SStr[128]
Definition: address.c:15

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));
195  return STATUS_INVALID_ADDRESS;
196  }
197  if (TdiAddress->AddressLength < TDI_ADDRESS_LENGTH_IP) {
199  (MID_TRACE,("AddressLength %x, Not valid (expected %x)\n",
200  TdiAddress->AddressLength, TDI_ADDRESS_LENGTH_IP));
201  return STATUS_INVALID_ADDRESS;
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 TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
CPPORT Port[4]
Definition: headless.c:34
#define MID_TRACE
Definition: debug.h:15
UCHAR Address[1]
Definition: tdi.h:340
static WCHAR Address[46]
Definition: ping.c:68
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
#define AddrInitIPv4(IPAddress, RawAddress)
Definition: address.h:16
ULONG in_addr
Definition: tdi.h:409
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
USHORT AddressType
Definition: tdi.h:339
USHORT sin_port
Definition: tdi.h:408
TA_ADDRESS Address[1]
Definition: tdi.h:377
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:543
USHORT AddressLength
Definition: tdi.h:338
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
return STATUS_SUCCESS
Definition: btrfs.c:2966

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 }
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
#define IP_ADDRESS_V4
Definition: ip.h:32
union IP_ADDRESS::@975 Address
#define IP_ADDRESS_V6
Definition: ip.h:33
UCHAR Type
Definition: ip.h:24
#define DN2H(dw)
Definition: addrconv.c:21
unsigned int ULONG
Definition: retypes.h:1

◆ 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) == BitTest ) {
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 TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
ULONG IPv4NToHl(ULONG Address)
Definition: address.c:56
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1631
#define BitTest
Definition: interlocked.h:7
#define DEBUG_DATALINK
Definition: debug.h:24
#define IP_ADDRESS_V4
Definition: ip.h:32
union IP_ADDRESS::@975 Address
UCHAR Type
Definition: ip.h:24
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1

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) {
159  case TDI_ADDRESS_TYPE_IP:
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 
172  return STATUS_INVALID_ADDRESS;
173 }
CPPORT Port[4]
Definition: headless.c:34
UCHAR Address[1]
Definition: tdi.h:340
int32_t INT
Definition: typedefs.h:56
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
static WCHAR Address[46]
Definition: ping.c:68
struct _TDI_ADDRESS_IP * PTDI_ADDRESS_IP
#define AddrInitIPv4(IPAddress, RawAddress)
Definition: address.h:16
ULONG in_addr
Definition: tdi.h:409
LONG TAAddressCount
Definition: tdi.h:376
#define TDI_ADDRESS_TYPE_IP
Definition: tdi.h:345
USHORT AddressType
Definition: tdi.h:339
USHORT sin_port
Definition: tdi.h:408
TA_ADDRESS Address[1]
Definition: tdi.h:377
#define STATUS_INVALID_ADDRESS
Definition: ntstatus.h:543
USHORT AddressLength
Definition: tdi.h:338
#define TDI_ADDRESS_LENGTH_IP
Definition: tdi.h:413
return STATUS_SUCCESS
Definition: btrfs.c:2966

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 }
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
#define DbgPrint
Definition: loader.c:25
#define IP_ADDRESS_V4
Definition: ip.h:32
union IP_ADDRESS::@975 Address
#define IP_ADDRESS_V6
Definition: ip.h:33
UCHAR Type
Definition: ip.h:24
USHORT IPv6_RAW_ADDRESS[8]
Definition: ip.h:19
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

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 }
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
#define IP_ADDRESS_V4
Definition: ip.h:32
union IP_ADDRESS::@975 Address
UCHAR Type
Definition: ip.h:24

◆ 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 }
#define IP_ADDRESS_V4
Definition: ip.h:32
static WCHAR Address[46]
Definition: ping.c:68
#define IP_ADDRESS_V6
Definition: ip.h:33

Referenced by AddrIsBroadcastMatch(), AddrReceiveMatch(), DGDeliverData(), DispTdiQueryIpHwAddress(), FileOpenAddress(), FindOnLinkInterface(), GetDefaultInterface(), ICMPSendDatagram(), 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 }
#define TI_DbgPrint(_t_, _x_)
Definition: debug.h:45
IPv4_RAW_ADDRESS IPv4Address
Definition: ip.h:26
#define DEBUG_DATALINK
Definition: debug.h:24
#define IP_ADDRESS_V4
Definition: ip.h:32
union IP_ADDRESS::@975 Address
UCHAR Type
Definition: ip.h:24
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

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 }
char CHAR
Definition: xmlstorage.h:175
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
const GLubyte * c
Definition: glext.h:8905
unsigned int ULONG
Definition: retypes.h:1

◆ IPAddressFree()

VOID IPAddressFree ( PVOID  Object)

Definition at line 99 of file address.c.

108 {
110 }
#define IP_ADDRESS_TAG
Definition: tags.h:18
static IUnknown Object
Definition: main.c:512
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

◆ 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 }
static WCHAR Address[46]
Definition: ping.c:68

Referenced by AddrCountPrefixBits().

◆ sprintf()

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

Definition at line 762 of file utprint.c.

766 {
767  va_list Args;
768  int Length;
769 
770 
771  va_start (Args, Format);
773  va_end (Args);
774 
775  return (Length);
776 }
int vsnprintf(char *String, ACPI_SIZE Size, const char *Format, va_list Args)
Definition: utprint.c:433
static WCHAR String[]
Definition: stringtable.c:55
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
char ** Args
Definition: acdebug.h:343
#define ACPI_UINT32_MAX
Definition: actypes.h:66
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define va_start(ap, A)
Definition: acmsvcex.h:91

Referenced by A2S(), and START_TEST().

Variable Documentation

◆ A2SStr

CHAR A2SStr[128]

Definition at line 15 of file address.c.

Referenced by A2S().