Move includes to header

This commit is contained in:
Jeremy Lakeman 2011-07-08 14:36:54 +09:30
parent a4591a0d87
commit ca09fcf104
2 changed files with 26 additions and 21 deletions

18
mphlr.h
View File

@ -29,6 +29,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "win32/win32.h" #include "win32/win32.h"
#else #else
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_LINUX_IF_H
#include <linux/if.h>
#endif
#ifdef HAVE_LINUX_NETLINK_H
#include <linux/netlink.h>
#endif
#ifdef HAVE_LINUX_RTNETLINK_H
#include <linux/rtnetlink.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
#endif #endif
#if !defined(FORASTERISK) && !defined(s_addr) #if !defined(FORASTERISK) && !defined(s_addr)

29
peers.c
View File

@ -19,25 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "mphlr.h" #include "mphlr.h"
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_LINUX_IF_H
#include <linux/if.h>
#endif
#ifdef HAVE_LINUX_NETLINK_H
#include <linux/netlink.h>
#endif
#ifdef HAVE_LINUX_RTNETLINK_H
#include <linux/rtnetlink.h>
#endif
#ifdef HAVE_IFADDRS_H
#include <ifaddrs.h>
#endif
char *batman_socket=NULL; char *batman_socket=NULL;
char *batman_peerfile=NULL; char *batman_peerfile=NULL;
@ -79,6 +60,8 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
size_t bytesRead; size_t bytesRead;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
if (debug>1) fprintf(stderr,"Reading broadcast addresses\n");
netsock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); netsock = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
memset(&addrRequest, 0, sizeof(addrRequest)); memset(&addrRequest, 0, sizeof(addrRequest));
@ -89,8 +72,12 @@ int getBroadcastAddresses(struct in_addr peers[],int *peer_count,int peer_max){
addrRequest.msg.ifa_family = AF_INET; addrRequest.msg.ifa_family = AF_INET;
addrRequest.msg.ifa_index = 0; // All interfaces. addrRequest.msg.ifa_index = 0; // All interfaces.
TEMP_FAILURE_RETRY(send(netsock, &addrRequest, addrRequest.netlinkHeader.nlmsg_len, 0)); while (send(netsock, &addrRequest, addrRequest.netlinkHeader.nlmsg_len, 0)==EINTR);
while((bytesRead = TEMP_FAILURE_RETRY(recv(netsock, buff, sizeof(buff), 0)))>0){
while(1){
while((bytesRead = recv(netsock, buff, sizeof(buff), 0))==EINTR);
if (bytesRead<=0) break;
for (hdr = (struct nlmsghdr*)buff; for (hdr = (struct nlmsghdr*)buff;
NLMSG_OK(hdr, (size_t)bytesRead); NLMSG_OK(hdr, (size_t)bytesRead);
hdr = NLMSG_NEXT(hdr, bytesRead)) { hdr = NLMSG_NEXT(hdr, bytesRead)) {