kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / iphlpapi / icmp.c
blob0dc2f1299bf605bb7e4f2c4b10db131ad2e5512b
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 /* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
164 sid=socket(AF_INET6,SOCK_DGRAM,IPPROTO_ICMPV6);
166 if (sid < 0) {
167 ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n");
168 SetLastError(ERROR_ACCESS_DENIED);
169 return INVALID_HANDLE_VALUE;
172 icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp));
173 if (icp==NULL) {
174 close(sid);
175 SetLastError(IP_NO_RESOURCES);
176 return INVALID_HANDLE_VALUE;
178 icp->sid=sid;
179 icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN;
180 return (HANDLE)icp;
184 /***********************************************************************
185 * Icmp6SendEcho2 (IPHLPAPI.@)
187 DWORD WINAPI Icmp6SendEcho2(
188 HANDLE IcmpHandle,
189 HANDLE Event,
190 PIO_APC_ROUTINE ApcRoutine,
191 PVOID ApcContext,
192 struct sockaddr_in6* SourceAddress,
193 struct sockaddr_in6* DestinationAddress,
194 LPVOID RequestData,
195 WORD RequestSize,
196 PIP_OPTION_INFORMATION RequestOptions,
197 LPVOID ReplyBuffer,
198 DWORD ReplySize,
199 DWORD Timeout
202 FIXME("(%p, %p, %p, %p, %p, %p, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle, Event,
203 ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData,
204 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
205 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
206 return 0;
210 /***********************************************************************
211 * IcmpCreateFile (IPHLPAPI.@)
213 HANDLE WINAPI IcmpCreateFile(VOID)
215 icmp_t* icp;
217 int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP);
218 if (sid < 0)
220 /* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */
221 sid=socket(AF_INET,SOCK_DGRAM,IPPROTO_ICMP);
223 if (sid < 0) {
224 ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n");
225 SetLastError(ERROR_ACCESS_DENIED);
226 return INVALID_HANDLE_VALUE;
229 icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp));
230 if (icp==NULL) {
231 close(sid);
232 SetLastError(IP_NO_RESOURCES);
233 return INVALID_HANDLE_VALUE;
235 icp->sid=sid;
236 icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN;
237 return (HANDLE)icp;
241 /***********************************************************************
242 * IcmpCloseHandle (IPHLPAPI.@)
244 BOOL WINAPI IcmpCloseHandle(HANDLE IcmpHandle)
246 icmp_t* icp=(icmp_t*)IcmpHandle;
247 if (IcmpHandle==INVALID_HANDLE_VALUE) {
248 /* FIXME: in fact win98 seems to ignore the handle value !!! */
249 SetLastError(ERROR_INVALID_HANDLE);
250 return FALSE;
253 close( icp->sid );
254 HeapFree(GetProcessHeap (), 0, icp);
255 return TRUE;
259 /***********************************************************************
260 * IcmpSendEcho (IPHLPAPI.@)
262 DWORD WINAPI IcmpSendEcho(
263 HANDLE IcmpHandle,
264 IPAddr DestinationAddress,
265 LPVOID RequestData,
266 WORD RequestSize,
267 PIP_OPTION_INFORMATION RequestOptions,
268 LPVOID ReplyBuffer,
269 DWORD ReplySize,
270 DWORD Timeout
273 icmp_t* icp=(icmp_t*)IcmpHandle;
274 unsigned char *buffer;
275 int reqsize, repsize;
277 struct icmp_echo_reply* ier;
278 struct ip* ip_header;
279 struct icmp* icmp_header;
280 char* endbuf;
281 int ip_header_len;
282 struct pollfd fdr;
283 DWORD send_time,recv_time;
284 struct sockaddr_in addr;
285 socklen_t addrlen;
286 unsigned short id,seq,cksum;
287 int res;
289 if (IcmpHandle==INVALID_HANDLE_VALUE) {
290 /* FIXME: in fact win98 seems to ignore the handle value !!! */
291 SetLastError(ERROR_INVALID_PARAMETER);
292 return 0;
295 if (!ReplyBuffer||!ReplySize) {
296 SetLastError(ERROR_INVALID_PARAMETER);
297 return 0;
300 if (ReplySize<sizeof(ICMP_ECHO_REPLY)) {
301 SetLastError(IP_BUF_TOO_SMALL);
302 return 0;
304 /* check the request size against SO_MAX_MSG_SIZE using getsockopt */
306 if (!DestinationAddress) {
307 SetLastError(ERROR_INVALID_NETNAME);
308 return 0;
311 /* Prepare the request */
312 id=getpid() & 0xFFFF;
313 seq=InterlockedIncrement(&icmp_sequence) & 0xFFFF;
315 reqsize=ICMP_MINLEN+RequestSize;
316 /* max ip header + max icmp header and error data + reply size(max 65535 on Windows) */
317 /* FIXME: request size of 65535 is not supported yet because max buffer size of raw socket on linux is 32767 */
318 repsize = MAXIPLEN + MAXICMPLEN + min( 65535, ReplySize );
319 buffer = HeapAlloc(GetProcessHeap(), 0, max( repsize, reqsize ));
320 if (buffer == NULL) {
321 SetLastError(ERROR_OUTOFMEMORY);
322 return 0;
325 icmp_header=(struct icmp*)buffer;
326 icmp_header->icmp_type=ICMP_ECHO;
327 icmp_header->icmp_code=0;
328 icmp_header->icmp_cksum=0;
329 icmp_header->icmp_id=id;
330 icmp_header->icmp_seq=seq;
331 memcpy(buffer+ICMP_MINLEN, RequestData, RequestSize);
332 icmp_header->icmp_cksum=cksum=in_cksum((u_short*)buffer,reqsize);
334 addr.sin_family=AF_INET;
335 addr.sin_addr.s_addr=DestinationAddress;
336 addr.sin_port=0;
338 if (RequestOptions!=NULL) {
339 int val;
340 if (icp->default_opts.OptionsSize==IP_OPTS_UNKNOWN) {
341 socklen_t len;
342 /* Before we mess with the options, get the default values */
343 len=sizeof(val);
344 getsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,&len);
345 icp->default_opts.Ttl=val;
347 len=sizeof(val);
348 getsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,&len);
349 icp->default_opts.Tos=val;
350 /* FIXME: missing: handling of IP 'flags', and all the other options */
353 val=RequestOptions->Ttl;
354 setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val));
355 val=RequestOptions->Tos;
356 setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val));
357 /* FIXME: missing: handling of IP 'flags', and all the other options */
359 icp->default_opts.OptionsSize=IP_OPTS_CUSTOM;
360 } else if (icp->default_opts.OptionsSize==IP_OPTS_CUSTOM) {
361 int val;
363 /* Restore the default options */
364 val=icp->default_opts.Ttl;
365 setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val));
366 val=icp->default_opts.Tos;
367 setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val));
368 /* FIXME: missing: handling of IP 'flags', and all the other options */
370 icp->default_opts.OptionsSize=IP_OPTS_DEFAULT;
373 /* Get ready for receiving the reply
374 * Do it before we send the request to minimize the risk of introducing delays
376 fdr.fd = icp->sid;
377 fdr.events = POLLIN;
378 addrlen=sizeof(addr);
379 ier=ReplyBuffer;
380 endbuf=(char *) ReplyBuffer+ReplySize;
382 /* Send the packet */
383 TRACE("Sending %d bytes (RequestSize=%d) to %s\n", reqsize, RequestSize, inet_ntoa(addr.sin_addr));
384 #if 0
385 if (TRACE_ON(icmp)){
386 int i;
387 printf("Output buffer:\n");
388 for (i=0;i<reqsize;i++)
389 printf("%2x,", buffer[i]);
390 printf("\n");
392 #endif
394 send_time = GetTickCount();
395 res=sendto(icp->sid, buffer, reqsize, 0, (struct sockaddr*)&addr, sizeof(addr));
396 if (res<0) {
397 if (errno==EMSGSIZE)
398 SetLastError(IP_PACKET_TOO_BIG);
399 else {
400 switch (errno) {
401 case ENETUNREACH:
402 SetLastError(IP_DEST_NET_UNREACHABLE);
403 break;
404 case EHOSTUNREACH:
405 SetLastError(IP_DEST_HOST_UNREACHABLE);
406 break;
407 default:
408 TRACE("unknown error: errno=%d\n",errno);
409 SetLastError(IP_GENERAL_FAILURE);
412 HeapFree(GetProcessHeap(), 0, buffer);
413 return 0;
416 /* Get the reply */
417 ip_header=(struct ip*)buffer;
418 ip_header_len=0; /* because gcc was complaining */
419 while (poll(&fdr,1,Timeout)>0) {
420 recv_time = GetTickCount();
421 res=recvfrom(icp->sid, buffer, repsize, 0, (struct sockaddr*)&addr, &addrlen);
422 TRACE("received %d bytes from %s\n",res, inet_ntoa(addr.sin_addr));
423 ier->Status=IP_REQ_TIMED_OUT;
425 /* Check whether we should ignore this packet */
426 if ((ip_header->ip_p==IPPROTO_ICMP) && (res>=sizeof(struct ip)+ICMP_MINLEN)) {
427 ip_header_len=ip_header->ip_hl << 2;
428 icmp_header=(struct icmp*)(((char*)ip_header)+ip_header_len);
429 TRACE("received an ICMP packet of type,code=%d,%d\n",icmp_header->icmp_type,icmp_header->icmp_code);
430 if (icmp_header->icmp_type==ICMP_ECHOREPLY) {
431 if ((icmp_header->icmp_id==id) && (icmp_header->icmp_seq==seq))
433 ier->Status=IP_SUCCESS;
434 SetLastError(NO_ERROR);
436 } else {
437 switch (icmp_header->icmp_type) {
438 case ICMP_UNREACH:
439 switch (icmp_header->icmp_code) {
440 case ICMP_UNREACH_HOST:
441 #ifdef ICMP_UNREACH_HOST_UNKNOWN
442 case ICMP_UNREACH_HOST_UNKNOWN:
443 #endif
444 #ifdef ICMP_UNREACH_ISOLATED
445 case ICMP_UNREACH_ISOLATED:
446 #endif
447 #ifdef ICMP_UNREACH_HOST_PROHIB
448 case ICMP_UNREACH_HOST_PROHIB:
449 #endif
450 #ifdef ICMP_UNREACH_TOSHOST
451 case ICMP_UNREACH_TOSHOST:
452 #endif
453 ier->Status=IP_DEST_HOST_UNREACHABLE;
454 break;
455 case ICMP_UNREACH_PORT:
456 ier->Status=IP_DEST_PORT_UNREACHABLE;
457 break;
458 case ICMP_UNREACH_PROTOCOL:
459 ier->Status=IP_DEST_PROT_UNREACHABLE;
460 break;
461 case ICMP_UNREACH_SRCFAIL:
462 ier->Status=IP_BAD_ROUTE;
463 break;
464 default:
465 ier->Status=IP_DEST_NET_UNREACHABLE;
467 break;
468 case ICMP_TIMXCEED:
469 if (icmp_header->icmp_code==ICMP_TIMXCEED_REASS)
470 ier->Status=IP_TTL_EXPIRED_REASSEM;
471 else
472 ier->Status=IP_TTL_EXPIRED_TRANSIT;
473 break;
474 case ICMP_PARAMPROB:
475 ier->Status=IP_PARAM_PROBLEM;
476 break;
477 case ICMP_SOURCEQUENCH:
478 ier->Status=IP_SOURCE_QUENCH;
479 break;
481 if (ier->Status!=IP_REQ_TIMED_OUT) {
482 struct ip* rep_ip_header;
483 struct icmp* rep_icmp_header;
484 /* The ICMP header size of all the packets we accept is the same */
485 rep_ip_header=(struct ip*)(((char*)icmp_header)+ICMP_MINLEN);
486 rep_icmp_header=(struct icmp*)(((char*)rep_ip_header)+(rep_ip_header->ip_hl << 2));
488 /* Make sure that this is really a reply to our packet */
489 if (ip_header_len+ICMP_MINLEN+(rep_ip_header->ip_hl << 2)+ICMP_MINLEN>ip_header->ip_len) {
490 ier->Status=IP_REQ_TIMED_OUT;
491 } else if ((rep_icmp_header->icmp_type!=ICMP_ECHO) ||
492 (rep_icmp_header->icmp_code!=0) ||
493 (rep_icmp_header->icmp_id!=id) ||
494 /* windows doesn't check this checksum, else tracert */
495 /* behind a Linux 2.2 masquerading firewall would fail*/
496 /* (rep_icmp_header->icmp_cksum!=cksum) || */
497 (rep_icmp_header->icmp_seq!=seq)) {
498 /* This was not a reply to one of our packets after all */
499 TRACE("skipping type,code=%d,%d id,seq=%d,%d cksum=%d\n",
500 rep_icmp_header->icmp_type,rep_icmp_header->icmp_code,
501 rep_icmp_header->icmp_id,rep_icmp_header->icmp_seq,
502 rep_icmp_header->icmp_cksum);
503 TRACE("expected type,code=8,0 id,seq=%d,%d cksum=%d\n",
504 id,seq,
505 cksum);
506 ier->Status=IP_REQ_TIMED_OUT;
512 if (ier->Status==IP_REQ_TIMED_OUT) {
513 /* This packet was not for us.
514 * Decrease the timeout so that we don't enter an endless loop even
515 * if we get flooded with ICMP packets that are not for us.
517 DWORD t = (recv_time - send_time);
518 if (Timeout > t) Timeout -= t;
519 else Timeout = 0;
520 continue;
521 } else {
522 /* Check free space, should be large enough for an ICMP_ECHO_REPLY and remainning icmp data */
523 if (endbuf-(char *)ier < sizeof(struct icmp_echo_reply)+(res-ip_header_len-ICMP_MINLEN)) {
524 res=ier-(ICMP_ECHO_REPLY *)ReplyBuffer;
525 SetLastError(IP_GENERAL_FAILURE);
526 goto done;
528 /* This is a reply to our packet */
529 memcpy(&ier->Address,&ip_header->ip_src,sizeof(IPAddr));
530 /* Status is already set */
531 ier->RoundTripTime= recv_time - send_time;
532 ier->DataSize=res-ip_header_len-ICMP_MINLEN;
533 ier->Reserved=0;
534 ier->Data=endbuf-ier->DataSize;
535 memcpy(ier->Data, ((char *)ip_header)+ip_header_len+ICMP_MINLEN, ier->DataSize);
536 ier->Options.Ttl=ip_header->ip_ttl;
537 ier->Options.Tos=ip_header->ip_tos;
538 ier->Options.Flags=ip_header->ip_off >> 13;
539 ier->Options.OptionsSize=ip_header_len-sizeof(struct ip);
540 if (ier->Options.OptionsSize!=0) {
541 ier->Options.OptionsData=(unsigned char *) ier->Data-ier->Options.OptionsSize;
542 /* FIXME: We are supposed to rearrange the option's 'source route' data */
543 memcpy(ier->Options.OptionsData, ((char *)ip_header)+ip_header_len, ier->Options.OptionsSize);
544 endbuf=(char*)ier->Options.OptionsData;
545 } else {
546 ier->Options.OptionsData=NULL;
547 endbuf=ier->Data;
550 /* Prepare for the next packet */
551 endbuf-=ier->DataSize;
552 ier++;
554 /* Check out whether there is more but don't wait this time */
555 Timeout=0;
558 res=ier-(ICMP_ECHO_REPLY*)ReplyBuffer;
559 if (res==0)
560 SetLastError(IP_REQ_TIMED_OUT);
561 done:
562 HeapFree(GetProcessHeap(), 0, buffer);
563 TRACE("received %d replies\n",res);
564 return res;
567 /***********************************************************************
568 * IcmpSendEcho2 (IPHLPAPI.@)
570 DWORD WINAPI IcmpSendEcho2(
571 HANDLE IcmpHandle,
572 HANDLE Event,
573 PIO_APC_ROUTINE ApcRoutine,
574 PVOID ApcContext,
575 IPAddr DestinationAddress,
576 LPVOID RequestData,
577 WORD RequestSize,
578 PIP_OPTION_INFORMATION RequestOptions,
579 LPVOID ReplyBuffer,
580 DWORD ReplySize,
581 DWORD Timeout
584 TRACE("(%p, %p, %p, %p, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle,
585 Event, ApcRoutine, ApcContext, DestinationAddress, RequestData,
586 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
588 if (Event)
590 FIXME("unsupported for events\n");
591 return 0;
593 if (ApcRoutine)
595 FIXME("unsupported for APCs\n");
596 return 0;
598 return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData,
599 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
602 /***********************************************************************
603 * IcmpSendEcho2Ex (IPHLPAPI.@)
605 DWORD WINAPI IcmpSendEcho2Ex(
606 HANDLE IcmpHandle,
607 HANDLE Event,
608 PIO_APC_ROUTINE ApcRoutine,
609 PVOID ApcContext,
610 IPAddr SourceAddress,
611 IPAddr DestinationAddress,
612 LPVOID RequestData,
613 WORD RequestSize,
614 PIP_OPTION_INFORMATION RequestOptions,
615 LPVOID ReplyBuffer,
616 DWORD ReplySize,
617 DWORD Timeout
620 TRACE("(%p, %p, %p, %p, %08x, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle,
621 Event, ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData,
622 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
624 if (Event)
626 FIXME("unsupported for events\n");
627 return 0;
629 if (ApcRoutine)
631 FIXME("unsupported for APCs\n");
632 return 0;
634 if (SourceAddress)
636 FIXME("unsupported for source addresses\n");
637 return 0;
640 return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData,
641 RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout);
645 * Copyright (c) 1989 The Regents of the University of California.
646 * All rights reserved.
648 * This code is derived from software contributed to Berkeley by
649 * Mike Muuss.
651 * Redistribution and use in source and binary forms, with or without
652 * modification, are permitted provided that the following conditions
653 * are met:
654 * 1. Redistributions of source code must retain the above copyright
655 * notice, this list of conditions and the following disclaimer.
656 * 2. Redistributions in binary form must reproduce the above copyright
657 * notice, this list of conditions and the following disclaimer in the
658 * documentation and/or other materials provided with the distribution.
659 * 3. Neither the name of the University nor the names of its contributors
660 * may be used to endorse or promote products derived from this software
661 * without specific prior written permission.
663 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
664 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
665 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
666 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
667 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
668 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
669 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
670 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
671 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
672 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
673 * SUCH DAMAGE.