Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.7 KiB

7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. From 66c1f59300b4841caebd5e8cebd38dfe73dc197e Mon Sep 17 00:00:00 2001
  2. From: Brent Cook <busterb@gmail.com>
  3. Date: Tue, 30 Dec 2014 09:02:50 -0600
  4. Subject: [PATCH 03/13] conditionally fill in sin_len/sin6_len if they exist
  5. ---
  6. src/usr.sbin/ntpd/config.c | 8 ++++++++
  7. src/usr.sbin/ntpd/parse.y | 8 +++++---
  8. 2 files changed, 13 insertions(+), 3 deletions(-)
  9. diff --git a/src/usr.sbin/ntpd/config.c b/src/usr.sbin/ntpd/config.c
  10. index e3eeed3d6..a84635ab7 100644
  11. --- a/src/usr.sbin/ntpd/config.c
  12. +++ b/src/usr.sbin/ntpd/config.c
  13. @@ -72,7 +72,9 @@ host_v4(const char *s)
  14. if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
  15. fatal(NULL);
  16. sa_in = (struct sockaddr_in *)&h->ss;
  17. +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  18. sa_in->sin_len = sizeof(struct sockaddr_in);
  19. +#endif
  20. sa_in->sin_family = AF_INET;
  21. sa_in->sin_addr.s_addr = ina.s_addr;
  22. @@ -94,7 +96,9 @@ host_v6(const char *s)
  23. if ((h = calloc(1, sizeof(struct ntp_addr))) == NULL)
  24. fatal(NULL);
  25. sa_in6 = (struct sockaddr_in6 *)&h->ss;
  26. +#ifdef SIN6_LEN
  27. sa_in6->sin6_len = sizeof(struct sockaddr_in6);
  28. +#endif
  29. sa_in6->sin6_family = AF_INET6;
  30. memcpy(&sa_in6->sin6_addr,
  31. &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
  32. @@ -156,12 +160,16 @@ host_dns(const char *s, struct ntp_addr **hn)
  33. h->ss.ss_family = res->ai_family;
  34. if (res->ai_family == AF_INET) {
  35. sa_in = (struct sockaddr_in *)&h->ss;
  36. +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  37. sa_in->sin_len = sizeof(struct sockaddr_in);
  38. +#endif
  39. sa_in->sin_addr.s_addr = ((struct sockaddr_in *)
  40. res->ai_addr)->sin_addr.s_addr;
  41. } else {
  42. sa_in6 = (struct sockaddr_in6 *)&h->ss;
  43. +#ifdef SIN6_LEN
  44. sa_in6->sin6_len = sizeof(struct sockaddr_in6);
  45. +#endif
  46. memcpy(&sa_in6->sin6_addr, &((struct sockaddr_in6 *)
  47. res->ai_addr)->sin6_addr, sizeof(struct in6_addr));
  48. }
  49. diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y
  50. index af4ad1731..8197fe953 100644
  51. --- a/src/usr.sbin/ntpd/parse.y
  52. +++ b/src/usr.sbin/ntpd/parse.y
  53. @@ -137,14 +137,16 @@ main : LISTEN ON address listen_opts {
  54. struct sockaddr_in6 sin6;
  55. sin4.sin_family = AF_INET;
  56. - sin4.sin_len = sizeof(struct sockaddr_in);
  57. sin6.sin6_family = AF_INET6;
  58. +#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  59. + sin4.sin_len = sizeof(struct sockaddr_in);
  60. sin6.sin6_len = sizeof(struct sockaddr_in6);
  61. +#endif
  62. if (inet_pton(AF_INET, $3, &sin4.sin_addr) == 1)
  63. - memcpy(&query_addr4, &sin4, sin4.sin_len);
  64. + memcpy(&query_addr4, &sin4, sizeof(struct in_addr));
  65. else if (inet_pton(AF_INET6, $3, &sin6.sin6_addr) == 1)
  66. - memcpy(&query_addr6, &sin6, sin6.sin6_len);
  67. + memcpy(&query_addr6, &sin6, sizeof(struct in6_addr));
  68. else {
  69. yyerror("invalid IPv4 or IPv6 address: %s\n",
  70. $3);
  71. --
  72. 2.13.0