10 #include <sys/socket.h>
11 #include <sys/types.h>
12 #include <sys/resource.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
30 typedef size_t ssize_t;
31 typedef unsigned __int16 uint16_t;
32 typedef unsigned __int32 uint32_t;
39 #include <netinet/in.h>
44 * Establishes a TCP/IP connection to @p host at port @p port.
45 * @param host Hostname to connect to
46 * @param port Port number
47 * @return The file descriptor on success, -1 otherwise
49 int firmnet_connect_tcp(const char *host, uint16_t port);
52 * Closes connection established on socket @p fd.
53 * @param fd The file descriptor identifying the connection
55 void firmnet_close_socket(int fd);
58 * Send message of size @p n from buffer @p buf to file descriptor @p fd.
59 * @param fd The file descriptor, the message should be send to.
60 * @param buf The buffer containing the message
61 * @param n The length of the message.
62 * @return Number of bytes written or -1 on failure.
64 ssize_t firmnet_send(int fd, const void *buf, size_t n);
67 * Try to read some bytes but block until a certain amount is read.
68 * @param fd The file descriptor.
69 * @param buf The buffer to read into.
70 * @param try The amount of bytes to try to read.
71 * @param at_least block until this many bytes are read.
72 * @return The number of bytes read or -1 on error.
74 ssize_t firmnet_recv(int fd, void *buf, size_t try, size_t at_least);
76 #endif /* _FIRMNET_H_ */