makefiles: Explicitly create destination dirs when installing symlinks.
[wine/zf.git] / dlls / iphlpapi / icmp.c
blob8e425ea68ed9a52e5d1e9336bcb3dee4ea0fb1da
1 /*
2 * ICMP
4 * Francois Gouget, 1999, based on the work of
5 * RW Hall, 1999, based on public domain code PING.C by Mike Muus (1983)
6 * and later works (c) 1989 Regents of Univ. of California - see copyright
7 * notice at end of source-code.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Future work:
25 * - Systems like FreeBSD don't seem to support the IP_TTL option and maybe others.
26 * But using IP_HDRINCL and building the IP header by hand might work.
27 * - Not all IP options are supported.
28 * - Are ICMP handles real handles, i.e. inheritable and all? There might be some
29 * more work to do here, including server side stuff with synchronization.
30 * - This API should probably be thread safe. Is it really?
31 * - Using the winsock functions has not been tested.
34 #include "config.h"
36 #include <sys/types.h>
37 #ifdef HAVE_SYS_SOCKET_H
38 # include <sys/socket.h>
39 #endif
40 #ifdef HAVE_NETDB_H
41 # include <netdb.h>
42 #endif
43 #ifdef HAVE_NETINET_IN_SYSTM_H
44 # include <netinet/in_systm.h>
45 #endif
46 #ifdef HAVE_NETINET_IN_H
47 # include <netinet/in.h>
48 #endif
50 #ifdef HAVE_SYS_TIME_H
51 # include <sys/time.h>
52 #endif
53 #include <stdarg.h>
54 #include <string.h>
55 #include <errno.h>
56 #ifdef HAVE_UNISTD_H
57 # include <unistd.h>
58 #endif
59 #ifdef HAVE_ARPA_INET_H
60 # include <arpa/inet.h>
61 #endif
62 #ifdef HAVE_SYS_POLL_H
63 # include <sys/poll.h>
64 #endif
66 #define USE_WS_PREFIX
68 #include "windef.h"
69 #include "winbase.h"
70 #include "winerror.h"
71 #include "winternl.h"
72 #include "ipexport.h"
73 #include "icmpapi.h"
74 #include "wine/debug.h"
76 /* Set up endianness macros for the ip and ip_icmp BSD headers */
77 #ifndef BIG_ENDIAN
78 #define BIG_ENDIAN 4321
79 #endif
80 #ifndef LITTLE_ENDIAN
81 #define LITTLE_ENDIAN 1234
82 #endif
83 #ifndef BYTE_ORDER
84 #ifdef WORDS_BIGENDIAN
85 #define BYTE_ORDER BIG_ENDIAN
86 #else
87 #define BYTE_ORDER LITTLE_ENDIAN
88 #endif
89 #endif /* BYTE_ORDER */
91 #define u_int16_t WORD
92 #define u_int32_t DWORD
94 /* These are BSD headers. We use these here because they are needed on
95 * libc5 Linux systems. On other platforms they are usually simply more
96 * complete than the native stuff, and cause less portability problems
97 * so we use them anyway.
99 #include "ip.h"
100 #include "ip_icmp.h"
103 WINE_DEFAULT_DEBUG_CHANNEL(icmp);
104 WINE_DECLARE_DEBUG_CHANNEL(winediag);
107 typedef struct {
108 int sid;
109 IP_OPTION_INFORMATION default_opts;
110 } icmp_t;
112 #define IP_OPTS_UNKNOWN 0
113 #define IP_OPTS_DEFAULT 1
114 #define IP_OPTS_CUSTOM 2
116 #define MAXIPLEN 60
117 #define MAXICMPLEN 76
119 /* The sequence number is unique process wide, so that all threads
120 * have a distinct sequence number.
122 static LONG icmp_sequence=0;
124 static int in_cksum(u_short *addr, int len)
126 int nleft=len;
127 u_short *w = addr;
128 int sum = 0;
129 u_short answer = 0;
131 while (nleft > 1) {
132 sum += *w++;
133 nleft -= 2;
136 if (nleft == 1) {
137 *(u_char *)(&answer) = *(u_char *)w;
138 sum += answer;
141 sum = (sum >> 16) + (sum & 0xffff);
142 sum += (sum >> 16);
143 answer = ~sum;
144 return(answer);
150 * Exported Routines.
153 /***********************************************************************
154 * Icmp6CreateFile (IPHLPAPI.@)
156 HANDLE WINAPI Icmp6CreateFile(VOID)
158 icmp_t* icp;
160 int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6);
161 if (sid < 0)
163 /* Some systems (e.g. Linux 3.0+ and Mac OS X) support
164 non-privileged ICMP via SOCK_DGRAM type. */
165 sid=socket(AF_INET6,SOCK_DGRAM,IPPROTO_ICMPV6);
167 if (sid < 0) {
168 ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
169 SetLastError(ERROR_ACCESS_DENIED);
170 return INVALID_HANDLE_VALUE;
173 icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp));
174 if (icp==NULL) {
175 close(sid);
176 SetLastError(IP_NO_RESOURCES);
177 return INVALID_HANDLE_VALUE;
179 icp->sid=sid;
180 icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN;
181 return (HANDLE)icp;
185 /***********************************************************************
186 * Icmp6SendEcho2 (IPHLPAPI.@)
188 DWORD WINAPI Icmp6SendEcho2(
189 HANDLE IcmpHandle,
190 HANDLE Event,
191 PIO_APC_ROUTINE ApcRoutine,
192 PVOID ApcContext,
193 struct sockaddr_in6* SourceAddress,
194 struct sockaddr_in6* DestinationAddress,
195 LPVOID RequestData,
196 WORD RequestSize,
197 PIP_OPTION_INFORMATION RequestOptions,
198 LPVOID ReplyBuffer,
199 DWORD ReplySize,
200 DWORD Timeout
203 FIXME("(%p, %p, %p, %p, %p, %p, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle, Event,
204 ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData,
205 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
206 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
207 return 0;
211 /***********************************************************************
212 * IcmpCreateFile (IPHLPAPI.@)
214 HANDLE WINAPI IcmpCreateFile(VOID)
216 icmp_t* icp;
218 int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
219 if (sid < 0)
221 /* Some systems (e.g. Linux 3.0+ and Mac OS X) support
222 non-privileged ICMP via SOCK_DGRAM type. */
223 sid=socket(AF_INET,SOCK_DGRAM,IPPROTO_ICMP);
225 if (sid < 0) {
226 ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n");
227 SetLastError(ERROR_ACCESS_DENIED);
228 return INVALID_HANDLE_VALUE;
231 icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp));
232 if (icp==NULL) {
233 close(sid);
234 SetLastError(IP_NO_RESOURCES);
235 return INVALID_HANDLE_VALUE;
237 icp->sid=sid;
238 icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN;
239 return (HANDLE)icp;
243 /***********************************************************************
244 * IcmpCloseHandle (IPHLPAPI.@)
246 BOOL WINAPI IcmpCloseHandle(HANDLE IcmpHandle)
248 icmp_t* icp=(icmp_t*)IcmpHandle;
249 if (IcmpHandle==INVALID_HANDLE_VALUE) {
250 /* FIXME: in fact win98 seems to ignore the handle value !!! */
251 SetLastError(ERROR_INVALID_HANDLE);
252 return FALSE;
255 close( icp->sid );
256 HeapFree(GetProcessHeap (), 0, icp);
257 return TRUE;
261 /***********************************************************************
262 * IcmpSendEcho (IPHLPAPI.@)
264 DWORD WINAPI IcmpSendEcho(
265 HANDLE IcmpHandle,
266 IPAddr DestinationAddress,
267 LPVOID RequestData,
268 WORD RequestSize,
269 PIP_OPTION_INFORMATION RequestOptions,
270 LPVOID ReplyBuffer,
271 DWORD ReplySize,
272 DWORD Timeout
275 icmp_t* icp=(icmp_t*)IcmpHandle;
276 unsigned char *buffer;
277 int reqsize, repsize;
279 struct icmp_echo_reply* ier;
280 struct ip* ip_header;
281 struct icmp* icmp_header;
282 char* endbuf;
283 int ip_header_len;
284 struct pollfd fdr;
285 DWORD send_time,recv_time;
286 struct sockaddr_in addr;
287 socklen_t addrlen;
288 unsigned short id,seq,cksum;
289 int res;
291 if (IcmpHandle==INVALID_HANDLE_VALUE) {
292 /* FIXME: in fact win98 seems to ignore the handle value !!! */
293 SetLastError(ERROR_INVALID_PARAMETER);
294 return 0;
297 if (!ReplyBuffer||!ReplySize) {
298 SetLastError(ERROR_INVALID_PARAMETER);
299 return 0;
302 if (ReplySize<sizeof(ICMP_ECHO_REPLY)) {
303 SetLastError(IP_BUF_TOO_SMALL);
304 return 0;
306 /* check the request size against SO_MAX_MSG_SIZE using getsockopt */
308 if (!DestinationAddress) {
309 SetLastError(ERROR_INVALID_NETNAME);
310 return 0;
313 /* Prepare the request */
314 id=getpid() & 0xFFFF;
315 seq=InterlockedIncrement(&icmp_sequence) & 0xFFFF;
317 reqsize=ICMP_MINLEN+RequestSize;
318 /* max ip header + max icmp header and error data + reply size(max 65535 on Windows) */
319 /* FIXME: request size of 65535 is not supported yet because max buffer size of raw socket on linux is 32767 */
320 repsize = MAXIPLEN + MAXICMPLEN + min( 65535, ReplySize );
321 buffer = HeapAlloc(GetProcessHeap(), 0, max( repsize, reqsize ));
322 if (buffer == NULL) {
323 SetLastError(ERROR_OUTOFMEMORY);
324 return 0;
327 icmp_header=(struct icmp*)buffer;
328 icmp_header->icmp_type=ICMP_ECHO;
329 icmp_header->icmp_code=0;
330 icmp_header->icmp_cksum=0;
331 icmp_header->icmp_id=id;
332 icmp_header->icmp_seq=seq;
333 memcpy(buffer+ICMP_MINLEN, RequestData, RequestSize);
334 icmp_header->icmp_cksum=cksum=in_cksum((u_short*)buffer,reqsize);
336 addr.sin_family=AF_INET;
337 addr.sin_addr.s_addr=DestinationAddress;
338 addr.sin_port=0;
340 if (RequestOptions!=NULL) {
341 int val;
342 if (icp->default_opts.OptionsSize==IP_OPTS_UNKNOWN) {
343 socklen_t len;
344 /* Before we mess with the options, get the default values */
345 len=sizeof(val);
346 getsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,&len);
347 icp->default_opts.Ttl=val;
349 len=sizeof(val);
350 getsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,&len);
351 icp->default_opts.Tos=val;
352 /* FIXME: missing: handling of IP 'flags', and all the other options */
355 val=RequestOptions->Ttl;
356 setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val));
357 val=RequestOptions->Tos;
358 setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val));
359 /* FIXME: missing: handling of IP 'flags', and all the other options */
361 icp->default_opts.OptionsSize=IP_OPTS_CUSTOM;
362 } else if (icp->default_opts.OptionsSize==IP_OPTS_CUSTOM) {
363 int val;
365 /* Restore the default options */
366 val=icp->default_opts.Ttl;
367 setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val));
368 val=icp->default_opts.Tos;
369 setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val));
370 /* FIXME: missing: handling of IP 'flags', and all the other options */
372 icp->default_opts.OptionsSize=IP_OPTS_DEFAULT;
375 /* Get ready for receiving the reply
376 * Do it before we send the request to minimize the risk of introducing delays
378 fdr.fd = icp->sid;
379 fdr.events = POLLIN;
380 addrlen=sizeof(addr);
381 ier=ReplyBuffer;
382 endbuf=(char *) ReplyBuffer+ReplySize;
384 /* Send the packet */
385 TRACE("Sending %d bytes (RequestSize=%d) to %s\n", reqsize, RequestSize, inet_ntoa(addr.sin_addr));
386 #if 0
387 if (TRACE_ON(icmp)){
388 int i;
389 printf("Output buffer:\n");
390 for (i=0;i<reqsize;i++)
391 printf("%2x,", buffer[i]);
392 printf("\n");
394 #endif
396 send_time = GetTickCount();
397 res=sendto(icp->sid, buffer, reqsize, 0, (struct sockaddr*)&addr, sizeof(addr));
398 if (res<0) {
399 if (errno==EMSGSIZE)
400 SetLastError(IP_PACKET_TOO_BIG);
401 else {
402 switch (errno) {
403 case ENETUNREACH:
404 SetLastError(IP_DEST_NET_UNREACHABLE);
405 break;
406 case EHOSTUNREACH:
407 SetLastError(IP_DEST_HOST_UNREACHABLE);
408 break;
409 default:
410 TRACE("unknown error: errno=%d\n",errno);
411 SetLastError(IP_GENERAL_FAILURE);
414 HeapFree(GetProcessHeap(), 0, buffer);
415 return 0;
418 /* Get the reply */
419 ip_header=(struct ip*)buffer;
420 ip_header_len=0; /* because gcc was complaining */
421 while (poll(&fdr,1,Timeout)>0) {
422 recv_time = GetTickCount();
423 res=recvfrom(icp->sid, buffer, repsize, 0, (struct sockaddr*)&addr, &addrlen);
424 TRACE("received %d bytes from %s\n",res, inet_ntoa(addr.sin_addr));
425 ier->Status=IP_REQ_TIMED_OUT;
427 /* Check whether we should ignore this packet */
428 if ((ip_header->ip_p==IPPROTO_ICMP) && (res>=sizeof(struct ip)+ICMP_MINLEN)) {
429 ip_header_len=ip_header->ip_hl << 2;
430 icmp_header=(struct icmp*)(((char*)ip_header)+ip_header_len);
431 TRACE("received an ICMP packet of type,code=%d,%d\n",icmp_header->icmp_type,icmp_header->icmp_code);
432 if (icmp_header->icmp_type==ICMP_ECHOREPLY) {
433 if ((icmp_header->icmp_id==id) && (icmp_header->icmp_seq==seq))
435 ier->Status=IP_SUCCESS;
436 SetLastError(NO_ERROR);
438 } else {
439 switch (icmp_header->icmp_type) {
440 case ICMP_UNREACH:
441 switch (icmp_header->icmp_code) {
442 case ICMP_UNREACH_HOST:
443 #ifdef ICMP_UNREACH_HOST_UNKNOWN
444 case ICMP_UNREACH_HOST_UNKNOWN:
445 #endif
446 #ifdef ICMP_UNREACH_ISOLATED
447 case ICMP_UNREACH_ISOLATED:
448 #endif
449 #ifdef ICMP_UNREACH_HOST_PROHIB
450 case ICMP_UNREACH_HOST_PROHIB:
451 #endif
452 #ifdef ICMP_UNREACH_TOSHOST
453 case ICMP_UNREACH_TOSHOST:
454 #endif
455 ier->Status=IP_DEST_HOST_UNREACHABLE;
456 break;
457 case ICMP_UNREACH_PORT:
458 ier->Status=IP_DEST_PORT_UNREACHABLE;
459 break;
460 case ICMP_UNREACH_PROTOCOL:
461 ier->Status=IP_DEST_PROT_UNREACHABLE;
462 break;
463 case ICMP_UNREACH_SRCFAIL:
464 ier->Status=IP_BAD_ROUTE;
465 break;
466 default:
467 ier->Status=IP_DEST_NET_UNREACHABLE;
469 break;
470 case ICMP_TIMXCEED:
471 if (icmp_header->icmp_code==ICMP_TIMXCEED_REASS)
472 ier->Status=IP_TTL_EXPIRED_REASSEM;
473 else
474 ier->Status=IP_TTL_EXPIRED_TRANSIT;
475 break;
476 case ICMP_PARAMPROB:
477 ier->Status=IP_PARAM_PROBLEM;
478 break;
479 case ICMP_SOURCEQUENCH:
480 ier->Status=IP_SOURCE_QUENCH;
481 break;
483 if (ier->Status!=IP_REQ_TIMED_OUT) {
484 struct ip* rep_ip_header;
485 struct icmp* rep_icmp_header;
486 /* The ICMP header size of all the packets we accept is the same */
487 rep_ip_header=(struct ip*)(((char*)icmp_header)+ICMP_MINLEN);
488 rep_icmp_header=(struct icmp*)(((char*)rep_ip_header)+(rep_ip_header->ip_hl << 2));
490 /* Make sure that this is really a reply to our packet */
491 if (ip_header_len+ICMP_MINLEN+(rep_ip_header->ip_hl << 2)+ICMP_MINLEN>ip_header->ip_len) {
492 ier->Status=IP_REQ_TIMED_OUT;
493 } else if ((rep_icmp_header->icmp_type!=ICMP_ECHO) ||
494 (rep_icmp_header->icmp_code!=0) ||
495 (rep_icmp_header->icmp_id!=id) ||
496 /* windows doesn't check this checksum, else tracert */
497 /* behind a Linux 2.2 masquerading firewall would fail*/
498 /* (rep_icmp_header->icmp_cksum!=cksum) || */
499 (rep_icmp_header->icmp_seq!=seq)) {
500 /* This was not a reply to one of our packets after all */
501 TRACE("skipping type,code=%d,%d id,seq=%d,%d cksum=%d\n",
502 rep_icmp_header->icmp_type,rep_icmp_header->icmp_code,
503 rep_icmp_header->icmp_id,rep_icmp_header->icmp_seq,
504 rep_icmp_header->icmp_cksum);
505 TRACE("expected type,code=8,0 id,seq=%d,%d cksum=%d\n",
506 id,seq,
507 cksum);
508 ier->Status=IP_REQ_TIMED_OUT;
514 if (ier->Status==IP_REQ_TIMED_OUT) {
515 /* This packet was not for us.
516 * Decrease the timeout so that we don't enter an endless loop even
517 * if we get flooded with ICMP packets that are not for us.
519 DWORD t = (recv_time - send_time);
520 if (Timeout > t) Timeout -= t;
521 else Timeout = 0;
522 continue;
523 } else {
524 /* Check free space, should be large enough for an ICMP_ECHO_REPLY and remainning icmp data */
525 if (endbuf-(char *)ier < sizeof(struct icmp_echo_reply)+(res-ip_header_len-ICMP_MINLEN)) {
526 res=ier-(ICMP_ECHO_REPLY *)ReplyBuffer;
527 SetLastError(IP_GENERAL_FAILURE);
528 goto done;
530 /* This is a reply to our packet */
531 memcpy(&ier->Address,&ip_header->ip_src,sizeof(IPAddr));
532 /* Status is already set */
533 ier->RoundTripTime= recv_time - send_time;
534 ier->DataSize=res-ip_header_len-ICMP_MINLEN;
535 ier->Reserved=0;
536 ier->Data=endbuf-ier->DataSize;
537 memcpy(ier->Data, ((char *)ip_header)+ip_header_len+ICMP_MINLEN, ier->DataSize);
538 ier->Options.Ttl=ip_header->ip_ttl;
539 ier->Options.Tos=ip_header->ip_tos;
540 ier->Options.Flags=ip_header->ip_off >> 13;
541 ier->Options.OptionsSize=ip_header_len-sizeof(struct ip);
542 if (ier->Options.OptionsSize!=0) {
543 ier->Options.OptionsData=(unsigned char *) ier->Data-ier->Options.OptionsSize;
544 /* FIXME: We are supposed to rearrange the option's 'source route' data */
545 memcpy(ier->Options.OptionsData, ((char *)ip_header)+ip_header_len, ier->Options.OptionsSize);
546 endbuf=(char*)ier->Options.OptionsData;
547 } else {
548 ier->Options.OptionsData=NULL;
549 endbuf=ier->Data;
552 /* Prepare for the next packet */
553 endbuf-=ier->DataSize;
554 ier++;
556 /* Check out whether there is more but don't wait this time */
557 Timeout=0;
560 res=ier-(ICMP_ECHO_REPLY*)ReplyBuffer;
561 if (res==0)
562 SetLastError(IP_REQ_TIMED_OUT);
563 done:
564 HeapFree(GetProcessHeap(), 0, buffer);
565 TRACE("received %d replies\n",res);
566 return res;
569 /***********************************************************************
570 * IcmpSendEcho2 (IPHLPAPI.@)
572 DWORD WINAPI IcmpSendEcho2(
573 HANDLE IcmpHandle,
574 HANDLE Event,
575 PIO_APC_ROUTINE ApcRoutine,
576 PVOID ApcContext,
577 IPAddr DestinationAddress,
578 LPVOID RequestData,
579 WORD RequestSize,
580 PIP_OPTION_INFORMATION RequestOptions,
581 LPVOID ReplyBuffer,
582 DWORD ReplySize,
583 DWORD Timeout
586 TRACE("(%p, %p, %p, %p, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle,
587 Event, ApcRoutine, ApcContext, DestinationAddress, RequestData,
588 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
590 if (Event)
592 FIXME("unsupported for events\n");
593 return 0;
595 if (ApcRoutine)
597 FIXME("unsupported for APCs\n");
598 return 0;
600 return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData,
601 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
604 /***********************************************************************
605 * IcmpSendEcho2Ex (IPHLPAPI.@)
607 DWORD WINAPI IcmpSendEcho2Ex(
608 HANDLE IcmpHandle,
609 HANDLE Event,
610 PIO_APC_ROUTINE ApcRoutine,
611 PVOID ApcContext,
612 IPAddr SourceAddress,
613 IPAddr DestinationAddress,
614 LPVOID RequestData,
615 WORD RequestSize,
616 PIP_OPTION_INFORMATION RequestOptions,
617 LPVOID ReplyBuffer,
618 DWORD ReplySize,
619 DWORD Timeout
622 TRACE("(%p, %p, %p, %p, %08x, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle,
623 Event, ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData,
624 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
626 if (Event)
628 FIXME("unsupported for events\n");
629 return 0;
631 if (ApcRoutine)
633 FIXME("unsupported for APCs\n");
634 return 0;
636 if (SourceAddress)
638 FIXME("unsupported for source addresses\n");
639 return 0;
642 return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData,
643 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
647 * Copyright (c) 1989 The Regents of the University of California.
648 * All rights reserved.
650 * This code is derived from software contributed to Berkeley by
651 * Mike Muuss.
653 * Redistribution and use in source and binary forms, with or without
654 * modification, are permitted provided that the following conditions
655 * are met:
656 * 1. Redistributions of source code must retain the above copyright
657 * notice, this list of conditions and the following disclaimer.
658 * 2. Redistributions in binary form must reproduce the above copyright
659 * notice, this list of conditions and the following disclaimer in the
660 * documentation and/or other materials provided with the distribution.
661 * 3. Neither the name of the University nor the names of its contributors
662 * may be used to endorse or promote products derived from this software
663 * without specific prior written permission.
665 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
666 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
667 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
668 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
669 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
670 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
671 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
672 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
673 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
674 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
675 * SUCH DAMAGE.