ethersim.h
6.01 KB
1
2
3
4
5
6
7
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
38
39
40
41
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* Copyright (C) 1996-1998 by the Board of Trustees
* of Leland Stanford Junior University.
*
* This file is part of the SimOS distribution.
* See LICENSE file for terms of the license.
*
*/
/*
* ethersim.h --
*
* Declarations of the external interfaces
* exported to the rest of the Sprite file system.
*
*
* $Header:
*/
#ifndef _ETHERSIM_H
#define _ETHERSIM_H
/*
* ETHER_SIM_PORT - UDP/IP port number to send ethernet packets to.
* ETHER_SIM_LOCAL_EADDR - First 4 bytes of the ethernet address of simulated
* host on the ethernet. Is this in host byorder.
*/
#define ETHER_SIM_PORT 3232
#define ETHER_SIM_LOCAL_EADDR 0x00010203 /* 0:1:2:3 */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <net/if.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#include <netinet/udp.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <signal.h>
#include <pwd.h>
#include <setjmp.h>
#include <netdb.h>
#include <errno.h>
#include <strings.h>
#include <varargs.h>
#include <stropts.h>
#include <poll.h>
#include <search.h>
#include <memory.h>
#include <stdlib.h>
#include <unistd.h>
#include <bstring.h>
#include "hash.h"
#include "ethersim.h"
#ifdef MACH_NRP
#include <netinet/udp.h>
#include "nd.h"
#endif
/*
* For snoop.
*/
#ifdef sgi
#include <net/raw.h>
#define ETHERHDRPAD RAW_HDRPAD(sizeof(struct ether_header))
struct etherpacket {
struct snoopheader snoop;
char pad[ETHERHDRPAD];
struct ether_header ether;
char data[ETHERMTU];
};
struct ether_ip_header{
struct ether_header etherHdr;
struct ip ipHdr;
};
#endif /* sgi */
/*
* Program options setable from the command line.
*/
extern u_long subnetaddr; /* Subnet address (i.e. 36.132.0.0). */
extern int simportnumber; /* UDP port of simulated ethernet. */
extern int noipforwarding; /* Boolean - Don't forward ip packet. */
extern char interfacename[32];/* Name of interface to forward IP . */
extern u_long routeraddr;
extern int verbose;
/*
* Buffer to hold the current packet being transmitted on the ethernet.
* This must be big enought to hold an ethernet MTU and its header. We
* add 128 bytes for good measure.
*/
extern char curPacket[ETHERMTU + sizeof(struct ether_header) + 128];
extern int simfd; /* Open file descriptor of simulated ethernet port. */
extern int netfd; /* Open file descriptor of network interface tap. */
#ifdef MACH_NRP
extern int nrpfd; /* Open file descriptor of socket or NRP server. */
extern char *nrphost; /* Host with NRP server. */
extern struct sockaddr_in nrpaddr;
extern int nrpaddrlen;
extern u_char my_sinetheraddr[6]; /* My simulated ether addr. */
extern struct in_addr my_simipaddr; /* My simulated ip addr. */
#endif
/*
* The ethernet address and IP network address of the interface being used.
*/
extern u_char myetheraddr[6];
extern u_long mynetaddr;
/*
* The internet address and netmask of the interface being used.
*/
extern u_long myinetAddr;
extern u_long mynetmask;
/*
* HostInfoRecord - Info kept per simulated host.
*/
typedef struct HostInfoRecord {
u_char etheraddr[6];/* Ethernet address of host. */
u_long inetAddr; /* Internet address of host. */
struct sockaddr fromaddr; /* Socket the of the simulated machines
* ethernet interface. */
int fromlen; /* Length in bytes of fromaddr. */
} HostInfoRecord;
/*
* Hash tables that map
* etheraddrTable - Ethernet addresses to HostInfoRecord.
* ipaddrTable - IP addresses to HostInfoRecord.
*/
extern Hash_Table etheraddrTable;
extern Hash_Table ipaddrTable;
/*
* Stupid SunOS header missing stuff.
*/
/* Options stuff. */
#ifdef sparc
extern char *optarg;
extern int optind;
extern int getopt( int , char*, char** );
extern int fprintf ();
extern int fscanf ();
extern int fgetc (FILE *stream);
extern void perror(char *msg);
extern int pclose (FILE *stream);
extern int ioctl(int fd, int request, caddr_t arg);
extern int socket(int domain, int type, int protocol);
extern int bind(int s, struct sockaddr *name, int namelen);
extern int recvfrom(int s, char *buf, int len, int flags,
struct sockaddr *from, int *fromlen);
extern int sendto(int s, char *msg, int len, int flags,
struct sockaddr *to, int tolen);
extern u_long inet_netof(struct in_addr in);
extern void bzero(void *b, int length);
extern void bcopy(void *a, void *b, int length);
extern int poll(struct pollfd *fds, unsigned long nfds, int timeout);
extern int putmsg(int fd, struct strbuf *ctlptr,
struct strbuf *dataptr, int flags);
extern long strtol(char *str, char **ptr, int base);
#endif /* sparc */
/*
* offsetof() return the offset of a field into the structure.
*/
#ifndef offsetof
#define offsetof(_t, _f) ((int) &(((_t *) 0)->_f))
#endif
#ifdef sparc
#define A(x) (hdrPtr->ether_shost.ether_addr_octet[x])
#define B(x) (hdrPtr->ether_dhost.ether_addr_octed[x])
#endif
#ifdef sgi
#define A(x) (hdrPtr->ether_shost[x])
#define B(x) (hdrPtr->ether_dhost[x])
#endif
/*
* Forward routine declartions.
*/
extern int serviceSimPort(void);
extern int serviceNetPort(void);
extern int outputPacket(char *packet, int size);
extern int lookupInterface(char *interfacename, u_long *inetAddrPtr,
u_long *netmaskPtr);
extern int validPacket(char *packet, int size, struct sockaddr *fromAddr,
int fromlen);
extern int ArpRequest(void *pin, int pinlen, void *pout, int *poutlen);
extern unsigned long FindGateway(unsigned long dstaddr);
extern void dispEtherPacket(int n, struct ether_header* hdrPtr, int tab);
#ifdef sparc
extern int initNITdevice(char *device, u_long subNetAddr, u_long netmask);
#endif
#ifdef sgi
#ifdef SIM_PROXY
extern int initSNPdevice(char *device, u_long *subNetAddr, u_long count, u_long netmask);
#else
extern int initSNPdevice(char *device, u_long subNetAddr, u_long netmask);
#endif
#endif
#endif /* _ETHERSIM_H */