igmpin.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/igmpin.c
  41. * \brief IGMP input functions.
  42. *
  43. * \verbatim
  44. * $Id: igmpin.c 3686 2011-12-04 14:20:38Z haraldkipp $
  45. * \endverbatim
  46. */
  47. #include <string.h>
  48. #include <net/if_var.h>
  49. #include <netinet/ipcsum.h>
  50. #include <netinet/igmp.h>
  51. #include <sys/socket.h>
  52. #include <netinet/tcp.h>
  53. #include <netinet/in.h>
  54. #include <netinet/ip.h>
  55. #include <errno.h>
  56. /*!
  57. * \addtogroup xgIGMP
  58. */
  59. /*@{*/
  60. /*!
  61. * \brief Process incoming IGMP packets.
  62. *
  63. * \param dev Identifies the device that received the packet.
  64. * \param nb Pointer to a network buffer structure containing the IGMP packet.
  65. */
  66. void NutIgmpInput(NUTDEVICE * dev, NETBUF * nb)
  67. {
  68. IGMP *igmp = (IGMP *) nb->nb_tp.vp;
  69. IFNET *nif;
  70. MCASTENTRY *mca;
  71. nif = dev->dev_icb;
  72. /*
  73. * Silently discard packets, which are too small.
  74. */
  75. if (igmp == NULL || nb->nb_tp.sz < IGMP_MINLEN) {
  76. NutNetBufFree(nb);
  77. return;
  78. }
  79. switch (igmp->igmp_type) {
  80. case IGMP_MEMBERSHIP_QUERY:
  81. /* Clear the received buffer first. */
  82. NutNetBufFree(nb);
  83. /* Go through the list and send reports */
  84. for (mca = nif->if_mcast; mca; mca = mca->mca_next) {
  85. /* Do not send for 224.0.0.1 */
  86. if (mca->mca_ip != INADDR_ALLHOSTS_GROUP) {
  87. NutIgmpJoinGroup(dev, mca->mca_ip);
  88. }
  89. }
  90. break;
  91. case IGMP_V1_MEMBERSHIP_REPORT:
  92. case IGMP_V2_MEMBERSHIP_REPORT:
  93. /* Not supported in the moment */
  94. NutNetBufFree(nb);
  95. break;
  96. default:
  97. /* Unrecognized message types are silently ignored. */
  98. NutNetBufFree(nb);
  99. }
  100. }
  101. /*@}*/