masqmail

diff src/libident/id_open.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children
line diff
     1.1 --- a/src/libident/id_open.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/libident/id_open.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -39,129 +39,120 @@
     1.4  
     1.5  
     1.6  /*
     1.7 -ident_t *id_open __P3(struct in_addr *, laddr,
     1.8 -		      struct in_addr *, faddr,
     1.9 -		      struct timeval *, timeout)
    1.10 +ident_t *id_open __P3(struct in_addr *, laddr, struct in_addr *, faddr, struct timeval *, timeout)
    1.11  */
    1.12  
    1.13 -ident_t *id_open __P((	__STRUCT_IN_ADDR_P laddr,
    1.14 -			__STRUCT_IN_ADDR_P faddr,
    1.15 -			__STRUCT_TIMEVAL_P timeout))
    1.16 +ident_t*
    1.17 +id_open __P((__STRUCT_IN_ADDR_P laddr, __STRUCT_IN_ADDR_P faddr, __STRUCT_TIMEVAL_P timeout))
    1.18  {
    1.19 -    ident_t *id;
    1.20 -    int res, tmperrno;
    1.21 -    struct sockaddr_in sin_laddr, sin_faddr;
    1.22 -    fd_set rs, ws, es;
    1.23 +	ident_t *id;
    1.24 +	int res, tmperrno;
    1.25 +	struct sockaddr_in sin_laddr, sin_faddr;
    1.26 +	fd_set rs, ws, es;
    1.27  #ifndef OLD_SETSOCKOPT
    1.28 -    int on = 1;
    1.29 -    struct linger linger;
    1.30 +	int on = 1;
    1.31 +	struct linger linger;
    1.32  #endif
    1.33 -    
    1.34 -    if ((id = (ident_t *) malloc(sizeof(*id))) == 0)
    1.35 -	return 0;
    1.36 -    
    1.37 -    if ((id->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    1.38 -    {
    1.39 -	free(id);
    1.40 -	return 0;
    1.41 -    }
    1.42 -    
    1.43 -    if (timeout)
    1.44 -    {
    1.45 -	if ((res = fcntl(id->fd, F_GETFL, 0)) < 0)
    1.46 -	    goto ERROR;
    1.47 +
    1.48 +	if ((id = (ident_t *) malloc(sizeof(*id))) == 0)
    1.49 +		return 0;
    1.50 +
    1.51 +	if ((id->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    1.52 +		free(id);
    1.53 +		return 0;
    1.54 +	}
    1.55 +
    1.56 +	if (timeout) {
    1.57 +		if ((res = fcntl(id->fd, F_GETFL, 0)) < 0)
    1.58 +			goto ERROR;
    1.59  
    1.60  #ifndef VMS
    1.61 -	if (fcntl(id->fd, F_SETFL, res | FNDELAY) < 0)
    1.62 -	    goto ERROR;
    1.63 +		if (fcntl(id->fd, F_SETFL, res | FNDELAY) < 0)
    1.64 +			goto ERROR;
    1.65  #endif
    1.66 -    }
    1.67 +	}
    1.68  
    1.69 -    /* We silently ignore errors if we can't change LINGER */
    1.70 +	/* We silently ignore errors if we can't change LINGER */
    1.71  #ifdef OLD_SETSOCKOPT
    1.72 -    /* Old style setsockopt() */
    1.73 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_DONTLINGER);
    1.74 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR);
    1.75 +	/* Old style setsockopt() */
    1.76 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_DONTLINGER);
    1.77 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR);
    1.78  #else
    1.79 -    /* New style setsockopt() */
    1.80 -    linger.l_onoff = 0;
    1.81 -    linger.l_linger = 0;
    1.82 -    
    1.83 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
    1.84 -    (void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on));
    1.85 +	/* New style setsockopt() */
    1.86 +	linger.l_onoff = 0;
    1.87 +	linger.l_linger = 0;
    1.88 +
    1.89 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
    1.90 +	(void) setsockopt(id->fd, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on));
    1.91  #endif
    1.92 -    
    1.93 -    id->buf[0] = '\0';
    1.94 -    
    1.95 -    bzero((char *)&sin_laddr, sizeof(sin_laddr));
    1.96 -    sin_laddr.sin_family = AF_INET;
    1.97 -    sin_laddr.sin_addr = *laddr;
    1.98 -    sin_laddr.sin_port = 0;
    1.99 -    
   1.100 -    if (bind(id->fd, (struct sockaddr *) &sin_laddr, sizeof(sin_laddr)) < 0)
   1.101 -    {
   1.102 +
   1.103 +	id->buf[0] = '\0';
   1.104 +
   1.105 +	bzero((char *) &sin_laddr, sizeof(sin_laddr));
   1.106 +	sin_laddr.sin_family = AF_INET;
   1.107 +	sin_laddr.sin_addr = *laddr;
   1.108 +	sin_laddr.sin_port = 0;
   1.109 +
   1.110 +	if (bind(id->fd, (struct sockaddr *) &sin_laddr, sizeof(sin_laddr)) < 0) {
   1.111  #ifdef DEBUG
   1.112 -	perror("libident: bind");
   1.113 +		perror("libident: bind");
   1.114  #endif
   1.115 -	goto ERROR;
   1.116 -    }
   1.117 -    
   1.118 -    bzero((char *)&sin_faddr, sizeof(sin_faddr));
   1.119 -    sin_faddr.sin_family = AF_INET;
   1.120 -    sin_faddr.sin_addr = *faddr;
   1.121 -    sin_faddr.sin_port = htons(IDPORT);
   1.122 +		goto ERROR;
   1.123 +	}
   1.124  
   1.125 -    errno = 0;
   1.126 -    res = connect(id->fd, (struct sockaddr *) &sin_faddr, sizeof(sin_faddr));
   1.127 -    if (res < 0 && errno != EINPROGRESS)
   1.128 -    {
   1.129 +	bzero((char *) &sin_faddr, sizeof(sin_faddr));
   1.130 +	sin_faddr.sin_family = AF_INET;
   1.131 +	sin_faddr.sin_addr = *faddr;
   1.132 +	sin_faddr.sin_port = htons(IDPORT);
   1.133 +
   1.134 +	errno = 0;
   1.135 +	res = connect(id->fd, (struct sockaddr *) &sin_faddr, sizeof(sin_faddr));
   1.136 +	if (res < 0 && errno != EINPROGRESS) {
   1.137  #ifdef DEBUG
   1.138 -	perror("libident: connect");
   1.139 +		perror("libident: connect");
   1.140  #endif
   1.141 -	goto ERROR;
   1.142 -    }
   1.143 +		goto ERROR;
   1.144 +	}
   1.145  
   1.146 -    if (timeout)
   1.147 -    {
   1.148 -	FD_ZERO(&rs);
   1.149 -	FD_ZERO(&ws);
   1.150 -	FD_ZERO(&es);
   1.151 -	
   1.152 -	FD_SET(id->fd, &rs);
   1.153 -	FD_SET(id->fd, &ws);
   1.154 -	FD_SET(id->fd, &es);
   1.155 +	if (timeout) {
   1.156 +		FD_ZERO(&rs);
   1.157 +		FD_ZERO(&ws);
   1.158 +		FD_ZERO(&es);
   1.159 +
   1.160 +		FD_SET(id->fd, &rs);
   1.161 +		FD_SET(id->fd, &ws);
   1.162 +		FD_SET(id->fd, &es);
   1.163  
   1.164  #ifdef __hpux
   1.165 -	if ((res = select(FD_SETSIZE, (int *) &rs, (int *) &ws, (int *) &es, timeout)) < 0)
   1.166 +		if ((res = select(FD_SETSIZE, (int *) &rs, (int *) &ws, (int *) &es, timeout)) < 0)
   1.167  #else
   1.168 -	if ((res = select(FD_SETSIZE, &rs, &ws, &es, timeout)) < 0)
   1.169 +		if ((res = select(FD_SETSIZE, &rs, &ws, &es, timeout)) < 0)
   1.170  #endif
   1.171 -	{
   1.172 +		{
   1.173  #ifdef DEBUG
   1.174 -	    perror("libident: select");
   1.175 +			perror("libident: select");
   1.176  #endif
   1.177 -	    goto ERROR;
   1.178 +			goto ERROR;
   1.179 +		}
   1.180 +
   1.181 +		if (res == 0) {
   1.182 +			errno = ETIMEDOUT;
   1.183 +			goto ERROR;
   1.184 +		}
   1.185 +
   1.186 +		if (FD_ISSET(id->fd, &es))
   1.187 +			goto ERROR;
   1.188 +
   1.189 +		if (!FD_ISSET(id->fd, &rs) && !FD_ISSET(id->fd, &ws))
   1.190 +			goto ERROR;
   1.191  	}
   1.192 -	
   1.193 -	if (res == 0)
   1.194 -	{
   1.195 -	    errno = ETIMEDOUT;
   1.196 -	    goto ERROR;
   1.197 -	}
   1.198 -	
   1.199 -	if (FD_ISSET(id->fd, &es))
   1.200 -	    goto ERROR;
   1.201 -	
   1.202 -	if (!FD_ISSET(id->fd, &rs) && !FD_ISSET(id->fd, &ws))
   1.203 -	    goto ERROR;
   1.204 -    }
   1.205 -    
   1.206 -    return id;
   1.207 -    
   1.208 +
   1.209 +	return id;
   1.210 +
   1.211    ERROR:
   1.212 -    tmperrno = errno;		/* Save, so close() won't erase it */
   1.213 -    close(id->fd);
   1.214 -    free(id);
   1.215 -    errno = tmperrno;
   1.216 -    return 0;
   1.217 +	tmperrno = errno;  /* Save, so close() won't erase it */
   1.218 +	close(id->fd);
   1.219 +	free(id);
   1.220 +	errno = tmperrno;
   1.221 +	return 0;
   1.222  }