OSWORD &C0

From BeebWiki
Revision as of 05:49, 12 April 2020 by Jgharston (talk | contribs) (typo.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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-253=Reserved, 254=Eureka
     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

Return values

OSWORD &C0 returns:

  1. define socket_EBADF 0x9u /*Bad descriptor*/
  2. define socket_EAGAIN 0xBu /*No more ports*/
  3. define socket_EFAULT 0xEu /*Bad address*/
  4. define socket_EINVAL 0x16u /*Invalid argument*/
  5. define socket_EWOULDBLOCK 0x23u /*Operation would block*/
  6. define socket_EINPROGRESS 0x24u /*Operation now in progress*/
  7. define socket_EALREADY 0x25u /*Operation already in progress*/
  8. define socket_ENOTSOCK 0x26u /*Socket operation on non-socket*/
  9. define socket_EDESTADDRREQ 0x27u /*Destination address required*/
  10. define socket_EMSGSIZE 0x28u /*Message too long*/
  11. define socket_EPROTOTYPE 0x29u /*Protocol wrong type for socket*/
  12. define socket_ENOPROTOOPT 0x2Au /*Protocol not available*/
  13. define socket_EPROTONOSUPPORT 0x2Bu /*Protocol not supported*/
  14. define socket_ESOCKTNOSUPPORT 0x2Cu /*Socket type not supported*/
  15. define socket_EOPNOTSUPP 0x2Du /*Operation not supported on socket*/
  16. define socket_EPFNOSUPPORT 0x2Eu /*Protocol family not supported*/
  17. define socket_EAFNOSUPPORT 0x2Fu /*Address family not supported by protocol family*/
  18. define socket_EADDRINUSE 0x30u /*Address already in use*/
  19. define socket_EADDRNOTAVAIL 0x31u /*Can't assign requested address*/
  20. define socket_ENETDOWN 0x32u /*Network is down*/
  21. define socket_ENETUNREACH 0x33u /*Network is unreachable*/
  22. define socket_ENETRESET 0x34u /*Network dropped connection on reset*/
  23. define socket_ECONNABORTED 0x35u /*Software caused connection abort*/
  24. define socket_ECONNRESET 0x36u /*Connection reset by peer*/
  25. define socket_ENOBUFS 0x37u /*No buffer space available*/
  26. define socket_EISCONN 0x38u /*Socket is already connected*/
  27. define socket_ENOTCONN 0x39u /*Socket is not connected*/
  28. define socket_ESHUTDOWN 0x3Au /*Can't send after socket shutdown*/
  29. define socket_ETOOMANYREFS 0x3Bu /*Too many references: can't splice*/
  30. define socket_ETIMEDOUT 0x3Cu /*Connection timed out*/
  31. define socket_ECONNREFUSED 0x3Du /*Connection refused*/
  32. define socket_EHOSTDOWN 0x40u /*Host is down*/
  33. define socket_EHOSTUNREACH 0x41u /*No route to host*/


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_GetHost(A$):A%=65
 DEFFNDNS_GetHostByName(A$):A%=64
 !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


OSWORD &C0 (192) - Eureka memory control

Specification

 On entry:
     XY?0      = &0C - send block length
     XY?1      = &0D - receive block length
     XY?2      = &FE - Eureka command
     XY?3      = &FF - Eureka command
     XY?4      = &0B - command block length
     XY?5      = command : 1 = Read from   64K RAM
                         : 2 = Write to    64K RAM
                         : 3 = Copy within 64K RAM
     XY+6..7   = Source start address
     XY+8..9   = Source end address
     XY+10..11 = Destination address

Jgharston 01:36, 19 December 2010 (UTC)