discvr.h 3.43 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1 2 3 4 5 6 7
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2002 University of Utah and the Flux Group.
 * All rights reserved.
 */

/*$Id: discvr.h,v 1.10 2002-07-04 14:10:55 stoller Exp $*/
Kristin Wright's avatar
Kristin Wright committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

#ifndef _TOPD_DISCVR_H_
#define _TOPD_DISCVR_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/time.h>

#include <netinet/in.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>		
#include <arpa/inet.h>

#define MAX_HOSTNAME       256
#define	INET6_ADDRSTRLEN    46	/* Max size of IPv6 address string: */
#define	SERV_PORT         9788	/* Server port */
#define	IFHADDRSIZ           8	/* UNP recommends allowing for 64-bit EUI-64 in future */
#define ETHADDRSIZ           6  /* Cheat and use for for many MAC address sizes */
#define	MAXLINE	          4096	/* Max text line length; only 
				 * needed until true packets are generated.  -lkw
				 */

38 39 40 41

#define Q_LISTEN 			1
#define QR_LISTEN			2

Kristin Wright's avatar
Kristin Wright committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#define print_nodeID(x) println_haddr((x), ETHADDRSIZ)

#define INCR_ALIGN(x,y)   ((x) += (y); ALIGN(x);)
                            
#define	socklen_t unsigned int	/* Length of sockaddr address */

/* The structure returned by recvfrom_flags() */
struct in_pktinfo {
  int     ipi_ifindex;          /* received interface index */
  struct in_addr ipi_addr;	/* dst IPv4 address */
};

#define MY_IFF_RECVIF   0x1     /* receiving interface */

struct ifi_info {
  char    ifi_name[IFNAMSIZ];	/* interface name, null terminated */
  u_char  ifi_haddr[IFHADDRSIZ];/* hardware address */
  u_short ifi_hlen;		/* #bytes in hardware address: 0, 6, 8 */
  short   ifi_flags;		/* IFF_xxx constants from <net/if.h> */
  short   ifi_myflags;		/* our own IFI_xxx flags */
  struct sockaddr  *ifi_addr;	/* primary address */
  struct sockaddr  *ifi_brdaddr;/* broadcast address */
  struct sockaddr  *ifi_dstaddr;/* destination address */
  struct ifi_info  *ifi_next;	/* next of these structures */
  struct topd_nborlist *ifi_nbors;/* neighbors */
67
  int 	 sock; 			/* socket associated with this interface */
Kristin Wright's avatar
Kristin Wright committed
68 69
};

70 71 72 73 74 75 76 77 78 79 80
#define MAX_INTERFACES 5
#define MAC_ADDR_LEN   20

typedef struct db_elem 
{
	char *hostname;
	char addrs[MAX_INTERFACES][MAC_ADDR_LEN];
}db_type;

#define MAX_NODES 100

Kristin Wright's avatar
Kristin Wright committed
81 82 83 84 85
/* Prototypes */

void 
serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen);

86
int *
Kristin Wright's avatar
Kristin Wright committed
87
forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
88
		     const char *mesg, const int mesglen, int *ptrSockNum);
Kristin Wright's avatar
Kristin Wright committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
struct ifi_info	*
get_ifi_info(int, int);

void			 
free_ifi_info(struct ifi_info *);

ssize_t	 
recvfrom_flags(int, void *, size_t, int *, struct sockaddr *, socklen_t *,
	       struct in_pktinfo *);

char*
if_indextoname(unsigned int, char *);

char*
sock_ntop(const struct sockaddr *, socklen_t);

char*
net_rt_iflist(int, int, size_t *);

void	 
get_rtaddrs(int, struct sockaddr *, struct sockaddr **);

u_int32_t
112 113
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors,
			  u_char [], u_char []);
Kristin Wright's avatar
Kristin Wright committed
114

115 116 117
int
is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead) ;

118 119 120 121 122 123
struct ifi_info *
get_ifi_struct(int sock, struct ifi_info * ifihead);

void
addMyID(char* mesg, int size);

124
void
125 126 127 128
get_recvIFADDR(u_char* recvIF,char *name,struct ifi_info * ifihead);

double
tod(void);
129

Kristin Wright's avatar
Kristin Wright committed
130

131 132 133
void
gen_nam_file(const char *mesg, size_t nbytes, char *);

134 135
void remove_socket(int sock_index,int* sock_list,int* sock_num);

Kristin Wright's avatar
Kristin Wright committed
136
#endif /* _TOPD_DISCVR_H_ */