/[monit]/monit/net.c
ViewVC logotype

Diff of /monit/net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.22 by hauk, Wed Jul 30 01:27:15 2003 UTC revision 1.23 by hauk, Wed Jul 30 02:24:35 2003 UTC
# Line 107  static int do_connect(int s, const struc Line 107  static int do_connect(int s, const struc
107    
108    
109  /**  /**
110   * Test INET Socket connection to host on port with the   * Test INET Socket connection to host on port with the specified
111   * specified socket protocol type. The protocol is normaly   * socket protocol type. The protocol should be either SOCK_STREAM or
112   * either SOCK_STREAM or SOCK_DGRAM.   * SOCK_DGRAM.
113   * @param hostname The host to connect to   * @param hostname The host to connect to
114   * @param port The portnumber to connect to   * @param port The portnumber to connect to
115   * @param protocol The socket protocol to use   * @param protocol The socket protocol to use
# Line 179  int check_socket(int socket) { Line 179  int check_socket(int socket) {
179    
180  /**  /**
181   * Verify that the udp socket is ready for i|o. The given socket must   * Verify that the udp socket is ready for i|o. The given socket must
182   * be a connected udp socket. The test is conducted by sending one   * be a connected udp socket if we should be able to test the udp
183   * byte to the server and check for a returned ICMP error when reading   * server. The test is conducted by sending one byte to the server and
184   * from the socket. A better test would be to send an empty SYN udp   * check for a returned ICMP error when reading from the socket. A
185   * package to avoid possibly raising an error from the server we are   * better test would be to send an empty SYN udp package to avoid
186   * testing but assembling an udp by hand requires SOCKET_RAW and   * possibly raising an error from the server we are testing but
187   * running the program as root.   * assembling an udp by hand requires SOCKET_RAW and running the
188     * program as root.
189   * @param socket A socket   * @param socket A socket
190   * @return TRUE if the socket is ready, otherwise FALSE.   * @return TRUE if the socket is ready, otherwise FALSE.
191   */   */
# Line 214  int check_udp_socket(int socket) { Line 215  int check_udp_socket(int socket) {
215    
216  /**  /**
217   * Create a non-blocking socket against hostname:port with the given   * Create a non-blocking socket against hostname:port with the given
218   * protocol.  The protocol is normaly either SOCK_STREAM or   * protocol. The protocol should be either SOCK_STREAM or SOCK_DGRAM.
  * SOCK_DGRAM.  
219   * @param hostname The host to open a socket at   * @param hostname The host to open a socket at
220   * @param port The port number to connect to   * @param port The port number to connect to
221   * @param protocol Socket protocol to use (SOCK_STREAM|SOCK_DGRAM)   * @param protocol Socket protocol to use (SOCK_STREAM|SOCK_DGRAM)
# Line 259  int create_socket(char *hostname, int po Line 259  int create_socket(char *hostname, int po
259    
260    
261  /**  /**
262   * Open a socket with given Port_T structure   * Open a socket using the given Port_T structure. The protocol,
263   * The protocol, destination and type are selected appropriately   * destination and type are selected appropriately.
264   * @param pp connection description   * @param p connection description
265   * @return The socket or -1 if an error occured.   * @return The socket or -1 if an error occured.
266   */   */
267  int create_generic_socket(Port_T p) {  int create_generic_socket(Port_T p) {
# Line 287  int create_generic_socket(Port_T p) { Line 287  int create_generic_socket(Port_T p) {
287    
288    
289  /**  /**
290   * Create a non-blocking socket against pathname with the given   * Create a non-blocking UNIX socket.
291   * protocol.     * @param pathname The pathname to use for the unix socket
  * @param pathname The unix socket to connect to  
  * @param protocol Socket protocol to use (SOCK_STREAM|SOCK_DGRAM)  
292   * @return The socket or -1 if an error occured.   * @return The socket or -1 if an error occured.
293   */   */
294  int create_unix_socket(char *pathname) {  int create_unix_socket(char *pathname) {
# Line 325  int create_unix_socket(char *pathname) { Line 323  int create_unix_socket(char *pathname) {
323    
324    
325  /**  /**
326   * Creates a blocking server socket (SOCK_STREAM type) and binds it to   * Creates a blocking server socket (SOCK_STREAM type) and bind it to
327   * the specified local port number, with the specified backlog. Set a   * the specified local port number, with the specified backlog. Set a
328   * socket option to make the port reusable again. This is useful if   * socket option to make the port reusable again. If a bind address is
329   * the server has been shut down, and then restarted right away while   * given the socket will only accept connect requests to this
330   * sockets are still active on its port. If a bind address is given   * addresses. If the bind address is NULL it will accept connections
331   * the socket will only accept connect requests to this addresses. If   * on any/all local addresses
  * the bind address is NULL it will default accepting connections on  
  * any/all local addresses  
332   * @param port The localhost port number to open   * @param port The localhost port number to open
333   * @param backlog The maximum queue length for incomming connections   * @param backlog The maximum queue length for incomming connections
334   * @param bindAddr the local address the server will bind to   * @param bindAddr the local address the server will bind to
# Line 393  int create_server_socket(int port, int b Line 389  int create_server_socket(int port, int b
389   */   */
390  int close_socket(int socket) {  int close_socket(int socket) {
391    
392    int rv= TRUE;    int r;
393    
394    if((shutdown(socket, 2) < 0)) {    shutdown(socket, 2);
     rv= FALSE;  
   }  
395        
396    if(close(socket) < 0) {    do {
397      rv= FALSE;      r= close(socket);
398    }    } while(r == -1 && errno == EINTR);
399        
400    return rv;    
401      return r;
402    
403  }  }
404    
# Line 558  int sock_read(int socket, void *buffer, Line 553  int sock_read(int socket, void *buffer,
553    
554  }  }
555    
   
 /**  
  * Get the local host name  
  * @return the name of the localhost.  
  * NULL if lookup failed  
  */  
 char *get_localhostname() {  
   
   char hostname[256];  
   
   if (gethostname(hostname, sizeof(hostname)) < 0) {  
       
     return NULL;  
       
   }  
   
   return (strdup(hostname));  
   
 }  
   
556    
557  /* ----------------------------------------------------------------- Private */  /* ----------------------------------------------------------------- Private */
558    

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26