TLVPick.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * void * TLVPick (void const * memory, size_t extent, uint8_t type);
  11. *
  12. * lldp.h
  13. *
  14. * search an IEEE 802.1AB TLV chain for the given type; return
  15. * the address of that TLV; return NULL when no match is found;
  16. *
  17. *--------------------------------------------------------------------*/
  18. #ifndef TLVPICK_SOURCE
  19. #define TLVPICK_SOURCE
  20. #include <stdio.h>
  21. #include <stdint.h>
  22. #include "../tools/types.h"
  23. #include "../lldp/lldp.h"
  24. void * TLVPick (void const * memory, size_t extent, uint8_t type)
  25. {
  26. byte * offset = (void *) (memory);
  27. while (extent > 0)
  28. {
  29. struct tlv * tlv = (struct tlv *) (offset);
  30. uint8_t mytype = TLV_TYPE (tlv);
  31. uint16_t mysize = TLV_SIZE (tlv);
  32. if (mytype == type)
  33. {
  34. return ((void *) (offset));
  35. }
  36. if (! tlv->head)
  37. {
  38. break;
  39. }
  40. offset += sizeof (* tlv) + mysize;
  41. extent -= sizeof (* tlv) + mysize;
  42. }
  43. return ((void *) (0));
  44. }
  45. #endif