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 int AF_INET
      TCP connection family.
      static CStdLib INSTANCE
      C STDLIB instance.
      static int IPPROTO_TCP
      Protocol for TCP connection.
      static int O_RDONLY
      Open flag for reading only.
      static int O_RDWR
      Open flag for reading and writing.
      static int SOCK_STREAM
      The "Socket as stream" type.
      static int STDIN_FILENO
      Standard input file descriptor.
      static int STDOUT_FILENO
      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

      All Methods Instance Methods Abstract Methods 
      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.
      String getenv​(String name)
      Get environment variable.
      int getpid()
      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.
      String 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.
    • Method Detail

      • 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