Tor 0.4.9.0-alpha-dev
proto_control0.c
Go to the documentation of this file.
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-2021, The Tor Project, Inc. */
5/* See LICENSE for licensing information */
6
7/**
8 * @file proto_control0.c
9 * @brief Code to detect the obsolete v0 control protocol.
10 **/
11
12#include "core/or/or.h"
13#include "lib/buf/buffers.h"
15
16/** Return 1 iff buf looks more like it has an (obsolete) v0 controller
17 * command on it than any valid v1 controller command. */
18int
20{
21 if (buf_datalen(buf) >= 4) {
22 char header[4];
23 uint16_t cmd;
24 buf_peek(buf, header, sizeof(header));
25 cmd = ntohs(get_uint16(header+2));
26 if (cmd <= 0x14)
27 return 1; /* This is definitely not a v1 control command. */
28 }
29 return 0;
30}
size_t buf_datalen(const buf_t *buf)
Definition: buffers.c:394
void buf_peek(const buf_t *buf, char *string, size_t string_len)
Definition: buffers.c:610
Header file for buffers.c.
static uint16_t get_uint16(const void *cp)
Definition: bytes.h:42
Master header file for Tor-specific functionality.
int peek_buf_has_control0_command(buf_t *buf)
Header for proto_control0.c.