2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Interfaces for TCP/IP handling (Windows and Unix like systems)
23 * @author Christian Wuerdig, copied from liblpp created by Sebastian Hack
28 #ifndef FIRM_NET_FIRMNET_H
29 #define FIRM_NET_FIRMNET_H
37 #include <sys/socket.h>
38 #include <sys/types.h>
39 #include <sys/resource.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
50 #define INADDR_NONE (in_addr_t)(-1)
63 typedef size_t ssize_t;
64 typedef unsigned __int16 uint16_t;
65 typedef unsigned __int32 uint32_t;
72 #include <netinet/in.h>
77 * Establishes a TCP/IP connection to @p host at port @p port.
78 * @param host Hostname to connect to
79 * @param port Port number
80 * @return The file descriptor on success, -1 otherwise
82 int firmnet_connect_tcp(const char *host, uint16_t port);
85 * Closes connection established on socket @p fd.
86 * @param fd The file descriptor identifying the connection
88 void firmnet_close_socket(int fd);
91 * Send message of size @p n from buffer @p buf to file descriptor @p fd.
92 * @param fd The file descriptor, the message should be send to.
93 * @param buf The buffer containing the message
94 * @param n The length of the message.
95 * @return Number of bytes written or -1 on failure.
97 ssize_t firmnet_send(int fd, const void *buf, size_t n);
100 * Try to read some bytes but block until a certain amount is read.
101 * @param fd The file descriptor.
102 * @param buf The buffer to read into.
103 * @param try The amount of bytes to try to read.
104 * @param at_least block until this many bytes are read.
105 * @return The number of bytes read or -1 on error.
107 ssize_t firmnet_recv(int fd, void *buf, size_t try, size_t at_least);