170-enable-getifaddrs.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. --- a/libc/inet/ifaddrs.c
  2. +++ b/libc/inet/ifaddrs.c
  3. @@ -38,6 +38,7 @@
  4. #include <unistd.h>
  5. #include "netlinkaccess.h"
  6. +#include "ifaddrs.h"
  7. libc_hidden_proto(socket)
  8. libc_hidden_proto(close)
  9. @@ -57,7 +58,6 @@ libc_hidden_proto(abort)
  10. #if __ASSUME_NETLINK_SUPPORT
  11. -#if 0 /* unused code */
  12. /* struct to hold the data for one ifaddrs entry, so we can allocate
  13. everything at once. */
  14. struct ifaddrs_storage
  15. @@ -74,8 +74,6 @@ struct ifaddrs_storage
  16. } addr, netmask, broadaddr;
  17. char name[IF_NAMESIZE + 1];
  18. };
  19. -#endif /* unused code */
  20. -
  21. void
  22. __netlink_free_handle (struct netlink_handle *h)
  23. @@ -323,8 +321,6 @@ __netlink_open (struct netlink_handle *h
  24. return 0;
  25. }
  26. -
  27. -#if 0 /* unused code */
  28. /* We know the number of RTM_NEWLINK entries, so we reserve the first
  29. # of entries for this type. All RTM_NEWADDR entries have an index
  30. pointer to the RTM_NEWLINK entry. To find the entry, create
  31. @@ -562,7 +558,7 @@ getifaddrs (struct ifaddrs **ifap)
  32. if ((rta_payload + 1) <= sizeof (ifas[ifa_index].name))
  33. {
  34. ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
  35. - *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
  36. + *(char *) mempcpy (ifas[ifa_index].name, rta_data,
  37. rta_payload) = '\0';
  38. }
  39. break;
  40. @@ -761,7 +757,7 @@ getifaddrs (struct ifaddrs **ifap)
  41. if (rta_payload + 1 <= sizeof (ifas[ifa_index].name))
  42. {
  43. ifas[ifa_index].ifa.ifa_name = ifas[ifa_index].name;
  44. - *(char *) __mempcpy (ifas[ifa_index].name, rta_data,
  45. + *(char *) mempcpy (ifas[ifa_index].name, rta_data,
  46. rta_payload) = '\0';
  47. }
  48. else
  49. @@ -872,6 +868,4 @@ freeifaddrs (struct ifaddrs *ifa)
  50. }
  51. #endif
  52. -#endif /* unused code */
  53. -
  54. #endif /* __ASSUME_NETLINK_SUPPORT */
  55. --- a/libc/inet/netlinkaccess.h
  56. +++ b/libc/inet/netlinkaccess.h
  57. @@ -61,14 +61,11 @@ struct netlink_handle
  58. };
  59. -#if 0 /* unused code */
  60. #if __ASSUME_NETLINK_SUPPORT == 0
  61. extern int __no_netlink_support attribute_hidden;
  62. #else
  63. # define __no_netlink_support 0
  64. #endif
  65. -#endif /* unused code */
  66. -
  67. extern int __netlink_open (struct netlink_handle *h) attribute_hidden;
  68. extern void __netlink_close (struct netlink_handle *h) attribute_hidden;
  69. --- /dev/null
  70. +++ b/include/ifaddrs.h
  71. @@ -0,0 +1,74 @@
  72. +/* ifaddrs.h -- declarations for getting network interface addresses
  73. + Copyright (C) 2002 Free Software Foundation, Inc.
  74. + This file is part of the GNU C Library.
  75. +
  76. + The GNU C Library is free software; you can redistribute it and/or
  77. + modify it under the terms of the GNU Lesser General Public
  78. + License as published by the Free Software Foundation; either
  79. + version 2.1 of the License, or (at your option) any later version.
  80. +
  81. + The GNU C Library is distributed in the hope that it will be useful,
  82. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  83. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  84. + Lesser General Public License for more details.
  85. +
  86. + You should have received a copy of the GNU Lesser General Public
  87. + License along with the GNU C Library; if not, write to the Free
  88. + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  89. + 02111-1307 USA. */
  90. +
  91. +#ifndef _IFADDRS_H
  92. +#define _IFADDRS_H 1
  93. +
  94. +#include <features.h>
  95. +#include <sys/socket.h>
  96. +
  97. +__BEGIN_DECLS
  98. +
  99. +/* The `getifaddrs' function generates a linked list of these structures.
  100. + Each element of the list describes one network interface. */
  101. +struct ifaddrs
  102. +{
  103. + struct ifaddrs *ifa_next; /* Pointer to the next structure. */
  104. +
  105. + char *ifa_name; /* Name of this network interface. */
  106. + unsigned int ifa_flags; /* Flags as from SIOCGIFFLAGS ioctl. */
  107. +
  108. + struct sockaddr *ifa_addr; /* Network address of this interface. */
  109. + struct sockaddr *ifa_netmask; /* Netmask of this interface. */
  110. + union
  111. + {
  112. + /* At most one of the following two is valid. If the IFF_BROADCAST
  113. + bit is set in `ifa_flags', then `ifa_broadaddr' is valid. If the
  114. + IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid.
  115. + It is never the case that both these bits are set at once. */
  116. + struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
  117. + struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
  118. + } ifa_ifu;
  119. + /* These very same macros are defined by <net/if.h> for `struct ifaddr'.
  120. + So if they are defined already, the existing definitions will be fine. */
  121. +# ifndef ifa_broadaddr
  122. +# define ifa_broadaddr ifa_ifu.ifu_broadaddr
  123. +# endif
  124. +# ifndef ifa_dstaddr
  125. +# define ifa_dstaddr ifa_ifu.ifu_dstaddr
  126. +# endif
  127. +
  128. + void *ifa_data; /* Address-specific data (may be unused). */
  129. +};
  130. +
  131. +
  132. +/* Create a linked list of `struct ifaddrs' structures, one for each
  133. + network interface on the host machine. If successful, store the
  134. + list in *IFAP and return 0. On errors, return -1 and set `errno'.
  135. +
  136. + The storage returned in *IFAP is allocated dynamically and can
  137. + only be properly freed by passing it to `freeifaddrs'. */
  138. +extern int getifaddrs (struct ifaddrs **__ifap) __THROW;
  139. +
  140. +/* Reclaim the storage allocated by a previous `getifaddrs' call. */
  141. +extern void freeifaddrs (struct ifaddrs *__ifa) __THROW;
  142. +
  143. +__END_DECLS
  144. +
  145. +#endif /* ifaddrs.h */