ReactOS  0.4.15-dev-3294-ge98684e
leases.c File Reference
#include <headers.h>
#include <datatypes.h>
#include <display.h>
#include <options.h>
#include <leases.h>
#include <utils.h>
Include dependency graph for leases.c:

Go to the source code of this file.

Functions

int init_leases_list ()
 
int find_lease (DHCPLEASE *dhcpl, u32b xid, u8b chaddr[])
 
int confirm_lease (DHCPLEASE *dhcpl, u32b xid)
 
int release_lease (DHCPLEASE *dhcpl, u32b xid, u8b chaddr[16])
 

Function Documentation

◆ confirm_lease()

int confirm_lease ( DHCPLEASE dhcpl,
u32b  xid 
)

Definition at line 183 of file leases.c.

184 {
185  int result = -1;
186  DHCPLIST *temp;
187 
188  for( temp = list; temp; temp=temp->next )
189  if( temp->xid == xid )
190  {
191  dhcpl->ip = temp->data.ip;
192  dhcpl->router = temp->data.router;
193  dhcpl->mask = temp->data.mask;
194  dhcpl->lease = temp->data.lease;
195  dhcpl->siaddr = temp->data.siaddr;
196  temp->available = BUSY;
197  temp->ltime = temp->data.lease;
198  result = 0;
199  return result;
200  }
201  return result;
202 }
u32b ip
Definition: datatypes.h:36
GLuint64EXT * result
Definition: glext.h:11304
LONGLONG xid
Definition: nfs41_driver.c:106
u32b mask
Definition: datatypes.h:38
u32b lease
Definition: datatypes.h:39
u32b siaddr
Definition: datatypes.h:40
u32b router
Definition: datatypes.h:37
Definition: _list.h:228
static calc_node_t temp
Definition: rpn_ieee.c:38
Definition: user_lib.h:47

Referenced by process_dhcp_packet().

◆ find_lease()

int find_lease ( DHCPLEASE dhcpl,
u32b  xid,
u8b  chaddr[] 
)

Definition at line 137 of file leases.c.

138 {
139  int result = -2;
140  DHCPLIST *temp;
141 
142  if( !dhcpl )
143  return -1;
144 
145  for( temp = list; temp; temp=temp->next )
146  if( !maccmp( temp->chaddr, chaddr ) )
147  release_lease( dhcpl, xid, chaddr);
148 
149  for( temp = list; temp; temp=temp->next )
150  if( ( !maccmp( temp->chaddr, chaddr )) && ( temp->type == STATIC ))
151  {
152  dhcpl->ip = temp->data.ip;
153  dhcpl->router = temp->data.router;
154  dhcpl->mask = temp->data.mask;
155  dhcpl->lease = temp->data.lease;
156  dhcpl->siaddr = temp->data.siaddr;
157  fprintf( stdout, "Assigning Static IP! \n");
158  temp->available = PROCESSING;
159  temp->xid = xid;
160  temp->ltime = MAX_PROCESS_TIME;
161  maccpy( temp->chaddr, chaddr);
162  result = 0;
163  return result;
164  }
165  else if( ( temp->available & FREE ) && ( temp->type == DYNAMIC ))
166  {
167  dhcpl->ip = temp->data.ip;
168  dhcpl->router = temp->data.router;
169  dhcpl->mask = temp->data.mask;
170  dhcpl->lease = temp->data.lease;
171  dhcpl->siaddr = temp->data.siaddr;
172  fprintf( stdout, "Assigning Dynamic IP! \n");
173  temp->available = PROCESSING;
174  temp->xid = xid;
175  temp->ltime = MAX_PROCESS_TIME;
176  maccpy( temp->chaddr, chaddr);
177  result = 0;
178  return result;
179  }
180  return result;
181 }
u32b ip
Definition: datatypes.h:36
int maccpy(u8b *, u8b *)
GLuint64EXT * result
Definition: glext.h:11304
LONGLONG xid
Definition: nfs41_driver.c:106
u32b mask
Definition: datatypes.h:38
FILE * stdout
u32b lease
Definition: datatypes.h:39
#define DYNAMIC
Definition: options.h:112
#define PROCESSING
Definition: options.h:109
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
u32b siaddr
Definition: datatypes.h:40
u32b router
Definition: datatypes.h:37
#define FREE(ptr, size)
Definition: auth_des.c:64
Definition: _list.h:228
#define STATIC
Definition: options.h:116
int release_lease(DHCPLEASE *dhcpl, u32b xid, u8b chaddr[16])
Definition: leases.c:204
static calc_node_t temp
Definition: rpn_ieee.c:38
#define MAX_PROCESS_TIME
Definition: options.h:10
int maccmp(u8b *, u8b *)

◆ init_leases_list()

int init_leases_list ( )

Definition at line 8 of file leases.c.

9 {
10  DHCPLIST *temp;
11  int i, j;
12  u8b chaddr[16];
13  FILE *config;
14  char line[80];
15  char textsubnet[16];
16  char textlease[5];
17  char textrouter[16];
18  char textmask[16];
19  char textlowrange[4], texthighrange[4];
20  char textserver[16];
21  u8b ip0, ip1, ip2, ip3;
22  u8b lowrange, highrange;
23  u8b textmac[17], textip[16];
24  u32b lease;
25 
26  /* Be nice variables and behave yourselves */
27 
28  for( j = 0; j < 16; j++ )
29  {
30  chaddr[j] = 0;
31  textsubnet[j] = 0;
32  textrouter[j] = 0;
33  textmask[j] = 0;
34  textip[j] = 0;
35  textmac[j] = 0;
36  }
37 
38  textlease[0] = 0;
39  textlowrange[0] = 0;
40  texthighrange[0] = 0;
41 
42  /* Now we can read our configuration file */
43 
44  config = fopen( "dhcp.conf", "r" );
45  if( !config )
46  {
47  perror("Reading config files");
48  exit( 0 );
49  }
50 
51  /* We _DO_ need a better parser */
52  list = (DHCPLIST *)malloc( sizeof( DHCPLIST ));
53  temp = list;
54  temp->back = NULL;
55 
56  while( (!feof( config )) && ( line ))
57  {
58  fscanf( config, "%s", line);
59  if( !strcmp( line, "subnet" ))
60  /* Read subnet parameters */
61  fscanf( config, "%s", textsubnet );
62 
63  if( !strcmp( line, "lease" ))
64  /* read lease parameters */
65  fscanf( config, "%s", textlease );
66 
67  if( !strcmp( line, "router" ))
68  fscanf( config, "%s", textrouter );
69 
70  if( !strcmp( line, "mask" ))
71  fscanf( config, "%s", textmask );
72 
73  if( !strcmp( line, "range" ))
74  fscanf( config, "%s %s", textlowrange, texthighrange );
75  if( !strcmp( line, "server" ))
76  fscanf( config, "%s", textserver );
77  if( !strcmp( line, "host" ))
78  {
79  /* Host Specific Configuration */
80  fscanf( config, "%s %s", textmac, textip );
81  str2mac( textmac, temp->chaddr );
82  temp->type = STATIC;
83  temp->data.ip = inet_addr( textip );
84  temp->next = (DHCPLIST *)malloc( sizeof( DHCPLIST ));
85  temp->next->back = temp;
86  temp = temp->next;
87  temp->next =NULL;
88  }
89  }
90  fclose( config );
91 
92  lowrange = (u8b)atoi( textlowrange );
93  highrange = (u8b)atoi( texthighrange );
94  lease = (u32b)atoi( textlease );
95 
96  /* Creating Static IP */
97 
98  for( temp = list; temp->next; temp = temp->next )
99  {
100  temp->available = FREE;
101  temp->xid = 0;
102  temp->data.router = inet_addr( textrouter );
103  temp->data.mask = inet_addr( textmask );
104  temp->data.lease = lease;
105  temp->data.siaddr = inet_addr( textserver );
106  }
107 
108  /* Creating Dynamic IP */
109 
110  for( i = lowrange; i < (highrange + 1); i++ )
111  {
112  temp->available = FREE;
113  temp->xid = 0;
114  temp->type = DYNAMIC;
115  maccpy( temp->chaddr, chaddr );
116  split_ip( textsubnet, &ip0, 0 );
117  split_ip( textsubnet, &ip1, 1 );
118  split_ip( textsubnet, &ip2, 2 );
119  temp->data.ip = i;
120  temp->data.ip = temp->data.ip << 8;
121  temp->data.ip += ip2;
122  temp->data.ip = temp->data.ip << 8;
123  temp->data.ip += ip1;
124  temp->data.ip = temp->data.ip << 8;
125  temp->data.ip += ip0;
126  temp->data.router = inet_addr( textrouter );
127  temp->data.mask = inet_addr( textmask );
128  temp->data.lease = lease;
129  temp->data.siaddr = inet_addr( textserver );
130  temp->next = (DHCPLIST *)malloc( sizeof( DHCPLIST ));
131  temp->next->back = temp;
132  temp = temp->next;
133  }
134  return 0;
135 }
_Check_return_ _CRTIMP int __cdecl fscanf(_Inout_ FILE *_File, _In_z_ _Scanf_format_string_ const char *_Format,...)
int maccpy(u8b *, u8b *)
struct config_s config
#define inet_addr(cp)
Definition: inet.h:98
int split_ip(char *, u8b *, int)
Definition: iputils.c:6
#define DYNAMIC
Definition: options.h:112
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
Definition: parser.c:48
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 GLint GLint j
Definition: glfuncs.h:250
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
int str2mac(u8b from[17], u8b to[16])
Definition: macutils.c:24
#define FREE(ptr, size)
Definition: auth_des.c:64
Definition: _list.h:228
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define STATIC
Definition: options.h:116
IN PCTCH line
Definition: pager.h:36
unsigned int u32b
Definition: datatypes.h:6
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 calc_node_t temp
Definition: rpn_ieee.c:38
#define list
Definition: rosglue.h:35
#define NULL
Definition: types.h:112
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
unsigned char u8b
Definition: datatypes.h:4
void exit(int exitcode)
Definition: _exit.c:33

Referenced by main().

◆ release_lease()

int release_lease ( DHCPLEASE dhcpl,
u32b  xid,
u8b  chaddr[16] 
)

Definition at line 204 of file leases.c.

205 {
206  int result = -1, i;
207  DHCPLIST *temp;
208  u8b nchaddr[16];
209 
210  for( i = 0; i < 16; i++ )
211  nchaddr[i] = 0;
212 
213  if( !dhcpl )
214  return -1;
215 
216  for( temp = list; temp; temp=temp->next )
217  if( !maccmp( temp->chaddr, chaddr ) )
218  {
219  /* We found the address */
220  result = 0;
221  fprintf( stdout, "Deleting %X::%X::%X::%X::%X::%X \n", temp->chaddr[0], temp->chaddr[1], temp->chaddr[2], temp->chaddr[3], temp->chaddr[4], temp->chaddr[5] );
222  temp->available = FREE;
223  temp->xid = 0;
224  /* maccpy( temp->chaddr, nchaddr ); */
225  } else {
226  /* No such address */
227  result = -1;
228  }
229 
230  return result;
231 }
GLuint64EXT * result
Definition: glext.h:11304
FILE * stdout
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define FREE(ptr, size)
Definition: auth_des.c:64
Definition: _list.h:228
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 calc_node_t temp
Definition: rpn_ieee.c:38
unsigned char u8b
Definition: datatypes.h:4
int maccmp(u8b *, u8b *)

Referenced by find_lease().