discvr.h 4.13 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1 2
/*
 * Copyright (c) 2000-2002 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 
 * {{{EMULAB-LICENSE
 * 
 * This file is part of the Emulab network testbed software.
 * 
 * This file is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * This file is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this file.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * }}}
Leigh Stoller's avatar
Leigh Stoller committed
22 23 24
 */

/*$Id: discvr.h,v 1.10 2002-07-04 14:10:55 stoller Exp $*/
Kristin Wright's avatar
Kristin Wright committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

#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
				 */

55 56 57 58

#define Q_LISTEN 			1
#define QR_LISTEN			2

Kristin Wright's avatar
Kristin Wright committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#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 */
84
  int 	 sock; 			/* socket associated with this interface */
Kristin Wright's avatar
Kristin Wright committed
85 86
};

87 88 89 90 91 92 93 94 95 96 97
#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
98 99 100 101 102
/* Prototypes */

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

103
int *
Kristin Wright's avatar
Kristin Wright committed
104
forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
105
		     const char *mesg, const int mesglen, int *ptrSockNum);
Kristin Wright's avatar
Kristin Wright committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
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
129 130
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors,
			  u_char [], u_char []);
Kristin Wright's avatar
Kristin Wright committed
131

132 133 134
int
is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead) ;

135 136 137 138 139 140
struct ifi_info *
get_ifi_struct(int sock, struct ifi_info * ifihead);

void
addMyID(char* mesg, int size);

141
void
142 143 144 145
get_recvIFADDR(u_char* recvIF,char *name,struct ifi_info * ifihead);

double
tod(void);
146

Kristin Wright's avatar
Kristin Wright committed
147

148 149 150
void
gen_nam_file(const char *mesg, size_t nbytes, char *);

151 152
void remove_socket(int sock_index,int* sock_list,int* sock_num);

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