Difference between revisions of "OSWORD &C0"

From BeebWiki
Jump to: navigation, search
(Added Resolver details.)
 
m (1 revision)
(No difference)

Revision as of 23:58, 28 August 2013

OSWORD &C0 (192) - IP Networking and DNS Resolver

Specification

   On entry:
       XY?0  = send block length
       XY?1  = receive block length
       XY?2  = command, 0-63=Socket, 64-127=Resolver, 128-255=Reserved
       XY?3  = 0, returns 0 or error value
       XY!4  = socket
       XY!8  =>data
       XY!12 = data length
       XY!16 = flags
       XY!20 =>IP address
       XY!24 = IP address length, if zero, X%!20 = IPv4 address

   On exit:
       XY?2 = 0 if call supported, unchanged if call unsupported or no handler present
       XY?3 = 0 or returned error
       XY!4 onwards: any returned data
       Memory pointed to by XY!8 on entry may be modified

Socket Commands

Commands passed in XY?2 are those in the RISC OS Socket_ SWIs, that is:

&00 Socket_Creat       X%!4=domain, X%!8=type,  X%!12=protocol
&01 Socket_Bind        X%!4=sock, X%!8=name,    X%!12=namelen
&02 Socket_Listen      X%!4=sock, X%!8=backlog
&03 Socket_Accept      X%!4=sock, X%!8=addr,    X%!12=len
&04 Socket_Connect     X%!4=sock, X%!8=name,    X%!12=namelen
&05 Socket_Recv        X%!4=sock, X%!8=buf,     X%!12=len,  X%!16=flags
&06 Socket_Recvfrom    X%!4=sock, X%!8=buf,     X%!12=len,  X%!16=flags, X%!16=from, X%!20=fromlen
&07 Socket_Recvmsg     X%!4=sock, X%!8=msg,     X%!12=flags
&08 Socket_Send        X%!4=sock, X%!8=msg,     X%!12=len,  X%!16=flags
&09 Socket_Sendto      X%!4=sock, X%!8=msg,     X%!12=len,  X%!16=flags, X%!16=to, X%!20=tolen
&0A Socket_Sendmsg     X%!4=sock, X%!8=msg,     X%!12=flags
&0B Socket_Shutdown    X%!4=sock, X%!8=how
&0C Socket_Setsockopt  X%!4=sock, X%!8=level,   X%!12=optname, X%!16=optval, X%!16=optlen
&0D Socket_Getsockopt  X%!4=sock, X%!8=level,   X%!12=optname, X%!16=optval, X%!16=optlen
&0E Socket_Getpeername X%!4=sock, X%!8=name,    X%!12=namelen
&0F Socket_Getsockname X%!4=sock, X%!8=name,    X%!12=namelen
&10 Socket_Close       X%!4=sock
&11 Socket_Select      X%!4=nfds, X%!8=readfds, X%!12=writefds, X%!16=exceptfds, X%!16=timeout
&12 Socket_Ioctl       X%!4=sock, X%!8=request, X%!12=argp
&13 Socket_Read        X%!4=sock, X%!8=buf,     X%!12=num
&14 Socket_Write       X%!4=sock, X%!8=buf,     X%!12=num
&15 Socket_Stat        X%!4=sock, X%!8=buf
&16 Socket_Readv       X%!4=sock, X%!8=iov,     X%!12=iovcnt
&17 Socket_Writev      X%!4=sock, X%!8=iov,     X%!12=iovcnt

Coding

The following is a BASIC Sockets library:

 REM > BLib.Socket
 DEFFNSocket_Open(   X%!4, X%!8, X%!12):A%=0
 DEFFNSocket_Bind(   X%!4, X%!8, X%!12):A%=1
 DEFFNSocket_Listen( X%!4, X%!8)       :A%=2
 DEFFNSocket_Accept( X%!4, X%!8, X%!12):A%=3
 DEFFNSocket_Connect(X%!4, X%!8, X%!12):A%=4
 DEFFNSocket_Read(   X%!4, X%!8, X%!12):A%=5
 DEFFNSocket_Write(  X%!4, X%!8, X%!12):A%=8
 DEFFNSocket_Close(  X%!4)             :A%=16
 !X%=&814:X%?2=A%:A%=192:CALL &FFF1:IFX%?3:=-X%?3 ELSE =X%!4

The calls return a negative number if the call fails, or a positive number (or zero) if the call succeeds, being the returned socket number or byte count, etc.

Specification

   On entry:
       XY?0  = send block length
       XY?1  = receive block length
       XY?2  = command, 0-63=Socket, 64-127=Resolver, 128-255=Reserved
       XY?3  = 0, returns 0 or error value
       XY!4  => host name

   On exit:
       XY?2 = 0 if call supported, unchanged if call unsupported or no handler present
       XY?3 = 0 or returned error
       XY!4 onwards: any returned data

Resolver Commands

Commands passed in XY?2 are those in the RISC OS Resolver_ SWIs plus &40, that is:

 &40 Resolver_GetHostByName
     On entry:  X%!4=>name,
     On exit:   X%!4=>name, X%!8=>aliases, X%!12=>type, X%!16=length, X%!20=>IP addresses
 &41 Resolver_GetHost
     On entry:  X%!4=>name,
     On exit:   X%!4=>name, X%!8=>aliases, X%!12=>type, X%!16=length, X%!20=>IP addresses

Coding

The following is a BASIC Resolver library:

 REM > BLib.DNS
 DEFFNDNS_GetHostByName(A$):A%=64
 DEFFNDNS_GetHost(      A$):A%=65
 !X%=&1808:X%?2=A%:X%!4=name%:$name%=A$:A%=192:CALL&FFF1:=X%+4 AND X%?3=0

The calls return zero if the call fails, or the address of an inet address structure.

See Also

Jgharston 01:36, 19 December 2010 (UTC)