NEW
  AUTO 3,1
				.LIST OFF	
				.OP	65C02
*--------------------------------------
K.ARPCACHE.SIZE .EQ 8
K.DNSCACHE.SIZE .EQ 8
K.SKTTABLE.SIZE	.EQ 16
K.FRMQUEUE.SIZE	.EQ 16
K.FRMSEND.RETRY	.EQ 10
K.ETH.FRAME.LEN	.EQ 1514
K.ARP.TTL		.EQ 600
K.ARP.PENDING.TTL .EQ 20
K.DNS.PENDING.TTL .EQ 20
K.IP.TTL		.EQ 64
K.DNS.MAXLEN	.EQ 64
K.DYNPORT.START	.EQ 49152
K.DYNPORT.END	.EQ 65535
K.TCP.MSS		.EQ K.ETH.FRAME.LEN-20-20-14
K.TCP.WSIZE		.EQ 2048
*--------------------------------------
LIBTCPIP.SETCFG			.EQ 4
LIBTCPIP.GETCFG			.EQ 6

LIBTCPIP.INCOMING		.EQ 8
LIBTCPIP.PULSE			.EQ 10

LIBTCPIP.ARP.Clear		.EQ 12
LIBTCPIP.ARP.Query		.EQ 14
LIBTCPIP.ARP.Add		.EQ 16
LIBTCPIP.ARP.GetCache	.EQ 18

LIBTCPIP.DNS.Clear		.EQ 20
LIBTCPIP.DNS.Query		.EQ 22
LIBTCPIP.DNS.Add		.EQ 24
LIBTCPIP.DNS.GetCache	.EQ 26

LIBTCPIP.HST.GetByName	.EQ 28
LIBTCPIP.HST.GetByAddr	.EQ 30

LIBTCPIP.Socket		.EQ 32
LIBTCPIP.Bind		.EQ 34
LIBTCPIP.Connect	.EQ 36
LIBTCPIP.Listen		.EQ 38

LIBTCPIP.Accept		.EQ 40
LIBTCPIP.shutdown	.EQ 42

LIBTCPIP.Read		.EQ 44
LIBTCPIP.Write		.EQ 46
LIBTCPIP.Recv		.EQ 48
LIBTCPIP.Send		.EQ 50

LIBTCPIP.RecvFrom	.EQ 52
LIBTCPIP.SendTo		.EQ 54

LIBTCPIP.getsockopt	.EQ 56
LIBTCPIP.setsockopt	.EQ 58

LIBTCPIP.EOF		.EQ 60
LIBTCPIP.GetTable	.EQ 62
*--------------------------------------
ERR.SKT.OOS			.EQ $BF
ERR.SKT.BUSY		.EQ $BE
ERR.SKT.BAD			.EQ $BD
ERR.SKT.NOCONN		.EQ $BC

ERR.DNS.PENDING		.EQ $B9
ERR.DNS.ERROR		.EQ $B8

ERR.ARP.PENDING		.EQ $B5
*--------------------------------------
UDP.PORT.DNS		.EQ 53
UDP.PORT.PMAP		.EQ 111
*--------------------------------------
*S.IPCFG.STATUS		.EQ 0
S.IPCFG.STATUS.OFF		.EQ %00000000	TCPIP Unconfigured
S.IPCFG.STATUS.SDISC	.EQ %00000001	DISCOVERY Sent
S.IPCFG.STATUS.ROFFER	.EQ %00000010	OFFER Received
S.IPCFG.STATUS.SREQ		.EQ %00000100	REQUEST Sent
S.IPCFG.STATUS.RACK		.EQ %00001000	ACK Received
S.IPCFG.STATUS.OK		.EQ %10000000	Fully configured (static or DHCP)
*S.IPCFG.DevID		.EQ 1
*S.IPCFG.DevFlags	.EQ 2
*
*S.IPCFG.MAC			.EQ 4
S.IPCFG.DHCPSRVR	.EQ 10
S.IPCFG.IP			.EQ 14
S.IPCFG.MASK		.EQ 18
S.IPCFG.GW			.EQ 22
S.IPCFG.DNS1		.EQ 26
S.IPCFG.DNS2		.EQ 30
S.IPCFG.HOSTNAME	.EQ 34				15+\0 C String
S.IPCFG.DOMAIN		.EQ 50				45+\0 C String
*
S.IPCFG				.EQ 96
*--------------------------------------
S.ARPCACHE.S		.EQ 0
S.ARPCACHE.S.PENDING	.EQ 1
S.ARPCACHE.S.STATIC		.EQ 2
S.ARPCACHE.S.RESOLVED	.EQ 128
S.ARPCACHE.TTL		.EQ 2
S.ARPCACHE.IP		.EQ 6
S.ARPCACHE.MAC		.EQ 10
*
S.ARPCACHE			.EQ 16
*--------------------------------------
S.DNSCACHE.STATUS	.EQ 0
S.DNSCACHE.STATUS.PENDING	.EQ 1
S.DNSCACHE.STATUS.STATIC	.EQ 2
S.DNSCACHE.STATUS.RESOLVED	.EQ 128
S.DNSCACHE.hNAME	.EQ 1
S.DNSCACHE.ID		.EQ 2				Store Message.Id in cache (pending req.)
S.DNSCACHE.TTL		.EQ 4
S.DNSCACHE.IP		.EQ 8
*
S.DNSCACHE			.EQ 12
*--------------------------------------
S.SOCKADDR.AF		.EQ 0

S.SOCKADDR.ADDR		.EQ 2
S.SOCKADDR.PORT		.EQ 6
*
S.SOCKADDR			.EQ 8
*--------------------------------------
S.SOCKET.AF			.EQ S.FD.DSOCK+0
S.SOCKET.T			.EQ S.FD.DSOCK+1
S.SOCKET.T.RAW			.EQ	0			S.FD.T.DSOCK,ICMP...
S.SOCKET.T.DGRAM		.EQ 2			S.FD.T.DSOCK,UDP
S.SOCKET.T.SEQPACKET	.EQ	4			S.FD.T.DSOCK,TCP
S.SOCKET.T.STREAM		.EQ	6			S.FD.T.SSOCK,TCP

S.SOCKET.PROTO		.EQ S.FD.DSOCK+2

S.SOCKET.O			.EQ S.FD.DSOCK+3
S.SOCKET.O.DEBUG		.EQ $01
S.SOCKET.O.ACCEPTCONN	.EQ $02
S.SOCKET.O.REUSEADDR	.EQ $04
S.SOCKET.O.KEEPALIVE	.EQ $08
S.SOCKET.O.DONTROUTE	.EQ $10
S.SOCKET.O.BROADCAST	.EQ $20
S.SOCKET.O.USELOOPBACK	.EQ $40
S.SOCKET.O.LINGER		.EQ $80

S.SOCKET.LOC.ADDR	.EQ S.FD.DSOCK+4
S.SOCKET.LOC.PORT	.EQ S.FD.DSOCK+8
S.SOCKET.REM.ADDR	.EQ S.FD.DSOCK+10
S.SOCKET.REM.PORT	.EQ S.FD.DSOCK+14
*--------------------------------------
* Listen type Queue
* Raw Type Queue
* Datagram type Queue
* Seq Packet type Queue
*--------------------------------------
S.SOCKET.HQ.HEAD	.EQ S.FD.DSOCK+16
S.SOCKET.HQ.TAIL	.EQ S.FD.DSOCK+17
S.SOCKET.HQ			.EQ S.FD.DSOCK+18
S.SOCKET.HQ.MAX			.EQ 14				14 hMem (frames)
*--------------------------------------
* Stream type Queue
*--------------------------------------
S.SOCKET.SQ.hInMem	.EQ S.FD.DSOCK+16
S.SOCKET.SQ.hOutMem	.EQ S.FD.DSOCK+17
*
S.SOCKET			.EQ S.FD.DSOCK+32
*--------------------------------------
S.SOCKET.TCP.S		.EQ S.SOCKET
S.SOCKET.TCP.S.CLOSED	.EQ 0
S.SOCKET.TCP.S.OPENED	.EQ 1
S.SOCKET.TCP.S.LISTEN	.EQ 2
S.SOCKET.TCP.S.SYNSENT	.EQ 3
S.SOCKET.TCP.S.SYNRCVD	.EQ 4
S.SOCKET.TCP.S.ESTBLSH	.EQ 5
S.SOCKET.TCP.S.CLWAIT	.EQ 6
S.SOCKET.TCP.S.LASTACK	.EQ 7
S.SOCKET.TCP.S.FINWT1	.EQ 8
S.SOCKET.TCP.S.FINWT2	.EQ 9
S.SOCKET.TCP.S.CLOSING	.EQ 10
S.SOCKET.TCP.S.TIMEWT	.EQ 11
*
S.SOCKET.TCP.O		.EQ S.SOCKET+1
*
S.SOCKET.TCP.INSEQNUM	.EQ S.SOCKET+2		Recv:Last SEQ received from remote
S.SOCKET.TCP.OUTNEXTSEQ	.EQ S.SOCKET+6		Send:Next SEQ to send
S.SOCKET.TCP.OUTSENTSEQ	.EQ S.SOCKET+10		Send:SEQ sent not yet ACKed (retransmit)
*
S.SOCKET.TCP.INTAIL		.EQ S.SOCKET+14
S.SOCKET.TCP.INHEAD		.EQ S.SOCKET+16
S.SOCKET.TCP.INFREE		.EQ S.SOCKET+18
S.SOCKET.TCP.INUSED		.EQ S.SOCKET+20
*
S.SOCKET.TCP.OUTTAIL	.EQ S.SOCKET+22
S.SOCKET.TCP.OUTTAILSENT	.EQ S.SOCKET+24	
S.SOCKET.TCP.OUTHEAD	.EQ S.SOCKET+26
S.SOCKET.TCP.OUTFREE	.EQ S.SOCKET+28
S.SOCKET.TCP.OUTTOSEND	.EQ S.SOCKET+30
S.SOCKET.TCP.OUTUSED	.EQ S.SOCKET+32
*
S.SOCKET.TCP		.EQ S.SOCKET+34
*--------------------------------------
S.ARP.HTYPE			.EQ	S.ETH.EII+0		$0001
S.ARP.PTYPE			.EQ	S.ETH.EII+2		$0800
S.ARP.HLEN			.EQ	S.ETH.EII+4		$06
S.ARP.PLEN			.EQ	S.ETH.EII+5		$04
S.ARP.OPERATION		.EQ	S.ETH.EII+6		REQ=$0001,REPLY=$0002
S.ARP.OPERATION.REQ	.EQ 1
S.ARP.OPERATION.REP	.EQ 2
S.ARP.SHA			.EQ S.ETH.EII+8		Sender MAC	
S.ARP.SPA			.EQ S.ETH.EII+14	Sender IP	
S.ARP.THA			.EQ S.ETH.EII+18	Target MAC	
S.ARP.TPA			.EQ S.ETH.EII+24	Target IP	
*
S.ARP				.EQ S.ETH.EII+28
*--------------------------------------
S.IP.V.IHL.DSCP.ECN	.EQ S.ETH.EII+0			$0045, IPV4,HDR=5DWORDs
S.IP.TOTAL.LENGTH	.EQ	S.ETH.EII+2
S.IP.IDENTIFICATION	.EQ	S.ETH.EII+4
S.IP.FRAGMENT.FLAGS	.EQ	S.ETH.EII+6
S.IP.TTL			.EQ	S.ETH.EII+8
S.IP.PROTOCOL		.EQ	S.ETH.EII+9
S.IP.PROTOCOL.ICMP		.EQ	1
S.IP.PROTOCOL.TCP		.EQ	6
S.IP.PROTOCOL.UDP		.EQ	17
S.IP.HDR.CHECKSUM	.EQ	S.ETH.EII+10
S.IP.SRC			.EQ S.ETH.EII+12
S.IP.DST			.EQ S.ETH.EII+16
*
S.IP				.EQ S.ETH.EII+20
*--------------------------------------
S.ICMP.TYPE			.EQ S.IP+0
S.ICMP.TYPE.ECHOREP		.EQ 0
S.ICMP.TYPE.UNREACH		.EQ 3
S.ICMP.TYPE.ECHOREQ		.EQ 8
S.ICMP.CODE			.EQ S.IP+1
S.ICMP.CHECKSUM		.EQ S.IP+2
S.ICMP.IDENTIFIER	.EQ S.IP+4
S.ICMP.SEQUENCE		.EQ S.IP+6
*
S.ICMP				.EQ S.IP+8
*--------------------------------------
S.TCPUDP.SRCPORT	.EQ S.IP+0
S.TCPUDP.DSTPORT	.EQ S.IP+2
*--------------------------------------
S.UDP.LENGTH		.EQ S.IP+4
S.UDP.CHECKSUM		.EQ S.IP+6			$0000 = DISABLE
*
S.UDP				.EQ S.IP+8
*--------------------------------------
S.TCP.SEQNUM		.EQ S.IP+4
S.TCP.ACKNUM		.EQ S.IP+8
S.TCP.DATAOFFSET	.EQ S.IP+12
S.TCP.OPTIONS		.EQ S.IP+13
S.TCP.OPTIONS.URG		.EQ %00100000
S.TCP.OPTIONS.ACK		.EQ %00010000
S.TCP.OPTIONS.PSH		.EQ %00001000
S.TCP.OPTIONS.RST		.EQ %00000100
S.TCP.OPTIONS.SYN		.EQ %00000010
S.TCP.OPTIONS.FIN		.EQ %00000001
S.TCP.WINDOW		.EQ S.IP+14
S.TCP.CHECKSUM		.EQ S.IP+16
S.TCP.URGPTR		.EQ S.IP+18
*
S.TCP				.EQ S.IP+20
*--------------------------------------
S.DNS.ID			.EQ S.UDP+0
S.DNS.F				.EQ S.UDP+2
S.DNS.F.QR				.EQ %10000000.00000000
S.DNS.F.OPCODE.I		.EQ %01000000.00000000
S.DNS.F.OPCODE.S		.EQ %00100000.00000000
S.DNS.F.AA				.EQ %00000100.00000000
S.DNS.F.TC				.EQ %00000010.00000000
S.DNS.F.RD				.EQ %00000001.00000000
S.DNS.F.RA				.EQ %00000000.10000000
S.DNS.F.RCODE.FRMT		.EQ %00000000.00000001
S.DNS.F.RCODE.SRVR		.EQ %00000000.00000010
S.DNS.F.RCODE.UKWN		.EQ %00000000.00000011
S.DNS.F.RCODE.NIMP		.EQ %00000000.00000100
S.DNS.F.RCODE.DENY		.EQ %00000000.00000101
S.DNS.QDCOUNT		.EQ S.UDP+4
S.DNS.ANCOUNT		.EQ S.UDP+6
S.DNS.NSCOUNT		.EQ S.UDP+8
S.DNS.ARCOUNT		.EQ S.UDP+10
*
S.DNS				.EQ S.UDP+12
*--------------------------------------
S.DNS.QTYPE.A		.EQ 1
S.DNS.QTYPE.NS		.EQ 2
S.DNS.QTYPE.CNAME	.EQ 5
S.DNS.QTYPE.SOA		.EQ 6
S.DNS.QTYPE.WKS		.EQ 11
S.DNS.QTYPE.PTR		.EQ 12
S.DNS.QTYPE.MX		.EQ 15
S.DNS.QTYPE.SRV		.EQ 33
S.DNS.QTYPE.ANY		.EQ 255
S.DNS.QCLASS.IN		.EQ 1
*--------------------------------------
MAN
SAVE INC/LIBTCPIP.I
LOAD USR/SRC/LIB/LIBTCPIP.S
ASM
