X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_net%2Fos_net.h;h=852eceac92e38085bec25e116e81d16342279d7d;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=68da2eb7cef96ac31c64b5f58503f26df959ca9f;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/os_net/os_net.h b/src/os_net/os_net.h old mode 100755 new mode 100644 index 68da2eb..852ecea --- a/src/os_net/os_net.h +++ b/src/os_net/os_net.h @@ -1,84 +1,122 @@ -/* @(#) $Id: os_net.h,v 1.12 2009/06/24 17:06:31 dcid Exp $ */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ -/* OS_net Library. - * APIs for many network operations. +/* OS_net Library + * APIs for many network operations */ -#ifndef __OS_NET_H +#include "headers/shared.h" +#include "config/client-config.h" +extern agent *agt; +#ifdef WIN32 +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0x0400 +#endif +#ifndef AI_V4MAPPED +#define AI_V4MAPPED 0x0800 +#endif +typedef unsigned short int sa_family_t; +#endif /* WIN32 */ + +#ifndef __OS_NET_H #define __OS_NET_H +#ifdef _WIN32 +#include +typedef uint8_t u_int8_t; +typedef uint16_t u_int16_t; +typedef uint32_t u_int32_t; +#endif +/* + * OSNetInfo is used to exchange a set of bound sockets for use with the + * select() function for monitoring incoming packets on multiple interfaces. + * This allows you to support IPv4 and IPv6 simultaneously. + */ -/* OS_Bindport* +typedef struct _OSNetInfo { + fd_set fdset; /* set of sockets used by select ()*/ + int fdmax; /* fd max socket for select() */ + int fds[FD_SETSIZE]; /* array of bound sockets for send() */ + int fdcnt; /* number of sockets in array */ + int status; /* return status (-1 is error) */ + int retval; /* return value (additional info) */ +} OSNetInfo; + +/* + * OS_Bindport* * Bind a specific port (protocol and a ip). * If the IP is not set, it is going to use ADDR_ANY - * Return the socket. + * Return a pointer to the OSNetInfo struct. */ -int OS_Bindporttcp(unsigned int _port, char *_ip); -int OS_Bindportudp(unsigned int _port, char *_ip); + +OSNetInfo *OS_Bindporttcp(char *_port, const char *_ip); +OSNetInfo *OS_Bindportudp(char *_port, const char *_ip); /* OS_BindUnixDomain * Bind to a specific file, using the "mode" permissions in * a Unix Domain socket. - */ -int OS_BindUnixDomain(char * path, int mode, int max_msg_size); -int OS_ConnectUnixDomain(char * path, int max_msg_size); + */ +int OS_BindUnixDomain(const char *path, mode_t mode, int max_msg_size) __attribute__((nonnull)); +int OS_ConnectUnixDomain(const char *path, int max_msg_size) __attribute__((nonnull)); int OS_getsocketsize(int ossock); - /* OS_Connect * Connect to a TCP/UDP socket */ -int OS_ConnectTCP(unsigned int _port, char *_ip); -int OS_ConnectUDP(unsigned int _port, char *_ip); +int OS_ConnectTCP(char *_port, const char *_ip); +int OS_ConnectUDP(char *_port, const char *_ip); /* OS_RecvUDP * Receive a UDP packet. Return NULL if failed */ char *OS_RecvUDP(int socket, int sizet); -int OS_RecvConnUDP(int socket, char *buffer, int buffer_size); - +int OS_RecvConnUDP(int socket, char *buffer, int buffer_size) __attribute__((nonnull)); /* OS_RecvUnix * Receive a message via a Unix socket */ -int OS_RecvUnix(int socket, int sizet, char *ret); - +int OS_RecvUnix(int socket, int sizet, char *ret) __attribute__((nonnull)); /* OS_RecvTCP * Receive a TCP packet */ -int OS_AcceptTCP(int socket, char *srcip, int addrsize); +int OS_AcceptTCP(int socket, char *srcip, size_t addrsize) __attribute__((nonnull)); char *OS_RecvTCP(int socket, int sizet); -int OS_RecvTCPBuffer(int socket, char *buffer, int sizet); - +int OS_RecvTCPBuffer(int socket, char *buffer, int sizet) __attribute__((nonnull)); -/* OS_SendTCP +/* OS_SendTCP * Send a TCP/UDP/UnixSocket packet (in a open socket) */ -int OS_SendTCP(int socket, char *msg); -int OS_SendTCPbySize(int socket, int size, char *msg); +int OS_SendTCP(int socket, const char *msg) __attribute__((nonnull)); +int OS_SendTCPbySize(int socket, int size, const char *msg) __attribute__((nonnull)); -int OS_SendUnix(int socket, char * msg, int size); +int OS_SendUnix(int socket, const char *msg, int size) __attribute__((nonnull)); -int OS_SendUDP(int socket, char *msg); -int OS_SendUDPbySize(int socket, int size, char *msg); - +int OS_SendUDPbySize(int socket, int size, const char *msg) __attribute__((nonnull)); /* OS_GetHost - * Calls gethostbyname + * Calls getaddrinfo */ -char *OS_GetHost(char *host, int attempts); +char *OS_GetHost(const char *host, unsigned int attempts); -#endif -/* EOF */ +/* satop + * Convert a sockaddr to a printable address. + */ +int satop(struct sockaddr *sa, char *dst, socklen_t size); + + +/* Close a network socket + * Returns 0 on success, else -1 or SOCKET_ERROR + */ +int OS_CloseSocket(int socket); + +#endif /* __OS_NET_H */ +