1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 * APIs for many network operations
14 #include "headers/shared.h"
15 #include "config/client-config.h"
19 #define AI_ADDRCONFIG 0x0400
22 #define AI_V4MAPPED 0x0800
24 typedef unsigned short int sa_family_t;
32 typedef uint8_t u_int8_t;
33 typedef uint16_t u_int16_t;
34 typedef uint32_t u_int32_t;
38 * OSNetInfo is used to exchange a set of bound sockets for use with the
39 * select() function for monitoring incoming packets on multiple interfaces.
40 * This allows you to support IPv4 and IPv6 simultaneously.
43 typedef struct _OSNetInfo {
44 fd_set fdset; /* set of sockets used by select ()*/
45 int fdmax; /* fd max socket for select() */
46 int fds[FD_SETSIZE]; /* array of bound sockets for send() */
47 int fdcnt; /* number of sockets in array */
48 int status; /* return status (-1 is error) */
49 int retval; /* return value (additional info) */
54 * Bind a specific port (protocol and a ip).
55 * If the IP is not set, it is going to use ADDR_ANY
56 * Return a pointer to the OSNetInfo struct.
59 OSNetInfo *OS_Bindporttcp(char *_port, const char *_ip);
60 OSNetInfo *OS_Bindportudp(char *_port, const char *_ip);
63 * Bind to a specific file, using the "mode" permissions in
64 * a Unix Domain socket.
66 int OS_BindUnixDomain(const char *path, mode_t mode, int max_msg_size) __attribute__((nonnull));
67 int OS_ConnectUnixDomain(const char *path, int max_msg_size) __attribute__((nonnull));
68 int OS_getsocketsize(int ossock);
71 * Connect to a TCP/UDP socket
73 int OS_ConnectTCP(char *_port, const char *_ip);
74 int OS_ConnectUDP(char *_port, const char *_ip);
77 * Receive a UDP packet. Return NULL if failed
79 char *OS_RecvUDP(int socket, int sizet);
80 int OS_RecvConnUDP(int socket, char *buffer, int buffer_size) __attribute__((nonnull));
83 * Receive a message via a Unix socket
85 int OS_RecvUnix(int socket, int sizet, char *ret) __attribute__((nonnull));
88 * Receive a TCP packet
90 int OS_AcceptTCP(int socket, char *srcip, size_t addrsize) __attribute__((nonnull));
91 char *OS_RecvTCP(int socket, int sizet);
92 int OS_RecvTCPBuffer(int socket, char *buffer, int sizet) __attribute__((nonnull));
95 * Send a TCP/UDP/UnixSocket packet (in a open socket)
97 int OS_SendTCP(int socket, const char *msg) __attribute__((nonnull));
98 int OS_SendTCPbySize(int socket, int size, const char *msg) __attribute__((nonnull));
100 int OS_SendUnix(int socket, const char *msg, int size) __attribute__((nonnull));
102 int OS_SendUDPbySize(int socket, int size, const char *msg) __attribute__((nonnull));
107 char *OS_GetHost(const char *host, unsigned int attempts);
111 * Convert a sockaddr to a printable address.
113 int satop(struct sockaddr *sa, char *dst, socklen_t size);
116 /* Close a network socket
117 * Returns 0 on success, else -1 or SOCKET_ERROR
119 int OS_CloseSocket(int socket);
121 #endif /* __OS_NET_H */