csum_partial_copy.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:2k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.  * INET An implementation of the TCP/IP protocol suite for the LINUX
  3.  * operating system.  INET is implemented using the  BSD Socket
  4.  * interface as the means of communication with the user level.
  5.  *
  6.  * MIPS specific IP/TCP/UDP checksumming routines
  7.  *
  8.  * Authors: Ralf Baechle, <ralf@waldorf-gmbh.de>
  9.  * Lots of code moved from tcp.c and ip.c; see those files
  10.  * for more names.
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License
  14.  * as published by the Free Software Foundation; either version
  15.  * 2 of the License, or (at your option) any later version.
  16.  *
  17.  * $Id: csum_partial_copy.c,v 1.2 1998/09/19 19:16:17 ralf Exp $
  18.  */
  19. #include <net/checksum.h>
  20. #include <linux/types.h>
  21. #include <asm/byteorder.h>
  22. #include <asm/string.h>
  23. #include <asm/uaccess.h>
  24. /*
  25.  * copy while checksumming, otherwise like csum_partial
  26.  */
  27. unsigned int csum_partial_copy(const char *src, char *dst, 
  28.                                int len, unsigned int sum)
  29. {
  30. /*
  31.  * It's 2:30 am and I don't feel like doing it real ...
  32.  * This is lots slower than the real thing (tm)
  33.  */
  34. sum = csum_partial(src, len, sum);
  35. memcpy(dst, src, len);
  36. return sum;
  37. }
  38. /*
  39.  * Copy from userspace and compute checksum.  If we catch an exception
  40.  * then zero the rest of the buffer.
  41.  */
  42. unsigned int csum_partial_copy_from_user (const char *src, char *dst,
  43.                                           int len, unsigned int sum,
  44.                                           int *err_ptr)
  45. {
  46. int missing;
  47. missing = copy_from_user(dst, src, len);
  48. if (missing) {
  49. memset(dst + len - missing, 0, missing);
  50. *err_ptr = -EFAULT;
  51. }
  52. return csum_partial(dst, len, sum);
  53. }