Long2ipstring

From Spectrum hardware wiki
Jump to: navigation, search

long2ipstring (IXCALL 0x3E39) - convert a 4 byte big endian value to a null-terminated dotted decimal IP string

ipstring2long (IXCALL 0x3E3C) - convert a dotted decimal IP string to a 4 byte big endian value

Synopsis

Assembly language

   ld hl, ipstring
   ld de, inetaddr
   ld ix, IPSTRING2LONG
   call IXCALL
   jr c, .error

   ld hl, inetaddr
   ld de, ipstring
   ld ix, LONG2IPSTRING
   call IXCALL

C

   #include <sys/types.h>
   #include <spectranet.h>

   void long2ipstring(in_addr_t *inetaddr, char *ipstring);
   int ipstring2long(char *ipstring, in_addr_t *inetaddr);

Description

The long2ipstring() and ipstring2long() functions convert a 4 byte big endian value to a null terminated dotted decimal string and vice versa. For the long2ipstring() function, the pointer to the string buffer must be large enough to receive 17 bytes of data (up to 16 bytes of dotted decimal IP address, plus the null terminator). The same is true for the memory pointed to by the DE register pair when using the assembly language interface.

Return values

The ipstring2long() function returns 0 on success, or -1 if the supplied string was not a valid dotted decimal IP address. The assembly language interface returns with the carry flag reset on success, or carry set if the supplied string was not valid.