Deleted Added
full compact
res_mkquery.c (170244) res_mkquery.c (186090)
1/*
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 52 unchanged lines hidden (view full) ---

61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
65 */
66
67#if defined(LIBC_SCCS) && !defined(lint)
68static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
1/*
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 52 unchanged lines hidden (view full) ---

61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
65 */
66
67#if defined(LIBC_SCCS) && !defined(lint)
68static const char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
69static const char rcsid[] = "$Id: res_mkquery.c,v 1.5.18.1 2005/04/27 05:01:11 sra Exp $";
69static const char rcsid[] = "$Id: res_mkquery.c,v 1.5.18.2 2008/04/03 23:15:15 marka Exp $";
70#endif /* LIBC_SCCS and not lint */
71#include <sys/cdefs.h>
70#endif /* LIBC_SCCS and not lint */
71#include <sys/cdefs.h>
72__FBSDID("$FreeBSD: head/lib/libc/resolv/res_mkquery.c 170244 2007-06-03 17:20:27Z ume $");
72__FBSDID("$FreeBSD: head/lib/libc/resolv/res_mkquery.c 186090 2008-12-14 19:39:53Z ume $");
73
74#include "port_before.h"
75#include <sys/types.h>
76#include <sys/param.h>
77#include <netinet/in.h>
78#include <arpa/nameser.h>
79#include <netdb.h>
80#include <resolv.h>

--- 115 unchanged lines hidden (view full) ---

196 default:
197 return (-1);
198 }
199 return (cp - buf);
200}
201
202#ifdef RES_USE_EDNS0
203/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
73
74#include "port_before.h"
75#include <sys/types.h>
76#include <sys/param.h>
77#include <netinet/in.h>
78#include <arpa/nameser.h>
79#include <netdb.h>
80#include <resolv.h>

--- 115 unchanged lines hidden (view full) ---

196 default:
197 return (-1);
198 }
199 return (cp - buf);
200}
201
202#ifdef RES_USE_EDNS0
203/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
204#ifndef T_OPT
205#define T_OPT 41
206#endif
207
208int
209res_nopt(res_state statp,
210 int n0, /*%< current offset in buffer */
211 u_char *buf, /*%< buffer to put query */
212 int buflen, /*%< size of buffer */
213 int anslen) /*%< UDP answer buffer size */
214{

--- 8 unchanged lines hidden (view full) ---

223
224 hp = (HEADER *) buf;
225 cp = buf + n0;
226 ep = buf + buflen;
227
228 if ((ep - cp) < 1 + RRFIXEDSZ)
229 return (-1);
230
204
205int
206res_nopt(res_state statp,
207 int n0, /*%< current offset in buffer */
208 u_char *buf, /*%< buffer to put query */
209 int buflen, /*%< size of buffer */
210 int anslen) /*%< UDP answer buffer size */
211{

--- 8 unchanged lines hidden (view full) ---

220
221 hp = (HEADER *) buf;
222 cp = buf + n0;
223 ep = buf + buflen;
224
225 if ((ep - cp) < 1 + RRFIXEDSZ)
226 return (-1);
227
231 *cp++ = 0; /*%< "." */
232 ns_put16(T_OPT, cp); /*%< TYPE */
228 *cp++ = 0; /*%< "." */
229 ns_put16(ns_t_opt, cp); /*%< TYPE */
233 cp += INT16SZ;
234 if (anslen > 0xffff)
235 anslen = 0xffff; /* limit to 16bit value */
230 cp += INT16SZ;
231 if (anslen > 0xffff)
232 anslen = 0xffff; /* limit to 16bit value */
236 ns_put16(anslen & 0xffff, cp); /*%< CLASS = UDP payload size */
233 ns_put16(anslen & 0xffff, cp); /*%< CLASS = UDP payload size */
237 cp += INT16SZ;
234 cp += INT16SZ;
238 *cp++ = NOERROR; /*%< extended RCODE */
239 *cp++ = 0; /*%< EDNS version */
235 *cp++ = NOERROR; /*%< extended RCODE */
236 *cp++ = 0; /*%< EDNS version */
237
240 if (statp->options & RES_USE_DNSSEC) {
241#ifdef DEBUG
242 if (statp->options & RES_DEBUG)
243 printf(";; res_opt()... ENDS0 DNSSEC\n");
244#endif
245 flags |= NS_OPT_DNSSEC_OK;
246 }
247 ns_put16(flags, cp);
248 cp += INT16SZ;
238 if (statp->options & RES_USE_DNSSEC) {
239#ifdef DEBUG
240 if (statp->options & RES_DEBUG)
241 printf(";; res_opt()... ENDS0 DNSSEC\n");
242#endif
243 flags |= NS_OPT_DNSSEC_OK;
244 }
245 ns_put16(flags, cp);
246 cp += INT16SZ;
249 ns_put16(0, cp); /*%< RDLEN */
247
248 ns_put16(0U, cp); /*%< RDLEN */
250 cp += INT16SZ;
249 cp += INT16SZ;
250
251 hp->arcount = htons(ntohs(hp->arcount) + 1);
252
253 return (cp - buf);
254}
251 hp->arcount = htons(ntohs(hp->arcount) + 1);
252
253 return (cp - buf);
254}
255
256/*
257 * Construct variable data (RDATA) block for OPT psuedo-RR, append it
258 * to the buffer, then update the RDLEN field (previously set to zero by
259 * res_nopt()) with the new RDATA length.
260 */
261int
262res_nopt_rdata(res_state statp,
263 int n0, /*%< current offset in buffer */
264 u_char *buf, /*%< buffer to put query */
265 int buflen, /*%< size of buffer */
266 u_char *rdata, /*%< ptr to start of opt rdata */
267 u_short code, /*%< OPTION-CODE */
268 u_short len, /*%< OPTION-LENGTH */
269 u_char *data) /*%< OPTION_DATA */
270{
271 register u_char *cp, *ep;
272
273#ifdef DEBUG
274 if ((statp->options & RES_DEBUG) != 0U)
275 printf(";; res_nopt_rdata()\n");
255#endif
256
276#endif
277
278 cp = buf + n0;
279 ep = buf + buflen;
280
281 if ((ep - cp) < (4 + len))
282 return (-1);
283
284 if (rdata < (buf + 2) || rdata >= ep)
285 return (-1);
286
287 ns_put16(code, cp);
288 cp += INT16SZ;
289
290 ns_put16(len, cp);
291 cp += INT16SZ;
292
293 memcpy(cp, data, len);
294 cp += len;
295
296 len = cp - rdata;
297 ns_put16(len, rdata - 2); /* Update RDLEN field */
298
299 return (cp - buf);
300}
301#endif
302
257/*! \file */
303/*! \file */