📄 net.h
字号:
/* * Utility functions for WATTCP for Softools Compiler and Rabbit 2000 * * (C) 2001 Compendium Technologies, Inc. * (C) 2001 Softools, Inc. * All rights reserved. * * This software is the proprietary information of Compendium Technologies, Inc. * and Softools, Inc. Use is subject to license terms. */#ifndef _SOFTOOLS_H_#define _SOFTOOLS_H_#include <limits.h>#include <string.h>#include "wattcp.h"#include <NetInterface.h>/* Use ANSI remapping to limit code changes */#define MAXINT INT_MAX/* Remap movmem to the ANSI memmov */#define movmem(source,destination,numbytes) memmove(destination,source,numbytes)// Used in bsdname.c#define qmove(source,destination,numbytes) memmove(destination,source,numbytes)#define outch(x) putchar(x)#define outs(x) puts(x)/* Definitions for min and max */#define min(A,B) ((A) < (B) ? (A) : (B))/*#define max(A,B) ((A) > (B) ? (A) : (B))*/unsigned int swapuint(unsigned int uint2swap);unsigned long swapulong(unsigned long ulong2swap);/* * Case insensitive string comparison */#define strcmpi(STRING1,STRING2) stricmp(STRING1, STRING2)/* * Byte swapping remapping to C routines in Softools.c */#define intel16(A) swapuint(A)#define intel(A) swapulong(A)#define swapuint(x) _asm( [ _A, _HL ], _HL = (x), "ld a,l", "ld l,h", "ld h,a", _HL )#define swapulong(x) _asm( [ _BC, _DE, _HL ], _BCDE = (x),\ "ld hl,bc", "ld b,e", "ld c,d", "ld d,l", "ld e,h", _BCDE )/*#define swapulong(x) _asm( [ _BC, _DE, _HL ], _BCDE = (x),\ "ld hl,bc", "ld b,e", "ld c,d", "ex de,hl", _BCDE )*//* * References to kbhit (keyboard hit) in multiple files. Don't worry about * this for now */#define kbhit()/* * References to _disable and _enable in multiple files. These appear to be * enabling/disabling interrupts */#define _disable()#define _enable()/* * Elements of the packet driver */#define pkt_send(buffer,length) (RealTekSendPacket(interfaceStats,buffer,length))#define pkt_release()/* * Far pointer offsets. Appears to be used to go down to 16 bit arithmetic in * Borland C. It doesn't appear relevant for the Softools compiler. */#define FP_OFF(x) (x)// These don't exist in ROMed envirments#define tcp_cbrk(x)/* * What kind of connection is this? Supports ethernet and eventually ppp. *//* Doing something wrong with this enum below.enum NetConnectionType { ETH_CONN, PPP_CONN};*/#define ETH_CONN 0#define PPP_CONN 1/* * Structure defines the configuration for an individual network connection, * This is broken up to eventually support PPP and ethernet in th)e same device */typedef struct { /*NetConnectionType connType;*/ int connType; unsigned long ipAddress; unsigned long netmask;} NetConnectionConfig;#define DOMAINNAME_LENGTH 50#define HOSTNAME_LENGTH 50/* * Structure defines the network configuration for the device. There is only * one of these per machine. */typedef struct { char hostName[HOSTNAME_LENGTH]; // Can be overwritten by DHCP char domainName[DOMAINNAME_LENGTH]; // Can be overwritten by DHCP unsigned long defaultIpGateway;} NetConfig;/* * Will change this later to support ethernet and ppp simultaneously */ #define NET_MAX_INTERFACES 1extern NetConfig configuration;extern NetConnectionConfig interfaces[NET_MAX_INTERFACES];void netConfigure(NetConfig *config);/* * Specify an optional list of DNS servers (as char *) after NetConnectionConfig * The return value indicates whether or not initialization and startup * succeeded. */int ethernetStart(NetConnectionConfig *ethConfig, ...);/* * Shut down the ethernet interface (i.e. at program exit or to reconfigure). */void ethernetStop(void);/* * Put this in a timer and have it go off every so often. */extern unsigned char netProcessBusy; // True when netProcess() is workingvoid near netProcess(void); // For use with timers and interrupts to // periodically process network packetsint far netProcessSocket(sock_type *sock); // Returns 1 when the socket passed // in closes./* * Utility to format a MAC (ethernet) address */char *etherAddressToString(char *string, eth_address *MAC);/* * Internal things associated with a network connection */typedef struct { // Interface statistics unsigned long numIncomingPackets; // Number of packets that have come in unsigned long numOutgoingPackets; // Number of packets that have gone out unsigned long numDroppedPackets; // Number of packets dropped unsigned long numIncomingBytes; // How many bytes have come in unsigned long numOutgoingBytes; // How many bytes have gone out unsigned long swappedIpAddress; // IP Address swapped for the network, // so we can avoid bunches of intel() // calls eth_address (*interfaceInit)(void); // (*interfaceReceivePacket)(NetConnection *interfaceStats);} NetConnection;extern NetConnection interfaceStats[NET_MAX_INTERFACES];extern eth_address eth_addr;#define netGetMAC(string) (etherAddressToString(string, ð_addr))/* * Items that were in pcconfig.c */extern word sock_delay; // Used to set timeout for DNS lookupsextern word multihomes; // Appears to be used to support multiple IP // addressesextern word sock_inactive; // Set timeouts on socket connections. 0 = never // timeout. In seconds.extern longword _cookies[MAX_COOKIES]; // Constructs for DHCPextern int _last_cookie; // Constructs for DHCP/* * Internal macro redefines for the WATTCP port to use the Softools * configuration. */#define defaultdomain (configuration.domainName)#define def_domain (configuration.domainName)#define _hostname (configuration.hostName)#define my_ip_addr (interfaces[0].ipAddress)#define my_ip_swapped (interfaceStats[0].swappedIpAddress)#define sin_mask (interfaces[0].netmask)/* * For maintaining lists of servers (name servers and cookies) */void _add_server(int *counter, int max, longword *array, longword value);/* * Array table configuration items */#define MAX_ARP_DATA 10 /* How many mappings to store in the ARP cache */#define MAX_NAMESERVERS 4 /* How many name servers to allow */extern longword def_nameservers[ MAX_NAMESERVERS ];#define DHCP_TIMEOUT 60 /* How long (in seconds) should DHCP wait before giving up */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -