~ubuntu-branches/ubuntu/trusty/dhcpcd/trusty-security

« back to all changes in this revision

Viewing changes to src/client.h

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2005-09-30 02:21:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050930022151-vq3xlcazj0bdpyf4
Tags: 1:2.0.0-2
Clear out /etc/dhcpc/resolv.conf and /var/lib/dhcpc/* 
during purge. (closes: #330515)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * dhcpcd - DHCP client daemon -
 
3
 * Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
 
4
 * Copyright (C) January, 1998 Sergei Viznyuk <sv@phystech.com>
 
5
 * Copyright (C) 2005 Roy Marples <uberlord@gentoo.org>
 
6
 * Copyright (C) 2005 Simon Kelley <simon@thekelleys.org.uk>
 
7
 * 
 
8
 * dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
 
9
 *
 
10
 * This is free software; you can redistribute it and/or modify it
 
11
 * under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
 * See the GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
23
 */
 
24
 
 
25
#ifndef CLIENT_H
 
26
#define CLIENT_H
 
27
 
 
28
#include "config.h"
 
29
 
 
30
#ifdef __GLIBC__
 
31
#include <net/ethernet.h>
 
32
#include <linux/types.h>
 
33
#include <linux/if_tr.h>
 
34
#else
 
35
#include <linux/if_ether.h>
 
36
#define ETHERTYPE_IP            0x0800
 
37
#define ETHERTYPE_ARP           0x0806
 
38
#endif
 
39
 
 
40
#define IPPACKET_SIZE           1500
 
41
#define MAGIC_COOKIE            0x63825363
 
42
#define BROADCAST_FLAG          0x8000
 
43
#define MAC_BCAST_ADDR          "\xff\xff\xff\xff\xff\xff"
 
44
#ifndef AF_PACKET
 
45
#define AF_PACKET               17      /* should have been in socketbits.h */
 
46
#endif
 
47
#define CLASS_ID_MAX_LEN        48
 
48
#define CLIENT_ID_MAX_LEN       48
 
49
#define HOSTNAME_MAX_LEN        64
 
50
#define HWADDR_TRIES            3
 
51
 
 
52
/* UDP port numbers for DHCP */
 
53
#define DHCP_SERVER_PORT        67      /* from client to server */
 
54
#define DHCP_CLIENT_PORT        68      /* from server to client */
 
55
 
 
56
/* DHCP message OP code */
 
57
#define DHCP_BOOTREQUEST        1
 
58
#define DHCP_BOOTREPLY          2
 
59
 
 
60
/* DHCP message type */
 
61
#define DHCP_DISCOVER           1
 
62
#define DHCP_OFFER              2
 
63
#define DHCP_REQUEST            3
 
64
#define DHCP_DECLINE            4
 
65
#define DHCP_ACK                5
 
66
#define DHCP_NAK                6
 
67
#define DHCP_RELEASE            7
 
68
#define DHCP_INFORM             8
 
69
/* DHCP RETRANSMISSION TIMEOUT (microseconds) */
 
70
#define DHCP_INITIAL_RTO        (4*1000000)
 
71
#define DHCP_MAX_RTO            (64*1000000)
 
72
 
 
73
/* DHCP option and value (cf. RFC1533) */
 
74
enum
 
75
{
 
76
  padOption                             =       0,
 
77
  subnetMask                            =       1,
 
78
  timerOffset                           =       2,
 
79
  routersOnSubnet                       =       3,
 
80
  timeServer                            =       4,
 
81
  nameServer                            =       5,
 
82
  dns                                   =       6,
 
83
  logServer                             =       7,
 
84
  cookieServer                          =       8,
 
85
  lprServer                             =       9,
 
86
  impressServer                         =       10,
 
87
  resourceLocationServer                =       11,
 
88
  hostName                              =       12,
 
89
  bootFileSize                          =       13,
 
90
  meritDumpFile                         =       14,
 
91
  domainName                            =       15,
 
92
  swapServer                            =       16,
 
93
  rootPath                              =       17,
 
94
  extentionsPath                        =       18,
 
95
  IPforwarding                          =       19,
 
96
  nonLocalSourceRouting                 =       20,
 
97
  policyFilter                          =       21,
 
98
  maxDgramReasmSize                     =       22,
 
99
  defaultIPTTL                          =       23,
 
100
  pathMTUagingTimeout                   =       24,
 
101
  pathMTUplateauTable                   =       25,
 
102
  ifMTU                                 =       26,
 
103
  allSubnetsLocal                       =       27,
 
104
  broadcastAddr                         =       28,
 
105
  performMaskDiscovery                  =       29,
 
106
  maskSupplier                          =       30,
 
107
  performRouterDiscovery                =       31,
 
108
  routerSolicitationAddr                =       32,
 
109
  staticRoute                           =       33,
 
110
  trailerEncapsulation                  =       34,
 
111
  arpCacheTimeout                       =       35,
 
112
  ethernetEncapsulation                 =       36,
 
113
  tcpDefaultTTL                         =       37,
 
114
  tcpKeepaliveInterval                  =       38,
 
115
  tcpKeepaliveGarbage                   =       39,
 
116
  nisDomainName                         =       40,
 
117
  nisServers                            =       41,
 
118
  ntpServers                            =       42,
 
119
  vendorSpecificInfo                    =       43,
 
120
  netBIOSnameServer                     =       44,
 
121
  netBIOSdgramDistServer                =       45,
 
122
  netBIOSnodeType                       =       46,
 
123
  netBIOSscope                          =       47,
 
124
  xFontServer                           =       48,
 
125
  xDisplayManager                       =       49,
 
126
  dhcpRequestedIPaddr                   =       50,
 
127
  dhcpIPaddrLeaseTime                   =       51,
 
128
  dhcpOptionOverload                    =       52,
 
129
  dhcpMessageType                       =       53,
 
130
  dhcpServerIdentifier                  =       54,
 
131
  dhcpParamRequest                      =       55,
 
132
  dhcpMsg                               =       56,
 
133
  dhcpMaxMsgSize                        =       57,
 
134
  dhcpT1value                           =       58,
 
135
  dhcpT2value                           =       59,
 
136
  dhcpClassIdentifier                   =       60,
 
137
  dhcpClientIdentifier                  =       61,
 
138
  dhcpFQDNHostName                      =       81,
 
139
  dnsSearchPath                         =       119, /* RFC 3397 */
 
140
  endOption                             =       255
 
141
};
 
142
 
 
143
/* SetFQDNHostName values - lsnybble used in flags
 
144
 * byte (see buildmsg.c), hsnybble to create order
 
145
 * and to allow 0x00 to mean disable
 
146
 */
 
147
enum {
 
148
  FQDNdisable                           =       0x00,
 
149
  FQDNnone                              =       0x18,
 
150
  FQDNptr                               =       0x20,
 
151
  FQDNboth                              =       0x31
 
152
};
 
153
 
 
154
typedef struct dhcpInterface
 
155
{
 
156
  unsigned char version[11];
 
157
  int           ciaddr;
 
158
  int           siaddr;
 
159
  int           class_len;
 
160
  int           client_len;
 
161
  unsigned int  xid;
 
162
  unsigned char shaddr[ETH_ALEN];
 
163
  unsigned char class_id[CLASS_ID_MAX_LEN];
 
164
  unsigned char client_id[CLIENT_ID_MAX_LEN];
 
165
#if 0
 
166
  unsigned char chaddr[ETH_ALEN];
 
167
#endif
 
168
} dhcpInterface;
 
169
 
 
170
typedef struct dhcpMessage
 
171
{
 
172
  u_char  op;           /* message type */
 
173
  u_char  htype;        /* hardware address type */
 
174
  u_char  hlen;         /* hardware address length */
 
175
  u_char  hops;         /* should be zero in client's message */
 
176
  u_int   xid;          /* transaction id */
 
177
  u_short secs;         /* elapsed time in sec. from trying to boot */
 
178
  u_short flags;
 
179
  u_int   ciaddr;       /* (previously allocated) client IP address */
 
180
  u_int   yiaddr;       /* 'your' client IP address */
 
181
  u_int   siaddr;       /* should be zero in client's messages */
 
182
  u_int   giaddr;       /* should be zero in client's messages */
 
183
  u_char  chaddr[16];   /* client's hardware address */
 
184
  u_char  sname[64];    /* server host name, null terminated string */
 
185
  u_char  file[128];    /* boot file name, null terminated string */
 
186
  u_char  options[312]; /* message options */
 
187
} __attribute__((packed)) dhcpMessage;
 
188
 
 
189
struct packed_ether_header {
 
190
  u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
 
191
  u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
 
192
  u_int16_t ether_type;                 /* packet type ID field */
 
193
} __attribute__((packed));
 
194
 
 
195
typedef struct udpipMessage
 
196
{
 
197
  struct packed_ether_header    ethhdr;
 
198
  char  udpipmsg[IPPACKET_SIZE];
 
199
  char  pad_for_tokenring_header[sizeof(struct trh_hdr) + sizeof(struct trllc)];
 
200
} __attribute__((packed)) udpipMessage;
 
201
 
 
202
typedef struct dhcpOptions
 
203
{
 
204
  u_char num;
 
205
  u_char len[256];
 
206
  void   *val[256];
 
207
} __attribute__((packed)) dhcpOptions;
 
208
 
 
209
int peekfd(int s,int tv_usec);
 
210
void *dhcpReboot();
 
211
void *dhcpStart();
 
212
void *dhcpInit();
 
213
void *dhcpRequest(unsigned xid,void (*buildDhcpMsg)(unsigned));
 
214
void *dhcpBound();
 
215
void *dhcpRenew();
 
216
void *dhcpRebind();
 
217
void *dhcpRelease();
 
218
void *dhcpStop();
 
219
void *dhcpInform();
 
220
#ifdef ARPCHECK
 
221
void *dhcpDecline();
 
222
#endif
 
223
 
 
224
#endif