📄 ethersim.h
字号:
/* * 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_NRPextern 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 sparcextern 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 sparcextern int initNITdevice(char *device, u_long subNetAddr, u_long netmask);#endif#ifdef sgi #ifdef SIM_PROXYextern int initSNPdevice(char *device, u_long *subNetAddr, u_long count, u_long netmask);#elseextern int initSNPdevice(char *device, u_long subNetAddr, u_long netmask);#endif#endif#endif /* _ETHERSIM_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -