proto_control0.c 786 B

123456789101112131415161718192021222324252627
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. #define BUFFERS_PRIVATE // XXXX remove.
  7. #include "or.h"
  8. #include "buffers.h"
  9. #include "proto_control0.h"
  10. /** Return 1 iff buf looks more like it has an (obsolete) v0 controller
  11. * command on it than any valid v1 controller command. */
  12. int
  13. peek_buf_has_control0_command(buf_t *buf)
  14. {
  15. if (buf->datalen >= 4) {
  16. char header[4];
  17. uint16_t cmd;
  18. peek_from_buf(header, sizeof(header), buf);
  19. cmd = ntohs(get_uint16(header+2));
  20. if (cmd <= 0x14)
  21. return 1; /* This is definitely not a v1 control command. */
  22. }
  23. return 0;
  24. }