102-deprecate-load16-be-replace-with-ntohs.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From f4ee43fa27e00a573d90a8cac68f12655570bbf7 Mon Sep 17 00:00:00 2001
  2. From: lwb1978 <[email protected]>
  3. Date: Tue, 4 Feb 2025 15:51:17 +0800
  4. Subject: [PATCH] Deprecate load16_be() function in favor to ntohs() function
  5. ---
  6. src/aead.c | 2 +-
  7. src/local.c | 6 +++---
  8. src/server.c | 2 +-
  9. src/udprelay.c | 2 +-
  10. src/utils.c | 8 --------
  11. src/utils.h | 1 -
  12. 6 files changed, 6 insertions(+), 15 deletions(-)
  13. --- a/src/aead.c
  14. +++ b/src/aead.c
  15. @@ -605,7 +605,7 @@ aead_chunk_decrypt(cipher_ctx_t *ctx, ui
  16. return CRYPTO_ERROR;
  17. assert(*plen == CHUNK_SIZE_LEN);
  18. - mlen = load16_be(len_buf);
  19. + mlen = ntohs(*(uint16_t*)len_buf);
  20. mlen = mlen & CHUNK_SIZE_MASK;
  21. if (mlen == 0)
  22. --- a/src/local.c
  23. +++ b/src/local.c
  24. @@ -390,7 +390,7 @@ server_handshake(EV_P_ ev_io *w, buffer_
  25. abuf->len += in_addr_len + 2;
  26. if (acl || verbose) {
  27. - uint16_t p = load16_be(buf->data + request_len + in_addr_len);
  28. + uint16_t p = ntohs(*(uint16_t*)(buf->data + request_len + in_addr_len));
  29. if (!inet_ntop(AF_INET, (const void *)(buf->data + request_len),
  30. ip, INET_ADDRSTRLEN)) {
  31. LOGI("inet_ntop(AF_INET): %s", strerror(errno));
  32. @@ -408,7 +408,7 @@ server_handshake(EV_P_ ev_io *w, buffer_
  33. abuf->len += name_len + 2;
  34. if (acl || verbose) {
  35. - uint16_t p = load16_be(buf->data + request_len + 1 + name_len);
  36. + uint16_t p = ntohs(*(uint16_t*)(buf->data + request_len + 1 + name_len));
  37. memcpy(host, buf->data + request_len + 1, name_len);
  38. host[name_len] = '\0';
  39. sprintf(port, "%d", p);
  40. @@ -422,7 +422,7 @@ server_handshake(EV_P_ ev_io *w, buffer_
  41. abuf->len += in6_addr_len + 2;
  42. if (acl || verbose) {
  43. - uint16_t p = load16_be(buf->data + request_len + in6_addr_len);
  44. + uint16_t p = ntohs(*(uint16_t*)(buf->data + request_len + in6_addr_len));
  45. if (!inet_ntop(AF_INET6, (const void *)(buf->data + request_len),
  46. ip, INET6_ADDRSTRLEN)) {
  47. LOGI("inet_ntop(AF_INET6): %s", strerror(errno));
  48. --- a/src/server.c
  49. +++ b/src/server.c
  50. @@ -1137,7 +1137,7 @@ server_recv_cb(EV_P_ ev_io *w, int reven
  51. return;
  52. }
  53. - port = ntohs(load16_be(server->buf->data + offset));
  54. + port = *(uint16_t*)(server->buf->data + offset);
  55. offset += 2;
  56. --- a/src/udprelay.c
  57. +++ b/src/udprelay.c
  58. @@ -316,7 +316,7 @@ parse_udprelay_header(const char *buf, c
  59. }
  60. if (port != NULL) {
  61. - sprintf(port, "%d", load16_be(buf + offset));
  62. + sprintf(port, "%d", ntohs(*(uint16_t*)(buf + offset)));
  63. }
  64. offset += 2;
  65. --- a/src/utils.c
  66. +++ b/src/utils.c
  67. @@ -571,14 +571,6 @@ get_default_conf(void)
  68. #endif
  69. }
  70. -uint16_t
  71. -load16_be(const void *s)
  72. -{
  73. - const uint8_t *in = (const uint8_t *)s;
  74. - return ((uint16_t)in[0] << 8)
  75. - | ((uint16_t)in[1]);
  76. -}
  77. -
  78. int
  79. get_mptcp(int enable)
  80. {
  81. --- a/src/utils.h
  82. +++ b/src/utils.h
  83. @@ -249,7 +249,6 @@ void *ss_realloc(void *ptr, size_t new_s
  84. int ss_is_ipv6addr(const char *addr);
  85. char *get_default_conf(void);
  86. -uint16_t load16_be(const void *s);
  87. int get_mptcp(int enable);
  88. #endif // _UTILS_H