SMB - attribute offset fixed, filetimes all fully working
[libogc.git] / libdb / uIP / uip_arch.c
blob50a5e937ad8b34284e6f8476bc6014de3e78c272
1 /*
2 * Copyright (c) 2001, Adam Dunkels.
3 * All rights reserved.
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior
15 * written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * This file is part of the uIP TCP/IP stack.
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
38 #include "uip.h"
39 #include "uip_arch.h"
40 #include "uip_ip.h"
41 #include "uip_tcp.h"
42 #include "uip_pbuf.h"
45 /*-----------------------------------------------------------------------------------*/
46 u16_t uip_chksum(u16_t *sdata, u32_t len)
48 u32_t acc;
50 for(acc = 0;len > 1;len -= 2) {
51 acc += *sdata++;
54 /* add up any odd byte */
55 if(len==1) {
56 acc += htons((u16_t)((((u8_t *)sdata)[0]&0xff)<<8));
58 while(acc>>16) acc = (acc&0xffffUL)+(acc>>16);
60 return (u16_t)acc;
63 /*-----------------------------------------------------------------------------------*/
64 u16_t uip_chksum_pseudo(struct uip_pbuf *p,struct uip_ip_addr *src,struct uip_ip_addr *dst,u8_t proto,u16_t proto_len)
66 u32_t acc,len,rem;
67 struct uip_pbuf *q;
68 u8_t swapped;
70 acc = 0;
71 swapped = 0;
73 rem = proto_len;
74 for(q=p;q!=NULL && rem>0;q=q->next) {
75 len = (rem>q->len)?q->len:rem;
76 acc += uip_chksum(q->payload,len);
77 rem -= len;
80 acc += (src->addr&0xffffUL);
81 acc += ((src->addr>>16)&0xffffUL);
82 acc += (dst->addr&0xffffUL);
83 acc += ((dst->addr>>16)&0xffffUL);
84 acc += (u32_t)htons(proto);
85 acc += (u32_t)htons(proto_len);
87 while(acc>>16) acc = (acc&0xffffUL)+(acc>>16);
89 return (u16_t)~(acc&0xffffUL);
91 /*-----------------------------------------------------------------------------------*/
92 u16_t
93 uip_ipchksum(void *dataptr,u16_t len)
95 return ~(uip_chksum(dataptr,len));
98 u16_t uip_ipchksum_pbuf(struct uip_pbuf *p)
100 u32_t acc;
101 struct uip_pbuf *q;
102 u8_t swapped;
104 acc = 0;
105 swapped = 0;
106 for(q = p; q != NULL; q = q->next) {
107 acc += uip_chksum(q->payload,q->len);
109 while(acc>>16) acc = (acc&0xffffUL)+(acc>>16);
111 return (u16_t)~(acc & 0xffffUL);
114 void uip_log(const char *filename,int line_nb,char *msg)
116 printf("%s(%d):\n%s\n",filename,line_nb,msg);
119 /*-----------------------------------------------------------------------------------*/