ReactOS 0.4.16-dev-1946-g52006dd
dhclient.c File Reference
#include <rosdhcp.h>
Include dependency graph for dhclient.c:

Go to the source code of this file.

Macros

#define PERIOD   0x2e
 
#define hyphenchar(c)   ((c) == 0x2d)
 
#define bslashchar(c)   ((c) == 0x5c)
 
#define periodchar(c)   ((c) == PERIOD)
 
#define asterchar(c)   ((c) == 0x2a)
 
#define alphachar(c)
 
#define digitchar(c)   ((c) >= 0x30 && (c) <= 0x39)
 
#define borderchar(c)   (alphachar(c) || digitchar(c))
 
#define middlechar(c)   (borderchar(c) || hyphenchar(c))
 
#define domainchar(c)   ((c) > 0x20 && (c) < 0x7f)
 
#define ASSERT_STATE(state_is, state_shouldbe)   {}
 
#define TIME_MAX   2147483647
 
#define ADVANCE(x, n)   (x += ROUNDUP((n)->sa_len))
 

Functions

void usage (void)
 
int check_option (struct client_lease *l, int option)
 
int ipv4addrs (char *buf)
 
int res_hnok (const char *dn)
 
charoption_as_string (unsigned int code, unsigned char *data, int len)
 
int fork_privchld (int, int)
 
int check_arp (struct interface_info *ip, struct client_lease *lp)
 
int init_client (void)
 
void stop_client (void)
 
void state_reboot (void *ipp)
 
void state_init (void *ipp)
 
void state_release (void *ipp)
 
void state_selecting (void *ipp)
 
void dhcpack (struct packet *packet)
 
void set_name_servers (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void unset_name_servers (PDHCP_ADAPTER Adapter)
 
void set_domain (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void unset_domain (PDHCP_ADAPTER Adapter)
 
void setup_adapter (PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
 
void reset_adapter (PDHCP_ADAPTER Adapter)
 
void bind_lease (struct interface_info *ip)
 
void unbind_lease (struct interface_info *ip)
 
void state_bound (void *ipp)
 
void bootp (struct packet *packet)
 
void dhcp (struct packet *packet)
 
void dhcpoffer (struct packet *packet)
 
struct client_leasepacket_to_lease (struct packet *packet)
 
void dhcpnak (struct packet *packet)
 
void send_discover (void *ipp)
 
void state_panic (void *ipp)
 
void send_request (void *ipp)
 
void send_decline (void *ipp)
 
void send_release (void *ipp)
 
void make_discover (struct interface_info *ip, struct client_lease *lease)
 
void make_request (struct interface_info *ip, struct client_lease *lease)
 
void make_decline (struct interface_info *ip, struct client_lease *lease)
 
void make_release (struct interface_info *ip, struct client_lease *lease)
 
void free_client_lease (struct client_lease *lease)
 
void rewrite_client_leases (struct interface_info *ifi)
 
void write_client_lease (struct interface_info *ip, struct client_lease *lease, int rewrite)
 
void priv_script_init (struct interface_info *ip, char *reason, char *medium)
 
void priv_script_write_params (struct interface_info *ip, char *prefix, struct client_lease *lease)
 
int dhcp_option_ev_name (char *buf, size_t buflen, struct dhcp_option *option)
 

Variables

unsigned long debug_trace_level = 0
 
charpath_dhclient_conf = _PATH_DHCLIENT_CONF
 
charpath_dhclient_db = NULL
 
int log_perror = 1
 
int privfd
 
struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }
 
struct in_addr inaddr_any
 
struct sockaddr_in sockaddr_broadcast
 
int log_priority
 
int no_daemon
 
int unknown_ok = 1
 
int routefd
 
time_t scripttime
 
FILEleaseFile
 

Macro Definition Documentation

◆ ADVANCE

#define ADVANCE (   x,
  n 
)    (x += ROUNDUP((n)->sa_len))

Definition at line 105 of file dhclient.c.

◆ alphachar

#define alphachar (   c)
Value:
(((c) >= 0x41 && (c) <= 0x5a) || \
((c) >= 0x61 && (c) <= 0x7a))
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80

Definition at line 63 of file dhclient.c.

◆ ASSERT_STATE

#define ASSERT_STATE (   state_is,
  state_shouldbe 
)    {}

Definition at line 88 of file dhclient.c.

◆ asterchar

#define asterchar (   c)    ((c) == 0x2a)

Definition at line 62 of file dhclient.c.

◆ borderchar

#define borderchar (   c)    (alphachar(c) || digitchar(c))

Definition at line 67 of file dhclient.c.

◆ bslashchar

#define bslashchar (   c)    ((c) == 0x5c)

Definition at line 60 of file dhclient.c.

◆ digitchar

#define digitchar (   c)    ((c) >= 0x30 && (c) <= 0x39)

Definition at line 65 of file dhclient.c.

◆ domainchar

#define domainchar (   c)    ((c) > 0x20 && (c) < 0x7f)

Definition at line 69 of file dhclient.c.

◆ hyphenchar

#define hyphenchar (   c)    ((c) == 0x2d)

Definition at line 59 of file dhclient.c.

◆ middlechar

#define middlechar (   c)    (borderchar(c) || hyphenchar(c))

Definition at line 68 of file dhclient.c.

◆ PERIOD

#define PERIOD   0x2e

Definition at line 58 of file dhclient.c.

◆ periodchar

#define periodchar (   c)    ((c) == PERIOD)

Definition at line 61 of file dhclient.c.

◆ TIME_MAX

#define TIME_MAX   2147483647

Definition at line 90 of file dhclient.c.

Function Documentation

◆ bind_lease()

void bind_lease ( struct interface_info ip)

Definition at line 703 of file dhclient.c.

704{
705 PDHCP_ADAPTER Adapter;
706 struct client_lease *new_lease = ip->client->new;
708
709 time(&cur_time);
710
711 /* Remember the medium. */
712 ip->client->new->medium = ip->client->medium;
713
714 /* Replace the old active lease with the new one. */
715 if (ip->client->active)
716 free_client_lease(ip->client->active);
717 ip->client->active = ip->client->new;
718 ip->client->new = NULL;
719
720 /* Set up a timeout to start the renewal process. */
721 /* Timeout of zero means no timeout (some implementations seem to use
722 * one day).
723 */
724 if( ip->client->active->renewal - cur_time )
725 add_timeout(ip->client->active->renewal, state_bound, ip);
726
727 note("bound to %s -- renewal in %ld seconds.",
728 piaddr(ip->client->active->address),
729 (long int)(ip->client->active->renewal - cur_time));
730
731 ip->client->state = S_BOUND;
732
733 Adapter = AdapterFindInfo( ip );
734
735 if( Adapter ) setup_adapter( Adapter, new_lease );
736 else {
737 warning("Could not find adapter for info %p\n", ip);
738 return;
739 }
740 set_name_servers( Adapter, new_lease );
741 set_domain( Adapter, new_lease );
742}
PDHCP_ADAPTER AdapterFindInfo(struct interface_info *ip)
Definition: adapter.c:530
void add_timeout(time_t when, void(*where)(void *), void *what)
Definition: dispatch.c:253
int note(char *format,...)
Definition: util.c:12
char * piaddr(struct iaddr addr)
Definition: util.c:6
void free_client_lease(struct client_lease *lease)
Definition: dhclient.c:1757
void state_bound(void *ipp)
Definition: dhclient.c:773
void setup_adapter(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:561
void set_domain(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:483
void set_name_servers(PDHCP_ADAPTER Adapter, struct client_lease *new_lease)
Definition: dhclient.c:421
time_t cur_time
@ S_BOUND
Definition: dhcpd.h:176
#define NULL
Definition: types.h:112
__kernel_time_t time_t
Definition: linux.h:252
__u16 time
Definition: mkdosfs.c:8
#define warning(s)
Definition: debug.h:83
Definition: dhcpd.h:62

Referenced by dhcpack(), and state_selecting().

◆ bootp()

void bootp ( struct packet packet)

Definition at line 799 of file dhclient.c.

800{
801 struct iaddrlist *ap;
802
803 if (packet->raw->op != BOOTREPLY)
804 return;
805
806 /* If there's a reject list, make sure this packet's sender isn't
807 on it. */
808 for (ap = packet->interface->client->config->reject_list;
809 ap; ap = ap->next) {
810 if (addr_eq(packet->client_addr, ap->addr)) {
811 note("BOOTREPLY from %s rejected.", piaddr(ap->addr));
812 return;
813 }
814 }
816}
int addr_eq(struct iaddr a, struct iaddr b)
Definition: util.c:100
#define BOOTREPLY
Definition: dhcp.h:79
void dhcpoffer(struct packet *packet)
Definition: dhclient.c:855
Definition: dhcpd.h:135
struct dhcp_packet * raw
Definition: dhcpd.h:136
struct interface_info * interface
Definition: dhcpd.h:142
struct iaddr client_addr
Definition: dhcpd.h:141
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by do_packet().

◆ check_arp()

int check_arp ( struct interface_info ip,
struct client_lease lp 
)

Definition at line 137 of file dhclient.c.

137 {
138 return 1;
139}

Referenced by dhcpoffer(), and state_selecting().

◆ check_option()

int check_option ( struct client_lease l,
int  option 
)

Definition at line 2055 of file dhclient.c.

2056{
2057 char *opbuf;
2058 char *sbuf;
2059
2060 /* we use this, since this is what gets passed to dhclient-script */
2061
2062 opbuf = pretty_print_option(option, l->options[option].data,
2063 l->options[option].len, 0, 0);
2064
2065 sbuf = option_as_string(option, l->options[option].data,
2066 l->options[option].len);
2067
2068 switch (option) {
2069 case DHO_SUBNET_MASK:
2070 case DHO_TIME_SERVERS:
2071 case DHO_NAME_SERVERS:
2072 case DHO_ROUTERS:
2074 case DHO_LOG_SERVERS:
2075 case DHO_COOKIE_SERVERS:
2076 case DHO_LPR_SERVERS:
2079 case DHO_SWAP_SERVER:
2081 case DHO_NIS_SERVERS:
2082 case DHO_NTP_SERVERS:
2085 case DHO_FONT_SERVERS:
2087 if (!ipv4addrs(opbuf)) {
2088 warning("Invalid IP address in option(%d): %s", option, opbuf);
2089 return (0);
2090 }
2091 return (1) ;
2092 case DHO_HOST_NAME:
2093 case DHO_DOMAIN_NAME:
2094 case DHO_NIS_DOMAIN:
2095 if (!res_hnok(sbuf))
2096 warning("Bogus Host Name option %d: %s (%s)", option,
2097 sbuf, opbuf);
2098 return (1);
2099 case DHO_PAD:
2100 case DHO_TIME_OFFSET:
2101 case DHO_BOOT_SIZE:
2102 case DHO_MERIT_DUMP:
2103 case DHO_ROOT_PATH:
2105 case DHO_IP_FORWARDING:
2107 case DHO_POLICY_FILTER:
2109 case DHO_DEFAULT_IP_TTL:
2112 case DHO_INTERFACE_MTU:
2115 case DHO_MASK_SUPPLIER:
2118 case DHO_STATIC_ROUTES:
2127 case DHO_NETBIOS_SCOPE:
2134 case DHO_DHCP_MESSAGE:
2141 case DHO_END:
2142 return (1);
2143 default:
2144 warning("unknown dhcp option value 0x%x", option);
2145 return (unknown_ok);
2146 }
2147}
char * pretty_print_option(unsigned int code, unsigned char *data, int len, int emit_commas, int emit_quotes)
Definition: options.c:396
#define DHO_DHCP_MESSAGE
Definition: dhcp.h:152
#define DHO_MASK_SUPPLIER
Definition: dhcp.h:126
#define DHO_TCP_KEEPALIVE_GARBAGE
Definition: dhcp.h:135
#define DHO_DHCP_MAX_MESSAGE_SIZE
Definition: dhcp.h:153
#define DHO_ROUTER_DISCOVERY
Definition: dhcp.h:127
#define DHO_NAME_SERVERS
Definition: dhcp.h:101
#define DHO_VENDOR_ENCAPSULATED_OPTIONS
Definition: dhcp.h:139
#define DHO_PERFORM_MASK_DISCOVERY
Definition: dhcp.h:125
#define DHO_NIS_SERVERS
Definition: dhcp.h:137
#define DHO_NON_LOCAL_SOURCE_ROUTING
Definition: dhcp.h:116
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_MERIT_DUMP
Definition: dhcp.h:110
#define DHO_NETBIOS_NAME_SERVERS
Definition: dhcp.h:140
#define DHO_DHCP_PARAMETER_REQUEST_LIST
Definition: dhcp.h:151
#define DHO_FONT_SERVERS
Definition: dhcp.h:144
#define DHO_NETBIOS_SCOPE
Definition: dhcp.h:143
#define DHO_LOG_SERVERS
Definition: dhcp.h:103
#define DHO_NETBIOS_NODE_TYPE
Definition: dhcp.h:142
#define DHO_NIS_DOMAIN
Definition: dhcp.h:136
#define DHO_PAD
Definition: dhcp.h:96
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define DHO_TCP_KEEPALIVE_INTERVAL
Definition: dhcp.h:134
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
#define DHO_TIME_SERVERS
Definition: dhcp.h:100
#define DHO_NETBIOS_DD_SERVER
Definition: dhcp.h:141
#define DHO_IP_FORWARDING
Definition: dhcp.h:115
#define DHO_IMPRESS_SERVERS
Definition: dhcp.h:106
#define DHO_TRAILER_ENCAPSULATION
Definition: dhcp.h:130
#define DHO_PATH_MTU_PLATEAU_TABLE
Definition: dhcp.h:121
#define DHO_DHCP_USER_CLASS_ID
Definition: dhcp.h:158
#define DHO_EXTENSIONS_PATH
Definition: dhcp.h:114
#define DHO_DHCP_CLIENT_IDENTIFIER
Definition: dhcp.h:157
#define DHO_TIME_OFFSET
Definition: dhcp.h:98
#define DHO_DEFAULT_TCP_TTL
Definition: dhcp.h:133
#define DHO_DHCP_MESSAGE_TYPE
Definition: dhcp.h:149
#define DHO_INTERFACE_MTU
Definition: dhcp.h:122
#define DHO_X_DISPLAY_MANAGER
Definition: dhcp.h:145
#define DHO_POLICY_FILTER
Definition: dhcp.h:117
#define DHO_ALL_SUBNETS_LOCAL
Definition: dhcp.h:123
#define DHO_MAX_DGRAM_REASSEMBLY
Definition: dhcp.h:118
#define DHO_END
Definition: dhcp.h:159
#define DHO_COOKIE_SERVERS
Definition: dhcp.h:104
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
#define DHO_DHCP_RENEWAL_TIME
Definition: dhcp.h:154
#define DHO_SWAP_SERVER
Definition: dhcp.h:112
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
#define DHO_DEFAULT_IP_TTL
Definition: dhcp.h:119
#define DHO_BOOT_SIZE
Definition: dhcp.h:109
#define DHO_DHCP_REBINDING_TIME
Definition: dhcp.h:155
#define DHO_DHCP_OPTION_OVERLOAD
Definition: dhcp.h:148
#define DHO_DHCP_SERVER_IDENTIFIER
Definition: dhcp.h:150
#define DHO_ROOT_PATH
Definition: dhcp.h:113
#define DHO_ARP_CACHE_TIMEOUT
Definition: dhcp.h:131
#define DHO_ROUTERS
Definition: dhcp.h:99
#define DHO_IEEE802_3_ENCAPSULATION
Definition: dhcp.h:132
#define DHO_DHCP_REQUESTED_ADDRESS
Definition: dhcp.h:146
#define DHO_DHCP_LEASE_TIME
Definition: dhcp.h:147
#define DHO_STATIC_ROUTES
Definition: dhcp.h:129
#define DHO_SUBNET_MASK
Definition: dhcp.h:97
#define DHO_DHCP_CLASS_IDENTIFIER
Definition: dhcp.h:156
#define DHO_LPR_SERVERS
Definition: dhcp.h:105
#define DHO_ROUTER_SOLICITATION_ADDRESS
Definition: dhcp.h:128
#define DHO_PATH_MTU_AGING_TIMEOUT
Definition: dhcp.h:120
#define DHO_RESOURCE_LOCATION_SERVERS
Definition: dhcp.h:107
r l[0]
Definition: byte_order.h:168
int unknown_ok
Definition: dhclient.c:94
int ipv4addrs(char *buf)
Definition: dhclient.c:2179
char * option_as_string(unsigned int code, unsigned char *data, int len)
Definition: dhclient.c:2199
int res_hnok(const char *dn)
Definition: dhclient.c:2150
Definition: getopt.h:109

Referenced by packet_to_lease().

◆ dhcp()

void dhcp ( struct packet packet)

Definition at line 819 of file dhclient.c.

820{
821 struct iaddrlist *ap;
822 void (*handler)(struct packet *);
823 char *type;
824
825 switch (packet->packet_type) {
826 case DHCPOFFER:
828 type = "DHCPOFFER";
829 break;
830 case DHCPNAK:
832 type = "DHCPNACK";
833 break;
834 case DHCPACK:
836 type = "DHCPACK";
837 break;
838 default:
839 return;
840 }
841
842 /* If there's a reject list, make sure this packet's sender isn't
843 on it. */
844 for (ap = packet->interface->client->config->reject_list;
845 ap; ap = ap->next) {
846 if (addr_eq(packet->client_addr, ap->addr)) {
847 note("%s from %s rejected.", type, piaddr(ap->addr));
848 return;
849 }
850 }
851 (*handler)(packet);
852}
#define DHCPNAK
Definition: dhcp.h:167
#define DHCPACK
Definition: dhcp.h:166
#define DHCPOFFER
Definition: dhcp.h:163
void dhcpnak(struct packet *packet)
Definition: dhclient.c:1068
void dhcpack(struct packet *packet)
Definition: dhclient.c:338
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int packet_type
Definition: dhcpd.h:138

Referenced by do_packet(), and START_TEST().

◆ dhcp_option_ev_name()

int dhcp_option_ev_name ( char buf,
size_t  buflen,
struct dhcp_option option 
)

Definition at line 2009 of file dhclient.c.

2010{
2011 int i;
2012
2013 for (i = 0; option->name[i]; i++) {
2014 if (i + 1 == buflen)
2015 return 0;
2016 if (option->name[i] == '-')
2017 buf[i] = '_';
2018 else
2019 buf[i] = option->name[i];
2020 }
2021
2022 buf[i] = 0;
2023 return 1;
2024}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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
WCHAR * name
Definition: getopt.h:110

Referenced by priv_script_write_params().

◆ dhcpack()

void dhcpack ( struct packet packet)

Definition at line 338 of file dhclient.c.

339{
341 struct client_lease *lease;
343
344 time(&cur_time);
345
346 /* If we're not receptive to an offer right now, or if the offer
347 has an unrecognizable transaction id, then just drop it. */
348 if (packet->interface->client->xid != packet->raw->xid ||
349 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
350 (memcmp(packet->interface->hw_address.haddr,
351 packet->raw->chaddr, packet->raw->hlen)))
352 return;
353
354 if (ip->client->state != S_REBOOTING &&
355 ip->client->state != S_REQUESTING &&
356 ip->client->state != S_RENEWING &&
357 ip->client->state != S_REBINDING)
358 return;
359
360 note("DHCPACK from %s", piaddr(packet->client_addr));
361
362 lease = packet_to_lease(packet);
363 if (!lease) {
364 note("packet_to_lease failed.");
365 return;
366 }
367
368 ip->client->new = lease;
369
370 /* Stop resending DHCPREQUEST. */
372
373 /* Figure out the lease time. */
374 if (ip->client->new->options[DHO_DHCP_LEASE_TIME].data)
375 ip->client->new->expiry = getULong(
376 ip->client->new->options[DHO_DHCP_LEASE_TIME].data);
377 else
378 ip->client->new->expiry = DHCP_DEFAULT_LEASE_TIME;
379 /* A number that looks negative here is really just very large,
380 because the lease expiry offset is unsigned. */
381 if (ip->client->new->expiry < 0)
382 ip->client->new->expiry = TIME_MAX;
383 /* XXX should be fixed by resetting the client state */
384 if (ip->client->new->expiry < 60)
385 ip->client->new->expiry = 60;
386
387 /* Take the server-provided renewal time if there is one;
388 otherwise figure it out according to the spec. */
389 if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len)
390 ip->client->new->renewal = getULong(
391 ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data);
392 else
393 ip->client->new->renewal = ip->client->new->expiry / 2;
394
395 /* Same deal with the rebind time. */
396 if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len)
397 ip->client->new->rebind = getULong(
398 ip->client->new->options[DHO_DHCP_REBINDING_TIME].data);
399 else
400 ip->client->new->rebind = ip->client->new->renewal +
401 ip->client->new->renewal / 2 + ip->client->new->renewal / 4;
402
403#ifdef __REACTOS__
404 ip->client->new->lease = ip->client->new->expiry;
405 ip->client->new->obtained = cur_time;
406#endif
407 ip->client->new->expiry += cur_time;
408 /* Lease lengths can never be negative. */
409 if (ip->client->new->expiry < cur_time)
410 ip->client->new->expiry = TIME_MAX;
411 ip->client->new->renewal += cur_time;
412 if (ip->client->new->renewal < cur_time)
413 ip->client->new->renewal = TIME_MAX;
414 ip->client->new->rebind += cur_time;
415 if (ip->client->new->rebind < cur_time)
416 ip->client->new->rebind = TIME_MAX;
417
418 bind_lease(ip);
419}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
void cancel_timeout(void(*where)(void *), void *what)
Definition: dispatch.c:316
u_int32_t getULong(unsigned char *data)
Definition: util.c:96
#define TIME_MAX
Definition: dhclient.c:90
struct client_lease * packet_to_lease(struct packet *packet)
Definition: dhclient.c:974
void bind_lease(struct interface_info *ip)
Definition: dhclient.c:703
@ S_REBOOTING
Definition: dhcpd.h:172
@ S_RENEWING
Definition: dhcpd.h:177
@ S_REBINDING
Definition: dhcpd.h:178
@ S_REQUESTING
Definition: dhcpd.h:175
#define DHCP_DEFAULT_LEASE_TIME
Definition: rosdhcp.h:32

Referenced by dhcp().

◆ dhcpnak()

void dhcpnak ( struct packet packet)

Definition at line 1068 of file dhclient.c.

1069{
1070 struct interface_info *ip = packet->interface;
1071
1072 /* If we're not receptive to an offer right now, or if the offer
1073 has an unrecognizable transaction id, then just drop it. */
1074 if (packet->interface->client->xid != packet->raw->xid ||
1075 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
1076 (memcmp(packet->interface->hw_address.haddr,
1077 packet->raw->chaddr, packet->raw->hlen)))
1078 return;
1079
1080 if (ip->client->state != S_REBOOTING &&
1081 ip->client->state != S_REQUESTING &&
1082 ip->client->state != S_RENEWING &&
1083 ip->client->state != S_REBINDING)
1084 return;
1085
1086 note("DHCPNAK from %s", piaddr(packet->client_addr));
1087
1088 if (!ip->client->active) {
1089 note("DHCPNAK with no active lease.\n");
1090 return;
1091 }
1092
1093 free_client_lease(ip->client->active);
1094 ip->client->active = NULL;
1095
1096 /* Stop sending DHCPREQUEST packets... */
1098
1099 ip->client->state = S_INIT;
1100 state_init(ip);
1101}
void state_init(void *ipp)
Definition: dhclient.c:210
@ S_INIT
Definition: dhcpd.h:173

Referenced by dhcp().

◆ dhcpoffer()

void dhcpoffer ( struct packet packet)

Definition at line 855 of file dhclient.c.

856{
858 struct client_lease *lease, *lp;
859 int i;
860 int arp_timeout_needed = 0, stop_selecting;
862 "DHCPOFFER" : "BOOTREPLY";
864
865 time(&cur_time);
866
867 /* If we're not receptive to an offer right now, or if the offer
868 has an unrecognizable transaction id, then just drop it. */
869 if (ip->client->state != S_SELECTING ||
870 packet->interface->client->xid != packet->raw->xid ||
871 (packet->interface->hw_address.hlen != packet->raw->hlen) ||
872 (memcmp(packet->interface->hw_address.haddr,
873 packet->raw->chaddr, packet->raw->hlen)))
874 return;
875
876 note("%s from %s", name, piaddr(packet->client_addr));
877
878
879 /* If this lease doesn't supply the minimum required parameters,
880 blow it off. */
881 for (i = 0; ip->client->config->required_options[i]; i++) {
882 if (!packet->options[ip->client->config->
883 required_options[i]].len) {
884 note("%s isn't satisfactory.", name);
885 return;
886 }
887 }
888
889 /* If we've already seen this lease, don't record it again. */
890 for (lease = ip->client->offered_leases;
891 lease; lease = lease->next) {
892 if (lease->address.len == sizeof(packet->raw->yiaddr) &&
893 !memcmp(lease->address.iabuf,
894 &packet->raw->yiaddr, lease->address.len)) {
895 debug("%s already seen.", name);
896 return;
897 }
898 }
899
900 lease = packet_to_lease(packet);
901 if (!lease) {
902 note("packet_to_lease failed.");
903 return;
904 }
905
906 /* If this lease was acquired through a BOOTREPLY, record that
907 fact. */
909 lease->is_bootp = 1;
910
911 /* Record the medium under which this lease was offered. */
912 lease->medium = ip->client->medium;
913
914 /* Send out an ARP Request for the offered IP address. */
915 if( !check_arp( ip, lease ) ) {
916 note("Arp check failed\n");
917 return;
918 }
919
920 /* Figure out when we're supposed to stop selecting. */
921 stop_selecting =
922 ip->client->first_sending + ip->client->config->select_interval;
923
924 /* If this is the lease we asked for, put it at the head of the
925 list, and don't mess with the arp request timeout. */
926 if (lease->address.len == ip->client->requested_address.len &&
927 !memcmp(lease->address.iabuf,
928 ip->client->requested_address.iabuf,
929 ip->client->requested_address.len)) {
930 lease->next = ip->client->offered_leases;
931 ip->client->offered_leases = lease;
932 } else {
933 /* If we already have an offer, and arping for this
934 offer would take us past the selection timeout,
935 then don't extend the timeout - just hope for the
936 best. */
937 if (ip->client->offered_leases &&
938 (cur_time + arp_timeout_needed) > stop_selecting)
939 arp_timeout_needed = 0;
940
941 /* Put the lease at the end of the list. */
942 lease->next = NULL;
943 if (!ip->client->offered_leases)
944 ip->client->offered_leases = lease;
945 else {
946 for (lp = ip->client->offered_leases; lp->next;
947 lp = lp->next)
948 ; /* nothing */
949 lp->next = lease;
950 }
951 }
952
953 /* If we're supposed to stop selecting before we've had time
954 to wait for the ARPREPLY, add some delay to wait for
955 the ARPREPLY. */
956 if (stop_selecting - cur_time < arp_timeout_needed)
957 stop_selecting = cur_time + arp_timeout_needed;
958
959 /* If the selecting interval has expired, go immediately to
960 state_selecting(). Otherwise, time out into
961 state_selecting at the select interval. */
962 if (stop_selecting <= 0)
964 else {
965 add_timeout(stop_selecting, state_selecting, ip);
967 }
968}
void send_discover(void *ipp)
Definition: dhclient.c:1108
void state_selecting(void *ipp)
Definition: dhclient.c:257
int check_arp(struct interface_info *ip, struct client_lease *lp)
Definition: dhclient.c:137
@ S_SELECTING
Definition: dhcpd.h:174
#define debug(msg)
Definition: key_call.c:71
struct string_list * medium
Definition: dhcpd.h:164
struct iaddr address
Definition: dhcpd.h:156
unsigned int is_bootp
Definition: dhcpd.h:166
struct client_lease * next
Definition: dhcpd.h:154
Definition: name.c:39
struct option_data options[256]
Definition: dhcpd.h:144

Referenced by bootp(), and dhcp().

◆ fork_privchld()

int fork_privchld ( int  ,
int   
)

◆ free_client_lease()

void free_client_lease ( struct client_lease lease)

Definition at line 1757 of file dhclient.c.

1758{
1759 int i;
1760
1761 if (lease->server_name)
1762 free(lease->server_name);
1763 if (lease->filename)
1764 free(lease->filename);
1765 for (i = 0; i < 256; i++) {
1766 if (lease->options[i].len)
1767 free(lease->options[i].data);
1768 }
1769 free(lease);
1770}
#define free
Definition: debug_ros.c:5
struct option_data options[256]
Definition: dhcpd.h:167
char * filename
Definition: dhcpd.h:163
char * server_name
Definition: dhcpd.h:157

Referenced by bind_lease(), dhcpnak(), packet_to_lease(), state_selecting(), and unbind_lease().

◆ init_client()

int init_client ( void  )

Definition at line 111 of file dhclient.c.

112{
113 ApiInit();
114 AdapterInit();
115
116 tzset();
117
119 sockaddr_broadcast.sin_family = AF_INET;
121 sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
122 inaddr_any.s_addr = INADDR_ANY;
124
125 return 1; // TRUE
126}
void AdapterInit()
Definition: adapter.c:192
VOID ApiInit()
Definition: api.c:18
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *)
Definition: dispatch.c:59
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, int len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
Definition: options.c:635
struct in_addr inaddr_any
Definition: dhclient.c:81
struct sockaddr_in sockaddr_broadcast
Definition: dhclient.c:82
#define REMOTE_PORT
Definition: dhcpd.h:113
#define AF_INET
Definition: tcpip.h:117
#define INADDR_BROADCAST
Definition: inet.h:82
#define INADDR_ANY
Definition: inet.h:80
#define htons(x)
Definition: module.h:215
_CRTIMP void __cdecl tzset(void)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by ServiceMain().

◆ ipv4addrs()

int ipv4addrs ( char buf)

Definition at line 2179 of file dhclient.c.

2180{
2181 char *tmp;
2182 struct in_addr jnk;
2183 int i = 0;
2184
2185 note("Input: %s", buf);
2186
2187 do {
2188 tmp = strtok(buf, " ");
2189 note("got %s", tmp);
2190 if( tmp && inet_aton(tmp, &jnk) ) i++;
2191 buf = NULL;
2192 } while( tmp );
2193
2194 return (i);
2195}
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
#define inet_aton(ap, inp)
Definition: adns_win32.h:161
Definition: tcpip.h:126

Referenced by check_option().

◆ make_decline()

void make_decline ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1619 of file dhclient.c.

1620{
1621 struct tree_cache *options[256], message_type_tree;
1622 struct tree_cache requested_address_tree;
1623 struct tree_cache server_id_tree, client_id_tree;
1624 unsigned char decline = DHCPDECLINE;
1625 int i;
1626
1627 memset(options, 0, sizeof(options));
1628 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1629
1630 /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */
1632 options[i] = &message_type_tree;
1633 options[i]->value = &decline;
1634 options[i]->len = sizeof(decline);
1635 options[i]->buf_size = sizeof(decline);
1636 options[i]->timeout = 0xFFFFFFFF;
1637
1638 /* Send back the server identifier... */
1640 options[i] = &server_id_tree;
1641 options[i]->value = lease->options[i].data;
1642 options[i]->len = lease->options[i].len;
1643 options[i]->buf_size = lease->options[i].len;
1644 options[i]->timeout = 0xFFFFFFFF;
1645
1646 /* Send back the address we're declining. */
1648 options[i] = &requested_address_tree;
1649 options[i]->value = lease->address.iabuf;
1650 options[i]->len = lease->address.len;
1651 options[i]->buf_size = lease->address.len;
1652 options[i]->timeout = 0xFFFFFFFF;
1653
1654 /* Send the uid if the user supplied one. */
1656 if (ip->client->config->send_options[i].len) {
1657 options[i] = &client_id_tree;
1658 options[i]->value = ip->client->config->send_options[i].data;
1659 options[i]->len = ip->client->config->send_options[i].len;
1660 options[i]->buf_size = ip->client->config->send_options[i].len;
1661 options[i]->timeout = 0xFFFFFFFF;
1662 }
1663
1664
1665 /* Set up the option buffer... */
1666 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1667 options);
1668 if (ip->client->packet_length < BOOTP_MIN_LEN)
1669 ip->client->packet_length = BOOTP_MIN_LEN;
1670
1671 ip->client->packet.op = BOOTREQUEST;
1672 ip->client->packet.htype = ip->hw_address.htype;
1673 ip->client->packet.hlen = ip->hw_address.hlen;
1674 ip->client->packet.hops = 0;
1675 ip->client->packet.xid = ip->client->xid;
1676 ip->client->packet.secs = 0; /* Filled in by send_request. */
1677 ip->client->packet.flags = 0;
1678
1679 /* ciaddr must always be zero. */
1680 memset(&ip->client->packet.ciaddr, 0,
1681 sizeof(ip->client->packet.ciaddr));
1682 memset(&ip->client->packet.yiaddr, 0,
1683 sizeof(ip->client->packet.yiaddr));
1684 memset(&ip->client->packet.siaddr, 0,
1685 sizeof(ip->client->packet.siaddr));
1686 memset(&ip->client->packet.giaddr, 0,
1687 sizeof(ip->client->packet.giaddr));
1688 memcpy(ip->client->packet.chaddr,
1689 ip->hw_address.haddr, ip->hw_address.hlen);
1690}
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, int mms, struct tree_cache **options)
Definition: options.c:199
#define BOOTP_MIN_LEN
Definition: dhcp.h:54
#define BOOTREQUEST
Definition: dhcp.h:78
#define DHCPDECLINE
Definition: dhcp.h:165
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ make_discover()

void make_discover ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1434 of file dhclient.c.

1435{
1436 unsigned char discover = DHCPDISCOVER;
1437 struct tree_cache *options[256];
1438 struct tree_cache option_elements[256];
1439 int i;
1441
1442 memset(option_elements, 0, sizeof(option_elements));
1443 memset(options, 0, sizeof(options));
1444 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1445
1446 /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */
1448 options[i] = &option_elements[i];
1449 options[i]->value = &discover;
1450 options[i]->len = sizeof(discover);
1451 options[i]->buf_size = sizeof(discover);
1452 options[i]->timeout = 0xFFFFFFFF;
1453
1454 /* Request the options we want */
1456 options[i] = &option_elements[i];
1457 options[i]->value = ip->client->config->requested_options;
1458 options[i]->len = ip->client->config->requested_option_count;
1459 options[i]->buf_size =
1460 ip->client->config->requested_option_count;
1461 options[i]->timeout = 0xFFFFFFFF;
1462
1463 /* If we had an address, try to get it again. */
1464 if (lease) {
1465 ip->client->requested_address = lease->address;
1467 options[i] = &option_elements[i];
1468 options[i]->value = lease->address.iabuf;
1469 options[i]->len = lease->address.len;
1470 options[i]->buf_size = lease->address.len;
1471 options[i]->timeout = 0xFFFFFFFF;
1472 } else
1473 ip->client->requested_address.len = 0;
1474
1475 /* Send any options requested in the config file. */
1476 for (i = 0; i < 256; i++)
1477 if (!options[i] &&
1478 ip->client->config->send_options[i].data) {
1479 options[i] = &option_elements[i];
1480 options[i]->value =
1481 ip->client->config->send_options[i].data;
1482 options[i]->len =
1483 ip->client->config->send_options[i].len;
1484 options[i]->buf_size =
1485 ip->client->config->send_options[i].len;
1486 options[i]->timeout = 0xFFFFFFFF;
1487 }
1488
1489 /* Set up the option buffer... */
1490 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1491 options);
1492 if (ip->client->packet_length < BOOTP_MIN_LEN)
1493 ip->client->packet_length = BOOTP_MIN_LEN;
1494
1495 ip->client->packet.op = BOOTREQUEST;
1496 ip->client->packet.htype = ip->hw_address.htype;
1497 ip->client->packet.hlen = ip->hw_address.hlen;
1498 ip->client->packet.hops = 0;
1499 ip->client->packet.xid = RtlRandom(&foo);
1500 ip->client->packet.secs = 0; /* filled in by send_discover. */
1501 ip->client->packet.flags = 0;
1502
1503 memset(&(ip->client->packet.ciaddr),
1504 0, sizeof(ip->client->packet.ciaddr));
1505 memset(&(ip->client->packet.yiaddr),
1506 0, sizeof(ip->client->packet.yiaddr));
1507 memset(&(ip->client->packet.siaddr),
1508 0, sizeof(ip->client->packet.siaddr));
1509 memset(&(ip->client->packet.giaddr),
1510 0, sizeof(ip->client->packet.giaddr));
1511 memcpy(ip->client->packet.chaddr,
1512 ip->hw_address.haddr, ip->hw_address.hlen);
1513}
#define DHCPDISCOVER
Definition: dhcp.h:162
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
NTSYSAPI ULONG NTAPI RtlRandom(_Inout_ PULONG Seed)
uint32_t ULONG
Definition: typedefs.h:59

Referenced by state_init().

◆ make_release()

void make_release ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1693 of file dhclient.c.

1694{
1695 struct tree_cache *options[256], message_type_tree;
1696 struct tree_cache server_id_tree, client_id_tree;
1697 unsigned char release = DHCPRELEASE;
1698 int i;
1699
1700 memset(options, 0, sizeof(options));
1701 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1702
1703 /* Set DHCP_MESSAGE_TYPE to DHCPRELEASE */
1705 options[i] = &message_type_tree;
1706 options[i]->value = &release;
1707 options[i]->len = sizeof(release);
1708 options[i]->buf_size = sizeof(release);
1709 options[i]->timeout = 0xFFFFFFFF;
1710
1711 /* Send back the server identifier... */
1713 options[i] = &server_id_tree;
1714 options[i]->value = lease->options[i].data;
1715 options[i]->len = lease->options[i].len;
1716 options[i]->buf_size = lease->options[i].len;
1717 options[i]->timeout = 0xFFFFFFFF;
1718
1719 /* Send the uid if the user supplied one. */
1721 if (ip->client->config->send_options[i].len)
1722 {
1723 options[i] = &client_id_tree;
1724 options[i]->value = ip->client->config->send_options[i].data;
1725 options[i]->len = ip->client->config->send_options[i].len;
1726 options[i]->buf_size = ip->client->config->send_options[i].len;
1727 options[i]->timeout = 0xFFFFFFFF;
1728 }
1729
1730 /* Set up the option buffer... */
1731 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, options);
1732 if (ip->client->packet_length < BOOTP_MIN_LEN)
1733 ip->client->packet_length = BOOTP_MIN_LEN;
1734
1735 ip->client->packet.op = BOOTREQUEST;
1736 ip->client->packet.htype = ip->hw_address.htype;
1737 ip->client->packet.hlen = ip->hw_address.hlen;
1738 ip->client->packet.hops = 0;
1739 ip->client->packet.xid = 0;
1740 ip->client->packet.secs = 0;
1741 ip->client->packet.flags = 0;
1742
1743 /* ciaddr is the address to be released */
1744 memcpy(&ip->client->packet.ciaddr,
1745 lease->address.iabuf, lease->address.len);
1746 memset(&ip->client->packet.yiaddr, 0,
1747 sizeof(ip->client->packet.yiaddr));
1748 memset(&ip->client->packet.siaddr, 0,
1749 sizeof(ip->client->packet.siaddr));
1750 memset(&ip->client->packet.giaddr, 0,
1751 sizeof(ip->client->packet.giaddr));
1752 memcpy(ip->client->packet.chaddr,
1753 ip->hw_address.haddr, ip->hw_address.hlen);
1754}
#define DHCPRELEASE
Definition: dhcp.h:168

Referenced by state_release().

◆ make_request()

void make_request ( struct interface_info ip,
struct client_lease lease 
)

Definition at line 1517 of file dhclient.c.

1518{
1519 unsigned char request = DHCPREQUEST;
1520 struct tree_cache *options[256];
1521 struct tree_cache option_elements[256];
1522 int i;
1523
1524 memset(options, 0, sizeof(options));
1525 memset(&ip->client->packet, 0, sizeof(ip->client->packet));
1526
1527 /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */
1529 options[i] = &option_elements[i];
1530 options[i]->value = &request;
1531 options[i]->len = sizeof(request);
1532 options[i]->buf_size = sizeof(request);
1533 options[i]->timeout = 0xFFFFFFFF;
1534
1535 /* Request the options we want */
1537 options[i] = &option_elements[i];
1538 options[i]->value = ip->client->config->requested_options;
1539 options[i]->len = ip->client->config->requested_option_count;
1540 options[i]->buf_size =
1541 ip->client->config->requested_option_count;
1542 options[i]->timeout = 0xFFFFFFFF;
1543
1544 /* If we are requesting an address that hasn't yet been assigned
1545 to us, use the DHCP Requested Address option. */
1546 if (ip->client->state == S_REQUESTING) {
1547 /* Send back the server identifier... */
1549 options[i] = &option_elements[i];
1550 options[i]->value = lease->options[i].data;
1551 options[i]->len = lease->options[i].len;
1552 options[i]->buf_size = lease->options[i].len;
1553 options[i]->timeout = 0xFFFFFFFF;
1554 }
1555 if (ip->client->state == S_REQUESTING ||
1556 ip->client->state == S_REBOOTING) {
1557 ip->client->requested_address = lease->address;
1559 options[i] = &option_elements[i];
1560 options[i]->value = lease->address.iabuf;
1561 options[i]->len = lease->address.len;
1562 options[i]->buf_size = lease->address.len;
1563 options[i]->timeout = 0xFFFFFFFF;
1564 } else
1565 ip->client->requested_address.len = 0;
1566
1567 /* Send any options requested in the config file. */
1568 for (i = 0; i < 256; i++)
1569 if (!options[i] &&
1570 ip->client->config->send_options[i].data) {
1571 options[i] = &option_elements[i];
1572 options[i]->value =
1573 ip->client->config->send_options[i].data;
1574 options[i]->len =
1575 ip->client->config->send_options[i].len;
1576 options[i]->buf_size =
1577 ip->client->config->send_options[i].len;
1578 options[i]->timeout = 0xFFFFFFFF;
1579 }
1580
1581 /* Set up the option buffer... */
1582 ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0,
1583 options);
1584 if (ip->client->packet_length < BOOTP_MIN_LEN)
1585 ip->client->packet_length = BOOTP_MIN_LEN;
1586
1587 ip->client->packet.op = BOOTREQUEST;
1588 ip->client->packet.htype = ip->hw_address.htype;
1589 ip->client->packet.hlen = ip->hw_address.hlen;
1590 ip->client->packet.hops = 0;
1591 ip->client->packet.xid = ip->client->xid;
1592 ip->client->packet.secs = 0; /* Filled in by send_request. */
1593
1594 /* If we own the address we're requesting, put it in ciaddr;
1595 otherwise set ciaddr to zero. */
1596 if (ip->client->state == S_BOUND ||
1597 ip->client->state == S_RENEWING ||
1598 ip->client->state == S_REBINDING) {
1599 memcpy(&ip->client->packet.ciaddr,
1600 lease->address.iabuf, lease->address.len);
1601 ip->client->packet.flags = 0;
1602 } else {
1603 memset(&ip->client->packet.ciaddr, 0,
1604 sizeof(ip->client->packet.ciaddr));
1605 ip->client->packet.flags = 0;
1606 }
1607
1608 memset(&ip->client->packet.yiaddr, 0,
1609 sizeof(ip->client->packet.yiaddr));
1610 memset(&ip->client->packet.siaddr, 0,
1611 sizeof(ip->client->packet.siaddr));
1612 memset(&ip->client->packet.giaddr, 0,
1613 sizeof(ip->client->packet.giaddr));
1614 memcpy(ip->client->packet.chaddr,
1615 ip->hw_address.haddr, ip->hw_address.hlen);
1616}
#define DHCPREQUEST
Definition: dhcp.h:164
Definition: tftpd.h:86

Referenced by state_bound(), state_reboot(), and state_selecting().

◆ option_as_string()

char * option_as_string ( unsigned int  code,
unsigned char data,
int  len 
)

Definition at line 2199 of file dhclient.c.

2200{
2201 static char optbuf[32768]; /* XXX */
2202 char *op = optbuf;
2203 int opleft = sizeof(optbuf);
2204 unsigned char *dp = data;
2205
2206 if (code > 255)
2207 error("option_as_string: bad code %d", code);
2208
2209 for (; dp < data + len; dp++) {
2210 if (!isascii(*dp) || !isprint(*dp)) {
2211 if (dp + 1 != data + len || *dp != 0) {
2212 _snprintf(op, opleft, "\\%03o", *dp);
2213 op += 4;
2214 opleft -= 4;
2215 }
2216 } else if (*dp == '"' || *dp == '\'' || *dp == '$' ||
2217 *dp == '`' || *dp == '\\') {
2218 *op++ = '\\';
2219 *op++ = *dp;
2220 opleft -= 2;
2221 } else {
2222 *op++ = *dp;
2223 opleft--;
2224 }
2225 }
2226 if (opleft < 1)
2227 goto toobig;
2228 *op = 0;
2229 return optbuf;
2230toobig:
2231 warning("dhcp option too large");
2232 return "<error>";
2233}
#define isprint(c)
Definition: acclib.h:73
UINT op
Definition: effect.c:236
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
#define isascii
Definition: ctype.h:742
#define error(str)
Definition: mkdosfs.c:1605
Definition: inflate.c:139
#define _snprintf
Definition: xmlstorage.h:200

Referenced by check_option().

◆ packet_to_lease()

struct client_lease * packet_to_lease ( struct packet packet)

Definition at line 974 of file dhclient.c.

975{
976 struct client_lease *lease;
977 int i;
978
979 lease = malloc(sizeof(struct client_lease));
980
981 if (!lease) {
982 warning("dhcpoffer: no memory to record lease.");
983 return (NULL);
984 }
985
986 memset(lease, 0, sizeof(*lease));
987
988 /* Copy the lease options. */
989 for (i = 0; i < 256; i++) {
990 if (packet->options[i].len) {
991 lease->options[i].data =
992 malloc(packet->options[i].len + 1);
993 if (!lease->options[i].data) {
994 warning("dhcpoffer: no memory for option %d", i);
995 free_client_lease(lease);
996 return (NULL);
997 } else {
998 memcpy(lease->options[i].data,
999 packet->options[i].data,
1000 packet->options[i].len);
1001 lease->options[i].len =
1002 packet->options[i].len;
1003 lease->options[i].data[lease->options[i].len] =
1004 0;
1005 }
1006 if (!check_option(lease,i)) {
1007 /* ignore a bogus lease offer */
1008 warning("Invalid lease option - ignoring offer");
1009 free_client_lease(lease);
1010 return (NULL);
1011 }
1012 }
1013 }
1014
1015 lease->address.len = sizeof(packet->raw->yiaddr);
1016 memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len);
1017#ifdef __REACTOS__
1018 if (packet->raw->siaddr.S_un.S_addr == 0)
1019 {
1020 lease->serveraddress.len = packet->client_addr.len;
1021 memcpy(lease->serveraddress.iabuf, &packet->client_addr.iabuf, packet->client_addr.len);
1022 }
1023 else
1024 {
1025 lease->serveraddress.len = sizeof(packet->raw->siaddr);
1026 memcpy(lease->serveraddress.iabuf, &packet->raw->siaddr, lease->serveraddress.len);
1027 }
1028#endif
1029
1030 /* If the server name was filled out, copy it. */
1032 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 2)) &&
1033 packet->raw->sname[0]) {
1034 lease->server_name = malloc(DHCP_SNAME_LEN + 1);
1035 if (!lease->server_name) {
1036 warning("dhcpoffer: no memory for server name.");
1037 free_client_lease(lease);
1038 return (NULL);
1039 }
1040 memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN);
1041 lease->server_name[DHCP_SNAME_LEN]='\0';
1042 if (!res_hnok(lease->server_name) ) {
1043 warning("Bogus server name %s", lease->server_name );
1044 free_client_lease(lease);
1045 return (NULL);
1046 }
1047
1048 }
1049
1050 /* Ditto for the filename. */
1052 !(packet->options[DHO_DHCP_OPTION_OVERLOAD].data[0] & 1)) &&
1053 packet->raw->file[0]) {
1054 /* Don't count on the NUL terminator. */
1055 lease->filename = malloc(DHCP_FILE_LEN + 1);
1056 if (!lease->filename) {
1057 warning("dhcpoffer: no memory for filename.");
1058 free_client_lease(lease);
1059 return (NULL);
1060 }
1061 memcpy(lease->filename, packet->raw->file, DHCP_FILE_LEN);
1062 lease->filename[DHCP_FILE_LEN]='\0';
1063 }
1064 return lease;
1065}
#define DHCP_SNAME_LEN
Definition: dhcp.h:46
#define DHCP_FILE_LEN
Definition: dhcp.h:47
#define malloc
Definition: debug_ros.c:4
int check_option(struct client_lease *l, int option)
Definition: dhclient.c:2055

Referenced by dhcpack(), and dhcpoffer().

◆ priv_script_init()

void priv_script_init ( struct interface_info ip,
char reason,
char medium 
)

Definition at line 1863 of file dhclient.c.

1864{
1865 if (ip) {
1866 // XXX Do we need to do anything?
1867 }
1868}

◆ priv_script_write_params()

void priv_script_write_params ( struct interface_info ip,
char prefix,
struct client_lease lease 
)

Definition at line 1871 of file dhclient.c.

1872{
1873 u_int8_t dbuf[1500];
1874 int i, len = 0;
1875
1876#if 0
1877 script_set_env(ip->client, prefix, "ip_address",
1878 piaddr(lease->address));
1879#endif
1880
1881 if (lease->options[DHO_SUBNET_MASK].len &&
1882 (lease->options[DHO_SUBNET_MASK].len <
1883 sizeof(lease->address.iabuf))) {
1884 struct iaddr netmask, subnet, broadcast;
1885
1886 memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data,
1887 lease->options[DHO_SUBNET_MASK].len);
1888 netmask.len = lease->options[DHO_SUBNET_MASK].len;
1889
1890 subnet = subnet_number(lease->address, netmask);
1891 if (subnet.len) {
1892#if 0
1893 script_set_env(ip->client, prefix, "network_number",
1894 piaddr(subnet));
1895#endif
1896 if (!lease->options[DHO_BROADCAST_ADDRESS].len) {
1897 broadcast = broadcast_addr(subnet, netmask);
1898 if (broadcast.len)
1899#if 0
1900 script_set_env(ip->client, prefix,
1901 "broadcast_address",
1902 piaddr(broadcast));
1903#else
1904 ;
1905#endif
1906 }
1907 }
1908 }
1909
1910#if 0
1911 if (lease->filename)
1912 script_set_env(ip->client, prefix, "filename", lease->filename);
1913 if (lease->server_name)
1914 script_set_env(ip->client, prefix, "server_name",
1915 lease->server_name);
1916#endif
1917
1918 for (i = 0; i < 256; i++) {
1919 u_int8_t *dp = NULL;
1920
1921 if (ip->client->config->defaults[i].len) {
1922 if (lease->options[i].len) {
1923 switch (
1924 ip->client->config->default_actions[i]) {
1925 case ACTION_DEFAULT:
1926 dp = lease->options[i].data;
1927 len = lease->options[i].len;
1928 break;
1929 case ACTION_SUPERSEDE:
1930supersede:
1931 dp = ip->client->
1932 config->defaults[i].data;
1933 len = ip->client->
1934 config->defaults[i].len;
1935 break;
1936 case ACTION_PREPEND:
1937 len = ip->client->
1938 config->defaults[i].len +
1939 lease->options[i].len;
1940 if (len >= sizeof(dbuf)) {
1941 warning("no space to %s %s",
1942 "prepend option",
1944 goto supersede;
1945 }
1946 dp = dbuf;
1947 memcpy(dp,
1948 ip->client->
1949 config->defaults[i].data,
1950 ip->client->
1951 config->defaults[i].len);
1952 memcpy(dp + ip->client->
1953 config->defaults[i].len,
1954 lease->options[i].data,
1955 lease->options[i].len);
1956 dp[len] = '\0';
1957 break;
1958 case ACTION_APPEND:
1959 len = ip->client->
1960 config->defaults[i].len +
1961 lease->options[i].len + 1;
1962 if (len > sizeof(dbuf)) {
1963 warning("no space to %s %s",
1964 "append option",
1966 goto supersede;
1967 }
1968 dp = dbuf;
1969 memcpy(dp,
1970 lease->options[i].data,
1971 lease->options[i].len);
1972 memcpy(dp + lease->options[i].len,
1973 ip->client->
1974 config->defaults[i].data,
1975 ip->client->
1976 config->defaults[i].len);
1977 dp[len-1] = '\0';
1978 }
1979 } else {
1980 dp = ip->client->
1981 config->defaults[i].data;
1982 len = ip->client->
1983 config->defaults[i].len;
1984 }
1985 } else if (lease->options[i].len) {
1986 len = lease->options[i].len;
1987 dp = lease->options[i].data;
1988 } else {
1989 len = 0;
1990 }
1991#if 0
1992 if (len) {
1993 char name[256];
1994
1995 if (dhcp_option_ev_name(name, sizeof(name),
1996 &dhcp_options[i]))
1997 script_set_env(ip->client, prefix, name,
1998 pretty_print_option(i, dp, len, 0, 0));
1999 }
2000#endif
2001 }
2002#if 0
2003 snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry);
2004 script_set_env(ip->client, prefix, "expiry", tbuf);
2005#endif
2006}
struct dhcp_option dhcp_options[256]
Definition: tables.c:68
struct iaddr broadcast_addr(struct iaddr addr, struct iaddr mask)
Definition: util.c:178
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
Definition: util.c:183
int dhcp_option_ev_name(char *buf, size_t buflen, struct dhcp_option *option)
Definition: dhclient.c:2009
void script_set_env(struct client_state *, const char *, const char *, const char *)
unsigned char u_int8_t
Definition: rosdhcp.h:35
time_t expiry
Definition: dhcpd.h:155
Definition: dhcpd.h:125
Character const *const prefix
Definition: tempnam.cpp:195
static const u8_t broadcast[6]
Definition: test_dhcp.c:23
#define snprintf
Definition: wintirpc.h:48

◆ res_hnok()

int res_hnok ( const char dn)

Definition at line 2150 of file dhclient.c.

2151{
2152 int pch = PERIOD, ch = *dn++;
2153
2154 while (ch != '\0') {
2155 int nch = *dn++;
2156
2157 if (periodchar(ch)) {
2158 ;
2159 } else if (periodchar(pch)) {
2160 if (!borderchar(ch))
2161 return (0);
2162 } else if (periodchar(nch) || nch == '\0') {
2163 if (!borderchar(ch))
2164 return (0);
2165 } else {
2166 if (!middlechar(ch))
2167 return (0);
2168 }
2169 pch = ch, ch = nch;
2170 }
2171 return (1);
2172}
#define middlechar(c)
Definition: dhclient.c:68
#define periodchar(c)
Definition: dhclient.c:61
#define borderchar(c)
Definition: dhclient.c:67
#define PERIOD
Definition: dhclient.c:58
#define pch(ap)
Definition: match.c:418
int nch
Definition: scanf.h:135

Referenced by check_option(), and packet_to_lease().

◆ reset_adapter()

void reset_adapter ( PDHCP_ADAPTER  Adapter)

Definition at line 652 of file dhclient.c.

652 {
653 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
654 CHAR IpAddress[] = "0.0.0.0";
655 CHAR SubnetMask[] = "255.0.0.0";
656 CHAR Server[] = "255.255.255.255";
657 HKEY hkey;
658 DWORD lease;
659 time_t cur_time, new_time;
660
661 time(&cur_time);
662
663 strcat(Buffer, Adapter->DhclientInfo.name);
665 hkey = NULL;
666
667 if( Adapter->NteContext )
668 {
669 DeleteIPAddress( Adapter->NteContext );
670 Adapter->NteContext = 0;
671 }
672
673 if (hkey) {
674 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)IpAddress, strlen(IpAddress)+1);
675 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)SubnetMask, strlen(SubnetMask)+1);
676 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)Server, strlen(Server)+1);
677
678 lease = 3600;
679 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&lease, sizeof(DWORD));
680 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&cur_time, sizeof(DWORD));
681 new_time = cur_time + lease;
682 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
683 new_time = cur_time + (lease / 2);
684 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
685 new_time = cur_time + lease - (lease / 8);
686 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_time, sizeof(DWORD));
687 }
688
689 if( Adapter->RouterMib.dwForwardNextHop ) {
690 DeleteIpForwardEntry( &Adapter->RouterMib );
691 }
692
693 if (hkey) {
694 RegDeleteValueA(hkey, "DhcpDefaultGateway");
695 }
696
697 if (hkey)
698 RegCloseKey(hkey);
699}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI DeleteIPAddress(ULONG NTEContext)
#define REG_SZ
Definition: layer.c:22
#define KEY_WRITE
Definition: nt_native.h:1034
#define REG_DWORD
Definition: sdbapi.c:615
strcat
Definition: string.h:92
static void Server(int port)
Definition: srltest.c:69
ULONG NteContext
Definition: rosdhcp.h:72
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:69
struct interface_info DhclientInfo
Definition: rosdhcp.h:73
DWORD dwForwardNextHop
Definition: ipmib.h:74
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
char CHAR
Definition: xmlstorage.h:175

Referenced by unbind_lease().

◆ rewrite_client_leases()

void rewrite_client_leases ( struct interface_info ifi)

Definition at line 1775 of file dhclient.c.

1776{
1777 struct client_lease *lp;
1778
1779 if (!leaseFile) {
1781 if (!leaseFile)
1782 error("can't create %s", path_dhclient_db);
1783 } else {
1786 }
1787
1788 for (lp = ifi->client->leases; lp; lp = lp->next)
1789 write_client_lease(ifi, lp, 1);
1790 if (ifi->client->active)
1791 write_client_lease(ifi, ifi->client->active, 1);
1792
1794}
char * path_dhclient_db
Definition: dhclient.c:74
void write_client_lease(struct interface_info *ip, struct client_lease *lease, int rewrite)
Definition: dhclient.c:1797
FILE * leaseFile
Definition: dhclient.c:1772
_CRTIMP void __cdecl rewind(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
struct client_state * client
Definition: dhcpd.h:241

Referenced by write_client_lease().

◆ send_decline()

void send_decline ( void ipp)

Definition at line 1395 of file dhclient.c.

1396{
1397 struct interface_info *ip = ipp;
1398
1399 note("DHCPDECLINE on %s to %s port %d", ip->name,
1400 inet_ntoa(sockaddr_broadcast.sin_addr),
1401 ntohs(sockaddr_broadcast.sin_port));
1402
1403 /* Send out a packet. */
1404 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1406}
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:160
#define ntohs(x)
Definition: module.h:210
ssize_t send_packet(struct interface_info *ip, struct dhcp_packet *p, size_t size, struct in_addr addr, struct sockaddr_in *broadcast, struct hardware *hardware)
Definition: socket.c:9

◆ send_discover()

void send_discover ( void ipp)

Definition at line 1108 of file dhclient.c.

1109{
1110 struct interface_info *ip = ipp;
1111 int interval, increase = 1;
1113
1114 DH_DbgPrint(MID_TRACE,("Doing discover on interface %p\n",ip));
1115
1116 time(&cur_time);
1117
1118 /* Figure out how long it's been since we started transmitting. */
1119 interval = cur_time - ip->client->first_sending;
1120
1121 /* If we're past the panic timeout, call the script and tell it
1122 we haven't found anything for this interface yet. */
1123 if (interval > ip->client->config->timeout) {
1124 state_panic(ip);
1125 ip->client->first_sending = cur_time;
1126 }
1127
1128 /* If we're selecting media, try the whole list before doing
1129 the exponential backoff, but if we've already received an
1130 offer, stop looping, because we obviously have it right. */
1131 if (!ip->client->offered_leases &&
1132 ip->client->config->media) {
1133 int fail = 0;
1134
1135 if (ip->client->medium) {
1136 ip->client->medium = ip->client->medium->next;
1137 increase = 0;
1138 }
1139 if (!ip->client->medium) {
1140 if (fail)
1141 error("No valid media types for %s!", ip->name);
1142 ip->client->medium = ip->client->config->media;
1143 increase = 1;
1144 }
1145
1146 note("Trying medium \"%s\" %d", ip->client->medium->string,
1147 increase);
1148 /* XXX Support other media types eventually */
1149 }
1150
1151 /*
1152 * If we're supposed to increase the interval, do so. If it's
1153 * currently zero (i.e., we haven't sent any packets yet), set
1154 * it to one; otherwise, add to it a random number between zero
1155 * and two times itself. On average, this means that it will
1156 * double with every transmission.
1157 */
1158 if (increase) {
1159 if (!ip->client->interval)
1160 ip->client->interval =
1161 ip->client->config->initial_interval;
1162 else {
1163 ip->client->interval += (rand() >> 2) %
1164 (2 * ip->client->interval);
1165 }
1166
1167 /* Don't backoff past cutoff. */
1168 if (ip->client->interval >
1169 ip->client->config->backoff_cutoff)
1170 ip->client->interval =
1171 ((ip->client->config->backoff_cutoff / 2)
1172 + ((rand() >> 2) %
1173 ip->client->config->backoff_cutoff));
1174 } else if (!ip->client->interval)
1175 ip->client->interval =
1176 ip->client->config->initial_interval;
1177
1178 /* If the backoff would take us to the panic timeout, just use that
1179 as the interval. */
1180 if (cur_time + ip->client->interval >
1181 ip->client->first_sending + ip->client->config->timeout)
1182 ip->client->interval =
1183 (ip->client->first_sending +
1184 ip->client->config->timeout) - cur_time + 1;
1185
1186 /* Record the number of seconds since we started sending. */
1187 if (interval < 65536)
1188 ip->client->packet.secs = htons(interval);
1189 else
1190 ip->client->packet.secs = htons(65535);
1191 ip->client->secs = ip->client->packet.secs;
1192
1193 note("DHCPDISCOVER on %s to %s port %d interval %ld",
1194 ip->name, inet_ntoa(sockaddr_broadcast.sin_addr),
1195 ntohs(sockaddr_broadcast.sin_port), (long int)ip->client->interval);
1196
1197 /* Send out a packet. */
1198 (void)send_packet(ip, &ip->client->packet, ip->client->packet_length,
1200
1201 DH_DbgPrint(MID_TRACE,("discover timeout: now %x -> then %x\n",
1202 cur_time, cur_time + ip->client->interval));
1203
1204 add_timeout(cur_time + ip->client->interval, send_discover, ip);
1205}
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
void state_panic(void *ipp)
Definition: dhclient.c:1214
static void increase(int &a_)
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10

Referenced by dhcpoffer(), send_discover(), state_init(), and state_selecting().

◆ send_release()

void send_release ( void ipp)

Definition at line 1409 of file dhclient.c.

1410{
1411 struct interface_info *ip = ipp;
1412 struct sockaddr_in destination;
1413 struct in_addr from;
1414
1415 memset(&destination, 0, sizeof(destination));
1416 memcpy(&destination.sin_addr.s_addr,
1417 ip->client->destination.iabuf,
1418 sizeof(destination.sin_addr.s_addr));
1419 destination.sin_port = htons(REMOTE_PORT);
1420 destination.sin_family = AF_INET;
1421
1422 memcpy(&from, ip->client->active->address.iabuf,
1423 sizeof(from));
1424
1425 note("DHCPRELEASE on %s to %s port %d", ip->name,
1426 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1427
1428 /* Send out a packet. */
1429 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1430 from, &destination, NULL);
1431}
CardRegion * from
Definition: spigame.cpp:19

Referenced by state_release().

◆ send_request()

void send_request ( void ipp)

Definition at line 1266 of file dhclient.c.

1267{
1268 struct interface_info *ip = ipp;
1269 struct sockaddr_in destination;
1270 struct in_addr from;
1271 int interval;
1273
1274 time(&cur_time);
1275
1276 /* Figure out how long it's been since we started transmitting. */
1277 interval = cur_time - ip->client->first_sending;
1278
1279 /* If we're in the INIT-REBOOT or REQUESTING state and we're
1280 past the reboot timeout, go to INIT and see if we can
1281 DISCOVER an address... */
1282 /* XXX In the INIT-REBOOT state, if we don't get an ACK, it
1283 means either that we're on a network with no DHCP server,
1284 or that our server is down. In the latter case, assuming
1285 that there is a backup DHCP server, DHCPDISCOVER will get
1286 us a new address, but we could also have successfully
1287 reused our old address. In the former case, we're hosed
1288 anyway. This is not a win-prone situation. */
1289 if ((ip->client->state == S_REBOOTING ||
1290 ip->client->state == S_REQUESTING) &&
1291 interval > ip->client->config->reboot_timeout) {
1292 ip->client->state = S_INIT;
1294 state_init(ip);
1295 return;
1296 }
1297
1298 /* If we're in the reboot state, make sure the media is set up
1299 correctly. */
1300 if (ip->client->state == S_REBOOTING &&
1301 !ip->client->medium &&
1302 ip->client->active->medium ) {
1303 /* If the medium we chose won't fly, go to INIT state. */
1304 /* XXX Nothing for now */
1305
1306 /* Record the medium. */
1307 ip->client->medium = ip->client->active->medium;
1308 }
1309
1310 /* If the lease has expired, relinquish the address and go back
1311 to the INIT state. */
1312 if (ip->client->state != S_REQUESTING &&
1313 cur_time > ip->client->active->expiry) {
1314 PDHCP_ADAPTER Adapter = AdapterFindInfo( ip );
1315 /* Run the client script with the new parameters. */
1316 /* No script actions necessary in the expiry case */
1317 /* Now do a preinit on the interface so that we can
1318 discover a new address. */
1319
1320 if( Adapter )
1321 {
1322 DeleteIPAddress( Adapter->NteContext );
1323 Adapter->NteContext = 0;
1324 }
1325
1326 ip->client->state = S_INIT;
1327 state_init(ip);
1328 return;
1329 }
1330
1331 /* Do the exponential backoff... */
1332 if (!ip->client->interval)
1333 ip->client->interval = ip->client->config->initial_interval;
1334 else
1335 ip->client->interval += ((rand() >> 2) %
1336 (2 * ip->client->interval));
1337
1338 /* Don't backoff past cutoff. */
1339 if (ip->client->interval >
1340 ip->client->config->backoff_cutoff)
1341 ip->client->interval =
1342 ((ip->client->config->backoff_cutoff / 2) +
1343 ((rand() >> 2) % ip->client->interval));
1344
1345 /* If the backoff would take us to the expiry time, just set the
1346 timeout to the expiry time. */
1347 if (ip->client->state != S_REQUESTING &&
1348 cur_time + ip->client->interval >
1349 ip->client->active->expiry)
1350 ip->client->interval =
1351 ip->client->active->expiry - cur_time + 1;
1352
1353 /* If the lease T2 time has elapsed, or if we're not yet bound,
1354 broadcast the DHCPREQUEST rather than unicasting. */
1355 memset(&destination, 0, sizeof(destination));
1356 if (ip->client->state == S_REQUESTING ||
1357 ip->client->state == S_REBOOTING ||
1358 cur_time > ip->client->active->rebind)
1359 destination.sin_addr.s_addr = INADDR_BROADCAST;
1360 else
1361 memcpy(&destination.sin_addr.s_addr,
1362 ip->client->destination.iabuf,
1363 sizeof(destination.sin_addr.s_addr));
1364 destination.sin_port = htons(REMOTE_PORT);
1365 destination.sin_family = AF_INET;
1366// destination.sin_len = sizeof(destination);
1367
1368 if (ip->client->state != S_REQUESTING)
1369 memcpy(&from, ip->client->active->address.iabuf,
1370 sizeof(from));
1371 else
1372 from.s_addr = INADDR_ANY;
1373
1374 /* Record the number of seconds since we started sending. */
1375 if (ip->client->state == S_REQUESTING)
1376 ip->client->packet.secs = ip->client->secs;
1377 else {
1378 if (interval < 65536)
1379 ip->client->packet.secs = htons(interval);
1380 else
1381 ip->client->packet.secs = htons(65535);
1382 }
1383
1384 note("DHCPREQUEST on %s to %s port %d", ip->name,
1385 inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
1386
1387 /* Send out a packet. */
1388 (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
1389 from, &destination, NULL);
1390
1391 add_timeout(cur_time + ip->client->interval, send_request, ip);
1392}

◆ set_domain()

void set_domain ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 483 of file dhclient.c.

485{
486 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
487 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
488 HKEY RegKey1, RegKey2;
489
490 strcat(Buffer1, Adapter->DhclientInfo.name);
491
492 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
493 {
494 return;
495 }
496
497 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
498 {
499 RegCloseKey(RegKey1);
500 return;
501 }
502
503 if (new_lease->options[DHO_DOMAIN_NAME].len)
504 {
505 DH_DbgPrint(MID_TRACE, ("Setting DhcpDomain: %s\n", new_lease->options[DHO_DOMAIN_NAME].data));
506
507 RegSetValueExA(RegKey1,
508 "DhcpDomain",
509 0,
510 REG_SZ,
511 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
512 new_lease->options[DHO_DOMAIN_NAME].len);
513
514 RegSetValueExA(RegKey2,
515 "DhcpDomain",
516 0,
517 REG_SZ,
518 (LPBYTE)new_lease->options[DHO_DOMAIN_NAME].data,
519 new_lease->options[DHO_DOMAIN_NAME].len);
520 }
521 else
522 {
523 RegDeleteValueW(RegKey1, L"DhcpDomain");
524 RegDeleteValueW(RegKey2, L"DhcpDomain");
525 }
526
527 RegCloseKey(RegKey1);
528 RegCloseKey(RegKey2);
529
530}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define MAX_PATH
Definition: compat.h:34
#define L(x)
Definition: resources.c:13

Referenced by bind_lease().

◆ set_name_servers()

void set_name_servers ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 421 of file dhclient.c.

421 {
422 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
423 HKEY RegKey;
424
425 strcat(Buffer, Adapter->DhclientInfo.name);
427 return;
428
429
430 if( new_lease->options[DHO_DOMAIN_NAME_SERVERS].len ) {
431
432 struct iaddr nameserver;
433 char *nsbuf;
434 int i, addrs =
435 new_lease->options[DHO_DOMAIN_NAME_SERVERS].len / sizeof(ULONG);
436
437 nsbuf = malloc( addrs * sizeof(IP_ADDRESS_STRING) );
438
439 if( nsbuf) {
440 nsbuf[0] = 0;
441 for( i = 0; i < addrs; i++ ) {
442 nameserver.len = sizeof(ULONG);
443 memcpy( nameserver.iabuf,
444 new_lease->options[DHO_DOMAIN_NAME_SERVERS].data +
445 (i * sizeof(ULONG)), sizeof(ULONG) );
446 strcat( nsbuf, piaddr(nameserver) );
447 if( i != addrs-1 ) strcat( nsbuf, "," );
448 }
449
450 DH_DbgPrint(MID_TRACE,("Setting DhcpNameserver: %s\n", nsbuf));
451
452 RegSetValueExA( RegKey, "DhcpNameServer", 0, REG_SZ,
453 (LPBYTE)nsbuf, strlen(nsbuf) + 1 );
454 free( nsbuf );
455 }
456
457 } else {
458 RegDeleteValueW( RegKey, L"DhcpNameServer" );
459 }
460
461 RegCloseKey( RegKey );
462
463}

Referenced by bind_lease().

◆ setup_adapter()

void setup_adapter ( PDHCP_ADAPTER  Adapter,
struct client_lease new_lease 
)

Definition at line 561 of file dhclient.c.

561 {
562 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
563 struct iaddr netmask;
564 HKEY hkey;
565 int i;
566
567 strcat(Buffer, Adapter->DhclientInfo.name);
569 hkey = NULL;
570
571
572 if( Adapter->NteContext )
573 {
574 DeleteIPAddress( Adapter->NteContext );
575 Adapter->NteContext = 0;
576 }
577
578 /* Set up our default router if we got one from the DHCP server */
579 if( new_lease->options[DHO_SUBNET_MASK].len ) {
581
582 memcpy( netmask.iabuf,
583 new_lease->options[DHO_SUBNET_MASK].data,
584 new_lease->options[DHO_SUBNET_MASK].len );
586 ( *((ULONG*)new_lease->address.iabuf),
587 *((ULONG*)netmask.iabuf),
588 Adapter->IfMib.dwIndex,
589 &Adapter->NteContext,
590 &Adapter->NteInstance );
591 if (hkey) {
592 RegSetValueExA(hkey, "DhcpIPAddress", 0, REG_SZ, (LPBYTE)piaddr(new_lease->address), strlen(piaddr(new_lease->address))+1);
593 Buffer[0] = '\0';
594 for(i = 0; i < new_lease->options[DHO_SUBNET_MASK].len; i++)
595 {
596 sprintf(&Buffer[strlen(Buffer)], "%u", new_lease->options[DHO_SUBNET_MASK].data[i]);
597 if (i + 1 < new_lease->options[DHO_SUBNET_MASK].len)
598 strcat(Buffer, ".");
599 }
600 RegSetValueExA(hkey, "DhcpSubnetMask", 0, REG_SZ, (LPBYTE)Buffer, strlen(Buffer)+1);
601 RegSetValueExA(hkey, "DhcpServer", 0, REG_SZ, (LPBYTE)piaddr(new_lease->serveraddress), strlen(piaddr(new_lease->serveraddress))+1);
602
603 RegSetValueExA(hkey, "Lease", 0, REG_DWORD, (LPBYTE)&new_lease->lease, sizeof(DWORD));
604 RegSetValueExA(hkey, "LeaseObtainedTime", 0, REG_DWORD, (LPBYTE)&new_lease->obtained, sizeof(DWORD));
605 RegSetValueExA(hkey, "LeaseTerminatesTime", 0, REG_DWORD, (LPBYTE)&new_lease->expiry, sizeof(DWORD));
606 RegSetValueExA(hkey, "T1", 0, REG_DWORD, (LPBYTE)&new_lease->renewal, sizeof(DWORD));
607 RegSetValueExA(hkey, "T2", 0, REG_DWORD, (LPBYTE)&new_lease->rebind, sizeof(DWORD));
608 }
609
610 if( !NT_SUCCESS(Status) )
611 warning("AddIPAddress: %lx\n", Status);
612 }
613
614 if( new_lease->options[DHO_ROUTERS].len ) {
616
617 Adapter->RouterMib.dwForwardDest = 0; /* Default route */
618 Adapter->RouterMib.dwForwardMask = 0;
619 Adapter->RouterMib.dwForwardMetric1 = 1;
620 Adapter->RouterMib.dwForwardIfIndex = Adapter->IfMib.dwIndex;
621
622 if( Adapter->RouterMib.dwForwardNextHop ) {
623 /* If we set a default route before, delete it before continuing */
624 DeleteIpForwardEntry( &Adapter->RouterMib );
625 }
626
627 Adapter->RouterMib.dwForwardNextHop =
628 *((ULONG*)new_lease->options[DHO_ROUTERS].data);
629
631
632 if( !NT_SUCCESS(Status) )
633 warning("CreateIpForwardEntry: %lx\n", Status);
634
635 if (hkey) {
636 Buffer[0] = '\0';
637 for(i = 0; i < new_lease->options[DHO_ROUTERS].len; i++)
638 {
639 sprintf(&Buffer[strlen(Buffer)], "%u", new_lease->options[DHO_ROUTERS].data[i]);
640 if (i + 1 < new_lease->options[DHO_ROUTERS].len)
641 strcat(Buffer, ".");
642 }
643 RegSetValueExA(hkey, "DhcpDefaultGateway", 0, REG_SZ, (LPBYTE)Buffer, strlen(Buffer)+1);
644 }
645 }
646
647 if (hkey)
648 RegCloseKey(hkey);
649}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance)
Definition: iphlpapi_main.c:67
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
#define sprintf
Definition: sprintf.c:45
ULONG NteInstance
Definition: rosdhcp.h:72
MIB_IFROW IfMib
Definition: rosdhcp.h:68
DWORD dwIndex
Definition: ifmib.h:38
DWORD dwForwardMetric1
Definition: ipmib.h:88
IF_INDEX dwForwardIfIndex
Definition: ipmib.h:75
DWORD dwForwardDest
Definition: ipmib.h:71
DWORD dwForwardMask
Definition: ipmib.h:72
time_t renewal
Definition: dhcpd.h:155
time_t rebind
Definition: dhcpd.h:155

Referenced by bind_lease().

◆ state_bound()

void state_bound ( void ipp)

Definition at line 773 of file dhclient.c.

774{
775 struct interface_info *ip = ipp;
776
778
779 /* T1 has expired. */
780 make_request(ip, ip->client->active);
781 ip->client->xid = ip->client->packet.xid;
782
783 if (ip->client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) {
784 memcpy(ip->client->destination.iabuf, ip->client->active->
786 ip->client->destination.len = 4;
787 } else
788 ip->client->destination = iaddr_broadcast;
789
790 time(&ip->client->first_sending);
791 ip->client->interval = ip->client->config->initial_interval;
792 ip->client->state = S_RENEWING;
793
794 /* Send the first packet immediately. */
796}
static int state
Definition: maze.c:121
void make_request(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1517
struct iaddr iaddr_broadcast
Definition: dhclient.c:80
#define ASSERT_STATE(state_is, state_shouldbe)
Definition: dhclient.c:88

Referenced by bind_lease().

◆ state_init()

void state_init ( void ipp)

Definition at line 210 of file dhclient.c.

211{
212 struct interface_info *ip = ipp;
213
215
216 /* Make a DHCPDISCOVER packet, and set appropriate per-interface
217 flags. */
218 make_discover(ip, ip->client->active);
219 ip->client->xid = ip->client->packet.xid;
220 ip->client->destination = iaddr_broadcast;
221 ip->client->state = S_SELECTING;
222 time(&ip->client->first_sending);
223 ip->client->interval = ip->client->config->initial_interval;
224
225 /* Add an immediate timeout to cause the first DHCPDISCOVER packet
226 to go out. */
228}
void make_discover(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1434

Referenced by AdapterDiscoveryThread(), device_init(), dhcpnak(), send_request(), state_reboot(), state_selecting(), wined3d_cs_create(), wined3d_cs_exec_reset_state(), and wined3d_device_reset().

◆ state_panic()

void state_panic ( void ipp)

Definition at line 1214 of file dhclient.c.

1215{
1216 struct interface_info *ip = ipp;
1217 uint16_t address_low;
1218 int i;
1219 IPAddr IpAddress;
1220 ULONG Buffer[20];
1222 DWORD ret;
1223 PDHCP_ADAPTER Adapter = AdapterFindInfo(ip);
1224
1225 note("No DHCPOFFERS received.");
1226
1227 if (Adapter && !Adapter->NteContext)
1228 {
1229 /* Generate an automatic private address */
1230 DbgPrint("DHCPCSVC: Failed to receive a response from a DHCP server. An automatic private address will be assigned.\n");
1231
1232 /* FIXME: The address generation code sucks */
1233 srand(0);
1234
1235 for (;;)
1236 {
1237 address_low = rand();
1238 for (i = 0; i < ip->hw_address.hlen; i++)
1239 address_low += ip->hw_address.haddr[i];
1240
1241 IpAddress = htonl(0xA9FE0000 | address_low); // 169.254.X.X
1242
1243 /* Send an ARP request to check if the IP address is already in use */
1244 BufferSize = sizeof(Buffer);
1245 ret = SendARP(IpAddress,
1246 IpAddress,
1247 Buffer,
1248 &BufferSize);
1249 DH_DbgPrint(MID_TRACE,("DHCPCSVC: SendARP returned %lu\n", ret));
1250 if (ret != 0)
1251 {
1252 /* The IP address is not in use */
1253 DH_DbgPrint(MID_TRACE,("DHCPCSVC: Using automatic private address\n"));
1254 AddIPAddress(IpAddress,
1255 htonl(0xFFFF0000), // 255.255.0.0
1256 Adapter->IfMib.dwIndex,
1257 &Adapter->NteContext,
1258 &Adapter->NteInstance);
1259 return;
1260 }
1261 }
1262 }
1263}
unsigned short int uint16_t
Definition: acefiex.h:54
#define BufferSize
Definition: mmc.h:75
return ret
Definition: mutex.c:146
#define DbgPrint
Definition: hal.h:12
DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen)
#define htonl(x)
Definition: module.h:214
ULONG IPAddr
Definition: pfhook.h:35
void __cdecl srand(_In_ unsigned int _Seed)
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by send_discover().

◆ state_reboot()

void state_reboot ( void ipp)

Definition at line 172 of file dhclient.c.

173{
174 struct interface_info *ip = ipp;
176
177 /* If we don't remember an active lease, go straight to INIT. */
178 if (!ip->client->active || ip->client->active->is_bootp) {
179 state_init(ip);
180 return;
181 }
182
183 /* We are in the rebooting state. */
184 ip->client->state = S_REBOOTING;
185
186 /* make_request doesn't initialize xid because it normally comes
187 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
188 so pick an xid now. */
189 ip->client->xid = RtlRandom(&foo);
190
191 /* Make a DHCPREQUEST packet, and set appropriate per-interface
192 flags. */
193 make_request(ip, ip->client->active);
194 ip->client->destination = iaddr_broadcast;
195 time(&ip->client->first_sending);
196 ip->client->interval = ip->client->config->initial_interval;
197
198 /* Zap the medium list... */
199 ip->client->medium = NULL;
200
201 /* Send out the first DHCPREQUEST packet. */
203}

Referenced by Server_AcquireParameters().

◆ state_release()

void state_release ( void ipp)

Definition at line 231 of file dhclient.c.

232{
233 struct interface_info *ip = ipp;
235
237
238 /* Make a DHCPRELEASE packet, and set appropriate per-interface
239 flags. */
240 make_release(ip, ip->client->active);
241
242 /* make_request doesn't initialize xid because it normally comes
243 from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
244 so pick an xid now. */
245 ip->client->xid = RtlRandom(&foo);
247
248 ip->client->state = S_RELEASED;
250}
void make_release(struct interface_info *ip, struct client_lease *lease)
Definition: dhclient.c:1693
void send_release(void *ipp)
Definition: dhclient.c:1409
void unbind_lease(struct interface_info *ip)
Definition: dhclient.c:745
@ S_RELEASED
Definition: dhcpd.h:180

Referenced by Server_ReleaseParameters().

◆ state_selecting()

void state_selecting ( void ipp)

Definition at line 257 of file dhclient.c.

258{
259 struct interface_info *ip = ipp;
260 struct client_lease *lp, *next, *picked;
262
264
265 time(&cur_time);
266
267 /* Cancel state_selecting and send_discover timeouts, since either
268 one could have got us here. */
271
272 /* We have received one or more DHCPOFFER packets. Currently,
273 the only criterion by which we judge leases is whether or
274 not we get a response when we arp for them. */
275 picked = NULL;
276 for (lp = ip->client->offered_leases; lp; lp = next) {
277 next = lp->next;
278
279 /* Check to see if we got an ARPREPLY for the address
280 in this particular lease. */
281 if (!picked) {
282 if( !check_arp(ip,lp) ) goto freeit;
283 picked = lp;
284 picked->next = NULL;
285 } else {
286freeit:
288 }
289 }
290 ip->client->offered_leases = NULL;
291
292 /* If we just tossed all the leases we were offered, go back
293 to square one. */
294 if (!picked) {
295 ip->client->state = S_INIT;
296 state_init(ip);
297 return;
298 }
299
300 /* If it was a BOOTREPLY, we can just take the address right now. */
301 if (!picked->options[DHO_DHCP_MESSAGE_TYPE].len) {
302 ip->client->new = picked;
303
304 /* Make up some lease expiry times
305 XXX these should be configurable. */
306 ip->client->new->expiry = cur_time + 12000;
307 ip->client->new->renewal += cur_time + 8000;
308 ip->client->new->rebind += cur_time + 10000;
309
310 ip->client->state = S_REQUESTING;
311
312 /* Bind to the address we received. */
313 bind_lease(ip);
314 return;
315 }
316
317 /* Go to the REQUESTING state. */
318 ip->client->destination = iaddr_broadcast;
319 ip->client->state = S_REQUESTING;
320 ip->client->first_sending = cur_time;
321 ip->client->interval = ip->client->config->initial_interval;
322
323 /* Make a DHCPREQUEST packet from the lease we picked. */
324 make_request(ip, picked);
325 ip->client->xid = ip->client->packet.xid;
326
327 /* Toss the lease we picked - we'll get it back in a DHCPACK. */
328 free_client_lease(picked);
329
330 /* Add an immediate timeout to send the first DHCPREQUEST packet. */
332}
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by dhcpoffer(), and state_selecting().

◆ stop_client()

void stop_client ( void  )

Definition at line 129 of file dhclient.c.

130{
131 // AdapterStop();
132 // ApiFree();
133 /* FIXME: Close pipe and kill pipe thread */
134}

Referenced by ServiceMain().

◆ unbind_lease()

void unbind_lease ( struct interface_info ip)

Definition at line 745 of file dhclient.c.

746{
747 PDHCP_ADAPTER Adapter;
748
749 if (ip->client->active) {
750 free_client_lease(ip->client->active);
751 ip->client->active = NULL;
752 }
753
754 Adapter = AdapterFindInfo( ip );
755 if (Adapter) {
756 reset_adapter(Adapter);
757 unset_name_servers(Adapter);
758 unset_domain(Adapter);
759 }
760 else {
761 warning("Could not find adapter for info %p\n", ip);
762 return;
763 }
764}
void unset_domain(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:533
void unset_name_servers(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:466
void reset_adapter(PDHCP_ADAPTER Adapter)
Definition: dhclient.c:652

Referenced by state_release().

◆ unset_domain()

void unset_domain ( PDHCP_ADAPTER  Adapter)

Definition at line 533 of file dhclient.c.

535{
536 CHAR Buffer1[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
537 CHAR Buffer2[MAX_PATH] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters";
538 HKEY RegKey1, RegKey2;
539
540 strcat(Buffer1, Adapter->DhclientInfo.name);
541
542 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer1, 0, KEY_WRITE, &RegKey1 ) != ERROR_SUCCESS)
543 {
544 return;
545 }
546
547 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, Buffer2, 0, KEY_WRITE, &RegKey2 ) != ERROR_SUCCESS)
548 {
549 RegCloseKey(RegKey1);
550 return;
551 }
552
553 RegDeleteValueW(RegKey1, L"DhcpDomain");
554 RegDeleteValueW(RegKey2, L"DhcpDomain");
555
556 RegCloseKey(RegKey1);
557 RegCloseKey(RegKey2);
558}

Referenced by unbind_lease().

◆ unset_name_servers()

void unset_name_servers ( PDHCP_ADAPTER  Adapter)

Definition at line 466 of file dhclient.c.

468{
469 CHAR Buffer[200] = "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
470 HKEY RegKey;
471
472 strcat(Buffer, Adapter->DhclientInfo.name);
474 return;
475
476 RegDeleteValueW( RegKey, L"DhcpNameServer" );
477
478 RegCloseKey( RegKey );
479}

Referenced by unbind_lease().

◆ usage()

◆ write_client_lease()

void write_client_lease ( struct interface_info ip,
struct client_lease lease,
int  rewrite 
)

Definition at line 1797 of file dhclient.c.

1799{
1800 static int leases_written;
1801 struct tm *t;
1802 int i;
1803
1804 if (!rewrite) {
1805 if (leases_written++ > 20) {
1807 leases_written = 0;
1808 }
1809 }
1810
1811 /* If the lease came from the config file, we don't need to stash
1812 a copy in the lease database. */
1813 if (lease->is_static)
1814 return;
1815
1816 if (!leaseFile) { /* XXX */
1818 if (!leaseFile) {
1819 error("can't create %s", path_dhclient_db);
1820 return;
1821 }
1822 }
1823
1824 fprintf(leaseFile, "lease {\n");
1825 if (lease->is_bootp)
1826 fprintf(leaseFile, " bootp;\n");
1827 fprintf(leaseFile, " interface \"%s\";\n", ip->name);
1828 fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address));
1829 if (lease->filename)
1830 fprintf(leaseFile, " filename \"%s\";\n", lease->filename);
1831 if (lease->server_name)
1832 fprintf(leaseFile, " server-name \"%s\";\n",
1833 lease->server_name);
1834 if (lease->medium)
1835 fprintf(leaseFile, " medium \"%s\";\n", lease->medium->string);
1836 for (i = 0; i < 256; i++)
1837 if (lease->options[i].len)
1838 fprintf(leaseFile, " option %s %s;\n",
1840 pretty_print_option(i, lease->options[i].data,
1841 lease->options[i].len, 1, 1));
1842
1843 t = gmtime(&lease->renewal);
1844 if (t)
1845 fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n",
1846 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1847 t->tm_hour, t->tm_min, t->tm_sec);
1848 t = gmtime(&lease->rebind);
1849 if (t)
1850 fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n",
1851 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1852 t->tm_hour, t->tm_min, t->tm_sec);
1853 t = gmtime(&lease->expiry);
1854 if (t)
1855 fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n",
1856 t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
1857 t->tm_hour, t->tm_min, t->tm_sec);
1858 fprintf(leaseFile, "}\n");
1860}
void rewrite_client_leases(struct interface_info *ifi)
Definition: dhclient.c:1775
GLdouble GLdouble t
Definition: gl.h:2047
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:415
unsigned int is_static
Definition: dhcpd.h:165
Definition: time.h:68

Referenced by rewrite_client_leases().

Variable Documentation

◆ debug_trace_level

unsigned long debug_trace_level = 0

Definition at line 71 of file dhclient.c.

◆ iaddr_broadcast

struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } }

Definition at line 80 of file dhclient.c.

Referenced by state_bound(), state_init(), state_reboot(), and state_selecting().

◆ inaddr_any

struct in_addr inaddr_any

Definition at line 81 of file dhclient.c.

Referenced by init_client(), send_decline(), and send_discover().

◆ leaseFile

FILE* leaseFile

Definition at line 1772 of file dhclient.c.

Referenced by rewrite_client_leases(), and write_client_lease().

◆ log_perror

int log_perror = 1

Definition at line 76 of file dhclient.c.

◆ log_priority

int log_priority

Definition at line 92 of file dhclient.c.

◆ no_daemon

int no_daemon

Definition at line 93 of file dhclient.c.

◆ path_dhclient_conf

char* path_dhclient_conf = _PATH_DHCLIENT_CONF

Definition at line 73 of file dhclient.c.

◆ path_dhclient_db

char* path_dhclient_db = NULL

Definition at line 74 of file dhclient.c.

Referenced by rewrite_client_leases(), and write_client_lease().

◆ privfd

int privfd

Definition at line 77 of file dhclient.c.

◆ routefd

int routefd

Definition at line 95 of file dhclient.c.

◆ scripttime

time_t scripttime

Definition at line 107 of file dhclient.c.

◆ sockaddr_broadcast

struct sockaddr_in sockaddr_broadcast

Definition at line 82 of file dhclient.c.

Referenced by init_client(), send_decline(), and send_discover().

◆ unknown_ok

int unknown_ok = 1

Definition at line 94 of file dhclient.c.

Referenced by check_option().