Convert sizeof foo to sizeof(foo).
[tinc] / src / protocol.c
index 1ec169a..79d5273 100644 (file)
@@ -41,6 +41,9 @@ static bool (*request_handlers[])(connection_t *, const char *) = {
                add_subnet_h, del_subnet_h,
                add_edge_h, del_edge_h,
                key_changed_h, req_key_h, ans_key_h, tcppacket_h, control_h,
+               NULL, NULL, /* Not "real" requests (yet) */
+               sptps_tcppacket_h,
+               udp_info_h, mtu_info_h,
 };
 
 /* Request names */
@@ -51,6 +54,7 @@ static char (*request_name[]) = {
                "PING", "PONG",
                "ADD_SUBNET", "DEL_SUBNET",
                "ADD_EDGE", "DEL_EDGE", "KEY_CHANGED", "REQ_KEY", "ANS_KEY", "PACKET", "CONTROL",
+               "REQ_PUBKEY", "ANS_PUBKEY", "SPTPS_PACKET", "UDP_INFO", "MTU_INFO",
 };
 
 static splay_tree_t *past_request_tree;
@@ -68,10 +72,11 @@ bool send_request(connection_t *c, const char *format, ...) {
           input buffer anyway */
 
        va_start(args, format);
-       len = vsnprintf(request, MAXBUFSIZE, format, args);
+       len = vsnprintf(request, sizeof(request), format, args);
+       request[sizeof(request) - 1] = 0;
        va_end(args);
 
-       if(len < 0 || len > MAXBUFSIZE - 1) {
+       if(len < 0 || len > sizeof(request) - 1) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Output buffer overflow while sending request to %s (%s)",
                           c->name, c->hostname);
                return false;
@@ -96,7 +101,7 @@ void forward_request(connection_t *from, const char *request) {
        char tmp[len + 1];
        memcpy(tmp, request, len);
        tmp[len] = '\n';
-       broadcast_meta(from, tmp, sizeof tmp);
+       broadcast_meta(from, tmp, sizeof(tmp));
 }
 
 bool receive_request(connection_t *c, const char *request) {
@@ -132,7 +137,8 @@ bool receive_request(connection_t *c, const char *request) {
                if(!request_handlers[reqno](c, request)) {
                        /* Something went wrong. Probably scriptkiddies. Terminate. */
 
-                       logger(DEBUG_ALWAYS, LOG_ERR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname);
+                       if(reqno != TERMREQ)
+                               logger(DEBUG_ALWAYS, LOG_ERR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname);
                        return false;
                }
        } else {
@@ -182,7 +188,7 @@ bool seen_request(const char *request) {
                logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Already seen request");
                return true;
        } else {
-               new = xmalloc(sizeof *new);
+               new = xmalloc(sizeof(*new));
                new->request = xstrdup(request);
                new->firstseen = now.tv_sec;
                splay_insert(past_request_tree, new);