Next: , Previous: , Up: posix socket   [Index]


4.15.2 Network hosts database

Struct Type: struct-hostent

Data structure type used to represent at the Scheme level struct hostent values. It has the following fields:

h_name

Bytevector, the official host name.

h_aliases

List of bytevectors, host name aliases.

h_addrtype

Fixnum, AF_INET or AF_INET6.

h_length

Fixnum, number of bytes in each host address bytevector.

h_addr_list

List of bytevectors each holding struct in_addr or struct in6_addr.

h_addr

Bytevector, it is the first in the list h_addr_list.

Function: make-struct-hostent h_name h_aliases h_addrtype h_length h_addr_list h_addr

Build and return an instance of struct-hostent.

Function: struct-hostent? obj

Return #t if obj is an instance of struct-hostent, otherwise return #f.

Function: struct-hostent-h_name hostent
Function: struct-hostent-h_aliases hostent
Function: struct-hostent-h_addrtype hostent
Function: struct-hostent-h_length hostent
Function: struct-hostent-h_addr_list hostent
Function: struct-hostent-h_addr hostent

Accessors for the fields of struct-hostent instances.

Function: gethostbyname hostname

Interface to the C function gethostbyname(), (libc)gethostbyname. Given the string or bytevector hostname holding the ASCII representation of a host name, build and return an instance of struct-hostent. If an error occurs, return an encoded h_errno value.

(import (vicare)
  (prefix (vicare posix) px.))

(px.gethostbyname "github.com")
⇒ #["struct-hostent"
       h_name="github.com"
       h_aliases=()
       h_addrtype=AF_INET
       h_length=4
       h_addr_list=(#vu8(207 97 227 239))
       h_addr=#vu8(207 97 227 239)]

(px.gethostbyname "google.com")
⇒ #["struct-hostent"
       h_name="google.com"
       h_aliases=()
       h_addrtype=AF_INET
       h_length=4
       h_addr_list=(#vu8(209 85 148 103)
                    #vu8(209 85 148 99)
                    #vu8(209 85 148 104)
                    #vu8(209 85 148 105)
                    #vu8(209 85 148 106)
                    #vu8(209 85 148 147))
       h_addr=#vu8(209 85 148 103)]
Function: gethostbyaddr addr

Interface to the C function gethostbyaddr(), (libc)gethostbyaddr. Given the bytevector addr holding a struct in_addr or a struct in6_addr, build and return an instance of struct-hostent; the type of address is automatically inferred from the length of the bytevector. If an error occurs: an exception is raised.

Function: host-entries

Interface to the C functions sethostent(), gethostent() and endhostent(), (libc)gethostbyaddr. Build and return a list of struct-hostent representing the entries in the hosts database.


Next: , Previous: , Up: posix socket   [Index]