proto_control0.c 745 B

1234567891011121314151617181920212223242526
  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. #include "or.h"
  7. #include "buffers.h"
  8. #include "proto_control0.h"
  9. /** Return 1 iff buf looks more like it has an (obsolete) v0 controller
  10. * command on it than any valid v1 controller command. */
  11. int
  12. peek_buf_has_control0_command(buf_t *buf)
  13. {
  14. if (buf_datalen(buf) >= 4) {
  15. char header[4];
  16. uint16_t cmd;
  17. buf_peek(buf, header, sizeof(header));
  18. cmd = ntohs(get_uint16(header+2));
  19. if (cmd <= 0x14)
  20. return 1; /* This is definitely not a v1 control command. */
  21. }
  22. return 0;
  23. }