csum_partial_copy.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

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. #include <net/checksum.h>
  18. #include <linux/types.h>
  19. #include <asm/byteorder.h>
  20. #include <asm/string.h>
  21. #include <asm/uaccess.h>
  22. /*
  23.  * copy while checksumming, otherwise like csum_partial
  24.  */
  25. unsigned int csum_partial_copy(const char *src, char *dst,
  26.                                int len, unsigned int sum)
  27. {
  28. /*
  29.  * It's 2:30 am and I don't feel like doing it real ...
  30.  * This is lots slower than the real thing (tm)
  31.  */
  32. sum = csum_partial(src, len, sum);
  33. memcpy(dst, src, len);
  34. return sum;
  35. }
  36. /*
  37.  * Copy from userspace and compute checksum.  If we catch an exception
  38.  * then zero the rest of the buffer.
  39.  */
  40. unsigned int csum_partial_copy_from_user (const char *src, char *dst,
  41.                                           int len, unsigned int sum,
  42.                                           int *err_ptr)
  43. {
  44. int missing;
  45. missing = copy_from_user(dst, src, len);
  46. if (missing) {
  47. memset(dst + len - missing, 0, missing);
  48. *err_ptr = -EFAULT;
  49. }
  50. return csum_partial(dst, len, sum);
  51. }