Interface CStdLib

All Superinterfaces:
com.sun.jna.Library

public interface CStdLib extends com.sun.jna.Library
C standard library with unix syscalls.
Since:
0.40
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.sun.jna.Library

    com.sun.jna.Library.Handler
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    TCP connection family.
    static final CStdLib
    C STDLIB instance.
    static final int
    Protocol for TCP connection.
    static final int
    Open flag for reading only.
    static final int
    Open flag for reading and writing.
    static final int
    The "Socket as stream" type.
    static final int
    Standard input file descriptor.
    static final int
    Standard output file descriptor.

    Fields inherited from interface com.sun.jna.Library

    OPTION_ALLOW_OBJECTS, OPTION_CALLING_CONVENTION, OPTION_CLASSLOADER, OPTION_FUNCTION_MAPPER, OPTION_INVOCATION_MAPPER, OPTION_OPEN_FLAGS, OPTION_STRING_ENCODING, OPTION_STRUCTURE_ALIGNMENT, OPTION_SYMBOL_PROVIDER, OPTION_TYPE_MAPPER
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    accept(int sockfd, SockaddrIn addr, com.sun.jna.ptr.IntByReference addrlen)
    Accept connection on socket.
    int
    bind(int sockfd, SockaddrIn addr, int addrlen)
    Assigns the address specified by addr to the socket referred to by the file descriptor sockfd.
    int
    close(int descriptor)
    Close file descriptor.
    int
    connect(int sockfd, SockaddrIn addr, int addrlen)
    Connects to the server at the specified IP address and port.
    int
    dup(int descriptor)
    Duplicates file descriptor.
    int
    dup2(int descriptor, int other)
    Duplicates a file descriptor to another.
    getenv(String name)
    Get environment variable.
    int
    The "getpid" syscall.
    int
    gettimeofday(GettimeofdaySyscall.Timeval timeval, com.sun.jna.Pointer timezone)
    Get current time.
    int
    inet_addr(String address)
    Convert IP string to binary form.
    int
    listen(int sockfd, int backlog)
    Listen for incoming connections on socket.
    int
    open(String path, int flags)
    The "open" syscall.
    int
    read(int descriptor, byte[] buf, int size)
    Read bytes from file descriptor.
    int
    recv(int sockfd, byte[] buf, int len, int flags)
    Receive a message from a socket.
    int
    send(int sockfd, byte[] buf, int len, int flags)
    Send a message to a socket.
    int
    socket(int domain, int type, int protocol)
    Create an endpoint for communication.
    strerror(int errno)
    Converts errno to a human-readable string.
    int
    write(int descriptor, String buf, int size)
    Writes given bytes buffer to file descriptor.
  • Field Details

    • INSTANCE

      static final CStdLib INSTANCE
      C STDLIB instance.
    • STDIN_FILENO

      static final int STDIN_FILENO
      Standard input file descriptor.
      See Also:
    • STDOUT_FILENO

      static final int STDOUT_FILENO
      Standard output file descriptor.
      See Also:
    • O_RDONLY

      static final int O_RDONLY
      Open flag for reading only.
      See Also:
    • O_RDWR

      static final int O_RDWR
      Open flag for reading and writing.
      See Also:
    • AF_INET

      static final int AF_INET
      TCP connection family.
      See Also:
    • SOCK_STREAM

      static final int SOCK_STREAM
      The "Socket as stream" type.
      See Also:
    • IPPROTO_TCP

      static final int IPPROTO_TCP
      Protocol for TCP connection.
      See Also:
  • Method Details

    • dup

      int dup(int descriptor)
      Duplicates file descriptor.
      Parameters:
      descriptor - Old file descriptor
      Returns:
      New file descriptor
    • dup2

      int dup2(int descriptor, int other)
      Duplicates a file descriptor to another.
      Parameters:
      descriptor - Old file descriptor
      other - New file descriptor
      Returns:
      Duplicated file descriptor
    • getpid

      int getpid()
      The "getpid" syscall.
      Returns:
      Process ID.
    • open

      int open(String path, int flags)
      The "open" syscall.
      Parameters:
      path - Path to file to open
      flags - Open flags
      Returns:
      File descriptor
    • close

      int close(int descriptor)
      Close file descriptor.
      Parameters:
      descriptor - File descriptor
      Returns:
      Zero on success, -1 on error
    • write

      int write(int descriptor, String buf, int size)
      Writes given bytes buffer to file descriptor.
      Parameters:
      descriptor - File descriptor.
      buf - Buffer.
      size - Number of bytes to be written.
      Returns:
      Number of bytes was written.
    • read

      int read(int descriptor, byte[] buf, int size)
      Read bytes from file descriptor.
      Parameters:
      descriptor - File descriptor.
      buf - Buffer.
      size - Number of bytes to be read.
      Returns:
      Number of bytes was read.
    • getenv

      String getenv(String name)
      Get environment variable.
      Parameters:
      name - Name of the variable
      Returns:
      Name of the environment variable
    • gettimeofday

      int gettimeofday(GettimeofdaySyscall.Timeval timeval, com.sun.jna.Pointer timezone)
      Get current time.
      Parameters:
      timeval - Timevalue
      timezone - Timezone
      Returns:
      Zero on success, -1 on error
    • socket

      int socket(int domain, int type, int protocol)
      Create an endpoint for communication.
      Parameters:
      domain - Socket domain
      type - Socket type
      protocol - Socket protocol
      Returns:
      New socket descriptor on success, -1 on error
    • connect

      int connect(int sockfd, SockaddrIn addr, int addrlen)
      Connects to the server at the specified IP address and port.
      Parameters:
      sockfd - Socket descriptor
      addr - Address structure
      addrlen - The size of the address structure
      Returns:
      Zero on success, -1 on error
    • bind

      int bind(int sockfd, SockaddrIn addr, int addrlen)
      Assigns the address specified by addr to the socket referred to by the file descriptor sockfd.
      Parameters:
      sockfd - Socket descriptor
      addr - Address structure
      addrlen - The size of the address structure
      Returns:
      Zero on success, -1 on error
    • listen

      int listen(int sockfd, int backlog)
      Listen for incoming connections on socket.
      Parameters:
      sockfd - Socket descriptor
      backlog - Specifies the queue length for completely established sockets waiting to be accepted
      Returns:
      Zero on success, -1 on error
    • accept

      int accept(int sockfd, SockaddrIn addr, com.sun.jna.ptr.IntByReference addrlen)
      Accept connection on socket.
      Parameters:
      sockfd - Socket descriptor
      addr - Address structure
      addrlen - The size of the address structure
      Returns:
      On success, file descriptor for the accepted socket (a nonnegative integer) is returned. On error, -1 is returned.
    • recv

      int recv(int sockfd, byte[] buf, int len, int flags)
      Receive a message from a socket.
      Parameters:
      sockfd - Socket descriptor
      buf - Byte buffer to store received bytes
      len - Size of received data
      flags - Flags
      Returns:
      The number of received bytes on success, -1 on error
    • send

      int send(int sockfd, byte[] buf, int len, int flags)
      Send a message to a socket.
      Parameters:
      sockfd - Socket descriptor
      buf - Byte buffer to store sent bytes
      len - Size of sent data
      flags - Flags
      Returns:
      The number of sent bytes on success, -1 on error
    • inet_addr

      int inet_addr(String address)
      Convert IP string to binary form.
      Parameters:
      address - IP address
      Returns:
      IP address in binary form
    • strerror

      String strerror(int errno)
      Converts errno to a human-readable string.
      Parameters:
      errno - The error number
      Returns:
      Error as string