summaryrefslogtreecommitdiff
path: root/net-mgmt/wide-dhcp/files/patch-as
blob: d41aee41140466e40b5706254878ec9bf9a5f685 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
--- client/dhcpc.c.orig	Fri Nov  3 01:40:40 1995
+++ client/dhcpc.c	Thu Mar 27 15:11:20 1997
@@ -53,6 +53,12 @@
 #ifndef sun
 #include <net/bpf.h>
 #endif
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#if (__FreeBSD_version == 199702) || (__FreeBSD_version >= 300000)
+#include <net/if_var.h>
+#endif
+#endif
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/if_ether.h>
@@ -86,6 +92,7 @@
 struct dhcp_reqspec reqspec;
 struct if_info intface;
 struct dhcp_param *param_list;
+int f_resolv, f_hostname;
 
 int (*fsm[MAX_STATES])();
 
@@ -227,6 +234,14 @@
 		((brdaddr.s_addr != 0) ? &brdaddr : NULL)) != 1) {
     set_route(paramp);
   }
+#ifdef __FreeBSD__
+  if (f_resolv) {
+	set_resolv(param_list);
+  }
+  if (f_hostname) {
+	set_hostname(param_list);
+  }
+#endif
 #endif
 
   return;
@@ -264,15 +279,8 @@
   /*
    * split conditions into pieces for debugging
    */
-#ifndef sun
-  if (ntohs(rcv.ip->ip_len) < DFLTBOOTPLEN + UDPHL + IPHL)
-    return(0);
-  if (ntohs(rcv.udp->uh_ulen) < DFLTBOOTPLEN + UDPHL)
-    return(0);
-#else
   if (rcv.udp->uh_dport != dhcpc_port)
     return(0);
-#endif 
   if (ripcksum != cksum((u_short *) rcv.ip, rcv.ip->ip_hl * 2))
     return(0);
   if (rcv.udp->uh_sum != 0 &&
@@ -321,15 +329,8 @@
   /*
    * split conditions into pieces for debugging
    */
-#ifndef sun
-  if (ntohs(rcv.ip->ip_len) < DFLTBOOTPLEN + UDPHL + IPHL)
-    return(0);
-  if (ntohs(rcv.udp->uh_ulen) < DFLTBOOTPLEN + UDPHL)
-    return(0);
-#else
   if (rcv.udp->uh_dport != dhcpc_port)
     return(0);
-#endif 
   if (ripcksum != cksum((u_short *) rcv.ip, rcv.ip->ip_hl * 2))
     return(0);
   if (rcv.udp->uh_sum != 0 &&
@@ -1740,7 +1741,11 @@
 void
 usage()
 {
-  fprintf(stderr, "Usage: dhcpc [-d] if_name\n");
+#ifdef __FreeBSD__
+  fprintf(stderr, "Usage: dhcpc [-v] [-drn] if_name\n");
+#else
+  fprintf(stderr, "Usage: dhcpc [-v] [-d] if_name\n");
+#endif
   exit(1);
 }
 
@@ -1760,17 +1765,42 @@
 {
   int debug = 0;
   int n = 0;
+  int count;
+  FILE *pid_file;
   struct if_info ifinfo;
+#ifdef __FreeBSD__
+  char pid_filename[MAXPATHLEN];
+#endif
 
   bzero(&reqspec, sizeof(reqspec));
   bzero(&ifinfo, sizeof(ifinfo));
+#ifdef __FreeBSD__
+#define COM_OPTS        "vdrn"
+#else
+#define COM_OPTS        "vd"
+#endif
+
   if (argc < 2) usage();
-  --argc, ++argv;
-  if (argv[0][0] == '-' && argv[0][1] == 'v') version();
-  if (argv[0][0] == '-' && argv[0][1] == 'd') {
-    debug = 1;
-    --argc, ++argv;
+
+  while ((count = getopt(argc, argv, COM_OPTS)) != EOF) {
+    switch (count) {
+      case 'v':
+        version();
+      case 'd':
+        debug = 1;
+        break;
+#ifdef __FreeBSD__
+      case 'r':
+        f_resolv = 1;
+        break;
+      case 'n':
+        f_hostname = 1;
+        break;
+#endif
+    }
   }
+  argc -= optind;
+  argv += optind;
 
   if (argc < 1) usage();
   strcpy(ifinfo.name, argv[0]);
@@ -1790,6 +1820,19 @@
       close(n);
     }
   }
+  /* initialization works well, so recored its own pid */
+#ifdef __FreeBSD__
+  strncpy(pid_filename, PATH_PID, MAXPATHLEN);
+  strncat(pid_filename, "/dhcpc.", (MAXPATHLEN - strlen(pid_filename)));
+  strncat(pid_filename, ifinfo.name, (MAXPATHLEN - strlen(pid_filename)));
+  strncat(pid_filename, ".pid", (MAXPATHLEN - strlen(pid_filename)));
+  if ((pid_file = fopen(pid_filename, "w")) != NULL) {
+#else
+  if ((pid_file = fopen(PATH_PID, "w")) != NULL) {
+#endif
+    fprintf(pid_file, "%d\n", (int) getpid());
+    fclose(pid_file);
+  }
 
   /*
    * set request specification
@@ -1802,6 +1845,11 @@
   reqspec.reqlist.list[reqspec.reqlist.len++] = SUBNET_MASK;
   reqspec.reqlist.list[reqspec.reqlist.len++] = ROUTER;
   reqspec.reqlist.list[reqspec.reqlist.len++] = BRDCAST_ADDR;
+#ifdef __FreeBSD__
+  reqspec.reqlist.list[reqspec.reqlist.len++] = DNS_DOMAIN;
+  reqspec.reqlist.list[reqspec.reqlist.len++] = DNS_SERVER;
+  reqspec.reqlist.list[reqspec.reqlist.len++] = HOSTNAME;
+#endif
   
   return(dhcp_client(&ifinfo));
 }