for (p = if_conf.ifc_buf;
p < if_conf.ifc_buf + if_conf.ifc_len;
p += entry_len) {
- struct ifreq *cur_req;
-
- /* let's hope the pointer is aligned */
- cur_req = (struct ifreq*) p;
+ /* p may be misaligned on macos. */
+ struct ifreq cur_req;
+ memcpy(&cur_req, p, sizeof(struct ifreq));
#ifdef HAVE_SOCKADDR_SA_LEN
- entry_len = cur_req->ifr_addr.sa_len + sizeof(cur_req->ifr_name);
+ entry_len = cur_req.ifr_addr.sa_len + sizeof(cur_req.ifr_name);
#else
/* if there's no sa_len, assume the ifr_addr field is a sockaddr */
- entry_len = sizeof(struct sockaddr) + sizeof(cur_req->ifr_name);
+ entry_len = sizeof(struct sockaddr) + sizeof(cur_req.ifr_name);
#endif
- entry_len = MAX(entry_len, sizeof(*cur_req));
+ entry_len = MAX(entry_len, sizeof(cur_req));
- if ((((struct sockaddr*)&cur_req->ifr_addr)->sa_family == AF_INET) &&
- (((struct sockaddr_in*)&cur_req->ifr_addr)->sin_addr.s_addr ==
+ if ((((struct sockaddr*)&cur_req.ifr_addr)->sa_family == AF_INET) &&
+ (((struct sockaddr_in*)&cur_req.ifr_addr)->sin_addr.s_addr ==
addr->s_addr)) {
#if defined(SIOCGIFINDEX)
- if (ioctl(php_sock->bsd_socket, SIOCGIFINDEX, (char*)cur_req)
+ if (ioctl(php_sock->bsd_socket, SIOCGIFINDEX, (char*)&cur_req)
== -1) {
#elif defined(HAVE_IF_NAMETOINDEX)
unsigned index_tmp;
- if ((index_tmp = if_nametoindex(cur_req->ifr_name)) == 0) {
+ if ((index_tmp = if_nametoindex(cur_req.ifr_name)) == 0) {
#else
#error Neither SIOCGIFINDEX nor if_nametoindex are available
#endif
goto err;
} else {
#if defined(SIOCGIFINDEX)
- *if_index = cur_req->ifr_ifindex;
+ *if_index = cur_req.ifr_ifindex;
#else
*if_index = index_tmp;
#endif