LLVMFuzzerInitialize:
   46|      2|int LLVMFuzzerInitialize(int *argc, char ***argv) {
   47|      2|  (void)argc;
   48|      2|  (void)argv;
   49|       |
   50|      2|#if defined(OPENSSL_INIT_NO_LOAD_CONFIG) && !defined(LIBRESSL_VERSION_NUMBER)
   51|       |  /*
   52|       |   * Keep fuzzing deterministic and avoid MSan reports from OpenSSL's
   53|       |   * environment-dependent config file loading in unsanitized libcrypto.
   54|       |   */
   55|      2|  OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL);
   56|      2|#endif
   57|       |
   58|      2|  seed_addr_mappings();
   59|       |
   60|      2|  return 0;
   61|      2|}
FuzzOpenSSLInit.c:seed_addr_mappings:
   29|      2|static void seed_addr_mappings(void) {
   30|      2|  ioa_addr pub4 = {0};
   31|      2|  ioa_addr priv4 = {0};
   32|      2|  ioa_addr pub6 = {0};
   33|      2|  ioa_addr priv6 = {0};
   34|       |
   35|      2|  if (make_ioa_addr((const uint8_t *)"192.0.2.1", 0, &pub4) == 0 &&
  ------------------
  |  Branch (35:7): [True: 2, False: 0]
  ------------------
   36|      2|      make_ioa_addr((const uint8_t *)"10.0.0.1", 0, &priv4) == 0) {
  ------------------
  |  Branch (36:7): [True: 2, False: 0]
  ------------------
   37|      2|    ioa_addr_add_mapping(&pub4, &priv4);
   38|      2|  }
   39|       |
   40|      2|  if (make_ioa_addr((const uint8_t *)"2001:db8::1", 0, &pub6) == 0 &&
  ------------------
  |  Branch (40:7): [True: 2, False: 0]
  ------------------
   41|      2|      make_ioa_addr((const uint8_t *)"fd00::1", 0, &priv6) == 0) {
  ------------------
  |  Branch (41:7): [True: 2, False: 0]
  ------------------
   42|      2|    ioa_addr_add_mapping(&pub6, &priv6);
   43|      2|  }
   44|      2|}

LLVMFuzzerTestOneInput:
  816|  1.79k|extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  817|  1.79k|  harness_stun_client(Data, Size);
  818|  1.79k|  harness_channel_data(Data, Size);
  819|  1.79k|  harness_addr_codec(Data, Size);
  820|  1.79k|  harness_message_builders(Data, Size);
  821|  1.79k|  harness_attr_get_first_addr(Data, Size);
  822|  1.79k|  harness_response_matrix(Data, Size);
  823|  1.79k|  harness_stun_buffer_api(Data, Size);
  824|  1.79k|  return 0;
  825|  1.79k|}
FuzzStunClient.c:harness_stun_client:
  212|  1.79k|static void harness_stun_client(const uint8_t *Data, size_t Size) {
  213|  1.79k|  if (Size < 10 || Size > 5120) {
  ------------------
  |  Branch (213:7): [True: 497, False: 1.30k]
  |  Branch (213:20): [True: 88, False: 1.21k]
  ------------------
  214|    585|    return;
  215|    585|  }
  216|       |
  217|  1.21k|  stun_buffer buf;
  218|  1.21k|  buf.len = Size;
  219|  1.21k|  memcpy(buf.buf, Data, buf.len);
  220|       |
  221|  1.21k|  if (!stun_is_command_message(&buf)) {
  ------------------
  |  Branch (221:7): [True: 1.05k, False: 154]
  ------------------
  222|  1.05k|    return;
  223|  1.05k|  }
  224|       |
  225|    154|  (void)stun_get_method_str(buf.buf, buf.len);
  226|    154|  (void)stun_get_msg_type_str(buf.buf, buf.len);
  227|       |
  228|    154|  if (stun_is_response(&buf) && stun_is_success_response(&buf) && stun_is_binding_response(&buf)) {
  ------------------
  |  Branch (228:7): [True: 142, False: 12]
  |  Branch (228:33): [True: 52, False: 90]
  |  Branch (228:67): [True: 8, False: 44]
  ------------------
  229|      8|    return;
  230|      8|  }
  231|       |
  232|    146|  stun_is_indication_str(buf.buf, buf.len);
  233|       |
  234|    146|  int err_code = 0;
  235|    146|  uint8_t err_msg[256] = {0};
  236|    146|  stun_is_error_response_str(buf.buf, buf.len, &err_code, err_msg, sizeof(err_msg));
  237|    146|}
FuzzStunClient.c:harness_channel_data:
  242|  1.79k|static void harness_channel_data(const uint8_t *Data, size_t Size) {
  243|  1.79k|  if (Size < 4 || Size > 8192) {
  ------------------
  |  Branch (243:7): [True: 274, False: 1.52k]
  |  Branch (243:19): [True: 65, False: 1.45k]
  ------------------
  244|    339|    return;
  245|    339|  }
  246|       |
  247|  1.45k|  uint8_t buf[8192] = {0};
  248|  1.45k|  memcpy(buf, Data, Size);
  249|       |
  250|  1.45k|  size_t app_len_tcp = 0;
  251|  1.45k|  size_t app_len_udp = 0;
  252|       |
  253|  1.45k|  int mlen_tcp = stun_get_message_len_str(buf, Size, 1, &app_len_tcp);
  254|  1.45k|  int mlen_udp = stun_get_message_len_str(buf, Size, 0, &app_len_udp);
  255|       |
  256|  1.45k|  if (mlen_tcp > 0) {
  ------------------
  |  Branch (256:7): [True: 533, False: 926]
  ------------------
  257|    533|    if (app_len_tcp > Size) {
  ------------------
  |  Branch (257:9): [True: 0, False: 533]
  ------------------
  258|      0|      __builtin_trap();
  259|      0|    }
  260|    533|    if ((size_t)mlen_tcp > Size) {
  ------------------
  |  Branch (260:9): [True: 0, False: 533]
  ------------------
  261|      0|      __builtin_trap();
  262|      0|    }
  263|    533|    if ((size_t)mlen_tcp < app_len_tcp) {
  ------------------
  |  Branch (263:9): [True: 0, False: 533]
  ------------------
  264|      0|      __builtin_trap();
  265|      0|    }
  266|    533|  }
  267|       |
  268|  1.45k|  if (mlen_udp > 0) {
  ------------------
  |  Branch (268:7): [True: 549, False: 910]
  ------------------
  269|    549|    if (app_len_udp > Size) {
  ------------------
  |  Branch (269:9): [True: 0, False: 549]
  ------------------
  270|      0|      __builtin_trap();
  271|      0|    }
  272|    549|    if ((size_t)mlen_udp > Size) {
  ------------------
  |  Branch (272:9): [True: 0, False: 549]
  ------------------
  273|      0|      __builtin_trap();
  274|      0|    }
  275|    549|  }
  276|       |
  277|  1.45k|  size_t blen_tcp = Size;
  278|  1.45k|  uint16_t chn_tcp = 0;
  279|  1.45k|  bool is_chan_tcp = stun_is_channel_message_str(buf, &blen_tcp, &chn_tcp, true);
  280|       |
  281|  1.45k|  size_t blen_udp = Size;
  282|  1.45k|  uint16_t chn_udp = 0;
  283|  1.45k|  bool is_chan_udp = stun_is_channel_message_str(buf, &blen_udp, &chn_udp, false);
  284|       |
  285|  1.45k|  if (is_chan_tcp && (blen_tcp < 4 || blen_tcp > Size)) {
  ------------------
  |  Branch (285:7): [True: 95, False: 1.36k]
  |  Branch (285:23): [True: 0, False: 95]
  |  Branch (285:39): [True: 0, False: 95]
  ------------------
  286|      0|    __builtin_trap();
  287|      0|  }
  288|  1.45k|  if (is_chan_udp && (blen_udp < 4 || blen_udp > Size)) {
  ------------------
  |  Branch (288:7): [True: 107, False: 1.35k]
  |  Branch (288:23): [True: 0, False: 107]
  |  Branch (288:39): [True: 0, False: 107]
  ------------------
  289|      0|    __builtin_trap();
  290|      0|  }
  291|  1.45k|}
FuzzStunClient.c:harness_addr_codec:
  296|  1.79k|static void harness_addr_codec(const uint8_t *Data, size_t Size) {
  297|  1.79k|  if (Size < 2 || Size > 64) {
  ------------------
  |  Branch (297:7): [True: 75, False: 1.72k]
  |  Branch (297:19): [True: 519, False: 1.20k]
  ------------------
  298|    594|    return;
  299|    594|  }
  300|       |
  301|  1.20k|  uint8_t tid[STUN_TID_SIZE] = {0};
  302|  1.20k|  size_t tid_bytes = Size > (STUN_TID_SIZE + 2) ? STUN_TID_SIZE : (Size > 2 ? Size - 2 : 0);
  ------------------
  |  |   53|  1.20k|#define STUN_TID_SIZE (12)
  ------------------
                size_t tid_bytes = Size > (STUN_TID_SIZE + 2) ? STUN_TID_SIZE : (Size > 2 ? Size - 2 : 0);
  ------------------
  |  |   53|    684|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (302:22): [True: 684, False: 520]
  |  Branch (302:68): [True: 436, False: 84]
  ------------------
  303|  1.20k|  memcpy(tid, Data, tid_bytes);
  304|  1.20k|  const uint8_t *payload = Data + tid_bytes;
  305|  1.20k|  int payload_len = (int)(Size - tid_bytes);
  306|       |
  307|  1.20k|  ioa_addr addr = {0};
  308|       |
  309|       |  /* XOR decode + round-trip */
  310|  1.20k|  if (stun_addr_decode(&addr, payload, payload_len, 1, STUN_MAGIC_COOKIE, tid) == 0) {
  ------------------
  |  |   60|  1.20k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (310:7): [True: 8, False: 1.19k]
  ------------------
  311|      8|    uint8_t enc_buf[32] = {0};
  312|      8|    int enc_len = 0;
  313|      8|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 1, STUN_MAGIC_COOKIE, tid) == 0) {
  ------------------
  |  |   60|      8|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (313:9): [True: 8, False: 0]
  ------------------
  314|      8|      ioa_addr addr2 = {0};
  315|      8|      stun_addr_decode(&addr2, enc_buf, enc_len, 1, STUN_MAGIC_COOKIE, tid);
  ------------------
  |  |   60|      8|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  316|      8|    }
  317|      8|  }
  318|       |
  319|       |  /* Plain decode + round-trip */
  320|  1.20k|  memset(&addr, 0, sizeof(addr));
  321|  1.20k|  if (stun_addr_decode(&addr, payload, payload_len, 0, 0, tid) == 0) {
  ------------------
  |  Branch (321:7): [True: 8, False: 1.19k]
  ------------------
  322|      8|    uint8_t enc_buf[32] = {0};
  323|      8|    int enc_len = 0;
  324|      8|    if (stun_addr_encode(&addr, enc_buf, &enc_len, 0, 0, tid) == 0) {
  ------------------
  |  Branch (324:9): [True: 8, False: 0]
  ------------------
  325|      8|      ioa_addr addr2 = {0};
  326|      8|      stun_addr_decode(&addr2, enc_buf, enc_len, 0, 0, tid);
  327|      8|    }
  328|      8|  }
  329|       |
  330|       |  /* Alternate magic cookie (old STUN) */
  331|  1.20k|  memset(&addr, 0, sizeof(addr));
  332|  1.20k|  uint32_t alt_cookie = 0;
  333|  1.20k|  if (Size >= 4) {
  ------------------
  |  Branch (333:7): [True: 1.00k, False: 199]
  ------------------
  334|  1.00k|    memcpy(&alt_cookie, Data, 4);
  335|  1.00k|  }
  336|  1.20k|  (void)stun_addr_decode(&addr, payload, payload_len, 1, alt_cookie, tid);
  337|  1.20k|}
FuzzStunClient.c:harness_message_builders:
  342|  1.79k|static void harness_message_builders(const uint8_t *Data, size_t Size) {
  343|  1.79k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (343:7): [True: 0, False: 1.79k]
  |  Branch (343:16): [True: 133, False: 1.66k]
  ------------------
  344|    133|    return;
  345|    133|  }
  346|       |
  347|  1.66k|  static const uint16_t kMethods[] = {
  348|  1.66k|      STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   82|  1.66k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   81|  1.66k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   87|  1.66k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.66k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   90|  1.66k|#define STUN_METHOD_CONNECT (0x000a)
  ------------------
  349|  1.66k|  };
  350|  1.66k|  static const uint16_t kErrorCodes[] = {
  351|  1.66k|      300, 400, 401, 403, 420, 437, 438, 440, 441, 442, 443, 446, 447, 486, 487, 500, 508, 699,
  352|  1.66k|  };
  353|       |
  354|  1.66k|  stun_tid tid = {0};
  355|  1.66k|  ioa_addr relay1 = {0};
  356|  1.66k|  ioa_addr relay2 = {0};
  357|  1.66k|  ioa_addr reflexive = {0};
  358|  1.66k|  ioa_addr peer = {0};
  359|  1.66k|  ioa_addr default_addr = {0};
  360|  1.66k|  char reason[96] = {0};
  361|  1.66k|  char mobile_id[96] = {0};
  362|  1.66k|  uint8_t raw[MAX_STUN_MESSAGE_SIZE] = {0};
  363|       |
  364|  1.66k|  fuzz_tid(Data, Size, 0, &tid);
  365|  1.66k|  fuzz_addr(Data, Size, 16, &relay1);
  366|  1.66k|  fuzz_addr(Data, Size, 40, &relay2);
  367|  1.66k|  fuzz_addr(Data, Size, 64, &reflexive);
  368|  1.66k|  fuzz_addr(Data, Size, 88, &peer);
  369|  1.66k|  fuzz_addr(Data, Size, 112, &default_addr);
  370|  1.66k|  fuzz_string(Data, Size, 136, reason, sizeof(reason));
  371|  1.66k|  fuzz_string(Data, Size, 232, mobile_id, sizeof(mobile_id));
  372|       |
  373|  1.66k|  const uint16_t method = kMethods[fuzz_byte(Data, Size, 328) % (sizeof(kMethods) / sizeof(kMethods[0]))];
  374|  1.66k|  const uint16_t error_code = kErrorCodes[fuzz_byte(Data, Size, 329) % (sizeof(kErrorCodes) / sizeof(kErrorCodes[0]))];
  375|  1.66k|  const uint32_t lifetime = fuzz_u32(Data, Size, 330);
  376|  1.66k|  const uint32_t max_lifetime = fuzz_u32(Data, Size, 334);
  377|  1.66k|  const uint64_t reservation_token = fuzz_u64(Data, Size, 338);
  378|  1.66k|  const uint16_t channel_number = fuzz_u16(Data, Size, 346);
  379|  1.66k|  const bool include_reason = fuzz_flag(Data, Size, 348);
  380|  1.66k|  const bool old_stun = fuzz_flag(Data, Size, 349);
  381|  1.66k|  const bool stun_backward_compatibility = fuzz_flag(Data, Size, 350);
  382|  1.66k|  const uint32_t old_cookie = fuzz_u32(Data, Size, 351);
  383|       |
  384|       |  /* Direct wrapper coverage for stun_init_error_response(). */
  385|  1.66k|  {
  386|  1.66k|    stun_buffer msg;
  387|  1.66k|    stun_init_buffer(&msg);
  388|  1.66k|    stun_init_error_response(method, &msg, error_code, reason[0] ? (const uint8_t *)reason : NULL, &tid,
  ------------------
  |  Branch (388:56): [True: 1.13k, False: 527]
  ------------------
  389|  1.66k|                             include_reason);
  390|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  391|  1.66k|  }
  392|       |
  393|       |  /* Success allocate response covers addr extraction; error allocate response
  394|       |   * forces the shared error builder path. */
  395|  1.66k|  {
  396|  1.66k|    stun_buffer msg;
  397|  1.66k|    stun_init_buffer(&msg);
  398|  1.66k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, fuzz_flag(Data, Size, 355) ? &relay2 : NULL, &reflexive,
  ------------------
  |  Branch (398:59): [True: 553, False: 1.11k]
  ------------------
  399|  1.66k|                                     lifetime, max_lifetime, 0, (const uint8_t *)reason, reservation_token, mobile_id,
  400|  1.66k|                                     include_reason);
  401|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  402|       |
  403|  1.66k|    size_t raw_len = sizeof(raw);
  404|  1.66k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, &relay2, &reflexive, lifetime, max_lifetime, 0,
  405|  1.66k|                                         (const uint8_t *)reason, reservation_token, mobile_id, include_reason);
  406|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  407|       |
  408|  1.66k|    stun_init_buffer(&msg);
  409|  1.66k|    (void)stun_set_allocate_response(&msg, &tid, NULL, NULL, NULL, lifetime, max_lifetime, error_code,
  410|  1.66k|                                     reason[0] ? (const uint8_t *)reason : NULL, reservation_token, mobile_id,
  ------------------
  |  Branch (410:38): [True: 1.13k, False: 527]
  ------------------
  411|  1.66k|                                     include_reason);
  412|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  413|       |
  414|  1.66k|    raw_len = sizeof(raw);
  415|  1.66k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, NULL, NULL, NULL, lifetime, max_lifetime, error_code,
  416|  1.66k|                                         reason[0] ? (const uint8_t *)reason : NULL, reservation_token, mobile_id,
  ------------------
  |  Branch (416:42): [True: 1.13k, False: 527]
  ------------------
  417|  1.66k|                                         include_reason);
  418|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  419|  1.66k|  }
  420|       |
  421|  1.66k|  {
  422|  1.66k|    stun_buffer msg;
  423|  1.66k|    stun_init_buffer(&msg);
  424|  1.66k|    (void)stun_set_binding_response(&msg, &tid, &reflexive, 0, (const uint8_t *)reason, include_reason);
  425|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |  109|  1.66k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  426|       |
  427|  1.66k|    size_t raw_len = sizeof(raw);
  428|  1.66k|    (void)stun_set_binding_response_str(raw, &raw_len, &tid, &reflexive, 0, (const uint8_t *)reason, old_cookie,
  429|  1.66k|                                        old_stun, stun_backward_compatibility, include_reason);
  430|  1.66k|    inspect_raw_message(raw, raw_len, old_stun ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |   95|    696|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                  inspect_raw_message(raw, raw_len, old_stun ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  109|  2.63k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (430:39): [True: 696, False: 969]
  ------------------
  431|  1.66k|                        &default_addr);
  432|       |
  433|  1.66k|    stun_init_buffer(&msg);
  434|  1.66k|    (void)stun_set_binding_response(&msg, &tid, NULL, error_code, reason[0] ? (const uint8_t *)reason : NULL,
  ------------------
  |  Branch (434:67): [True: 1.13k, False: 527]
  ------------------
  435|  1.66k|                                    include_reason);
  436|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  437|       |
  438|  1.66k|    raw_len = sizeof(raw);
  439|  1.66k|    (void)stun_set_binding_response_str(raw, &raw_len, &tid, NULL, error_code,
  440|  1.66k|                                        reason[0] ? (const uint8_t *)reason : NULL, old_cookie, old_stun,
  ------------------
  |  Branch (440:41): [True: 1.13k, False: 527]
  ------------------
  441|  1.66k|                                        stun_backward_compatibility, include_reason);
  442|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  443|  1.66k|  }
  444|       |
  445|  1.66k|  {
  446|  1.66k|    stun_buffer msg;
  447|  1.66k|    stun_init_buffer(&msg);
  448|  1.66k|    (void)stun_set_channel_bind_request(&msg, fuzz_flag(Data, Size, 356) ? &peer : NULL, channel_number);
  ------------------
  |  Branch (448:47): [True: 642, False: 1.02k]
  ------------------
  449|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  450|       |
  451|  1.66k|    size_t raw_len = sizeof(raw);
  452|  1.66k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, fuzz_flag(Data, Size, 357) ? &peer : NULL, channel_number);
  ------------------
  |  Branch (452:60): [True: 612, False: 1.05k]
  ------------------
  453|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  454|       |
  455|  1.66k|    stun_init_buffer(&msg);
  456|  1.66k|    stun_set_channel_bind_response(&msg, &tid, 0, (const uint8_t *)reason, include_reason);
  457|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  458|       |
  459|  1.66k|    raw_len = sizeof(raw);
  460|  1.66k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, error_code, reason[0] ? (const uint8_t *)reason : NULL,
  ------------------
  |  Branch (460:73): [True: 1.13k, False: 527]
  ------------------
  461|  1.66k|                                       include_reason);
  462|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  463|  1.66k|  }
  464|  1.66k|}
FuzzStunClient.c:fuzz_tid:
   57|  4.99k|static void fuzz_tid(const uint8_t *Data, size_t Size, size_t idx, stun_tid *tid) {
   58|  4.99k|  if (!tid) {
  ------------------
  |  Branch (58:7): [True: 0, False: 4.99k]
  ------------------
   59|      0|    return;
   60|      0|  }
   61|       |
   62|  4.99k|  memset(tid, 0, sizeof(*tid));
   63|  64.9k|  for (size_t i = 0; i < STUN_TID_SIZE; ++i) {
  ------------------
  |  |   53|  64.9k|#define STUN_TID_SIZE (12)
  ------------------
  |  Branch (63:22): [True: 59.9k, False: 4.99k]
  ------------------
   64|  59.9k|    tid->tsx_id[i] = fuzz_byte(Data, Size, idx + i);
   65|  59.9k|  }
   66|  4.99k|}
FuzzStunClient.c:fuzz_addr:
   68|  21.0k|static void fuzz_addr(const uint8_t *Data, size_t Size, size_t idx, ioa_addr *addr) {
   69|  21.0k|  if (!addr) {
  ------------------
  |  Branch (69:7): [True: 0, False: 21.0k]
  ------------------
   70|      0|    return;
   71|      0|  }
   72|       |
   73|  21.0k|  memset(addr, 0, sizeof(*addr));
   74|       |
   75|  21.0k|  if (fuzz_flag(Data, Size, idx)) {
  ------------------
  |  Branch (75:7): [True: 8.59k, False: 12.4k]
  ------------------
   76|  8.59k|    addr->s6.sin6_family = AF_INET6;
   77|  8.59k|    addr->s6.sin6_port = htons(fuzz_u16(Data, Size, idx + 1));
   78|   146k|    for (size_t i = 0; i < 16; ++i) {
  ------------------
  |  Branch (78:24): [True: 137k, False: 8.59k]
  ------------------
   79|   137k|      addr->s6.sin6_addr.s6_addr[i] = fuzz_byte(Data, Size, idx + 3 + i);
   80|   137k|    }
   81|  8.59k|    if (!memcmp(addr->s6.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) {
  ------------------
  |  Branch (81:9): [True: 46, False: 8.55k]
  ------------------
   82|     46|      addr->s6.sin6_addr.s6_addr[15] = 1;
   83|     46|    }
   84|  12.4k|  } else {
   85|  12.4k|    addr->s4.sin_family = AF_INET;
   86|  12.4k|    addr->s4.sin_port = htons(fuzz_u16(Data, Size, idx + 1));
   87|       |    addr->s4.sin_addr.s_addr = htonl(fuzz_u32(Data, Size, idx + 3) | 1u);
   88|  12.4k|  }
   89|  21.0k|}
FuzzStunClient.c:fuzz_string:
   42|  9.99k|static void fuzz_string(const uint8_t *Data, size_t Size, size_t idx, char *out, size_t out_size) {
   43|  9.99k|  if (!out || !out_size) {
  ------------------
  |  Branch (43:7): [True: 0, False: 9.99k]
  |  Branch (43:15): [True: 0, False: 9.99k]
  ------------------
   44|      0|    return;
   45|      0|  }
   46|       |
   47|  9.99k|  const size_t max_len = out_size - 1;
   48|  9.99k|  const size_t len = max_len ? (size_t)(fuzz_byte(Data, Size, idx) % (max_len + 1)) : 0;
  ------------------
  |  Branch (48:22): [True: 9.99k, False: 0]
  ------------------
   49|       |
   50|   267k|  for (size_t i = 0; i < len; ++i) {
  ------------------
  |  Branch (50:22): [True: 257k, False: 9.99k]
  ------------------
   51|   257k|    out[i] = (char)('A' + (fuzz_byte(Data, Size, idx + 1 + i) % 26));
   52|   257k|  }
   53|       |
   54|  9.99k|  out[len] = '\0';
   55|  9.99k|}
FuzzStunClient.c:fuzz_byte:
   26|   684k|static uint8_t fuzz_byte(const uint8_t *Data, size_t Size, size_t idx) { return Size ? Data[idx % Size] : 0; }
  ------------------
  |  Branch (26:81): [True: 684k, False: 0]
  ------------------
FuzzStunClient.c:fuzz_u32:
   32|  29.1k|static uint32_t fuzz_u32(const uint8_t *Data, size_t Size, size_t idx) {
   33|  29.1k|  return ((uint32_t)fuzz_u16(Data, Size, idx) << 16) | (uint32_t)fuzz_u16(Data, Size, idx + 2);
   34|  29.1k|}
FuzzStunClient.c:fuzz_u64:
   36|  3.33k|static uint64_t fuzz_u64(const uint8_t *Data, size_t Size, size_t idx) {
   37|  3.33k|  return ((uint64_t)fuzz_u32(Data, Size, idx) << 32) | (uint64_t)fuzz_u32(Data, Size, idx + 4);
   38|  3.33k|}
FuzzStunClient.c:fuzz_u16:
   28|  85.9k|static uint16_t fuzz_u16(const uint8_t *Data, size_t Size, size_t idx) {
   29|  85.9k|  return (uint16_t)(((uint16_t)fuzz_byte(Data, Size, idx) << 8) | (uint16_t)fuzz_byte(Data, Size, idx + 1));
   30|  85.9k|}
FuzzStunClient.c:fuzz_flag:
   40|  37.6k|static bool fuzz_flag(const uint8_t *Data, size_t Size, size_t idx) { return (fuzz_byte(Data, Size, idx) & 1u) != 0; }
FuzzStunClient.c:inspect_buffer_message:
   91|  41.6k|static void inspect_buffer_message(stun_buffer *msg, uint16_t addr_attr_type, const ioa_addr *default_addr) {
   92|  41.6k|  if (!msg) {
  ------------------
  |  Branch (92:7): [True: 0, False: 41.6k]
  ------------------
   93|      0|    return;
   94|      0|  }
   95|       |
   96|  41.6k|  (void)stun_get_command_message_len(msg);
   97|  41.6k|  (void)stun_is_command_message(msg);
   98|  41.6k|  (void)stun_is_request(msg);
   99|  41.6k|  (void)stun_is_response(msg);
  100|  41.6k|  (void)stun_is_success_response(msg);
  101|  41.6k|  (void)stun_is_binding_response(msg);
  102|  41.6k|  (void)stun_get_method(msg);
  103|  41.6k|  (void)stun_get_msg_type(msg);
  104|       |
  105|  41.6k|  {
  106|  41.6k|    int err_code = 0;
  107|  41.6k|    uint8_t err_msg[256] = {0};
  108|  41.6k|    (void)stun_is_error_response(msg, &err_code, err_msg, sizeof(err_msg));
  109|  41.6k|  }
  110|       |
  111|  41.6k|  {
  112|  41.6k|    ioa_addr parsed = {0};
  113|  41.6k|    (void)stun_attr_get_first_addr(msg, addr_attr_type, &parsed, default_addr);
  114|  41.6k|  }
  115|       |
  116|  41.6k|  {
  117|  41.6k|    stun_attr_ref attr = stun_attr_get_first(msg);
  118|   114k|    while (attr) {
  ------------------
  |  Branch (118:12): [True: 72.8k, False: 41.6k]
  ------------------
  119|  72.8k|      (void)stun_attr_get_type(attr);
  120|  72.8k|      (void)stun_attr_get_len(attr);
  121|  72.8k|      if (stun_attr_is_addr(attr)) {
  ------------------
  |  Branch (121:11): [True: 23.8k, False: 48.9k]
  ------------------
  122|  23.8k|        ioa_addr parsed = {0};
  123|  23.8k|        (void)stun_attr_get_addr(msg, attr, &parsed, default_addr);
  124|  23.8k|      }
  125|  72.8k|      attr = stun_attr_get_next(msg, attr);
  126|  72.8k|    }
  127|  41.6k|  }
  128|       |
  129|  41.6k|  (void)stun_attr_get_first_channel_number(msg);
  130|  41.6k|}
FuzzStunClient.c:inspect_raw_message:
  132|  34.9k|static void inspect_raw_message(const uint8_t *buf, size_t len, uint16_t addr_attr_type, const ioa_addr *default_addr) {
  133|  34.9k|  if (!buf || !len) {
  ------------------
  |  Branch (133:7): [True: 0, False: 34.9k]
  |  Branch (133:15): [True: 0, False: 34.9k]
  ------------------
  134|      0|    return;
  135|      0|  }
  136|       |
  137|  34.9k|  (void)stun_is_command_message_str((uint8_t *)buf, len);
  138|  34.9k|  (void)stun_is_request_str(buf, len);
  139|  34.9k|  (void)stun_is_response_str(buf, len);
  140|  34.9k|  (void)stun_is_success_response_str(buf, len);
  141|  34.9k|  (void)stun_is_binding_response_str(buf, len);
  142|  34.9k|  (void)stun_get_method_str(buf, len);
  143|  34.9k|  (void)stun_get_msg_type_str(buf, len);
  144|       |
  145|  34.9k|  {
  146|  34.9k|    int err_code = 0;
  147|  34.9k|    uint8_t err_msg[256] = {0};
  148|  34.9k|    (void)stun_is_error_response_str(buf, len, &err_code, err_msg, sizeof(err_msg));
  149|  34.9k|  }
  150|       |
  151|  34.9k|  {
  152|  34.9k|    ioa_addr parsed = {0};
  153|  34.9k|    (void)stun_attr_get_first_addr_str(buf, len, addr_attr_type, &parsed, default_addr);
  154|  34.9k|  }
  155|       |
  156|  34.9k|  {
  157|  34.9k|    stun_attr_ref attr = stun_attr_get_first_str(buf, len);
  158|  92.5k|    while (attr) {
  ------------------
  |  Branch (158:12): [True: 57.5k, False: 34.9k]
  ------------------
  159|  57.5k|      (void)stun_attr_get_type(attr);
  160|  57.5k|      (void)stun_attr_get_len(attr);
  161|  57.5k|      if (stun_attr_is_addr(attr)) {
  ------------------
  |  Branch (161:11): [True: 26.9k, False: 30.6k]
  ------------------
  162|  26.9k|        ioa_addr parsed = {0};
  163|  26.9k|        (void)stun_attr_get_addr_str(buf, len, attr, &parsed, default_addr);
  164|  26.9k|      }
  165|  57.5k|      attr = stun_attr_get_next_str(buf, len, attr);
  166|  57.5k|    }
  167|  34.9k|  }
  168|       |
  169|  34.9k|  (void)stun_attr_get_first_channel_number_str(buf, len);
  170|  34.9k|}
FuzzStunClient.c:harness_attr_get_first_addr:
  187|  1.79k|static void harness_attr_get_first_addr(const uint8_t *Data, size_t Size) {
  188|  1.79k|  if (Size < STUN_HEADER_LENGTH || Size > 5120) {
  ------------------
  |  |   46|  3.59k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (188:7): [True: 642, False: 1.15k]
  |  Branch (188:36): [True: 88, False: 1.06k]
  ------------------
  189|    730|    return;
  190|    730|  }
  191|       |
  192|  1.06k|  stun_buffer msg;
  193|  1.06k|  msg.len = Size;
  194|  1.06k|  memcpy(msg.buf, Data, Size);
  195|       |
  196|  1.06k|  ioa_addr default_addr = {0};
  197|  1.06k|  fuzz_addr(Data, Size, 0, &default_addr);
  198|       |
  199|  1.06k|  const size_t num_attrs = sizeof(kFirstAddrAttrs) / sizeof(kFirstAddrAttrs[0]);
  200|  9.61k|  for (size_t i = 0; i < num_attrs; ++i) {
  ------------------
  |  Branch (200:22): [True: 8.54k, False: 1.06k]
  ------------------
  201|  8.54k|    ioa_addr parsed = {0};
  202|  8.54k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, NULL);
  203|       |
  204|  8.54k|    memset(&parsed, 0, sizeof(parsed));
  205|  8.54k|    (void)stun_attr_get_first_addr(&msg, kFirstAddrAttrs[i], &parsed, &default_addr);
  206|  8.54k|  }
  207|  1.06k|}
FuzzStunClient.c:harness_response_matrix:
  477|  1.79k|static void harness_response_matrix(const uint8_t *Data, size_t Size) {
  478|  1.79k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (478:7): [True: 0, False: 1.79k]
  |  Branch (478:16): [True: 133, False: 1.66k]
  ------------------
  479|    133|    return;
  480|    133|  }
  481|       |
  482|  1.66k|  stun_tid tid = {0};
  483|  1.66k|  ioa_addr relay1 = {0};
  484|  1.66k|  ioa_addr relay2 = {0};
  485|  1.66k|  ioa_addr reflexive = {0};
  486|  1.66k|  ioa_addr peer = {0};
  487|  1.66k|  ioa_addr default_addr = {0};
  488|  1.66k|  char reason[96] = {0};
  489|  1.66k|  char mobile_id[96] = {0};
  490|  1.66k|  uint8_t raw[MAX_STUN_MESSAGE_SIZE] = {0};
  491|       |
  492|  1.66k|  fuzz_tid(Data, Size, 0, &tid);
  493|  1.66k|  fuzz_addr(Data, Size, 16, &relay1);
  494|  1.66k|  fuzz_addr(Data, Size, 40, &relay2);
  495|  1.66k|  fuzz_addr(Data, Size, 64, &reflexive);
  496|  1.66k|  fuzz_addr(Data, Size, 88, &peer);
  497|  1.66k|  fuzz_addr(Data, Size, 112, &default_addr);
  498|  1.66k|  fuzz_string(Data, Size, 136, reason, sizeof(reason));
  499|  1.66k|  fuzz_string(Data, Size, 232, mobile_id, sizeof(mobile_id));
  500|       |
  501|  1.66k|  const uint32_t max_lifetime = fuzz_u32(Data, Size, 328) | 1u;
  502|  1.66k|  const uint64_t reservation_token = fuzz_u64(Data, Size, 332) | 1ull;
  503|  1.66k|  const uint16_t channel_number_valid = (uint16_t)(0x4000u + (fuzz_u16(Data, Size, 340) % (0x7FFFu - 0x4000u + 1u)));
  504|  1.66k|  const uint32_t old_cookie = fuzz_u32(Data, Size, 344);
  505|       |
  506|       |  /* stun_init_error_response — cover (reason NULL vs set) × (include reason). */
  507|  1.66k|  {
  508|  1.66k|    stun_buffer msg;
  509|  1.66k|    stun_init_buffer(&msg);
  510|  1.66k|    stun_init_error_response(STUN_METHOD_ALLOCATE, &msg, 437, NULL, &tid, false);
  ------------------
  |  |   82|  1.66k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
  511|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  512|       |
  513|  1.66k|    stun_init_buffer(&msg);
  514|  1.66k|    stun_init_error_response(STUN_METHOD_BINDING, &msg, 400, (const uint8_t *)reason, &tid, true);
  ------------------
  |  |   81|  1.66k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  515|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  516|  1.66k|  }
  517|       |
  518|       |  /* stun_set_allocate_response / _str — cover every optional-field branch and
  519|       |   * the error path independently of the fuzzer selectors. */
  520|  1.66k|  {
  521|  1.66k|    stun_buffer msg;
  522|       |
  523|       |    /* Minimal success: relay1 only, no reflexive, no reservation, no mobile id,
  524|       |     * lifetime 0 (triggers the <1 default branch). */
  525|  1.66k|    stun_init_buffer(&msg);
  526|  1.66k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, NULL, NULL, 0, max_lifetime, 0, NULL, 0, NULL, false);
  527|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  528|       |
  529|  1.66k|    size_t raw_len = sizeof(raw);
  530|  1.66k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, NULL, NULL, 0, max_lifetime, 0, NULL, 0, NULL,
  531|  1.66k|                                         false);
  532|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  533|       |
  534|       |    /* Full success: both relays + reflexive + reservation + mobile id,
  535|       |     * lifetime > max (triggers clamp branch). */
  536|  1.66k|    stun_init_buffer(&msg);
  537|  1.66k|    (void)stun_set_allocate_response(&msg, &tid, &relay1, &relay2, &reflexive, max_lifetime + 1, max_lifetime, 0,
  538|  1.66k|                                     (const uint8_t *)reason, reservation_token, mobile_id, true);
  539|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  540|       |
  541|  1.66k|    raw_len = sizeof(raw);
  542|  1.66k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, &relay1, &relay2, &reflexive, max_lifetime + 1,
  543|  1.66k|                                         max_lifetime, 0, (const uint8_t *)reason, reservation_token, mobile_id, true);
  544|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  545|       |
  546|       |    /* Error path with and without a reason string. */
  547|  1.66k|    stun_init_buffer(&msg);
  548|  1.66k|    (void)stun_set_allocate_response(&msg, &tid, NULL, NULL, NULL, 0, max_lifetime, 441, NULL, 0, NULL, false);
  549|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  550|       |
  551|  1.66k|    raw_len = sizeof(raw);
  552|  1.66k|    (void)stun_set_allocate_response_str(raw, &raw_len, &tid, NULL, NULL, NULL, 0, max_lifetime, 508,
  553|  1.66k|                                         (const uint8_t *)reason, 0, NULL, true);
  554|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  555|  1.66k|  }
  556|       |
  557|       |  /* stun_set_binding_response / _str — cover success × error × old_stun. */
  558|  1.66k|  {
  559|  1.66k|    stun_buffer msg;
  560|       |
  561|  1.66k|    stun_init_buffer(&msg);
  562|  1.66k|    (void)stun_set_binding_response(&msg, &tid, &reflexive, 0, NULL, false);
  563|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |  109|  1.66k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  564|       |
  565|  1.66k|    stun_init_buffer(&msg);
  566|  1.66k|    (void)stun_set_binding_response(&msg, &tid, NULL, 420, (const uint8_t *)reason, true);
  567|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  568|       |
  569|  1.66k|    const bool matrix_old_stun[] = {false, true};
  570|  1.66k|    const bool matrix_backcompat[] = {false, true};
  571|  4.99k|    for (size_t o = 0; o < sizeof(matrix_old_stun) / sizeof(matrix_old_stun[0]); ++o) {
  ------------------
  |  Branch (571:24): [True: 3.33k, False: 1.66k]
  ------------------
  572|  9.99k|      for (size_t b = 0; b < sizeof(matrix_backcompat) / sizeof(matrix_backcompat[0]); ++b) {
  ------------------
  |  Branch (572:26): [True: 6.66k, False: 3.33k]
  ------------------
  573|  6.66k|        size_t raw_len = sizeof(raw);
  574|  6.66k|        (void)stun_set_binding_response_str(raw, &raw_len, &tid, &reflexive, 0, NULL, old_cookie, matrix_old_stun[o],
  575|  6.66k|                                            matrix_backcompat[b], false);
  576|  6.66k|        inspect_raw_message(raw, raw_len,
  577|  6.66k|                            matrix_old_stun[o] ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |   95|  3.33k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
                                          matrix_old_stun[o] ? STUN_ATTRIBUTE_MAPPED_ADDRESS : STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS,
  ------------------
  |  |  109|  9.99k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (577:29): [True: 3.33k, False: 3.33k]
  ------------------
  578|  6.66k|                            &default_addr);
  579|       |
  580|  6.66k|        raw_len = sizeof(raw);
  581|  6.66k|        (void)stun_set_binding_response_str(raw, &raw_len, &tid, NULL, 500, (const uint8_t *)reason, old_cookie,
  582|  6.66k|                                            matrix_old_stun[o], matrix_backcompat[b], true);
  583|  6.66k|        inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  6.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  584|  6.66k|      }
  585|  3.33k|    }
  586|  1.66k|  }
  587|       |
  588|       |  /* stun_set_channel_bind_request / _str — cover peer NULL vs set. */
  589|  1.66k|  {
  590|  1.66k|    stun_buffer msg;
  591|       |
  592|  1.66k|    stun_init_buffer(&msg);
  593|  1.66k|    (void)stun_set_channel_bind_request(&msg, NULL, channel_number_valid);
  594|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  595|       |
  596|  1.66k|    stun_init_buffer(&msg);
  597|  1.66k|    (void)stun_set_channel_bind_request(&msg, &peer, channel_number_valid);
  598|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  599|       |
  600|  1.66k|    size_t raw_len = sizeof(raw);
  601|  1.66k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, NULL, channel_number_valid);
  602|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  603|       |
  604|  1.66k|    raw_len = sizeof(raw);
  605|  1.66k|    (void)stun_set_channel_bind_request_str(raw, &raw_len, &peer, channel_number_valid);
  606|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  607|  1.66k|  }
  608|       |
  609|       |  /* stun_set_channel_bind_response / _str — cover success vs error. */
  610|  1.66k|  {
  611|  1.66k|    stun_buffer msg;
  612|       |
  613|  1.66k|    stun_init_buffer(&msg);
  614|  1.66k|    stun_set_channel_bind_response(&msg, &tid, 0, NULL, false);
  615|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  616|       |
  617|  1.66k|    stun_init_buffer(&msg);
  618|  1.66k|    stun_set_channel_bind_response(&msg, &tid, 438, (const uint8_t *)reason, true);
  619|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  620|       |
  621|  1.66k|    size_t raw_len = sizeof(raw);
  622|  1.66k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, 0, NULL, false);
  623|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  624|       |
  625|  1.66k|    raw_len = sizeof(raw);
  626|  1.66k|    stun_set_channel_bind_response_str(raw, &raw_len, &tid, 486, (const uint8_t *)reason, true);
  627|  1.66k|    inspect_raw_message(raw, raw_len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  628|  1.66k|  }
  629|  1.66k|}
FuzzStunClient.c:harness_stun_buffer_api:
  653|  1.79k|static void harness_stun_buffer_api(const uint8_t *Data, size_t Size) {
  654|  1.79k|  if (!Size || Size > 4096) {
  ------------------
  |  Branch (654:7): [True: 0, False: 1.79k]
  |  Branch (654:16): [True: 133, False: 1.66k]
  ------------------
  655|    133|    return;
  656|    133|  }
  657|       |
  658|  1.66k|  static const uint16_t kMethods[] = {
  659|  1.66k|      STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   82|  1.66k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   81|  1.66k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   87|  1.66k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   83|  1.66k|#define STUN_METHOD_REFRESH (0x0004)
  ------------------
                    STUN_METHOD_ALLOCATE, STUN_METHOD_BINDING, STUN_METHOD_CHANNEL_BIND, STUN_METHOD_REFRESH, STUN_METHOD_CONNECT,
  ------------------
  |  |   90|  1.66k|#define STUN_METHOD_CONNECT (0x000a)
  ------------------
  660|  1.66k|  };
  661|       |
  662|  1.66k|  stun_tid tid = {0};
  663|  1.66k|  ioa_addr peer = {0};
  664|  1.66k|  ioa_addr default_addr = {0};
  665|  1.66k|  char attr_value[64] = {0};
  666|  1.66k|  char rt[8] = {0};
  667|       |
  668|  1.66k|  fuzz_tid(Data, Size, 0, &tid);
  669|  1.66k|  fuzz_addr(Data, Size, 16, &peer);
  670|  1.66k|  fuzz_addr(Data, Size, 40, &default_addr);
  671|  1.66k|  fuzz_string(Data, Size, 64, attr_value, sizeof(attr_value));
  672|  1.66k|  fuzz_string(Data, Size, 128, rt, sizeof(rt));
  673|       |
  674|  1.66k|  const uint16_t method = kMethods[fuzz_byte(Data, Size, 200) % (sizeof(kMethods) / sizeof(kMethods[0]))];
  675|  1.66k|  const uint32_t lifetime = fuzz_u32(Data, Size, 201);
  676|  1.66k|  const uint16_t channel_number = (uint16_t)(0x4000u + (fuzz_u16(Data, Size, 205) & 0x3FFFu));
  677|  1.66k|  const uint8_t transport = fuzz_byte(Data, Size, 207);
  678|  1.66k|  const uint8_t even_port_value = fuzz_byte(Data, Size, 208);
  679|  1.66k|  const bool af4 = fuzz_flag(Data, Size, 209);
  680|  1.66k|  const bool af6 = fuzz_flag(Data, Size, 210);
  681|  1.66k|  const bool mobile = fuzz_flag(Data, Size, 211);
  682|  1.66k|  const bool padding = fuzz_flag(Data, Size, 212);
  683|  1.66k|  const int chan_payload_len = (int)(fuzz_u16(Data, Size, 213) % 256);
  684|  1.66k|  const int ep = (int)(int8_t)fuzz_byte(Data, Size, 215);
  685|       |
  686|       |  /* NULL-guard branches. */
  687|  1.66k|  (void)stun_get_size(NULL);
  688|  1.66k|  (void)stun_init_buffer(NULL);
  689|  1.66k|  (void)stun_get_msg_type(NULL);
  690|  1.66k|  {
  691|  1.66k|    stun_tid scratch = {0};
  692|  1.66k|    stun_tid_generate_in_message(NULL, &scratch);
  693|  1.66k|  }
  694|       |
  695|       |  /* stun_init_request — also covers stun_get_size (non-NULL), the static
  696|       |   * stun_init_command helper, and stun_attr_add* / stun_attr_get_first_by_type
  697|       |   * over the freshly built message. */
  698|  1.66k|  {
  699|  1.66k|    stun_buffer msg;
  700|  1.66k|    stun_init_buffer(&msg);
  701|  1.66k|    stun_init_request(method, &msg);
  702|       |
  703|  1.66k|    stun_tid extracted = {0};
  704|  1.66k|    stun_tid_from_message(&msg, &extracted);
  705|  1.66k|    stun_tid_generate_in_message(&msg, &extracted);
  706|       |
  707|  1.66k|    const int alen = (int)strlen(attr_value);
  708|  1.66k|    (void)stun_attr_add(&msg, STUN_ATTRIBUTE_USERNAME, attr_value, alen);
  ------------------
  |  |  100|  1.66k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  709|  1.66k|    (void)stun_attr_add_channel_number(&msg, channel_number);
  710|  1.66k|    (void)stun_attr_add_addr(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &peer);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  711|  1.66k|    (void)stun_attr_add_even_port(&msg, even_port_value);
  712|  1.66k|    (void)stun_attr_add_even_port(&msg, 0);
  713|       |
  714|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_USERNAME);
  ------------------
  |  |  100|  1.66k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  715|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  117|  1.66k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  716|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  717|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_EVEN_PORT);
  ------------------
  |  |  123|  1.66k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  718|       |
  719|  1.66k|    (void)stun_is_indication(&msg);
  720|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  721|  1.66k|  }
  722|       |
  723|       |  /* stun_init_indication — drives the IS_STUN_INDICATION branch of
  724|       |   * stun_is_indication. */
  725|  1.66k|  {
  726|  1.66k|    stun_buffer msg;
  727|  1.66k|    stun_init_buffer(&msg);
  728|  1.66k|    stun_init_indication(method, &msg);
  729|  1.66k|    (void)stun_is_indication(&msg);
  730|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &default_addr);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  731|  1.66k|  }
  732|       |
  733|       |  /* stun_init_success_response. */
  734|  1.66k|  {
  735|  1.66k|    stun_buffer msg;
  736|  1.66k|    stun_init_buffer(&msg);
  737|  1.66k|    stun_init_success_response(method, &msg, &tid);
  738|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  739|  1.66k|  }
  740|       |
  741|       |  /* stun_set_allocate_request — both rt NULL and rt non-NULL paths. */
  742|  1.66k|  {
  743|  1.66k|    stun_buffer msg;
  744|  1.66k|    stun_init_buffer(&msg);
  745|  1.66k|    (void)stun_set_allocate_request(&msg, lifetime, af4, af6, transport, mobile, rt[0] ? rt : NULL, ep);
  ------------------
  |  Branch (745:82): [True: 1.00k, False: 661]
  ------------------
  746|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  747|       |
  748|  1.66k|    stun_init_buffer(&msg);
  749|  1.66k|    (void)stun_set_allocate_request(&msg, lifetime, !af4, !af6, transport, !mobile, NULL, ep);
  750|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, &default_addr);
  ------------------
  |  |  122|  1.66k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  751|  1.66k|  }
  752|       |
  753|       |  /* stun_set_binding_request + stun_prepare_binding_request (both currently
  754|       |   * delegate to stun_set_binding_request_str but exercise the wrappers). */
  755|  1.66k|  {
  756|  1.66k|    stun_buffer msg;
  757|  1.66k|    stun_init_buffer(&msg);
  758|  1.66k|    stun_set_binding_request(&msg);
  759|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  760|       |
  761|  1.66k|    stun_init_buffer(&msg);
  762|  1.66k|    stun_prepare_binding_request(&msg);
  763|  1.66k|    inspect_buffer_message(&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, &default_addr);
  ------------------
  |  |   95|  1.66k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  764|  1.66k|  }
  765|       |
  766|       |  /* stun_init_channel_message + stun_is_channel_message wrappers. */
  767|  1.66k|  {
  768|  1.66k|    stun_buffer msg;
  769|  1.66k|    stun_init_buffer(&msg);
  770|  1.66k|    if (stun_init_channel_message(channel_number, &msg, chan_payload_len, padding)) {
  ------------------
  |  Branch (770:9): [True: 1.66k, False: 0]
  ------------------
  771|  1.66k|      uint16_t parsed_chn = 0;
  772|  1.66k|      (void)stun_is_channel_message(&msg, &parsed_chn, true);
  773|  1.66k|      (void)stun_is_channel_message(&msg, &parsed_chn, false);
  774|  1.66k|    }
  775|  1.66k|    {
  776|  1.66k|      uint16_t chn = 0;
  777|  1.66k|      (void)stun_is_channel_message(NULL, &chn, false);
  778|  1.66k|    }
  779|  1.66k|  }
  780|       |
  781|       |  /* Raw fuzzer bytes through the wrapper-form predicates so they see
  782|       |   * malformed inputs the serializer paths above never produce. */
  783|  1.66k|  {
  784|  1.66k|    stun_buffer msg;
  785|  1.66k|    msg.len = Size > sizeof(msg.buf) ? sizeof(msg.buf) : Size;
  ------------------
  |  Branch (785:15): [True: 0, False: 1.66k]
  ------------------
  786|  1.66k|    memcpy(msg.buf, Data, msg.len);
  787|       |
  788|  1.66k|    (void)stun_is_indication(&msg);
  789|       |
  790|  1.66k|    stun_tid extracted = {0};
  791|  1.66k|    stun_tid_from_message(&msg, &extracted);
  792|       |
  793|  1.66k|    {
  794|  1.66k|      uint16_t chn = 0;
  795|  1.66k|      const size_t saved_len = msg.len;
  796|  1.66k|      (void)stun_is_channel_message(&msg, &chn, true);
  797|  1.66k|      msg.len = saved_len;
  798|  1.66k|      (void)stun_is_channel_message(&msg, &chn, false);
  799|  1.66k|    }
  800|       |
  801|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_USERNAME);
  ------------------
  |  |  100|  1.66k|#define STUN_ATTRIBUTE_USERNAME (0x0006)
  ------------------
  802|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_XOR_PEER_ADDRESS);
  ------------------
  |  |  120|  1.66k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  803|  1.66k|    (void)stun_attr_get_first_by_type(&msg, STUN_ATTRIBUTE_CHANNEL_NUMBER);
  ------------------
  |  |  117|  1.66k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  804|  1.66k|  }
  805|  1.66k|}

turn_malloc_impl:
  938|      8|void *turn_malloc_impl(size_t sz, const char *file, int line) {
  939|      8|  void *ptr = malloc(sz);
  940|      8|  if (!ptr && sz) {
  ------------------
  |  Branch (940:7): [True: 0, False: 8]
  |  Branch (940:15): [True: 0, False: 0]
  ------------------
  941|      0|    turn_out_of_memory(file, line, "malloc", sz);
  942|      0|  }
  943|      8|  return ptr;
  944|      8|}
turn_realloc_impl:
  954|      8|void *turn_realloc_impl(void *ptr, size_t sz, const char *file, int line) {
  955|      8|  void *newptr = realloc(ptr, sz);
  956|      8|  if (!newptr && sz) {
  ------------------
  |  Branch (956:7): [True: 0, False: 8]
  |  Branch (956:18): [True: 0, False: 0]
  ------------------
  957|      0|    turn_out_of_memory(file, line, "realloc", sz);
  958|      0|  }
  959|      8|  return newptr;
  960|      8|}

stun_init_buffer:
   41|  44.9k|int stun_init_buffer(stun_buffer *buf) {
   42|  44.9k|  if (!buf) {
  ------------------
  |  Branch (42:7): [True: 1.66k, False: 43.2k]
  ------------------
   43|  1.66k|    return -1;
   44|  1.66k|  }
   45|  43.2k|  memset(buf->buf, 0, sizeof(buf->buf));
   46|  43.2k|  buf->len = 0;
   47|  43.2k|  buf->offset = 0;
   48|  43.2k|  buf->coffset = 0;
   49|  43.2k|  return 0;
   50|  44.9k|}
stun_get_size:
   52|  11.6k|int stun_get_size(const stun_buffer *buf) {
   53|  11.6k|  if (!buf) {
  ------------------
  |  Branch (53:7): [True: 1.66k, False: 9.99k]
  ------------------
   54|  1.66k|    return 0;
   55|  1.66k|  }
   56|  9.99k|  return sizeof(buf->buf);
   57|  11.6k|}
stun_tid_from_message:
   61|  3.33k|void stun_tid_from_message(const stun_buffer *buf, stun_tid *id) {
   62|  3.33k|  stun_tid_from_message_str(buf->buf, (size_t)(buf->len), id);
   63|  3.33k|}
stun_tid_generate_in_message:
   65|  3.33k|void stun_tid_generate_in_message(stun_buffer *buf, stun_tid *id) {
   66|  3.33k|  if (buf) {
  ------------------
  |  Branch (66:7): [True: 1.66k, False: 1.66k]
  ------------------
   67|  1.66k|    stun_tid_generate_in_message_str(buf->buf, id);
   68|  1.66k|  }
   69|  3.33k|}
stun_is_command_message:
   80|  42.8k|bool stun_is_command_message(const stun_buffer *buf) {
   81|  42.8k|  if (!buf || buf->len <= 0) {
  ------------------
  |  Branch (81:7): [True: 0, False: 42.8k]
  |  Branch (81:15): [True: 0, False: 42.8k]
  ------------------
   82|      0|    return false;
   83|  42.8k|  } else {
   84|  42.8k|    return stun_is_command_message_str(buf->buf, (size_t)(buf->len));
   85|  42.8k|  }
   86|  42.8k|}
stun_is_request:
   88|  41.6k|bool stun_is_request(const stun_buffer *buf) { return stun_is_request_str(buf->buf, (size_t)buf->len); }
stun_is_success_response:
   90|  41.7k|bool stun_is_success_response(const stun_buffer *buf) {
   91|  41.7k|  return stun_is_success_response_str(buf->buf, (size_t)(buf->len));
   92|  41.7k|}
stun_is_error_response:
   94|  41.6k|bool stun_is_error_response(const stun_buffer *buf, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
   95|  41.6k|  return stun_is_error_response_str(buf->buf, (size_t)(buf->len), err_code, err_msg, err_msg_size);
   96|  41.6k|}
stun_is_response:
   98|  41.7k|bool stun_is_response(const stun_buffer *buf) { return stun_is_response_str(buf->buf, (size_t)(buf->len)); }
stun_is_indication:
  100|  4.99k|bool stun_is_indication(const stun_buffer *buf) {
  101|  4.99k|  if (is_channel_msg(buf)) {
  ------------------
  |  Branch (101:7): [True: 558, False: 4.43k]
  ------------------
  102|    558|    return false;
  103|    558|  }
  104|  4.43k|  return IS_STUN_INDICATION(stun_get_msg_type(buf));
  ------------------
  |  |   63|  4.43k|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  105|  4.99k|}
stun_get_method:
  107|  41.6k|uint16_t stun_get_method(const stun_buffer *buf) { return stun_get_method_str(buf->buf, (size_t)(buf->len)); }
stun_get_msg_type:
  109|  47.7k|uint16_t stun_get_msg_type(const stun_buffer *buf) {
  110|  47.7k|  if (!buf) {
  ------------------
  |  Branch (110:7): [True: 1.66k, False: 46.0k]
  ------------------
  111|  1.66k|    return (uint16_t)-1;
  112|  1.66k|  }
  113|  46.0k|  return stun_get_msg_type_str(buf->buf, (size_t)buf->len);
  114|  47.7k|}
stun_init_request:
  123|  1.66k|void stun_init_request(uint16_t method, stun_buffer *buf) { stun_init_command(stun_make_request(method), buf); }
stun_init_indication:
  125|  1.66k|void stun_init_indication(uint16_t method, stun_buffer *buf) { stun_init_command(stun_make_indication(method), buf); }
stun_init_success_response:
  127|  1.66k|void stun_init_success_response(uint16_t method, stun_buffer *buf, stun_tid *id) {
  128|  1.66k|  buf->len = stun_get_size(buf);
  129|  1.66k|  stun_init_success_response_str(method, buf->buf, &(buf->len), id);
  130|  1.66k|}
stun_init_error_response:
  133|  4.99k|                              stun_tid *id, bool include_reason_string) {
  134|  4.99k|  buf->len = stun_get_size(buf);
  135|  4.99k|  stun_init_error_response_str(method, buf->buf, &(buf->len), error_code, reason, id, include_reason_string);
  136|  4.99k|}
stun_get_command_message_len:
  140|  41.6k|int stun_get_command_message_len(const stun_buffer *buf) {
  141|  41.6k|  return stun_get_command_message_len_str(buf->buf, buf->len);
  142|  41.6k|}
stun_init_channel_message:
  146|  1.66k|bool stun_init_channel_message(uint16_t chnumber, stun_buffer *buf, int length, bool do_padding) {
  147|  1.66k|  return stun_init_channel_message_str(chnumber, buf->buf, &(buf->len), length, do_padding);
  148|  1.66k|}
stun_is_channel_message:
  150|  8.32k|bool stun_is_channel_message(stun_buffer *buf, uint16_t *chnumber, bool is_padding_mandatory) {
  151|  8.32k|  if (!buf) {
  ------------------
  |  Branch (151:7): [True: 1.66k, False: 6.66k]
  ------------------
  152|  1.66k|    return false;
  153|  1.66k|  }
  154|  6.66k|  size_t blen = buf->len;
  155|  6.66k|  const bool ret = stun_is_channel_message_str(buf->buf, &blen, chnumber, is_padding_mandatory);
  156|  6.66k|  if (ret) {
  ------------------
  |  Branch (156:7): [True: 3.51k, False: 3.14k]
  ------------------
  157|  3.51k|    buf->len = blen;
  158|  3.51k|  }
  159|  6.66k|  return ret;
  160|  8.32k|}
stun_set_allocate_request:
  165|  3.33k|                               const char *rt, int ep) {
  166|  3.33k|  return stun_set_allocate_request_str(buf->buf, &(buf->len), lifetime, af4, af6, transport, mobile, rt, ep);
  167|  3.33k|}
stun_set_allocate_response:
  172|  8.32k|                                uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
  173|       |
  174|  8.32k|  return stun_set_allocate_response_str(buf->buf, &(buf->len), tid, relayed_addr1, relayed_addr2, reflexive_addr,
  175|  8.32k|                                        lifetime, max_lifetime, error_code, reason, reservation_token, mobile_id,
  176|  8.32k|                                        include_reason_string);
  177|  8.32k|}
stun_set_channel_bind_request:
  181|  4.99k|uint16_t stun_set_channel_bind_request(stun_buffer *buf, const ioa_addr *peer_addr, uint16_t channel_number) {
  182|       |
  183|  4.99k|  return stun_set_channel_bind_request_str(buf->buf, &(buf->len), peer_addr, channel_number);
  184|  4.99k|}
stun_set_channel_bind_response:
  187|  4.99k|                                    bool include_reason_string) {
  188|  4.99k|  stun_set_channel_bind_response_str(buf->buf, &(buf->len), tid, error_code, reason, include_reason_string);
  189|  4.99k|}
stun_attr_get_first:
  193|  41.6k|stun_attr_ref stun_attr_get_first(const stun_buffer *buf) { return stun_attr_get_first_str(buf->buf, buf->len); }
stun_attr_get_next:
  195|  72.8k|stun_attr_ref stun_attr_get_next(const stun_buffer *buf, stun_attr_ref prev) {
  196|  72.8k|  return stun_attr_get_next_str(buf->buf, buf->len, prev);
  197|  72.8k|}
stun_attr_add:
  203|  4.99k|bool stun_attr_add(stun_buffer *buf, uint16_t attr, const char *avalue, int alen) {
  204|  4.99k|  return stun_attr_add_str(buf->buf, &(buf->len), attr, (const uint8_t *)avalue, alen);
  205|  4.99k|}
stun_attr_add_channel_number:
  207|  1.66k|bool stun_attr_add_channel_number(stun_buffer *buf, uint16_t chnumber) {
  208|  1.66k|  return stun_attr_add_channel_number_str(buf->buf, &(buf->len), chnumber);
  209|  1.66k|}
stun_attr_add_addr:
  211|  1.66k|bool stun_attr_add_addr(stun_buffer *buf, uint16_t attr_type, const ioa_addr *ca) {
  212|  1.66k|  return stun_attr_add_addr_str(buf->buf, &(buf->len), attr_type, ca);
  213|  1.66k|}
stun_attr_get_addr:
  215|  23.8k|bool stun_attr_get_addr(const stun_buffer *buf, stun_attr_ref attr, ioa_addr *ca, const ioa_addr *default_addr) {
  216|  23.8k|  return stun_attr_get_addr_str(buf->buf, buf->len, attr, ca, default_addr);
  217|  23.8k|}
stun_attr_get_first_addr:
  219|  58.7k|bool stun_attr_get_first_addr(const stun_buffer *buf, uint16_t attr_type, ioa_addr *ca, const ioa_addr *default_addr) {
  220|  58.7k|  return stun_attr_get_first_addr_str(buf->buf, buf->len, attr_type, ca, default_addr);
  221|  58.7k|}
stun_attr_add_even_port:
  223|  3.33k|bool stun_attr_add_even_port(stun_buffer *buf, uint8_t value) {
  224|  3.33k|  if (value) {
  ------------------
  |  Branch (224:7): [True: 1.20k, False: 2.12k]
  ------------------
  225|  1.20k|    value = 0x80;
  226|  1.20k|  }
  227|  3.33k|  return stun_attr_add(buf, STUN_ATTRIBUTE_EVEN_PORT, (const char *)&value, 1);
  ------------------
  |  |  123|  3.33k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  228|  3.33k|}
stun_attr_get_first_channel_number:
  230|  41.6k|uint16_t stun_attr_get_first_channel_number(const stun_buffer *buf) {
  231|  41.6k|  return stun_attr_get_first_channel_number_str(buf->buf, buf->len);
  232|  41.6k|}
stun_attr_get_first_by_type:
  234|  11.6k|stun_attr_ref stun_attr_get_first_by_type(const stun_buffer *buf, uint16_t attr_type) {
  235|  11.6k|  return stun_attr_get_first_by_type_str(buf->buf, buf->len, attr_type);
  236|  11.6k|}
stun_set_binding_request:
  240|  1.66k|void stun_set_binding_request(stun_buffer *buf) { stun_set_binding_request_str(buf->buf, (size_t *)(&(buf->len))); }
stun_set_binding_response:
  243|  6.66k|                               const uint8_t *reason, bool include_reason_string) {
  244|  6.66k|  return stun_set_binding_response_str(buf->buf, &(buf->len), tid, reflexive_addr, error_code, reason, 0, false, true,
  245|  6.66k|                                       include_reason_string);
  246|  6.66k|}
stun_prepare_binding_request:
  248|  1.66k|void stun_prepare_binding_request(stun_buffer *buf) { stun_set_binding_request_str(buf->buf, (size_t *)(&(buf->len))); }
stun_is_binding_response:
  250|  41.6k|bool stun_is_binding_response(const stun_buffer *buf) { return stun_is_binding_response_str(buf->buf, buf->len); }
stun_buffer.c:is_channel_msg:
   73|  4.99k|static inline bool is_channel_msg(const stun_buffer *buf) {
   74|  4.99k|  if (buf && buf->len > 0) {
  ------------------
  |  Branch (74:7): [True: 4.99k, False: 0]
  |  Branch (74:14): [True: 4.99k, False: 0]
  ------------------
   75|  4.99k|    return is_channel_msg_str(buf->buf, (size_t)(buf->len));
   76|  4.99k|  }
   77|      0|  return false;
   78|  4.99k|}
stun_buffer.c:stun_init_command:
  118|  3.33k|static void stun_init_command(uint16_t message_type, stun_buffer *buf) {
  119|  3.33k|  buf->len = stun_get_size(buf);
  120|  3.33k|  stun_init_command_str(message_type, buf->buf, &(buf->len));
  121|  3.33k|}

addr_set_any:
   48|   192k|void addr_set_any(ioa_addr *addr) {
   49|   192k|  if (addr) {
  ------------------
  |  Branch (49:7): [True: 192k, False: 0]
  ------------------
   50|   192k|    memset(addr, 0, sizeof(ioa_addr));
   51|   192k|  }
   52|   192k|}
addr_any_no_port:
   78|  95.2k|int addr_any_no_port(const ioa_addr *addr) {
   79|  95.2k|  if (!addr) {
  ------------------
  |  Branch (79:7): [True: 0, False: 95.2k]
  ------------------
   80|      0|    return 1;
   81|      0|  }
   82|       |
   83|  95.2k|  if (addr->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (83:7): [True: 61.8k, False: 33.4k]
  ------------------
   84|  61.8k|    return (addr->s4.sin_addr.s_addr == 0);
   85|  61.8k|  } else if (addr->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (85:14): [True: 33.4k, False: 0]
  ------------------
   86|  33.4k|    size_t i;
   87|  56.0k|    for (i = 0; i < sizeof(addr->s6.sin6_addr); i++) {
  ------------------
  |  Branch (87:17): [True: 56.0k, False: 22]
  ------------------
   88|  56.0k|      if (((const char *)(&(addr->s6.sin6_addr)))[i]) {
  ------------------
  |  Branch (88:11): [True: 33.4k, False: 22.6k]
  ------------------
   89|  33.4k|        return 0;
   90|  33.4k|      }
   91|  56.0k|    }
   92|  33.4k|  }
   93|       |
   94|     22|  return 1;
   95|  95.2k|}
addr_eq_no_port:
  180|   270k|int addr_eq_no_port(const ioa_addr *a1, const ioa_addr *a2) {
  181|       |
  182|   270k|  if (!a1) {
  ------------------
  |  Branch (182:7): [True: 0, False: 270k]
  ------------------
  183|      0|    return (!a2);
  184|   270k|  } else if (!a2) {
  ------------------
  |  Branch (184:14): [True: 0, False: 270k]
  ------------------
  185|      0|    return (!a1);
  186|      0|  }
  187|       |
  188|   270k|  if (a1->ss.sa_family == a2->ss.sa_family) {
  ------------------
  |  Branch (188:7): [True: 130k, False: 140k]
  ------------------
  189|   130k|    if (a1->ss.sa_family == AF_INET) {
  ------------------
  |  Branch (189:9): [True: 82.2k, False: 47.8k]
  ------------------
  190|  82.2k|      if ((int)a1->s4.sin_addr.s_addr == (int)a2->s4.sin_addr.s_addr) {
  ------------------
  |  Branch (190:11): [True: 335, False: 81.8k]
  ------------------
  191|    335|        return 1;
  192|    335|      }
  193|  82.2k|    } else if (a1->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (193:16): [True: 47.8k, False: 0]
  ------------------
  194|  47.8k|      if (memcmp(&(a1->s6.sin6_addr), &(a2->s6.sin6_addr), sizeof(struct in6_addr)) == 0) {
  ------------------
  |  Branch (194:11): [True: 134, False: 47.7k]
  ------------------
  195|    134|        return 1;
  196|    134|      }
  197|  47.8k|    }
  198|   130k|  }
  199|   270k|  return 0;
  200|   270k|}
make_ioa_addr:
  202|      8|int make_ioa_addr(const uint8_t *saddr0, uint16_t port, ioa_addr *addr) {
  203|       |
  204|      8|  if (!saddr0 || !addr) {
  ------------------
  |  Branch (204:7): [True: 0, False: 8]
  |  Branch (204:18): [True: 0, False: 8]
  ------------------
  205|      0|    return -1;
  206|      0|  }
  207|       |
  208|      8|  char ssaddr[257];
  209|      8|  STRCPY(ssaddr, saddr0);
  ------------------
  |  |  242|      8|  do {                                                                                                                 \
  |  |  243|      8|    if ((const char *)(dst) != (const char *)(src)) {                                                                  \
  |  |  ------------------
  |  |  |  Branch (243:9): [True: 8, False: 0]
  |  |  ------------------
  |  |  244|      8|      if (sizeof(dst) == sizeof(char *))                                                                               \
  |  |  ------------------
  |  |  |  Branch (244:11): [Folded, False: 8]
  |  |  ------------------
  |  |  245|      8|        strcpy(((char *)(dst)), (const char *)(src));                                                                  \
  |  |  246|      8|      else {                                                                                                           \
  |  |  247|      8|        size_t szdst = sizeof((dst));                                                                                  \
  |  |  248|      8|        strncpy((char *)(dst), (const char *)(src), szdst);                                                            \
  |  |  249|      8|        ((char *)(dst))[szdst - 1] = 0;                                                                                \
  |  |  250|      8|      }                                                                                                                \
  |  |  251|      8|    }                                                                                                                  \
  |  |  252|      8|  } while (0)
  |  |  ------------------
  |  |  |  Branch (252:12): [Folded, False: 8]
  |  |  ------------------
  ------------------
  210|       |
  211|      8|  char *saddr = ssaddr;
  212|      8|  while (*saddr == ' ') {
  ------------------
  |  Branch (212:10): [True: 0, False: 8]
  ------------------
  213|      0|    ++saddr;
  214|      0|  }
  215|       |
  216|      8|  size_t len = strlen(saddr);
  217|      8|  while (len > 0) {
  ------------------
  |  Branch (217:10): [True: 8, False: 0]
  ------------------
  218|      8|    if (saddr[len - 1] == ' ') {
  ------------------
  |  Branch (218:9): [True: 0, False: 8]
  ------------------
  219|      0|      saddr[len - 1] = 0;
  220|      0|      --len;
  221|      8|    } else {
  222|      8|      break;
  223|      8|    }
  224|      8|  }
  225|       |
  226|      8|  memset(addr, 0, sizeof(ioa_addr));
  227|      8|  if ((len == 0) || (inet_pton(AF_INET, saddr, &addr->s4.sin_addr) == 1)) {
  ------------------
  |  Branch (227:7): [True: 0, False: 8]
  |  Branch (227:21): [True: 4, False: 4]
  ------------------
  228|      4|    addr->s4.sin_family = AF_INET;
  229|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  230|       |    addr->s4.sin_len = sizeof(struct sockaddr_in);
  231|       |#endif
  232|      4|    addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|      4|#define nswap16(s) ntohs(s)
  ------------------
  233|      4|  } else if (inet_pton(AF_INET6, saddr, &addr->s6.sin6_addr) == 1) {
  ------------------
  |  Branch (233:14): [True: 4, False: 0]
  ------------------
  234|      4|    addr->s6.sin6_family = AF_INET6;
  235|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  236|       |    addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  237|       |#endif
  238|      4|    addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|      4|#define nswap16(s) ntohs(s)
  ------------------
  239|      4|  } else {
  240|      0|    struct addrinfo addr_hints;
  241|      0|    struct addrinfo *addr_result = NULL;
  242|      0|    int err;
  243|       |
  244|      0|    memset(&addr_hints, 0, sizeof(struct addrinfo));
  245|      0|    addr_hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
  246|      0|    addr_hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
  247|      0|    addr_hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
  248|      0|    addr_hints.ai_protocol = 0;          /* Any protocol */
  249|      0|    addr_hints.ai_canonname = NULL;
  250|      0|    addr_hints.ai_addr = NULL;
  251|      0|    addr_hints.ai_next = NULL;
  252|       |
  253|      0|    err = getaddrinfo(saddr, NULL, &addr_hints, &addr_result);
  254|      0|    if ((err != 0) || (!addr_result)) {
  ------------------
  |  Branch (254:9): [True: 0, False: 0]
  |  Branch (254:23): [True: 0, False: 0]
  ------------------
  255|      0|      fprintf(stderr, "error resolving '%s' hostname: %s\n", saddr, gai_strerror(err));
  256|      0|      return -1;
  257|      0|    }
  258|       |
  259|      0|    int family = AF_INET;
  260|      0|    struct addrinfo *addr_result_orig = addr_result;
  261|      0|    int found = 0;
  262|       |
  263|      0|  beg_af:
  264|       |
  265|      0|    while (addr_result) {
  ------------------
  |  Branch (265:12): [True: 0, False: 0]
  ------------------
  266|       |
  267|      0|      if (addr_result->ai_family == family) {
  ------------------
  |  Branch (267:11): [True: 0, False: 0]
  ------------------
  268|      0|        if (addr_result->ai_family == AF_INET) {
  ------------------
  |  Branch (268:13): [True: 0, False: 0]
  ------------------
  269|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  270|      0|          addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|      0|#define nswap16(s) ntohs(s)
  ------------------
  271|       |#if defined(TURN_HAS_SIN_LEN) /* tested when configured */
  272|       |          addr->s4.sin_len = sizeof(struct sockaddr_in);
  273|       |#endif
  274|      0|          found = 1;
  275|      0|          break;
  276|      0|        } else if (addr_result->ai_family == AF_INET6) {
  ------------------
  |  Branch (276:20): [True: 0, False: 0]
  ------------------
  277|      0|          memcpy(addr, addr_result->ai_addr, addr_result->ai_addrlen);
  278|      0|          addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|      0|#define nswap16(s) ntohs(s)
  ------------------
  279|       |#if defined(SIN6_LEN) /* this define is required by IPv6 if used */
  280|       |          addr->s6.sin6_len = sizeof(struct sockaddr_in6);
  281|       |#endif
  282|      0|          found = 1;
  283|      0|          break;
  284|      0|        }
  285|      0|      }
  286|       |
  287|      0|      addr_result = addr_result->ai_next;
  288|      0|    }
  289|       |
  290|      0|    if (!found && family == AF_INET) {
  ------------------
  |  Branch (290:9): [True: 0, False: 0]
  |  Branch (290:19): [True: 0, False: 0]
  ------------------
  291|      0|      family = AF_INET6;
  292|      0|      addr_result = addr_result_orig;
  293|      0|      goto beg_af;
  294|      0|    }
  295|       |
  296|      0|    freeaddrinfo(addr_result_orig);
  297|      0|  }
  298|       |
  299|      8|  return 0;
  300|      8|}
addr_set_port:
  407|  11.3k|void addr_set_port(ioa_addr *addr, uint16_t port) {
  408|  11.3k|  if (addr) {
  ------------------
  |  Branch (408:7): [True: 11.3k, False: 0]
  ------------------
  409|  11.3k|    if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (409:9): [True: 7.13k, False: 4.21k]
  ------------------
  410|  7.13k|      addr->s4.sin_port = nswap16(port);
  ------------------
  |  |   86|  7.13k|#define nswap16(s) ntohs(s)
  ------------------
  411|  7.13k|    } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (411:16): [True: 4.21k, False: 0]
  ------------------
  412|       |      addr->s6.sin6_port = nswap16(port);
  ------------------
  |  |   86|  4.21k|#define nswap16(s) ntohs(s)
  ------------------
  413|  4.21k|    }
  414|  11.3k|  }
  415|  11.3k|}
addr_get_port:
  417|  11.3k|uint16_t addr_get_port(const ioa_addr *addr) {
  418|  11.3k|  if (!addr) {
  ------------------
  |  Branch (418:7): [True: 0, False: 11.3k]
  ------------------
  419|      0|    return 0;
  420|      0|  }
  421|       |
  422|  11.3k|  if (addr->s4.sin_family == AF_INET) {
  ------------------
  |  Branch (422:7): [True: 11.1k, False: 156]
  ------------------
  423|  11.1k|    return nswap16(addr->s4.sin_port);
  ------------------
  |  |   86|  11.1k|#define nswap16(s) ntohs(s)
  ------------------
  424|  11.1k|  } else if (addr->s6.sin6_family == AF_INET6) {
  ------------------
  |  Branch (424:14): [True: 156, False: 0]
  ------------------
  425|    156|    return nswap16(addr->s6.sin6_port);
  ------------------
  |  |   86|    156|#define nswap16(s) ntohs(s)
  ------------------
  426|    156|  }
  427|      0|  return 0;
  428|  11.3k|}
ioa_addr_add_mapping:
  676|      4|void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv) {
  677|      4|  const size_t new_size = msz + sizeof(ioa_addr *);
  678|      4|  public_addrs = (ioa_addr **)turn_realloc(public_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  679|      4|  private_addrs = (ioa_addr **)turn_realloc(private_addrs, new_size);
  ------------------
  |  |  121|      4|#define turn_realloc(ptr, sz) turn_realloc_impl((ptr), (sz), __FILE__, __LINE__)
  ------------------
  680|      4|  public_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  681|      4|  private_addrs[mcount] = (ioa_addr *)turn_malloc(sizeof(ioa_addr));
  ------------------
  |  |  119|      4|#define turn_malloc(sz) turn_malloc_impl((sz), __FILE__, __LINE__)
  ------------------
  682|      4|  addr_cpy(public_addrs[mcount], apub);
  683|      4|  addr_cpy(private_addrs[mcount], apriv);
  684|      4|  ++mcount;
  685|      4|  msz += sizeof(ioa_addr *);
  686|      4|}
map_addr_from_public_to_private:
  688|  84.6k|void map_addr_from_public_to_private(const ioa_addr *public_addr, ioa_addr *private_addr) {
  689|  84.6k|  size_t i;
  690|   253k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (690:15): [True: 169k, False: 84.3k]
  ------------------
  691|   169k|    if (addr_eq_no_port(public_addr, public_addrs[i])) {
  ------------------
  |  Branch (691:9): [True: 292, False: 168k]
  ------------------
  692|    292|      addr_cpy(private_addr, private_addrs[i]);
  693|    292|      addr_set_port(private_addr, addr_get_port(public_addr));
  694|    292|      return;
  695|    292|    }
  696|   169k|  }
  697|  84.3k|  addr_cpy(private_addr, public_addr);
  698|  84.3k|}
map_addr_from_private_to_public:
  700|  50.7k|void map_addr_from_private_to_public(const ioa_addr *private_addr, ioa_addr *public_addr) {
  701|  50.7k|  size_t i;
  702|   152k|  for (i = 0; i < mcount; ++i) {
  ------------------
  |  Branch (702:15): [True: 101k, False: 50.6k]
  ------------------
  703|   101k|    if (addr_eq_no_port(private_addr, private_addrs[i])) {
  ------------------
  |  Branch (703:9): [True: 177, False: 101k]
  ------------------
  704|    177|      addr_cpy(public_addr, public_addrs[i]);
  705|    177|      addr_set_port(public_addr, addr_get_port(private_addr));
  706|    177|      return;
  707|    177|    }
  708|   101k|  }
  709|  50.6k|  addr_cpy(public_addr, private_addr);
  710|  50.6k|}

ns_turn_ioaddr.c:addr_cpy:
   87|   135k|static inline void addr_cpy(ioa_addr *dst, const ioa_addr *src) {
   88|   135k|  if (dst && src) {
  ------------------
  |  Branch (88:7): [True: 135k, False: 0]
  |  Branch (88:14): [True: 135k, False: 0]
  ------------------
   89|   135k|    memcpy(dst, src, sizeof(ioa_addr));
   90|   135k|  }
   91|   135k|}
ns_turn_msg.c:addr_cpy:
   87|  10.8k|static inline void addr_cpy(ioa_addr *dst, const ioa_addr *src) {
   88|  10.8k|  if (dst && src) {
  ------------------
  |  Branch (88:7): [True: 10.8k, False: 0]
  |  Branch (88:14): [True: 10.8k, False: 0]
  ------------------
   89|  10.8k|    memcpy(dst, src, sizeof(ioa_addr));
   90|  10.8k|  }
   91|  10.8k|}

turn_random_number:
  123|   241k|long turn_random_number(void) {
  124|   241k|  long ret = 0;
  125|   241k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  126|   241k|  ret = (long)fuzz_prng_next();
  127|       |#else
  128|       |  if (!RAND_bytes((unsigned char *)&ret, sizeof(ret)))
  129|       |#if defined(WINDOWS)
  130|       |    ret = rand();
  131|       |#else
  132|       |    ret = random();
  133|       |#endif
  134|       |#endif
  135|   241k|  return ret;
  136|   241k|}
stun_get_command_message_len_str:
  533|   925k|int stun_get_command_message_len_str(const uint8_t *buf, size_t len) {
  534|   925k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   925k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (534:7): [True: 1.98k, False: 923k]
  ------------------
  535|  1.98k|    return -1;
  536|  1.98k|  }
  537|       |
  538|       |  /* Validate the size the buffer claims to be */
  539|   923k|  const size_t bufLen = (size_t)(turn_read_u16(buf + 2) + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   923k|#define STUN_HEADER_LENGTH (20)
  ------------------
  540|   923k|  if (bufLen > len) {
  ------------------
  |  Branch (540:7): [True: 8.86k, False: 914k]
  ------------------
  541|  8.86k|    return -1;
  542|  8.86k|  }
  543|       |
  544|   914k|  return bufLen;
  545|   923k|}
stun_make_type:
  557|  76.5k|uint16_t stun_make_type(uint16_t method) {
  558|  76.5k|  method = method & 0x0FFF;
  559|  76.5k|  return ((method & 0x000F) | ((method & 0x0070) << 1) | ((method & 0x0380) << 2) | ((method & 0x0C00) << 2));
  560|  76.5k|}
stun_get_method_str:
  562|   145k|uint16_t stun_get_method_str(const uint8_t *buf, size_t len) {
  563|   145k|  if (!buf || len < 2) {
  ------------------
  |  Branch (563:7): [True: 0, False: 145k]
  |  Branch (563:15): [True: 0, False: 145k]
  ------------------
  564|      0|    return (uint16_t)-1;
  565|      0|  }
  566|       |
  567|   145k|  const uint16_t tt = turn_read_u16(buf);
  568|       |
  569|   145k|  return (tt & 0x000F) | ((tt & 0x00E0) >> 1) | ((tt & 0x0E00) >> 2) | ((tt & 0x3000) >> 2);
  570|   145k|}
stun_get_msg_type_str:
  572|   471k|uint16_t stun_get_msg_type_str(const uint8_t *buf, size_t len) {
  573|   471k|  if (!buf || len < 2) {
  ------------------
  |  Branch (573:7): [True: 0, False: 471k]
  |  Branch (573:15): [True: 75, False: 471k]
  ------------------
  574|     75|    return (uint16_t)-1;
  575|     75|  }
  576|   471k|  return (turn_read_u16(buf) & 0x3FFF);
  577|   471k|}
is_channel_msg_str:
  579|   333k|bool is_channel_msg_str(const uint8_t *buf, size_t blen) {
  580|   333k|  return (buf && blen >= 4 && STUN_VALID_CHANNEL(turn_read_u16(buf)));
  ------------------
  |  |  163|   333k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 748, False: 332k]
  |  |  |  Branch (163:53): [True: 558, False: 190]
  |  |  ------------------
  ------------------
  |  Branch (580:11): [True: 333k, False: 0]
  |  Branch (580:18): [True: 333k, False: 274]
  ------------------
  581|   333k|}
stun_is_command_message_str:
  585|   154k|bool stun_is_command_message_str(const uint8_t *buf, size_t blen) {
  586|   154k|  if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   154k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (586:7): [True: 154k, False: 0]
  |  Branch (586:14): [True: 154k, False: 145]
  ------------------
  587|   154k|    if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|   154k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 539, False: 153k]
  |  |  |  Branch (163:53): [True: 460, False: 79]
  |  |  ------------------
  ------------------
  588|   153k|      if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (588:11): [True: 153k, False: 79]
  ------------------
  589|   153k|        if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|   153k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (589:13): [True: 137k, False: 15.8k]
  ------------------
  590|   137k|          const uint16_t len = turn_read_u16(buf + 2);
  591|   137k|          if ((len & 0x0003) == 0) {
  ------------------
  |  Branch (591:15): [True: 137k, False: 10]
  ------------------
  592|   137k|            if ((size_t)(len + STUN_HEADER_LENGTH) == blen) {
  ------------------
  |  |   46|   137k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (592:17): [True: 137k, False: 60]
  ------------------
  593|   137k|              return true;
  594|   137k|            }
  595|   137k|          }
  596|   137k|        }
  597|   153k|      }
  598|   153k|    }
  599|   154k|  }
  600|  16.6k|  return false;
  601|   154k|}
stun_is_request_str:
  653|  76.5k|bool stun_is_request_str(const uint8_t *buf, size_t len) {
  654|  76.5k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (654:7): [True: 0, False: 76.5k]
  ------------------
  655|      0|    return false;
  656|      0|  }
  657|  76.5k|  return IS_STUN_REQUEST(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   62|  76.5k|#define IS_STUN_REQUEST(msg_type) (((msg_type)&0x0110) == 0x0000)
  ------------------
  658|  76.5k|}
stun_is_success_response_str:
  660|  76.7k|bool stun_is_success_response_str(const uint8_t *buf, size_t len) {
  661|  76.7k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (661:7): [True: 0, False: 76.7k]
  ------------------
  662|      0|    return false;
  663|      0|  }
  664|  76.7k|  return IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   64|  76.7k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  ------------------
  665|  76.7k|}
stun_is_error_response_str:
  667|  76.7k|bool stun_is_error_response_str(const uint8_t *buf, size_t len, int *err_code, uint8_t *err_msg, size_t err_msg_size) {
  668|  76.7k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (668:7): [True: 0, False: 76.7k]
  ------------------
  669|      0|    return false;
  670|      0|  }
  671|  76.7k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  76.7k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 28.3k, False: 48.3k]
  |  |  ------------------
  ------------------
  672|  28.3k|    if (err_code) {
  ------------------
  |  Branch (672:9): [True: 28.3k, False: 0]
  ------------------
  673|  28.3k|      stun_attr_ref sar = stun_attr_get_first_by_type_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE);
  ------------------
  |  |  103|  28.3k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  674|  28.3k|      if (sar) {
  ------------------
  |  Branch (674:11): [True: 28.3k, False: 45]
  ------------------
  675|  28.3k|        if (stun_attr_get_len(sar) >= 4) {
  ------------------
  |  Branch (675:13): [True: 28.3k, False: 10]
  ------------------
  676|  28.3k|          const uint8_t *val = (const uint8_t *)stun_attr_get_value(sar);
  677|  28.3k|          *err_code = (int)(val[2] * 100 + val[3]);
  678|  28.3k|          if (err_msg && err_msg_size > 0) {
  ------------------
  |  Branch (678:15): [True: 28.3k, False: 0]
  |  Branch (678:26): [True: 28.3k, False: 0]
  ------------------
  679|  28.3k|            err_msg[0] = 0;
  680|  28.3k|            if (stun_attr_get_len(sar) > 4) {
  ------------------
  |  Branch (680:17): [True: 14.0k, False: 14.3k]
  ------------------
  681|  14.0k|              size_t msg_len = stun_attr_get_len(sar) - 4;
  682|  14.0k|              if (msg_len > (err_msg_size - 1)) {
  ------------------
  |  Branch (682:19): [True: 14, False: 14.0k]
  ------------------
  683|     14|                msg_len = err_msg_size - 1;
  684|     14|              }
  685|  14.0k|              memcpy(err_msg, val + 4, msg_len);
  686|  14.0k|              err_msg[msg_len] = 0;
  687|  14.0k|            }
  688|  28.3k|          }
  689|  28.3k|        }
  690|  28.3k|      }
  691|  28.3k|    }
  692|  28.3k|    return true;
  693|  28.3k|  }
  694|  48.3k|  return false;
  695|  76.7k|}
stun_is_response_str:
  758|  98.1k|bool stun_is_response_str(const uint8_t *buf, size_t len) {
  759|  98.1k|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (759:7): [True: 0, False: 98.1k]
  ------------------
  760|      0|    return false;
  761|      0|  }
  762|  98.1k|  if (IS_STUN_SUCCESS_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   64|  98.1k|#define IS_STUN_SUCCESS_RESP(msg_type) (((msg_type)&0x0110) == 0x0100)
  |  |  ------------------
  |  |  |  Branch (64:40): [True: 36.3k, False: 61.7k]
  |  |  ------------------
  ------------------
  763|  36.3k|    return true;
  764|  36.3k|  }
  765|  61.7k|  if (IS_STUN_ERR_RESP(stun_get_msg_type_str(buf, len))) {
  ------------------
  |  |   65|  61.7k|#define IS_STUN_ERR_RESP(msg_type) (((msg_type)&0x0110) == 0x0110)
  |  |  ------------------
  |  |  |  Branch (65:36): [True: 38.0k, False: 23.7k]
  |  |  ------------------
  ------------------
  766|  38.0k|    return true;
  767|  38.0k|  }
  768|  23.7k|  return false;
  769|  61.7k|}
stun_is_indication_str:
  771|    146|bool stun_is_indication_str(const uint8_t *buf, size_t len) {
  772|    146|  if (is_channel_msg_str(buf, len)) {
  ------------------
  |  Branch (772:7): [True: 0, False: 146]
  ------------------
  773|      0|    return false;
  774|      0|  }
  775|    146|  return IS_STUN_INDICATION(stun_get_msg_type_str(buf, len));
  ------------------
  |  |   63|    146|#define IS_STUN_INDICATION(msg_type) (((msg_type)&0x0110) == 0x0010)
  ------------------
  776|    146|}
stun_make_request:
  778|  18.3k|uint16_t stun_make_request(uint16_t method) { return GET_STUN_REQUEST(stun_make_type(method)); }
  ------------------
  |  |   67|  18.3k|#define GET_STUN_REQUEST(msg_type) (msg_type & 0xFEEF)
  ------------------
stun_make_indication:
  780|  1.66k|uint16_t stun_make_indication(uint16_t method) { return GET_STUN_INDICATION(stun_make_type(method)); }
  ------------------
  |  |   68|  1.66k|#define GET_STUN_INDICATION(msg_type) ((msg_type & 0xFEEF) | 0x0010)
  ------------------
stun_make_success_response:
  782|  28.3k|uint16_t stun_make_success_response(uint16_t method) { return GET_STUN_SUCCESS_RESP(stun_make_type(method)); }
  ------------------
  |  |   69|  28.3k|#define GET_STUN_SUCCESS_RESP(msg_type) ((msg_type & 0xFEEF) | 0x0100)
  ------------------
stun_make_error_response:
  784|  28.3k|uint16_t stun_make_error_response(uint16_t method) { return GET_STUN_ERR_RESP(stun_make_type(method)); }
  ------------------
  |  |   70|  28.3k|#define GET_STUN_ERR_RESP(msg_type) (msg_type | 0x0110)
  ------------------
stun_init_buffer_str:
  788|  76.5k|void stun_init_buffer_str(uint8_t *buf, size_t *len) {
  789|  76.5k|  *len = STUN_HEADER_LENGTH;
  ------------------
  |  |   46|  76.5k|#define STUN_HEADER_LENGTH (20)
  ------------------
  790|  76.5k|  memset(buf, 0, *len);
  791|  76.5k|}
stun_init_command_str:
  793|  68.5k|void stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len) {
  794|  68.5k|  stun_init_buffer_str(buf, len);
  795|  68.5k|  message_type &= (uint16_t)(0x3FFF);
  796|  68.5k|  turn_write_u16(buf, message_type);
  797|  68.5k|  turn_write_u16(buf + 2, 0);
  798|  68.5k|  turn_write_u32(buf + 4, STUN_MAGIC_COOKIE);
  ------------------
  |  |   60|  68.5k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  799|       |  stun_tid_generate_in_message_str(buf, NULL);
  800|  68.5k|}
old_stun_init_command_str:
  802|  8.05k|void old_stun_init_command_str(uint16_t message_type, uint8_t *buf, size_t *len, uint32_t cookie) {
  803|  8.05k|  stun_init_buffer_str(buf, len);
  804|  8.05k|  message_type &= (uint16_t)(0x3FFF);
  805|  8.05k|  turn_write_u16(buf, message_type);
  806|  8.05k|  turn_write_u16(buf + 2, 0);
  807|  8.05k|  turn_write_u32(buf + 4, cookie);
  808|       |  stun_tid_generate_in_message_str(buf, NULL);
  809|  8.05k|}
stun_init_request_str:
  811|  16.6k|void stun_init_request_str(uint16_t method, uint8_t *buf, size_t *len) {
  812|  16.6k|  stun_init_command_str(stun_make_request(method), buf, len);
  813|  16.6k|}
stun_init_success_response_str:
  819|  24.2k|void stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id) {
  820|  24.2k|  stun_init_command_str(stun_make_success_response(method), buf, len);
  821|  24.2k|  if (id) {
  ------------------
  |  Branch (821:7): [True: 24.2k, False: 0]
  ------------------
  822|  24.2k|    stun_tid_message_cpy(buf, id);
  823|  24.2k|  }
  824|  24.2k|}
old_stun_init_success_response_str:
  826|  4.02k|void old_stun_init_success_response_str(uint16_t method, uint8_t *buf, size_t *len, stun_tid *id, uint32_t cookie) {
  827|  4.02k|  old_stun_init_command_str(stun_make_success_response(method), buf, len, cookie);
  828|  4.02k|  if (id) {
  ------------------
  |  Branch (828:7): [True: 4.02k, False: 0]
  ------------------
  829|  4.02k|    stun_tid_message_cpy(buf, id);
  830|  4.02k|  }
  831|  4.02k|}
get_default_reason:
  833|    894|const uint8_t *get_default_reason(int error_code) {
  834|    894|  const char *reason = "Unknown error";
  835|       |
  836|    894|  switch (error_code) {
  837|    300|  case 300:
  ------------------
  |  Branch (837:3): [True: 300, False: 594]
  ------------------
  838|    300|    reason = "Try Alternate";
  839|    300|    break;
  840|     60|  case 400:
  ------------------
  |  Branch (840:3): [True: 60, False: 834]
  ------------------
  841|     60|    reason = "Bad Request";
  842|     60|    break;
  843|     36|  case 401:
  ------------------
  |  Branch (843:3): [True: 36, False: 858]
  ------------------
  844|     36|    reason = "Unauthorized";
  845|     36|    break;
  846|    108|  case 403:
  ------------------
  |  Branch (846:3): [True: 108, False: 786]
  ------------------
  847|    108|    reason = "Forbidden";
  848|    108|    break;
  849|      0|  case 404:
  ------------------
  |  Branch (849:3): [True: 0, False: 894]
  ------------------
  850|      0|    reason = "Not Found";
  851|      0|    break;
  852|     60|  case 420:
  ------------------
  |  Branch (852:3): [True: 60, False: 834]
  ------------------
  853|     60|    reason = "Unknown Attribute";
  854|     60|    break;
  855|     12|  case 437:
  ------------------
  |  Branch (855:3): [True: 12, False: 882]
  ------------------
  856|     12|    reason = "Allocation Mismatch";
  857|     12|    break;
  858|     18|  case 438:
  ------------------
  |  Branch (858:3): [True: 18, False: 876]
  ------------------
  859|     18|    reason = "Stale Nonce";
  860|     18|    break;
  861|     36|  case 440:
  ------------------
  |  Branch (861:3): [True: 36, False: 858]
  ------------------
  862|     36|    reason = "Address Family not Supported";
  863|     36|    break;
  864|     30|  case 441:
  ------------------
  |  Branch (864:3): [True: 30, False: 864]
  ------------------
  865|     30|    reason = "Wrong Credentials";
  866|     30|    break;
  867|     42|  case 442:
  ------------------
  |  Branch (867:3): [True: 42, False: 852]
  ------------------
  868|     42|    reason = "Unsupported Transport Protocol";
  869|     42|    break;
  870|     18|  case 443:
  ------------------
  |  Branch (870:3): [True: 18, False: 876]
  ------------------
  871|     18|    reason = "Peer Address Family Mismatch";
  872|     18|    break;
  873|     12|  case 446:
  ------------------
  |  Branch (873:3): [True: 12, False: 882]
  ------------------
  874|     12|    reason = "Connection Already Exists";
  875|     12|    break;
  876|     30|  case 447:
  ------------------
  |  Branch (876:3): [True: 30, False: 864]
  ------------------
  877|     30|    reason = "Connection Timeout or Failure";
  878|     30|    break;
  879|     42|  case 486:
  ------------------
  |  Branch (879:3): [True: 42, False: 852]
  ------------------
  880|     42|    reason = "Allocation Quota Reached";
  881|     42|    break;
  882|     18|  case 487:
  ------------------
  |  Branch (882:3): [True: 18, False: 876]
  ------------------
  883|     18|    reason = "Role Conflict";
  884|     18|    break;
  885|     18|  case 500:
  ------------------
  |  Branch (885:3): [True: 18, False: 876]
  ------------------
  886|     18|    reason = "Server Error";
  887|     18|    break;
  888|     24|  case 508:
  ------------------
  |  Branch (888:3): [True: 24, False: 870]
  ------------------
  889|     24|    reason = "Insufficient Capacity";
  890|     24|    break;
  891|     30|  default:;
  ------------------
  |  Branch (891:3): [True: 30, False: 864]
  ------------------
  892|    894|  };
  893|       |
  894|    894|  return (const uint8_t *)reason;
  895|    894|}
old_stun_init_error_response_str:
  933|  4.02k|                                      bool include_reason_string) {
  934|       |
  935|  4.02k|  old_stun_init_command_str(stun_make_error_response(method), buf, len, cookie);
  936|       |
  937|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, true);
  938|  4.02k|}
stun_init_error_response_str:
  941|  24.2k|                                  const uint8_t *reason, stun_tid *id, bool include_reason_string) {
  942|       |
  943|  24.2k|  stun_init_command_str(stun_make_error_response(method), buf, len);
  944|       |
  945|       |  stun_init_error_response_common_str(buf, len, error_code, reason, id, include_reason_string, false);
  946|  24.2k|}
stun_init_channel_message_str:
  950|  1.66k|bool stun_init_channel_message_str(uint16_t chnumber, uint8_t *buf, size_t *len, int length, bool do_padding) {
  951|  1.66k|  uint16_t rlen = (uint16_t)length;
  952|       |
  953|       |  /* Reject before rounding: length near INT_MAX can overflow (length+3)/4+header. */
  954|  1.66k|  if (length < 0 || (int)(MAX_STUN_MESSAGE_SIZE - 4) < length ||
  ------------------
  |  |  223|  1.66k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (954:7): [True: 0, False: 1.66k]
  |  Branch (954:21): [True: 0, False: 1.66k]
  ------------------
  955|  1.66k|      (do_padding && ((int)MAX_STUN_MESSAGE_SIZE < (4 + ((length + 3) & ~3))))) {
  ------------------
  |  |  223|    616|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (955:8): [True: 616, False: 1.04k]
  |  Branch (955:22): [True: 0, False: 616]
  ------------------
  956|      0|    return false;
  957|      0|  }
  958|  1.66k|  turn_write_u16(buf, chnumber);
  959|  1.66k|  turn_write_u16(buf + 2, (uint16_t)length);
  960|       |
  961|  1.66k|  if (do_padding && (rlen & 0x0003)) {
  ------------------
  |  Branch (961:7): [True: 616, False: 1.04k]
  |  Branch (961:21): [True: 404, False: 212]
  ------------------
  962|    404|    const uint16_t padded = ((rlen >> 2) + 1) << 2;
  963|       |    // Zero the pad bytes so stale buffer contents are not leaked on the wire
  964|       |    // (matches the padding handling in stun_attr_add_str).
  965|    404|    memset(buf + 4 + rlen, 0, (size_t)(padded - rlen));
  966|    404|    rlen = padded;
  967|    404|  }
  968|       |
  969|  1.66k|  *len = 4 + rlen;
  970|       |
  971|       |  return true;
  972|  1.66k|}
stun_is_channel_message_str:
  974|  9.57k|bool stun_is_channel_message_str(const uint8_t *buf, size_t *blen, uint16_t *chnumber, bool mandatory_padding) {
  975|  9.57k|  uint16_t datalen_header;
  976|  9.57k|  uint16_t datalen_actual;
  977|       |
  978|  9.57k|  if (!blen || (*blen < 4)) {
  ------------------
  |  Branch (978:7): [True: 0, False: 9.57k]
  |  Branch (978:16): [True: 548, False: 9.03k]
  ------------------
  979|    548|    return false;
  980|    548|  }
  981|       |
  982|  9.03k|  const uint16_t chn = turn_read_u16(buf);
  983|  9.03k|  if (!STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  163|  9.03k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 6.42k, False: 2.60k]
  |  |  |  Branch (163:53): [True: 5.66k, False: 764]
  |  |  ------------------
  ------------------
  984|  3.36k|    return false;
  985|  3.36k|  }
  986|       |
  987|       |  /* Clamp to uint16_t range for comparison without mutating the caller's
  988|       |   * *blen — the modification to *blen at the end of this function is
  989|       |   * intentional (it reports actual message length consumed), but clamping
  990|       |   * during validation must not alter the caller's view of the buffer size
  991|       |   * if the function later returns false (issue #1837). */
  992|  5.66k|  const uint16_t blen16 = (*blen > (uint16_t)-1) ? (uint16_t)-1 : (uint16_t)*blen;
  ------------------
  |  Branch (992:27): [True: 0, False: 5.66k]
  ------------------
  993|  5.66k|  datalen_actual = blen16 - 4;
  994|  5.66k|  datalen_header = turn_read_u16(buf + 2);
  995|       |
  996|  5.66k|  if (datalen_header > datalen_actual) {
  ------------------
  |  Branch (996:7): [True: 1.69k, False: 3.96k]
  ------------------
  997|  1.69k|    return false;
  998|  1.69k|  }
  999|       |
 1000|  3.96k|  if (datalen_header != datalen_actual) {
  ------------------
  |  Branch (1000:7): [True: 982, False: 2.98k]
  ------------------
 1001|       |
 1002|       |    /* maybe there are padding bytes for 32-bit alignment. Mandatory for TCP. Optional for UDP */
 1003|       |
 1004|    982|    if (datalen_actual & 0x0003) {
  ------------------
  |  Branch (1004:9): [True: 268, False: 714]
  ------------------
 1005|       |
 1006|    268|      if (mandatory_padding) {
  ------------------
  |  Branch (1006:11): [True: 134, False: 134]
  ------------------
 1007|    134|        return false;
 1008|    134|      } else if (datalen_header == 0) {
  ------------------
  |  Branch (1008:18): [True: 23, False: 111]
  ------------------
 1009|     23|        return false;
 1010|    111|      } else {
 1011|    111|        const uint16_t diff = datalen_actual - datalen_header;
 1012|    111|        if (diff > 3) {
  ------------------
  |  Branch (1012:13): [True: 89, False: 22]
  ------------------
 1013|     89|          return false;
 1014|     89|        }
 1015|    111|      }
 1016|    268|    }
 1017|    982|  }
 1018|       |
 1019|  3.72k|  *blen = datalen_header + 4;
 1020|       |
 1021|  3.72k|  if (chnumber) {
  ------------------
  |  Branch (1021:7): [True: 3.72k, False: 0]
  ------------------
 1022|  3.72k|    *chnumber = chn;
 1023|  3.72k|  }
 1024|       |
 1025|       |  return true;
 1026|  3.96k|}
is_http:
 1074|  2.55k|int is_http(const char *s, size_t blen) {
 1075|  2.55k|  if (s && blen >= 12) {
  ------------------
  |  Branch (1075:7): [True: 2.55k, False: 0]
  |  Branch (1075:12): [True: 2.06k, False: 492]
  ------------------
 1076|  2.06k|    if (has_prefix(s, blen, "GET ", false) || has_prefix(s, blen, "POST ", false) ||
  ------------------
  |  Branch (1076:9): [True: 234, False: 1.82k]
  |  Branch (1076:47): [True: 154, False: 1.67k]
  ------------------
 1077|  1.67k|        has_prefix(s, blen, "DELETE ", false) || has_prefix(s, blen, "PUT ", false)) {
  ------------------
  |  Branch (1077:9): [True: 2, False: 1.67k]
  |  Branch (1077:50): [True: 354, False: 1.31k]
  ------------------
 1078|    744|      const char *sp = findstr(s + 4, blen - 4, " HTTP/", false);
 1079|    744|      if (sp) {
  ------------------
  |  Branch (1079:11): [True: 700, False: 44]
  ------------------
 1080|    700|        sp += 6;
 1081|    700|        const size_t diff_blen = sp - s;
 1082|    700|        if (diff_blen + 4 <= blen) {
  ------------------
  |  Branch (1082:13): [True: 668, False: 32]
  ------------------
 1083|    668|          sp = findstr(sp, blen - diff_blen, "\r\n\r\n", false);
 1084|    668|          if (sp) {
  ------------------
  |  Branch (1084:15): [True: 586, False: 82]
  ------------------
 1085|    586|            int ret_len = (int)(sp - s + 4);
 1086|       |            /* RFC 9112 Section 5: whitespace between the colon and the field value is optional. */
 1087|    586|            const char *clheader = "content-length:";
 1088|    586|            const char *cl = findstr(s, sp - s, clheader, true);
 1089|    586|            if (cl) {
  ------------------
  |  Branch (1089:17): [True: 408, False: 178]
  ------------------
 1090|       |              /* RFC 9110 Section 8.6: Content-Length is 1*DIGIT; parse it inside the header block only. */
 1091|    408|              const unsigned long max_clen = 0x0FFFFFFF;
 1092|    408|              const char *p = cl + strlen(clheader);
 1093|    408|              unsigned long clen = 0;
 1094|  1.06k|              while (p < sp && (*p == ' ' || *p == '\t')) {
  ------------------
  |  Branch (1094:22): [True: 1.04k, False: 14]
  |  Branch (1094:33): [True: 212, False: 836]
  |  Branch (1094:46): [True: 442, False: 394]
  ------------------
 1095|    654|                ++p;
 1096|    654|              }
 1097|  2.62k|              while (p < sp && *p >= '0' && *p <= '9' && clen < max_clen) {
  ------------------
  |  Branch (1097:22): [True: 2.35k, False: 264]
  |  Branch (1097:32): [True: 2.26k, False: 96]
  |  Branch (1097:45): [True: 2.22k, False: 38]
  |  Branch (1097:58): [True: 2.21k, False: 10]
  ------------------
 1098|  2.21k|                clen = clen * 10 + (unsigned long)(*p - '0');
 1099|  2.21k|                ++p;
 1100|  2.21k|              }
 1101|    918|              while (p < sp && (*p == ' ' || *p == '\t')) {
  ------------------
  |  Branch (1101:22): [True: 654, False: 264]
  |  Branch (1101:33): [True: 244, False: 410]
  |  Branch (1101:46): [True: 266, False: 144]
  ------------------
 1102|    510|                ++p;
 1103|    510|              }
 1104|       |              /* Anything but the end of the header line after the digits makes the value invalid. */
 1105|    408|              const bool at_line_end = (p == sp) || (*p == '\r');
  ------------------
  |  Branch (1105:40): [True: 264, False: 144]
  |  Branch (1105:53): [True: 12, False: 132]
  ------------------
 1106|    408|              if (at_line_end && clen > 0 && clen < max_clen) {
  ------------------
  |  Branch (1106:19): [True: 276, False: 132]
  |  Branch (1106:34): [True: 258, False: 18]
  |  Branch (1106:46): [True: 190, False: 68]
  ------------------
 1107|    190|                ret_len += (int)clen;
 1108|    190|              }
 1109|    408|            }
 1110|    586|            return ret_len;
 1111|    586|          }
 1112|    668|        }
 1113|    700|      }
 1114|    744|    }
 1115|  2.06k|  }
 1116|  1.96k|  return 0;
 1117|  2.55k|}
stun_get_message_len_str:
 1119|  2.91k|int stun_get_message_len_str(uint8_t *buf, size_t blen, int padding, size_t *app_len) {
 1120|  2.91k|  if (buf && blen) {
  ------------------
  |  Branch (1120:7): [True: 2.91k, False: 0]
  |  Branch (1120:14): [True: 2.91k, False: 0]
  ------------------
 1121|       |    /* STUN request/response ? */
 1122|  2.91k|    if (buf && blen >= STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|  2.91k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1122:9): [True: 2.91k, False: 0]
  |  Branch (1122:16): [True: 2.18k, False: 736]
  ------------------
 1123|  2.18k|      if (!STUN_VALID_CHANNEL(turn_read_u16(buf))) {
  ------------------
  |  |  163|  2.18k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 1.11k, False: 1.06k]
  |  |  |  Branch (163:53): [True: 958, False: 160]
  |  |  ------------------
  ------------------
 1124|  1.22k|        if ((((uint8_t)buf[0]) & ((uint8_t)(0xC0))) == 0) {
  ------------------
  |  Branch (1124:13): [True: 1.06k, False: 160]
  ------------------
 1125|  1.06k|          if (turn_read_u32(buf + 4) == STUN_MAGIC_COOKIE) {
  ------------------
  |  |   60|  1.06k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1125:15): [True: 450, False: 614]
  ------------------
 1126|       |            /* Widen so body length near 0xFFFF cannot wrap uint16_t and desync the stream. */
 1127|    450|            uint32_t len = (uint32_t)turn_read_u16(buf + 2);
 1128|    450|            if ((len & 0x0003u) == 0) {
  ------------------
  |  Branch (1128:17): [True: 430, False: 20]
  ------------------
 1129|    430|              len += STUN_HEADER_LENGTH;
  ------------------
  |  |   46|    430|#define STUN_HEADER_LENGTH (20)
  ------------------
 1130|       |              /* Declared size cannot fit the stream buffer: never "incomplete". */
 1131|    430|              if (len > (uint32_t)MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  223|    430|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1131:19): [True: 8, False: 422]
  ------------------
 1132|      8|                return 0;
 1133|      8|              }
 1134|    422|              if (len <= blen) {
  ------------------
  |  Branch (1134:19): [True: 358, False: 64]
  ------------------
 1135|    358|                *app_len = len;
 1136|    358|                return (int)len;
 1137|    358|              }
 1138|    422|            }
 1139|    450|          }
 1140|  1.06k|        }
 1141|  1.22k|      }
 1142|  2.18k|    }
 1143|       |
 1144|       |    // HTTP request ?
 1145|  2.55k|    {
 1146|  2.55k|      const int http_len = is_http(((char *)buf), blen);
 1147|  2.55k|      if ((http_len > 0) && ((size_t)http_len <= blen)) {
  ------------------
  |  Branch (1147:11): [True: 586, False: 1.96k]
  |  Branch (1147:29): [True: 396, False: 190]
  ------------------
 1148|    396|        *app_len = (size_t)http_len;
 1149|    396|        return http_len;
 1150|    396|      }
 1151|  2.55k|    }
 1152|       |
 1153|       |    /* STUN channel ? */
 1154|  2.15k|    if (blen >= 4) {
  ------------------
  |  Branch (1154:9): [True: 2.15k, False: 0]
  ------------------
 1155|  2.15k|      const uint16_t chn = turn_read_u16(buf);
 1156|  2.15k|      if (STUN_VALID_CHANNEL(chn)) {
  ------------------
  |  |  163|  2.15k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 1.20k, False: 952]
  |  |  |  Branch (163:53): [True: 820, False: 384]
  |  |  ------------------
  ------------------
 1157|       |
 1158|       |        /* Widen so 4 + data_len near 0xFFFF cannot wrap uint16_t and desync the stream. */
 1159|    820|        uint32_t bret = 4u + (uint32_t)turn_read_u16(buf + 2);
 1160|       |
 1161|    820|        *app_len = bret;
 1162|       |
 1163|    820|        if (padding && (bret & 0x0003u)) {
  ------------------
  |  Branch (1163:13): [True: 410, False: 410]
  |  Branch (1163:24): [True: 139, False: 271]
  ------------------
 1164|    139|          bret = ((bret >> 2) + 1u) << 2;
 1165|    139|        }
 1166|       |
 1167|    820|        if (bret > (uint32_t)MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  223|    820|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1167:13): [True: 20, False: 800]
  ------------------
 1168|     20|          return 0;
 1169|     20|        }
 1170|       |
 1171|    800|        if (bret <= blen) {
  ------------------
  |  Branch (1171:13): [True: 328, False: 472]
  ------------------
 1172|    328|          return (int)bret;
 1173|    328|        }
 1174|    800|      }
 1175|  2.15k|    }
 1176|  2.15k|  }
 1177|       |
 1178|  1.80k|  return -1;
 1179|  2.91k|}
stun_set_allocate_request_str:
 1184|  3.33k|                                   bool mobile, const char *rt, int ep) {
 1185|       |
 1186|  3.33k|  stun_init_request_str(STUN_METHOD_ALLOCATE, buf, len);
  ------------------
  |  |   82|  3.33k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1187|       |
 1188|       |  // REQUESTED-TRANSPORT
 1189|  3.33k|  {
 1190|  3.33k|    uint8_t field[4];
 1191|  3.33k|    field[0] = transport;
 1192|  3.33k|    field[1] = 0;
 1193|  3.33k|    field[2] = 0;
 1194|  3.33k|    field[3] = 0;
 1195|  3.33k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_TRANSPORT, field, sizeof(field))) {
  ------------------
  |  |  124|  3.33k|#define STUN_ATTRIBUTE_REQUESTED_TRANSPORT (0x0019)
  ------------------
  |  Branch (1195:9): [True: 0, False: 3.33k]
  ------------------
 1196|      0|      return false;
 1197|      0|    }
 1198|  3.33k|  }
 1199|       |
 1200|       |  // LIFETIME
 1201|  3.33k|  {
 1202|  3.33k|    if (lifetime < 1) {
  ------------------
  |  Branch (1202:9): [True: 310, False: 3.02k]
  ------------------
 1203|    310|      lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   73|    310|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1204|    310|    }
 1205|  3.33k|    uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  3.33k|#define nswap32(ul) ntohl(ul)
  ------------------
 1206|  3.33k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  118|  3.33k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1206:9): [True: 0, False: 3.33k]
  ------------------
 1207|      0|      return false;
 1208|      0|    }
 1209|  3.33k|  }
 1210|       |
 1211|       |  // MICE
 1212|  3.33k|  if (mobile) {
  ------------------
  |  Branch (1212:7): [True: 1.66k, False: 1.66k]
  ------------------
 1213|  1.66k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (const uint8_t *)"", 0)) {
  ------------------
  |  |   47|  1.66k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1213:9): [True: 0, False: 1.66k]
  ------------------
 1214|      0|      return false;
 1215|      0|    }
 1216|  1.66k|  }
 1217|       |
 1218|  3.33k|  if (ep > -1) {
  ------------------
  |  Branch (1218:7): [True: 2.50k, False: 822]
  ------------------
 1219|  2.50k|    uint8_t value = ep ? 0x80 : 0x00;
  ------------------
  |  Branch (1219:21): [True: 1.44k, False: 1.06k]
  ------------------
 1220|  2.50k|    if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_EVEN_PORT, (const uint8_t *)&value, 1)) {
  ------------------
  |  |  123|  2.50k|#define STUN_ATTRIBUTE_EVEN_PORT (0x0018)
  ------------------
  |  Branch (1220:9): [True: 0, False: 2.50k]
  ------------------
 1221|      0|      return false;
 1222|      0|    }
 1223|  2.50k|  }
 1224|       |
 1225|       |  // RESERVATION-TOKEN, EVEN-PORT and DUAL-ALLOCATION are mutually exclusive:
 1226|  3.33k|  if (rt) {
  ------------------
  |  Branch (1226:7): [True: 1.00k, False: 2.32k]
  ------------------
 1227|       |
 1228|  1.00k|    stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (const uint8_t *)rt, 8);
  ------------------
  |  |  127|  1.00k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1229|       |
 1230|  2.32k|  } else {
 1231|       |
 1232|       |    // ADRESS-FAMILY
 1233|  2.32k|    if (af4 && !af6) {
  ------------------
  |  Branch (1233:9): [True: 1.17k, False: 1.15k]
  |  Branch (1233:16): [True: 342, False: 832]
  ------------------
 1234|    342|      uint8_t field[4];
 1235|    342|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4;
  ------------------
  |  |  168|    342|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV4 (0x01)
  ------------------
 1236|    342|      field[1] = 0;
 1237|    342|      field[2] = 0;
 1238|    342|      field[3] = 0;
 1239|    342|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  108|    342|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1239:11): [True: 0, False: 342]
  ------------------
 1240|      0|        return false;
 1241|      0|      }
 1242|    342|    }
 1243|       |
 1244|  2.32k|    if (af6 && !af4) {
  ------------------
  |  Branch (1244:9): [True: 1.21k, False: 1.10k]
  |  Branch (1244:16): [True: 386, False: 832]
  ------------------
 1245|    386|      uint8_t field[4];
 1246|    386|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  169|    386|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1247|    386|      field[1] = 0;
 1248|    386|      field[2] = 0;
 1249|    386|      field[3] = 0;
 1250|    386|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  108|    386|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY (0x0017)
  ------------------
  |  Branch (1250:11): [True: 0, False: 386]
  ------------------
 1251|      0|        return false;
 1252|      0|      }
 1253|    386|    }
 1254|       |
 1255|  2.32k|    if (af4 && af6) {
  ------------------
  |  Branch (1255:9): [True: 1.17k, False: 1.15k]
  |  Branch (1255:16): [True: 832, False: 342]
  ------------------
 1256|    832|      uint8_t field[4];
 1257|    832|      field[0] = (uint8_t)STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6;
  ------------------
  |  |  169|    832|#define STUN_ATTRIBUTE_REQUESTED_ADDRESS_FAMILY_VALUE_IPV6 (0x02)
  ------------------
 1258|    832|      field[1] = 0;
 1259|    832|      field[2] = 0;
 1260|    832|      field[3] = 0;
 1261|    832|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY, field, sizeof(field))) {
  ------------------
  |  |  144|    832|#define STUN_ATTRIBUTE_ADDITIONAL_ADDRESS_FAMILY (0x8000)
  ------------------
  |  Branch (1261:11): [True: 0, False: 832]
  ------------------
 1262|      0|        return false;
 1263|      0|      }
 1264|    832|    }
 1265|  2.32k|  }
 1266|       |
 1267|  3.33k|  return true;
 1268|  3.33k|}
stun_set_allocate_response_str:
 1273|  16.6k|                                    uint64_t reservation_token, char *mobile_id, bool include_reason_string) {
 1274|       |
 1275|  16.6k|  if (!error_code) {
  ------------------
  |  Branch (1275:7): [True: 9.99k, False: 6.66k]
  ------------------
 1276|       |
 1277|  9.99k|    stun_init_success_response_str(STUN_METHOD_ALLOCATE, buf, len, tid);
  ------------------
  |  |   82|  9.99k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1278|       |
 1279|  9.99k|    if (relayed_addr1) {
  ------------------
  |  Branch (1279:9): [True: 9.99k, False: 0]
  ------------------
 1280|  9.99k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr1)) {
  ------------------
  |  |  122|  9.99k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1280:11): [True: 0, False: 9.99k]
  ------------------
 1281|      0|        return false;
 1282|      0|      }
 1283|  9.99k|    }
 1284|       |
 1285|  9.99k|    if (relayed_addr2) {
  ------------------
  |  Branch (1285:9): [True: 5.54k, False: 4.44k]
  ------------------
 1286|  5.54k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS, relayed_addr2)) {
  ------------------
  |  |  122|  5.54k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1286:11): [True: 0, False: 5.54k]
  ------------------
 1287|      0|        return false;
 1288|      0|      }
 1289|  5.54k|    }
 1290|       |
 1291|  9.99k|    if (reflexive_addr) {
  ------------------
  |  Branch (1291:9): [True: 6.66k, False: 3.33k]
  ------------------
 1292|  6.66k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  109|  6.66k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1292:11): [True: 0, False: 6.66k]
  ------------------
 1293|      0|        return false;
 1294|      0|      }
 1295|  6.66k|    }
 1296|       |
 1297|  9.99k|    if (reservation_token) {
  ------------------
  |  Branch (1297:9): [True: 6.56k, False: 3.42k]
  ------------------
 1298|  6.56k|      reservation_token = nswap64(reservation_token);
  ------------------
  |  |   88|  6.56k|#define nswap64(ull) ioa_ntoh64(ull)
  |  |  ------------------
  |  |  |  |  115|  6.56k|#define ioa_ntoh64 _ioa_ntoh64
  |  |  ------------------
  ------------------
 1299|  6.56k|      stun_attr_add_str(buf, len, STUN_ATTRIBUTE_RESERVATION_TOKEN, (uint8_t *)(&reservation_token), 8);
  ------------------
  |  |  127|  6.56k|#define STUN_ATTRIBUTE_RESERVATION_TOKEN (0x0022)
  ------------------
 1300|  6.56k|    }
 1301|       |
 1302|  9.99k|    {
 1303|  9.99k|      if (lifetime < 1) {
  ------------------
  |  Branch (1303:11): [True: 3.65k, False: 6.33k]
  ------------------
 1304|  3.65k|        lifetime = STUN_DEFAULT_ALLOCATE_LIFETIME;
  ------------------
  |  |   73|  3.65k|#define STUN_DEFAULT_ALLOCATE_LIFETIME (600)
  ------------------
 1305|  6.33k|      } else if (lifetime > max_lifetime) {
  ------------------
  |  Branch (1305:18): [True: 4.63k, False: 1.69k]
  ------------------
 1306|  4.63k|        lifetime = max_lifetime;
 1307|  4.63k|      }
 1308|       |
 1309|  9.99k|      uint32_t field = nswap32(lifetime);
  ------------------
  |  |   87|  9.99k|#define nswap32(ul) ntohl(ul)
  ------------------
 1310|  9.99k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_LIFETIME, (uint8_t *)(&field), sizeof(field))) {
  ------------------
  |  |  118|  9.99k|#define STUN_ATTRIBUTE_LIFETIME (0x000D)
  ------------------
  |  Branch (1310:11): [True: 0, False: 9.99k]
  ------------------
 1311|      0|        return false;
 1312|      0|      }
 1313|  9.99k|    }
 1314|       |
 1315|  9.99k|    if (mobile_id && *mobile_id) {
  ------------------
  |  Branch (1315:9): [True: 6.66k, False: 3.33k]
  |  Branch (1315:22): [True: 4.70k, False: 1.96k]
  ------------------
 1316|  4.70k|      if (!stun_attr_add_str(buf, len, STUN_ATTRIBUTE_MOBILITY_TICKET, (uint8_t *)mobile_id, (int)strlen(mobile_id))) {
  ------------------
  |  |   47|  4.70k|#define STUN_ATTRIBUTE_MOBILITY_TICKET (0x8030)
  ------------------
  |  Branch (1316:11): [True: 0, False: 4.70k]
  ------------------
 1317|      0|        return false;
 1318|      0|      }
 1319|  4.70k|    }
 1320|       |
 1321|  9.99k|  } else {
 1322|  6.66k|    stun_init_error_response_str(STUN_METHOD_ALLOCATE, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   82|  6.66k|#define STUN_METHOD_ALLOCATE (0x0003)
  ------------------
 1323|  6.66k|  }
 1324|       |
 1325|  16.6k|  return true;
 1326|  16.6k|}
stun_set_channel_bind_request_str:
 1331|  9.99k|                                           uint16_t channel_number) {
 1332|       |
 1333|  9.99k|  if (!STUN_VALID_CHANNEL_BIND(channel_number)) {
  ------------------
  |  |  162|  9.99k|#define STUN_VALID_CHANNEL_BIND(chn) ((chn) >= 0x4000 && (chn) <= 0x4FFF)
  |  |  ------------------
  |  |  |  Branch (162:39): [True: 8.19k, False: 1.79k]
  |  |  |  Branch (162:58): [True: 3.19k, False: 5.00k]
  |  |  ------------------
  ------------------
 1334|  6.79k|    channel_number = 0x4000 + ((uint16_t)(((uint32_t)turn_random_number()) % (0x4FFF - 0x4000 + 1)));
 1335|  6.79k|  }
 1336|       |
 1337|  9.99k|  stun_init_request_str(STUN_METHOD_CHANNEL_BIND, buf, len);
  ------------------
  |  |   87|  9.99k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1338|       |
 1339|  9.99k|  if (!stun_attr_add_channel_number_str(buf, len, channel_number)) {
  ------------------
  |  Branch (1339:7): [True: 0, False: 9.99k]
  ------------------
 1340|      0|    return 0;
 1341|      0|  }
 1342|       |
 1343|  9.99k|  if (!peer_addr) {
  ------------------
  |  Branch (1343:7): [True: 5.40k, False: 4.58k]
  ------------------
 1344|  5.40k|    ioa_addr ca;
 1345|  5.40k|    memset(&ca, 0, sizeof(ioa_addr));
 1346|       |
 1347|  5.40k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &ca)) {
  ------------------
  |  |  120|  5.40k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1347:9): [True: 0, False: 5.40k]
  ------------------
 1348|      0|      return 0;
 1349|      0|    }
 1350|  5.40k|  } else {
 1351|  4.58k|    if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_PEER_ADDRESS, peer_addr)) {
  ------------------
  |  |  120|  4.58k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1351:9): [True: 0, False: 4.58k]
  ------------------
 1352|      0|      return 0;
 1353|      0|    }
 1354|  4.58k|  }
 1355|       |
 1356|  9.99k|  return channel_number;
 1357|  9.99k|}
stun_set_channel_bind_response_str:
 1360|  9.99k|                                        bool include_reason_string) {
 1361|  9.99k|  if (!error_code) {
  ------------------
  |  Branch (1361:7): [True: 4.99k, False: 4.99k]
  ------------------
 1362|  4.99k|    stun_init_success_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, tid);
  ------------------
  |  |   87|  4.99k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1363|  4.99k|  } else {
 1364|  4.99k|    stun_init_error_response_str(STUN_METHOD_CHANNEL_BIND, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   87|  4.99k|#define STUN_METHOD_CHANNEL_BIND (0x0009)
  ------------------
 1365|  4.99k|  }
 1366|  9.99k|}
stun_set_binding_request_str:
 1370|  3.33k|void stun_set_binding_request_str(uint8_t *buf, size_t *len) { stun_init_request_str(STUN_METHOD_BINDING, buf, len); }
  ------------------
  |  |   81|  3.33k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
stun_set_binding_response_str:
 1376|  23.3k|{
 1377|  23.3k|  if (!error_code) {
  ------------------
  |  Branch (1377:7): [True: 11.6k, False: 11.6k]
  ------------------
 1378|  11.6k|    if (!old_stun) {
  ------------------
  |  Branch (1378:9): [True: 7.62k, False: 4.02k]
  ------------------
 1379|  7.62k|      stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid);
  ------------------
  |  |   81|  7.62k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1380|  7.62k|    } else {
 1381|  4.02k|      old_stun_init_success_response_str(STUN_METHOD_BINDING, buf, len, tid, cookie);
  ------------------
  |  |   81|  4.02k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1382|  4.02k|    }
 1383|  11.6k|    if (!old_stun && reflexive_addr) {
  ------------------
  |  Branch (1383:9): [True: 7.62k, False: 4.02k]
  |  Branch (1383:22): [True: 7.62k, False: 0]
  ------------------
 1384|  7.62k|      if (!stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |  109|  7.62k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1384:11): [True: 0, False: 7.62k]
  ------------------
 1385|      0|        return false;
 1386|      0|      }
 1387|  7.62k|    }
 1388|       |    /* MAPPED-ADDRESS is the only address attribute RFC 3489 defines, so the old-STUN
 1389|       |     * path always needs it. On the modern path it is purely a backward-compatibility
 1390|       |     * courtesy for clients that cannot parse XOR-MAPPED-ADDRESS, and it widens the
 1391|       |     * response, so it stays opt-in there. */
 1392|  11.6k|    if (reflexive_addr) {
  ------------------
  |  Branch (1392:9): [True: 11.6k, False: 0]
  ------------------
 1393|  11.6k|      if ((old_stun || stun_backward_compatibility) &&
  ------------------
  |  Branch (1393:12): [True: 4.02k, False: 7.62k]
  |  Branch (1393:24): [True: 5.28k, False: 2.34k]
  ------------------
 1394|  9.31k|          !stun_attr_add_addr_str(buf, len, STUN_ATTRIBUTE_MAPPED_ADDRESS, reflexive_addr)) {
  ------------------
  |  |   95|  9.31k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1394:11): [True: 0, False: 9.31k]
  ------------------
 1395|      0|        return false;
 1396|      0|      }
 1397|  11.6k|    }
 1398|  11.6k|  } else if (!old_stun) {
  ------------------
  |  Branch (1398:14): [True: 7.62k, False: 4.02k]
  ------------------
 1399|  7.62k|    stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, include_reason_string);
  ------------------
  |  |   81|  7.62k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1400|  7.62k|  } else {
 1401|  4.02k|    old_stun_init_error_response_str(STUN_METHOD_BINDING, buf, len, error_code, reason, tid, cookie,
  ------------------
  |  |   81|  4.02k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
 1402|  4.02k|                                     include_reason_string);
 1403|  4.02k|  }
 1404|       |
 1405|  23.3k|  return true;
 1406|  23.3k|}
stun_is_binding_response_str:
 1421|  76.6k|bool stun_is_binding_response_str(const uint8_t *buf, size_t len) {
 1422|  76.6k|  if (stun_is_command_message_str(buf, len) && (stun_get_method_str(buf, len) == STUN_METHOD_BINDING)) {
  ------------------
  |  |   81|  68.8k|#define STUN_METHOD_BINDING (0x0001)
  ------------------
  |  Branch (1422:7): [True: 68.8k, False: 7.77k]
  |  Branch (1422:48): [True: 21.3k, False: 47.4k]
  ------------------
 1423|  21.3k|    if (stun_is_response_str(buf, len)) {
  ------------------
  |  Branch (1423:9): [True: 17.6k, False: 3.73k]
  ------------------
 1424|  17.6k|      return true;
 1425|  17.6k|    }
 1426|  21.3k|  }
 1427|  59.0k|  return false;
 1428|  76.6k|}
stun_tid_from_message_str:
 1466|   150k|void stun_tid_from_message_str(const uint8_t *buf, size_t len, stun_tid *id) {
 1467|   150k|  UNUSED_ARG(len);
  ------------------
  |  |  218|   150k|  do {                                                                                                                 \
  |  |  219|   150k|    A = A;                                                                                                             \
  |  |  220|   150k|  } while (0)
  |  |  ------------------
  |  |  |  Branch (220:12): [Folded, False: 150k]
  |  |  ------------------
  ------------------
 1468|   150k|  stun_tid_from_string(buf + 8, id);
 1469|   150k|}
stun_tid_message_cpy:
 1471|   134k|void stun_tid_message_cpy(uint8_t *buf, const stun_tid *id) {
 1472|   134k|  if (buf && id) {
  ------------------
  |  Branch (1472:7): [True: 134k, False: 0]
  |  Branch (1472:14): [True: 134k, False: 0]
  ------------------
 1473|   134k|    stun_tid_string_cpy(buf + 8, id);
 1474|   134k|  }
 1475|   134k|}
stun_tid_generate:
 1477|  78.2k|void stun_tid_generate(stun_tid *id) {
 1478|  78.2k|  if (id) {
  ------------------
  |  Branch (1478:7): [True: 78.2k, False: 0]
  ------------------
 1479|  78.2k|    turn_random_tid_size(id->tsx_id);
 1480|  78.2k|  }
 1481|  78.2k|}
stun_tid_generate_in_message_str:
 1483|  78.2k|void stun_tid_generate_in_message_str(uint8_t *buf, stun_tid *id) {
 1484|  78.2k|  stun_tid tmp;
 1485|  78.2k|  if (!id) {
  ------------------
  |  Branch (1485:7): [True: 76.5k, False: 1.66k]
  ------------------
 1486|  76.5k|    id = &tmp;
 1487|  76.5k|  }
 1488|  78.2k|  stun_tid_generate(id);
 1489|  78.2k|  stun_tid_message_cpy(buf, id);
 1490|  78.2k|}
stun_attr_get_type:
 1514|   908k|int stun_attr_get_type(stun_attr_ref attr) {
 1515|   908k|  if (attr) {
  ------------------
  |  Branch (1515:7): [True: 908k, False: 0]
  ------------------
 1516|   908k|    return (int)turn_read_u16(attr);
 1517|   908k|  }
 1518|      0|  return -1;
 1519|   908k|}
stun_attr_get_len:
 1521|  1.32M|int stun_attr_get_len(stun_attr_ref attr) {
 1522|  1.32M|  if (attr) {
  ------------------
  |  Branch (1522:7): [True: 1.32M, False: 0]
  ------------------
 1523|  1.32M|    return (int)turn_read_u16((const uint8_t *)attr + 2);
 1524|  1.32M|  }
 1525|      0|  return -1;
 1526|  1.32M|}
stun_attr_get_value:
 1528|   135k|const uint8_t *stun_attr_get_value(stun_attr_ref attr) {
 1529|   135k|  if (attr) {
  ------------------
  |  Branch (1529:7): [True: 135k, False: 0]
  ------------------
 1530|   135k|    const int len = (int)turn_read_u16((const uint8_t *)attr + 2);
 1531|   135k|    if (len < 1) {
  ------------------
  |  Branch (1531:9): [True: 5.53k, False: 130k]
  ------------------
 1532|  5.53k|      return NULL;
 1533|  5.53k|    }
 1534|   130k|    return ((const uint8_t *)attr) + 4;
 1535|   135k|  }
 1536|      0|  return NULL;
 1537|   135k|}
stun_attr_get_channel_number:
 1557|  11.6k|uint16_t stun_attr_get_channel_number(stun_attr_ref attr) {
 1558|  11.6k|  if (attr) {
  ------------------
  |  Branch (1558:7): [True: 11.6k, False: 0]
  ------------------
 1559|  11.6k|    const uint8_t *value = stun_attr_get_value(attr);
 1560|  11.6k|    if (value && (stun_attr_get_len(attr) >= 2)) {
  ------------------
  |  Branch (1560:9): [True: 11.6k, False: 0]
  |  Branch (1560:18): [True: 11.6k, False: 0]
  ------------------
 1561|  11.6k|      const uint16_t cn = turn_read_u16(value);
 1562|  11.6k|      if (STUN_VALID_CHANNEL(cn)) {
  ------------------
  |  |  163|  11.6k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 11.6k, False: 0]
  |  |  |  Branch (163:53): [True: 11.6k, False: 0]
  |  |  ------------------
  ------------------
 1563|  11.6k|        return cn;
 1564|  11.6k|      }
 1565|  11.6k|    }
 1566|  11.6k|  }
 1567|      0|  return 0;
 1568|  11.6k|}
stun_attr_is_addr:
 1591|   366k|bool stun_attr_is_addr(stun_attr_ref attr) {
 1592|       |
 1593|   366k|  if (attr) {
  ------------------
  |  Branch (1593:7): [True: 366k, False: 0]
  ------------------
 1594|   366k|    switch (stun_attr_get_type(attr)) {
 1595|  33.1k|    case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  33.1k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1595:5): [True: 33.1k, False: 333k]
  ------------------
 1596|  80.7k|    case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  80.7k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1596:5): [True: 47.5k, False: 318k]
  ------------------
 1597|   135k|    case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|   135k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1597:5): [True: 54.2k, False: 312k]
  ------------------
 1598|   172k|    case STUN_ATTRIBUTE_MAPPED_ADDRESS:
  ------------------
  |  |   95|   172k|#define STUN_ATTRIBUTE_MAPPED_ADDRESS (0x0001)
  ------------------
  |  Branch (1598:5): [True: 37.6k, False: 328k]
  ------------------
 1599|   176k|    case STUN_ATTRIBUTE_ALTERNATE_SERVER:
  ------------------
  |  |  114|   176k|#define STUN_ATTRIBUTE_ALTERNATE_SERVER (0x8023)
  ------------------
  |  Branch (1599:5): [True: 3.94k, False: 362k]
  ------------------
 1600|   177k|    case OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS:
  ------------------
  |  |   96|   177k|#define OLD_STUN_ATTRIBUTE_RESPONSE_ADDRESS (0x0002)
  ------------------
  |  Branch (1600:5): [True: 1.31k, False: 365k]
  ------------------
 1601|   180k|    case OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS:
  ------------------
  |  |   98|   180k|#define OLD_STUN_ATTRIBUTE_SOURCE_ADDRESS (0x0004)
  ------------------
  |  Branch (1601:5): [True: 2.80k, False: 363k]
  ------------------
 1602|   181k|    case OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS:
  ------------------
  |  |   99|   181k|#define OLD_STUN_ATTRIBUTE_CHANGED_ADDRESS (0x0005)
  ------------------
  |  Branch (1602:5): [True: 712, False: 365k]
  ------------------
 1603|   181k|    case OLD_STUN_ATTRIBUTE_REFLECTED_FROM:
  ------------------
  |  |  105|   181k|#define OLD_STUN_ATTRIBUTE_REFLECTED_FROM (0x000B)
  ------------------
  |  Branch (1603:5): [True: 366, False: 366k]
  ------------------
 1604|   184k|    case STUN_ATTRIBUTE_RESPONSE_ORIGIN:
  ------------------
  |  |  136|   184k|#define STUN_ATTRIBUTE_RESPONSE_ORIGIN (0x802B)
  ------------------
  |  Branch (1604:5): [True: 2.56k, False: 363k]
  ------------------
 1605|   185k|    case STUN_ATTRIBUTE_OTHER_ADDRESS:
  ------------------
  |  |  137|   185k|#define STUN_ATTRIBUTE_OTHER_ADDRESS (0x802C)
  ------------------
  |  Branch (1605:5): [True: 918, False: 365k]
  ------------------
 1606|   185k|      return true;
 1607|      0|      break;
 1608|   181k|    default:;
  ------------------
  |  Branch (1608:5): [True: 181k, False: 185k]
  ------------------
 1609|   366k|    };
 1610|   181k|  }
 1611|   181k|  return false;
 1612|   366k|}
stun_attr_get_first_by_type_str:
 1634|  40.0k|stun_attr_ref stun_attr_get_first_by_type_str(const uint8_t *buf, size_t len, uint16_t attr_type) {
 1635|  40.0k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1636|  70.3k|  while (attr) {
  ------------------
  |  Branch (1636:10): [True: 65.3k, False: 4.96k]
  ------------------
 1637|  65.3k|    if (stun_attr_get_type(attr) == attr_type) {
  ------------------
  |  Branch (1637:9): [True: 35.0k, False: 30.3k]
  ------------------
 1638|  35.0k|      return attr;
 1639|  35.0k|    }
 1640|  30.3k|    attr = stun_attr_get_next_str(buf, len, attr);
 1641|  30.3k|  }
 1642|       |
 1643|  4.96k|  return NULL;
 1644|  40.0k|}
stun_attr_get_first_str:
 1679|   286k|stun_attr_ref stun_attr_get_first_str(const uint8_t *buf, size_t len) {
 1680|   286k|  const int bufLen = stun_get_command_message_len_str(buf, len);
 1681|   286k|  if (bufLen > STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   286k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (1681:7): [True: 239k, False: 47.4k]
  ------------------
 1682|   239k|    stun_attr_ref attr = (stun_attr_ref)(buf + STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   239k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1683|   239k|    return stun_attr_check_valid(attr, bufLen - STUN_HEADER_LENGTH);
  ------------------
  |  |   46|   239k|#define STUN_HEADER_LENGTH (20)
  ------------------
 1684|   239k|  }
 1685|       |
 1686|  47.4k|  return NULL;
 1687|   286k|}
stun_attr_get_next_str:
 1689|   466k|stun_attr_ref stun_attr_get_next_str(const uint8_t *buf, size_t len, stun_attr_ref prev) {
 1690|   466k|  if (!prev) {
  ------------------
  |  Branch (1690:7): [True: 0, False: 466k]
  ------------------
 1691|      0|    return stun_attr_get_first_str(buf, len);
 1692|   466k|  } else {
 1693|   466k|    const uint8_t *end = buf + stun_get_command_message_len_str(buf, len);
 1694|   466k|    int attrlen = stun_attr_get_len(prev);
 1695|   466k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1696|   466k|    if (rem4) {
  ------------------
  |  Branch (1696:9): [True: 88.7k, False: 377k]
  ------------------
 1697|  88.7k|      attrlen = attrlen + 4 - (int)rem4;
 1698|  88.7k|    }
 1699|       |    /* Note the order here: operations on attrlen are untrusted as they may overflow */
 1700|   466k|    if (attrlen < end - (const uint8_t *)prev - 4) {
  ------------------
  |  Branch (1700:9): [True: 312k, False: 154k]
  ------------------
 1701|   312k|      const uint8_t *attr_end = (const uint8_t *)prev + 4 + attrlen;
 1702|   312k|      return stun_attr_check_valid(attr_end, end - attr_end);
 1703|   312k|    }
 1704|   154k|    return NULL;
 1705|   466k|  }
 1706|   466k|}
stun_attr_add_str:
 1708|   130k|bool stun_attr_add_str(uint8_t *buf, size_t *len, uint16_t attr, const uint8_t *avalue, int alen) {
 1709|   130k|  if (alen < 0) {
  ------------------
  |  Branch (1709:7): [True: 0, False: 130k]
  ------------------
 1710|      0|    alen = 0;
 1711|      0|  }
 1712|   130k|  uint8_t tmp[1];
 1713|   130k|  if (!avalue) {
  ------------------
  |  Branch (1713:7): [True: 0, False: 130k]
  ------------------
 1714|      0|    alen = 0;
 1715|      0|    avalue = tmp;
 1716|      0|  }
 1717|   130k|  const int clen = stun_get_command_message_len_str(buf, *len);
 1718|   130k|  int newlen = clen + 4 + alen;
 1719|   130k|  const int newlenrem4 = newlen & 0x00000003;
 1720|   130k|  int paddinglen = 0;
 1721|   130k|  if (newlenrem4) {
  ------------------
  |  Branch (1721:7): [True: 18.6k, False: 111k]
  ------------------
 1722|  18.6k|    paddinglen = 4 - newlenrem4;
 1723|  18.6k|    newlen = newlen + paddinglen;
 1724|  18.6k|  }
 1725|       |
 1726|   130k|  if (newlen >= MAX_STUN_MESSAGE_SIZE) {
  ------------------
  |  |  223|   130k|#define MAX_STUN_MESSAGE_SIZE (65507)
  ------------------
  |  Branch (1726:7): [True: 0, False: 130k]
  ------------------
 1727|      0|    return false;
 1728|      0|  }
 1729|       |
 1730|   130k|  uint8_t *attr_start = buf + clen;
 1731|       |
 1732|   130k|  stun_set_command_message_len_str(buf, newlen);
 1733|   130k|  *len = newlen;
 1734|       |
 1735|   130k|  turn_write_u16(attr_start, attr);
 1736|   130k|  turn_write_u16(attr_start + 2, (uint16_t)alen);
 1737|   130k|  if (alen > 0) {
  ------------------
  |  Branch (1737:7): [True: 128k, False: 2.13k]
  ------------------
 1738|   128k|    memcpy(attr_start + 4, avalue, alen);
 1739|   128k|  }
 1740|       |
 1741|       |  // Write 0 padding to not leak data
 1742|   130k|  memset(attr_start + 4 + alen, 0, paddinglen);
 1743|       |
 1744|       |  return true;
 1745|   130k|}
stun_attr_add_addr_str:
 1747|  50.7k|bool stun_attr_add_addr_str(uint8_t *buf, size_t *len, uint16_t attr_type, const ioa_addr *ca) {
 1748|       |
 1749|  50.7k|  stun_tid tid;
 1750|  50.7k|  stun_tid_from_message_str(buf, *len, &tid);
 1751|       |
 1752|  50.7k|  int xor_ed = 0;
 1753|  50.7k|  switch (attr_type) {
 1754|  14.2k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  14.2k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1754:3): [True: 14.2k, False: 36.5k]
  ------------------
 1755|  25.9k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  25.9k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1755:3): [True: 11.6k, False: 39.1k]
  ------------------
 1756|  41.4k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  41.4k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1756:3): [True: 15.5k, False: 35.2k]
  ------------------
 1757|  41.4k|    xor_ed = 1;
 1758|  41.4k|    break;
 1759|  9.31k|  default:;
  ------------------
  |  Branch (1759:3): [True: 9.31k, False: 41.4k]
  ------------------
 1760|  50.7k|  };
 1761|       |
 1762|  50.7k|  ioa_addr public_addr;
 1763|  50.7k|  map_addr_from_private_to_public(ca, &public_addr);
 1764|       |
 1765|  50.7k|  uint8_t cfield[64];
 1766|  50.7k|  int clen = 0;
 1767|  50.7k|  if (stun_addr_encode(&public_addr, cfield, &clen, xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  50.7k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1767:7): [True: 0, False: 50.7k]
  ------------------
 1768|      0|    return false;
 1769|      0|  }
 1770|       |
 1771|  50.7k|  if (!stun_attr_add_str(buf, len, attr_type, (uint8_t *)(&cfield), clen)) {
  ------------------
  |  Branch (1771:7): [True: 0, False: 50.7k]
  ------------------
 1772|      0|    return false;
 1773|      0|  }
 1774|       |
 1775|  50.7k|  return true;
 1776|  50.7k|}
stun_attr_get_addr_str:
 1779|  96.0k|                            const ioa_addr *default_addr) {
 1780|  96.0k|  stun_tid tid;
 1781|  96.0k|  stun_tid_from_message_str(buf, len, &tid);
 1782|  96.0k|  ioa_addr public_addr;
 1783|       |
 1784|  96.0k|  addr_set_any(ca);
 1785|  96.0k|  addr_set_any(&public_addr);
 1786|       |
 1787|  96.0k|  const int attr_type = stun_attr_get_type(attr);
 1788|  96.0k|  if (attr_type < 0) {
  ------------------
  |  Branch (1788:7): [True: 0, False: 96.0k]
  ------------------
 1789|      0|    return false;
 1790|      0|  }
 1791|       |
 1792|  96.0k|  int xor_ed = 0;
 1793|  96.0k|  switch (attr_type) {
 1794|  23.3k|  case STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS:
  ------------------
  |  |  109|  23.3k|#define STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS (0x0020)
  ------------------
  |  Branch (1794:3): [True: 23.3k, False: 72.6k]
  ------------------
 1795|  49.7k|  case STUN_ATTRIBUTE_XOR_PEER_ADDRESS:
  ------------------
  |  |  120|  49.7k|#define STUN_ATTRIBUTE_XOR_PEER_ADDRESS (0x0012)
  ------------------
  |  Branch (1795:3): [True: 26.4k, False: 69.5k]
  ------------------
 1796|  78.8k|  case STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS:
  ------------------
  |  |  122|  78.8k|#define STUN_ATTRIBUTE_XOR_RELAYED_ADDRESS (0x0016)
  ------------------
  |  Branch (1796:3): [True: 29.1k, False: 66.8k]
  ------------------
 1797|  78.8k|    xor_ed = 1;
 1798|  78.8k|    break;
 1799|  17.1k|  default:;
  ------------------
  |  Branch (1799:3): [True: 17.1k, False: 78.8k]
  ------------------
 1800|  96.0k|  };
 1801|       |
 1802|  96.0k|  const uint8_t *cfield = stun_attr_get_value(attr);
 1803|  96.0k|  if (!cfield) {
  ------------------
  |  Branch (1803:7): [True: 5.53k, False: 90.4k]
  ------------------
 1804|  5.53k|    return false;
 1805|  5.53k|  }
 1806|       |
 1807|  90.4k|  if (stun_addr_decode(&public_addr, cfield, stun_attr_get_len(attr), xor_ed, STUN_MAGIC_COOKIE, tid.tsx_id) < 0) {
  ------------------
  |  |   60|  90.4k|#define STUN_MAGIC_COOKIE (0x2112A442)
  ------------------
  |  Branch (1807:7): [True: 5.81k, False: 84.6k]
  ------------------
 1808|  5.81k|    return false;
 1809|  5.81k|  }
 1810|       |
 1811|  84.6k|  map_addr_from_public_to_private(&public_addr, ca);
 1812|       |
 1813|  84.6k|  if (default_addr && addr_any_no_port(ca) && !addr_any_no_port(default_addr)) {
  ------------------
  |  Branch (1813:7): [True: 84.3k, False: 282]
  |  Branch (1813:23): [True: 10.8k, False: 73.4k]
  |  Branch (1813:47): [True: 10.8k, False: 0]
  ------------------
 1814|  10.8k|    const uint16_t port = addr_get_port(ca);
 1815|  10.8k|    addr_cpy(ca, default_addr);
 1816|  10.8k|    addr_set_port(ca, port);
 1817|  10.8k|  }
 1818|       |
 1819|       |  return true;
 1820|  90.4k|}
stun_attr_get_first_addr_str:
 1823|  93.6k|                                  const ioa_addr *default_addr) {
 1824|  93.6k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1825|       |
 1826|   295k|  while (attr) {
  ------------------
  |  Branch (1826:10): [True: 236k, False: 59.8k]
  ------------------
 1827|   236k|    if (stun_attr_is_addr(attr) && (attr_type == stun_attr_get_type(attr))) {
  ------------------
  |  Branch (1827:9): [True: 134k, False: 101k]
  |  Branch (1827:36): [True: 45.2k, False: 89.2k]
  ------------------
 1828|  45.2k|      if (stun_attr_get_addr_str(buf, len, attr, ca, default_addr)) {
  ------------------
  |  Branch (1828:11): [True: 33.8k, False: 11.3k]
  ------------------
 1829|  33.8k|        return true;
 1830|  33.8k|      }
 1831|  45.2k|    }
 1832|   202k|    attr = stun_attr_get_next_str(buf, len, attr);
 1833|   202k|  }
 1834|       |
 1835|  59.8k|  return false;
 1836|  93.6k|}
stun_attr_add_channel_number_str:
 1838|  11.6k|bool stun_attr_add_channel_number_str(uint8_t *buf, size_t *len, uint16_t chnumber) {
 1839|       |
 1840|  11.6k|  uint16_t field[2];
 1841|  11.6k|  field[0] = nswap16(chnumber);
  ------------------
  |  |   86|  11.6k|#define nswap16(s) ntohs(s)
  ------------------
 1842|  11.6k|  field[1] = 0;
 1843|       |
 1844|  11.6k|  return stun_attr_add_str(buf, len, STUN_ATTRIBUTE_CHANNEL_NUMBER, (uint8_t *)(field), sizeof(field));
  ------------------
  |  |  117|  11.6k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
 1845|  11.6k|}
stun_attr_get_first_channel_number_str:
 1873|  76.5k|uint16_t stun_attr_get_first_channel_number_str(const uint8_t *buf, size_t len) {
 1874|       |
 1875|  76.5k|  stun_attr_ref attr = stun_attr_get_first_str(buf, len);
 1876|   180k|  while (attr) {
  ------------------
  |  Branch (1876:10): [True: 115k, False: 64.9k]
  ------------------
 1877|   115k|    if (stun_attr_get_type(attr) == STUN_ATTRIBUTE_CHANNEL_NUMBER) {
  ------------------
  |  |  117|   115k|#define STUN_ATTRIBUTE_CHANNEL_NUMBER (0x000C)
  ------------------
  |  Branch (1877:9): [True: 11.6k, False: 103k]
  ------------------
 1878|  11.6k|      const uint16_t ret = stun_attr_get_channel_number(attr);
 1879|  11.6k|      if (STUN_VALID_CHANNEL(ret)) {
  ------------------
  |  |  163|  11.6k|#define STUN_VALID_CHANNEL(chn) ((chn) >= 0x4000 && (chn) <= 0x7FFF)
  |  |  ------------------
  |  |  |  Branch (163:34): [True: 11.6k, False: 0]
  |  |  |  Branch (163:53): [True: 11.6k, False: 0]
  |  |  ------------------
  ------------------
 1880|  11.6k|        return ret;
 1881|  11.6k|      }
 1882|  11.6k|    }
 1883|   103k|    attr = stun_attr_get_next_str(buf, len, attr);
 1884|   103k|  }
 1885|       |
 1886|  64.9k|  return 0;
 1887|  76.5k|}
ns_turn_msg.c:fuzz_prng_next:
  112|   241k|static uint64_t fuzz_prng_next(void) {
  113|   241k|  static uint64_t state = UINT64_C(0x9e3779b97f4a7c15);
  114|       |
  115|   241k|  state += UINT64_C(0x9e3779b97f4a7c15);
  116|   241k|  uint64_t z = state;
  117|   241k|  z = (z ^ (z >> 30)) * UINT64_C(0xbf58476d1ce4e5b9);
  118|       |  z = (z ^ (z >> 27)) * UINT64_C(0x94d049bb133111eb);
  119|   241k|  return z ^ (z >> 31);
  120|   241k|}
ns_turn_msg.c:stun_init_error_response_common_str:
  898|  28.3k|                                                stun_tid *id, bool include_reason_string, bool pad_reason_phrase) {
  899|       |
  900|  28.3k|  if (include_reason_string && (!reason || !strcmp((const char *)reason, "Unknown error"))) {
  ------------------
  |  Branch (900:7): [True: 18.7k, False: 9.56k]
  |  Branch (900:33): [True: 894, False: 17.8k]
  |  Branch (900:44): [True: 0, False: 17.8k]
  ------------------
  901|    894|    reason = get_default_reason(error_code);
  902|    894|  }
  903|       |
  904|  28.3k|  uint8_t avalue[513];
  905|  28.3k|  memset(avalue, 0, sizeof(avalue));
  906|  28.3k|  avalue[0] = 0;
  907|  28.3k|  avalue[1] = 0;
  908|  28.3k|  avalue[2] = (uint8_t)(error_code / 100);
  909|  28.3k|  avalue[3] = (uint8_t)(error_code % 100);
  910|  28.3k|  if (include_reason_string) {
  ------------------
  |  Branch (910:7): [True: 18.7k, False: 9.56k]
  ------------------
  911|  18.7k|    strncpy((char *)(avalue + 4), (const char *)reason, sizeof(avalue) - 4);
  912|  18.7k|  }
  913|  28.3k|  avalue[sizeof(avalue) - 1] = 0;
  914|  28.3k|  int alen = 4 + (int)strlen((const char *)(avalue + 4));
  915|       |
  916|       |  /* RFC 3489 Section 11.2.9 requires a reason phrase length that is a multiple of 4;
  917|       |   * RFC 8489 Section 14 requires the declared length to exclude padding. */
  918|  28.3k|  if (pad_reason_phrase) {
  ------------------
  |  Branch (918:7): [True: 4.02k, False: 24.2k]
  ------------------
  919|  4.02k|    const int rem = alen % 4;
  920|  4.02k|    if (rem) {
  ------------------
  |  Branch (920:9): [True: 1.93k, False: 2.09k]
  ------------------
  921|  1.93k|      alen += (4 - rem);
  922|  1.93k|    }
  923|  4.02k|  }
  924|       |
  925|  28.3k|  stun_attr_add_str(buf, len, STUN_ATTRIBUTE_ERROR_CODE, (uint8_t *)avalue, alen);
  ------------------
  |  |  103|  28.3k|#define STUN_ATTRIBUTE_ERROR_CODE (0x0009)
  ------------------
  926|  28.3k|  if (id) {
  ------------------
  |  Branch (926:7): [True: 28.3k, False: 0]
  ------------------
  927|  28.3k|    stun_tid_message_cpy(buf, id);
  928|  28.3k|  }
  929|  28.3k|}
ns_turn_msg.c:has_prefix:
 1065|  7.22k|static inline bool has_prefix(const char *buf, size_t blen, const char *prefix, bool ignore_case) {
 1066|  7.22k|  if (!buf || !prefix) {
  ------------------
  |  Branch (1066:7): [True: 0, False: 7.22k]
  |  Branch (1066:15): [True: 0, False: 7.22k]
  ------------------
 1067|      0|    return false;
 1068|      0|  }
 1069|       |
 1070|  7.22k|  const size_t prefix_len = strlen(prefix);
 1071|  7.22k|  return (prefix_len <= blen) && sheadof(prefix, buf, ignore_case);
  ------------------
  |  Branch (1071:10): [True: 7.22k, False: 0]
  |  Branch (1071:34): [True: 744, False: 6.48k]
  ------------------
 1072|  7.22k|}
ns_turn_msg.c:sheadof:
 1030|   620k|static inline bool sheadof(const char *head, const char *full, bool ignore_case) {
 1031|   678k|  while (*head) {
  ------------------
  |  Branch (1031:10): [True: 675k, False: 2.43k]
  ------------------
 1032|   675k|    if (*head != *full) {
  ------------------
  |  Branch (1032:9): [True: 626k, False: 49.3k]
  ------------------
 1033|   626k|      if (ignore_case && (tolower((unsigned char)*head) == tolower((unsigned char)*full))) {
  ------------------
  |  Branch (1033:11): [True: 230k, False: 396k]
  |  Branch (1033:26): [True: 8.61k, False: 221k]
  |  Branch (1033:27): [True: 0, False: 0]
  |  Branch (1033:27): [True: 0, False: 0]
  |  Branch (1033:27): [Folded, False: 230k]
  |  Branch (1033:60): [True: 0, False: 0]
  |  Branch (1033:60): [True: 0, False: 0]
  |  Branch (1033:60): [Folded, False: 230k]
  ------------------
 1034|       |        // OK
 1035|   617k|      } else {
 1036|   617k|        return false;
 1037|   617k|      }
 1038|   626k|    }
 1039|  58.0k|    ++head;
 1040|  58.0k|    ++full;
 1041|  58.0k|  }
 1042|  2.43k|  return true;
 1043|   620k|}
ns_turn_msg.c:findstr:
 1045|  1.99k|static inline const char *findstr(const char *hay, size_t slen, const char *needle, bool ignore_case) {
 1046|  1.99k|  const char *ret = NULL;
 1047|       |
 1048|  1.99k|  if (hay && slen && needle) {
  ------------------
  |  Branch (1048:7): [True: 1.99k, False: 0]
  |  Branch (1048:14): [True: 1.99k, False: 0]
  |  Branch (1048:22): [True: 1.99k, False: 0]
  ------------------
 1049|  1.99k|    const size_t nlen = strlen(needle);
 1050|  1.99k|    if (nlen <= slen) {
  ------------------
  |  Branch (1050:9): [True: 1.95k, False: 42]
  ------------------
 1051|  1.95k|      const size_t smax = slen - nlen + 1;
 1052|  1.95k|      const char *sp = hay;
 1053|   613k|      for (size_t i = 0; i < smax; ++i) {
  ------------------
  |  Branch (1053:26): [True: 612k, False: 262]
  ------------------
 1054|   612k|        if (sheadof(needle, sp + i, ignore_case)) {
  ------------------
  |  Branch (1054:13): [True: 1.69k, False: 611k]
  ------------------
 1055|  1.69k|          ret = sp + i;
 1056|  1.69k|          break;
 1057|  1.69k|        }
 1058|   612k|      }
 1059|  1.95k|    }
 1060|  1.99k|  }
 1061|       |
 1062|  1.99k|  return ret;
 1063|  1.99k|}
ns_turn_msg.c:stun_tid_from_string:
 1460|   150k|static void stun_tid_from_string(const uint8_t *s, stun_tid *id) {
 1461|   150k|  if (s && id) {
  ------------------
  |  Branch (1461:7): [True: 150k, False: 0]
  |  Branch (1461:12): [True: 150k, False: 0]
  ------------------
 1462|   150k|    memcpy(id->tsx_id, s, STUN_TID_SIZE);
  ------------------
  |  |   53|   150k|#define STUN_TID_SIZE (12)
  ------------------
 1463|   150k|  }
 1464|   150k|}
ns_turn_msg.c:stun_tid_string_cpy:
 1454|   134k|static void stun_tid_string_cpy(uint8_t *s, const stun_tid *id) {
 1455|   134k|  if (s && id) {
  ------------------
  |  Branch (1455:7): [True: 134k, False: 0]
  |  Branch (1455:12): [True: 134k, False: 0]
  ------------------
 1456|   134k|    memcpy(s, id->tsx_id, STUN_TID_SIZE);
  ------------------
  |  |   53|   134k|#define STUN_TID_SIZE (12)
  ------------------
 1457|   134k|  }
 1458|   134k|}
ns_turn_msg.c:turn_random_tid_size:
  154|  78.2k|static void turn_random_tid_size(void *id) {
  155|  78.2k|  uint8_t *ar = (uint8_t *)id;
  156|  78.2k|#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
  157|  78.2k|  if (ar) {
  ------------------
  |  Branch (157:7): [True: 78.2k, False: 0]
  ------------------
  158|   313k|    for (size_t i = 0; i < 3; ++i) {
  ------------------
  |  Branch (158:24): [True: 234k, False: 78.2k]
  ------------------
  159|   234k|      const uint32_t r = (uint32_t)turn_random_number();
  160|   234k|      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  161|   234k|    }
  162|  78.2k|  }
  163|       |#else
  164|       |  if (!RAND_bytes((unsigned char *)ar, 12)) {
  165|       |    for (size_t i = 0; i < 3; ++i) {
  166|       |      const uint32_t r = (uint32_t)turn_random_number();
  167|       |      memcpy(ar + i * sizeof(r), &r, sizeof(r));
  168|       |    }
  169|       |  }
  170|       |#endif
  171|  78.2k|}
ns_turn_msg.c:stun_attr_check_valid:
 1658|   551k|static stun_attr_ref stun_attr_check_valid(stun_attr_ref attr, size_t remaining) {
 1659|   551k|  if (remaining >= 4) {
  ------------------
  |  Branch (1659:7): [True: 551k, False: 877]
  ------------------
 1660|       |    /* Read the size of the attribute */
 1661|   551k|    size_t attrlen = stun_attr_get_len(attr);
 1662|   551k|    remaining -= 4;
 1663|       |
 1664|       |    /* Round to boundary */
 1665|   551k|    const uint16_t rem4 = ((uint16_t)attrlen) & 0x0003;
 1666|   551k|    if (rem4) {
  ------------------
  |  Branch (1666:9): [True: 102k, False: 448k]
  ------------------
 1667|   102k|      attrlen = attrlen + 4 - (int)rem4;
 1668|   102k|    }
 1669|       |
 1670|       |    /* Check that there's enough space remaining */
 1671|   551k|    if (attrlen <= remaining) {
  ------------------
  |  Branch (1671:9): [True: 547k, False: 3.82k]
  ------------------
 1672|   547k|      return attr;
 1673|   547k|    }
 1674|   551k|  }
 1675|       |
 1676|  4.70k|  return NULL;
 1677|   551k|}
ns_turn_msg.c:stun_set_command_message_len_str:
  547|   130k|static bool stun_set_command_message_len_str(uint8_t *buf, int len) {
  548|   130k|  if (len < STUN_HEADER_LENGTH) {
  ------------------
  |  |   46|   130k|#define STUN_HEADER_LENGTH (20)
  ------------------
  |  Branch (548:7): [True: 0, False: 130k]
  ------------------
  549|      0|    return false;
  550|      0|  }
  551|   130k|  turn_write_u16(buf + 2, (uint16_t)(len - STUN_HEADER_LENGTH));
  ------------------
  |  |   46|   130k|#define STUN_HEADER_LENGTH (20)
  ------------------
  552|       |  return true;
  553|   130k|}

stun_addr_encode:
   42|  50.8k|int stun_addr_encode(const ioa_addr *ca, uint8_t *cfield, int *clen, int xor_ed, uint32_t mc, const uint8_t *tsx_id) {
   43|       |
   44|  50.8k|  if (!cfield || !clen || !ca || !tsx_id) {
  ------------------
  |  Branch (44:7): [True: 0, False: 50.8k]
  |  Branch (44:18): [True: 0, False: 50.8k]
  |  Branch (44:27): [True: 0, False: 50.8k]
  |  Branch (44:34): [True: 0, False: 50.8k]
  ------------------
   45|      0|    return -1;
   46|      0|  }
   47|       |
   48|  50.8k|  if (ca->ss.sa_family == AF_INET || ca->ss.sa_family == 0) {
  ------------------
  |  Branch (48:7): [True: 26.9k, False: 23.8k]
  |  Branch (48:38): [True: 5.40k, False: 18.4k]
  ------------------
   49|       |
   50|       |    /* IPv4 address */
   51|       |
   52|  32.3k|    *clen = 8;
   53|       |
   54|  32.3k|    cfield[0] = 0;
   55|  32.3k|    cfield[1] = 1; // IPv4 family
   56|       |
   57|  32.3k|    if (xor_ed) {
  ------------------
  |  Branch (57:9): [True: 27.0k, False: 5.29k]
  ------------------
   58|       |
   59|       |      /* Port */
   60|  27.0k|      const uint16_t port = (ca->s4.sin_port) ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  27.0k|#define nswap16(s) ntohs(s)
  ------------------
   61|  27.0k|      memcpy(cfield + 2, &port, sizeof(port));
   62|       |
   63|       |      /* Address */
   64|  27.0k|      const uint32_t addr = (ca->s4.sin_addr.s_addr) ^ nswap32(mc);
  ------------------
  |  |   87|  27.0k|#define nswap32(ul) ntohl(ul)
  ------------------
   65|  27.0k|      memcpy(cfield + 4, &addr, sizeof(addr));
   66|       |
   67|  27.0k|    } else {
   68|       |
   69|       |      /* Port */
   70|  5.29k|      const uint16_t port = ca->s4.sin_port;
   71|  5.29k|      memcpy(cfield + 2, &port, sizeof(port));
   72|       |
   73|       |      /* Address */
   74|  5.29k|      const uint32_t addr = ca->s4.sin_addr.s_addr;
   75|  5.29k|      memcpy(cfield + 4, &addr, sizeof(addr));
   76|  5.29k|    }
   77|       |
   78|  32.3k|  } else if (ca->ss.sa_family == AF_INET6) {
  ------------------
  |  Branch (78:14): [True: 18.4k, False: 0]
  ------------------
   79|       |
   80|       |    /* IPv6 address */
   81|       |
   82|  18.4k|    *clen = 20;
   83|       |
   84|  18.4k|    cfield[0] = 0;
   85|  18.4k|    cfield[1] = 2; // IPv6 family
   86|       |
   87|  18.4k|    if (xor_ed) {
  ------------------
  |  Branch (87:9): [True: 14.4k, False: 4.02k]
  ------------------
   88|       |
   89|  14.4k|      unsigned int i;
   90|  14.4k|      uint8_t *dst = ((uint8_t *)cfield) + 4;
   91|  14.4k|      const uint8_t *src = (const uint8_t *)&(ca->s6.sin6_addr);
   92|  14.4k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  14.4k|#define nswap32(ul) ntohl(ul)
  ------------------
   93|       |
   94|       |      /* Port */
   95|  14.4k|      const uint16_t port = ca->s6.sin6_port ^ nswap16(mc >> 16);
  ------------------
  |  |   86|  14.4k|#define nswap16(s) ntohs(s)
  ------------------
   96|  14.4k|      memcpy(cfield + 2, &port, sizeof(port));
   97|       |
   98|       |      /* Address */
   99|       |
  100|  72.1k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (100:19): [True: 57.6k, False: 14.4k]
  ------------------
  101|  57.6k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  102|  57.6k|      }
  103|   187k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (103:19): [True: 173k, False: 14.4k]
  ------------------
  104|   173k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  105|   173k|      }
  106|       |
  107|  14.4k|    } else {
  108|       |
  109|       |      /* Port */
  110|  4.02k|      const uint16_t port = ca->s6.sin6_port;
  111|  4.02k|      memcpy(cfield + 2, &port, sizeof(port));
  112|       |
  113|       |      /* Address */
  114|  4.02k|      memcpy(((uint8_t *)cfield) + 4, &ca->s6.sin6_addr, 16);
  115|  4.02k|    }
  116|       |
  117|  18.4k|  } else {
  118|      0|    return -1;
  119|      0|  }
  120|       |
  121|  50.8k|  return 0;
  122|  50.8k|}
stun_addr_decode:
  124|  94.0k|int stun_addr_decode(ioa_addr *ca, const uint8_t *cfield, int len, int xor_ed, uint32_t mc, const uint8_t *tsx_id) {
  125|       |
  126|  94.0k|  if (!cfield || !len || !ca || !tsx_id || (len < 8)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 94.0k]
  |  Branch (126:18): [True: 0, False: 94.0k]
  |  Branch (126:26): [True: 0, False: 94.0k]
  |  Branch (126:33): [True: 0, False: 94.0k]
  |  Branch (126:44): [True: 4.45k, False: 89.6k]
  ------------------
  127|  4.45k|    return -1;
  128|  4.45k|  }
  129|       |
  130|  89.6k|  if (cfield[0] != 0) {
  ------------------
  |  Branch (130:7): [True: 1.94k, False: 87.6k]
  ------------------
  131|  1.94k|    return -1;
  132|  1.94k|  }
  133|       |
  134|  87.6k|  int sa_family;
  135|       |
  136|  87.6k|  if (cfield[1] == 1) {
  ------------------
  |  Branch (136:7): [True: 56.2k, False: 31.4k]
  ------------------
  137|  56.2k|    sa_family = AF_INET;
  138|  56.2k|  } else if (cfield[1] == 2) {
  ------------------
  |  Branch (138:14): [True: 30.0k, False: 1.41k]
  ------------------
  139|  30.0k|    sa_family = AF_INET6;
  140|  30.0k|  } else {
  141|  1.41k|    return -1;
  142|  1.41k|  }
  143|       |
  144|  86.2k|  ca->ss.sa_family = sa_family;
  145|       |
  146|  86.2k|  if (sa_family == AF_INET) {
  ------------------
  |  Branch (146:7): [True: 56.2k, False: 30.0k]
  ------------------
  147|       |
  148|  56.2k|    if (len != 8) {
  ------------------
  |  Branch (148:9): [True: 960, False: 55.2k]
  ------------------
  149|    960|      return -1;
  150|    960|    }
  151|       |
  152|       |    /* IPv4 address */
  153|       |
  154|       |    /* Port */
  155|  55.2k|    memcpy(&ca->s4.sin_port, cfield + 2, sizeof(ca->s4.sin_port));
  156|       |
  157|       |    /* Address */
  158|  55.2k|    memcpy(&ca->s4.sin_addr.s_addr, cfield + 4, sizeof(ca->s4.sin_addr.s_addr));
  159|       |
  160|  55.2k|    if (xor_ed) {
  ------------------
  |  Branch (160:9): [True: 47.4k, False: 7.81k]
  ------------------
  161|  47.4k|      ca->s4.sin_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  47.4k|#define nswap16(s) ntohs(s)
  ------------------
  162|  47.4k|      ca->s4.sin_addr.s_addr ^= nswap32(mc);
  ------------------
  |  |   87|  47.4k|#define nswap32(ul) ntohl(ul)
  ------------------
  163|  47.4k|    }
  164|       |
  165|  55.2k|  } else if (sa_family == AF_INET6) {
  ------------------
  |  Branch (165:14): [True: 30.0k, False: 0]
  ------------------
  166|       |
  167|       |    /* IPv6 address */
  168|       |
  169|  30.0k|    if (len != 20) {
  ------------------
  |  Branch (169:9): [True: 621, False: 29.4k]
  ------------------
  170|    621|      return -1;
  171|    621|    }
  172|       |
  173|       |    /* Port */
  174|  29.4k|    memcpy(&ca->s6.sin6_port, cfield + 2, sizeof(ca->s6.sin6_port));
  175|       |
  176|       |    /* Address */
  177|  29.4k|    memcpy(&ca->s6.sin6_addr, ((const uint8_t *)cfield) + 4, 16);
  178|       |
  179|  29.4k|    if (xor_ed) {
  ------------------
  |  Branch (179:9): [True: 23.5k, False: 5.89k]
  ------------------
  180|       |
  181|  23.5k|      unsigned int i;
  182|  23.5k|      uint8_t *dst;
  183|  23.5k|      const uint8_t *src;
  184|  23.5k|      uint32_t magic = nswap32(mc);
  ------------------
  |  |   87|  23.5k|#define nswap32(ul) ntohl(ul)
  ------------------
  185|       |
  186|       |      /* Port */
  187|  23.5k|      ca->s6.sin6_port ^= nswap16(mc >> 16);
  ------------------
  |  |   86|  23.5k|#define nswap16(s) ntohs(s)
  ------------------
  188|       |
  189|       |      /* Address */
  190|  23.5k|      src = ((const uint8_t *)cfield) + 4;
  191|  23.5k|      dst = (uint8_t *)&ca->s6.sin6_addr;
  192|   117k|      for (i = 0; i < 4; ++i) {
  ------------------
  |  Branch (192:19): [True: 94.0k, False: 23.5k]
  ------------------
  193|  94.0k|        dst[i] = (uint8_t)(src[i] ^ ((const uint8_t *)&magic)[i]);
  194|  94.0k|      }
  195|   305k|      for (i = 0; i < 12; ++i) {
  ------------------
  |  Branch (195:19): [True: 282k, False: 23.5k]
  ------------------
  196|   282k|        dst[i + 4] = (uint8_t)(src[i + 4] ^ tsx_id[i]);
  197|   282k|      }
  198|  23.5k|    }
  199|       |
  200|  29.4k|  } else {
  201|      0|    return -1;
  202|      0|  }
  203|       |
  204|  84.6k|  return 0;
  205|  86.2k|}

ns_turn_msg.c:turn_read_u16:
  127|  4.56M|static inline uint16_t turn_read_u16(const void *field) {
  128|  4.56M|  uint16_t v;
  129|  4.56M|  memcpy(&v, field, sizeof(v));
  130|       |  return nswap16(v);
  ------------------
  |  |   86|  4.56M|#define nswap16(s) ntohs(s)
  ------------------
  131|  4.56M|}
ns_turn_msg.c:turn_read_u32:
  133|   154k|static inline uint32_t turn_read_u32(const void *field) {
  134|   154k|  uint32_t v;
  135|   154k|  memcpy(&v, field, sizeof(v));
  136|       |  return nswap32(v);
  ------------------
  |  |   87|   154k|#define nswap32(ul) ntohl(ul)
  ------------------
  137|   154k|}
ns_turn_msg.c:turn_write_u16:
  145|   547k|static inline void turn_write_u16(void *field, uint16_t v) {
  146|       |  const uint16_t raw = nswap16(v);
  ------------------
  |  |   86|   547k|#define nswap16(s) ntohs(s)
  ------------------
  147|   547k|  memcpy(field, &raw, sizeof(raw));
  148|   547k|}
ns_turn_msg.c:turn_write_u32:
  150|  76.5k|static inline void turn_write_u32(void *field, uint32_t v) {
  151|       |  const uint32_t raw = nswap32(v);
  ------------------
  |  |   87|  76.5k|#define nswap32(ul) ntohl(ul)
  ------------------
  152|  76.5k|  memcpy(field, &raw, sizeof(raw));
  153|  76.5k|}
ns_turn_msg.c:_ioa_ntoh64:
   90|  6.56k|static inline uint64_t _ioa_ntoh64(uint64_t v) {
   91|  6.56k|#if BYTE_ORDER == LITTLE_ENDIAN
   92|  6.56k|  uint8_t *src = (uint8_t *)&v;
   93|  6.56k|  uint8_t *dst = src + 7;
   94|  32.8k|  while (src < dst) {
  ------------------
  |  Branch (94:10): [True: 26.2k, False: 6.56k]
  ------------------
   95|  26.2k|    uint8_t vdst = *dst;
   96|  26.2k|    *(dst--) = *src;
   97|  26.2k|    *(src++) = vdst;
   98|  26.2k|  }
   99|       |#elif BYTE_ORDER == BIG_ENDIAN
  100|       |  /* OK */
  101|       |#else
  102|       |#error WRONG BYTE_ORDER SETTING
  103|       |#endif
  104|  6.56k|  return v;
  105|  6.56k|}

