igmpout.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2007 by egnite Software GmbH
  3. * Copyright (c) 1992, 1993 The Regents of the University of California
  4. * Copyright (c) 1988 Stephen Deering.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Stephen Deering of Stanford University
  8. *
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of the copyright holders nor the names of
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  32. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  34. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * For additional information see http://www.ethernut.de/
  38. */
  39. /*!
  40. * \file net/igmpout.c
  41. * \brief IGMP output functions.
  42. *
  43. * \verbatim
  44. * $Id: igmpout.c 3683 2011-12-04 13:42:04Z haraldkipp $
  45. * \endverbatim
  46. */
  47. #include <netinet/in.h>
  48. #include <netinet/ip.h>
  49. #include <netinet/ipcsum.h>
  50. #include <netinet/igmp.h>
  51. #include <string.h>
  52. /*!
  53. * \addtogroup xgIGMP
  54. */
  55. /*@{*/
  56. /*!
  57. * \brief Send an IGMP datagram.
  58. *
  59. * Known IGMP types are:
  60. *
  61. * - #IGMP_MEMBERSHIP_QUERY Membership query.
  62. * - #IGMP_V1_MEMBERSHIP_REPORT Version 1 membership report.
  63. * - #IGMP_V2_MEMBERSHIP_REPORT Version 2 membership report.
  64. * - #IGMP_V2_LEAVE_GROUP Leave-group message.
  65. *
  66. * \param type IGMP packet type.
  67. * \param dest Destination IP address.
  68. * \param nb Network buffer structure containing the datagram.
  69. *
  70. * \return 0 on success, -1 otherwise.
  71. */
  72. int NutIgmpOutput(uint8_t type, uint32_t dest, NETBUF * nb)
  73. {
  74. IGMP *igmp;
  75. if ((nb = NutNetBufAlloc(nb, NBAF_TRANSPORT, sizeof(IGMP))) == 0) {
  76. return -1;
  77. }
  78. igmp = (IGMP *) nb->nb_tp.vp;
  79. nb->nb_tp.sz = sizeof(IGMP);
  80. igmp->igmp_type = type;
  81. igmp->igmp_code = 0;
  82. igmp->igmp_group = dest;
  83. igmp->igmp_cksum = 0;
  84. igmp->igmp_cksum = NutIpChkSum(0, nb->nb_tp.vp, nb->nb_tp.sz);
  85. return NutIpOutput(IPPROTO_IGMP, dest, nb);
  86. }
  87. /*@}*/