masqmail
diff src/interface.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 | 41958685480d |
line diff
1.1 --- a/src/interface.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/interface.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -21,79 +21,75 @@ 1.4 /* define if you get problems... */ 1.5 /*#define SOCKADDR_OLD 1*/ 1.6 1.7 -gboolean init_sockaddr(struct sockaddr_in *name, interface *iface) 1.8 +gboolean 1.9 +init_sockaddr(struct sockaddr_in * name, interface * iface) 1.10 { 1.11 - struct hostent *he; 1.12 - struct in_addr ia; 1.13 - 1.14 + struct hostent *he; 1.15 + struct in_addr ia; 1.16 + 1.17 #ifdef SOCKADDR_OLD 1.18 - /* here I tried to be intelligent and failed. */ 1.19 - if(isalpha(iface->address[0])){ 1.20 - if ((he = gethostbyname(iface->address)) == NULL) { 1.21 - logwrite(LOG_ALERT, 1.22 - "local address '%s' unknown. (deleting)\n", 1.23 - iface->address); 1.24 - return FALSE; 1.25 - } 1.26 - memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); 1.27 - }else if(isdigit(iface->address[0])){ 1.28 - if(inet_aton(iface->address, &ia)){ 1.29 - memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); 1.30 - }else{ 1.31 - logwrite(LOG_ALERT, 1.32 - "invalid address '%s': inet_aton() failed (deleting)\n", 1.33 - iface->address); 1.34 - return FALSE; 1.35 - } 1.36 - }else{ 1.37 - logwrite(LOG_ALERT, 1.38 - "invalid address '%s', should begin with a aphanumeric (deleting)\n", 1.39 - iface->address); 1.40 - return FALSE; 1.41 - } 1.42 + /* here I tried to be intelligent and failed. */ 1.43 + if (isalpha(iface->address[0])) { 1.44 + if ((he = gethostbyname(iface->address)) == NULL) { 1.45 + logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); 1.46 + return FALSE; 1.47 + } 1.48 + memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); 1.49 + } else if (isdigit(iface->address[0])) { 1.50 + if (inet_aton(iface->address, &ia)) { 1.51 + memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); 1.52 + } else { 1.53 + logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed (deleting)\n", iface->address); 1.54 + return FALSE; 1.55 + } 1.56 + } else { 1.57 + logwrite(LOG_ALERT, "invalid address '%s', should begin with a aphanumeric (deleting)\n", iface->address); 1.58 + return FALSE; 1.59 + } 1.60 #else 1.61 - /* this is how others to it. I follow the crowd... */ 1.62 - if(inet_aton(iface->address, &ia) != 0){ 1.63 - /* IP address */ 1.64 - memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); 1.65 - }else{ 1.66 - if ((he = gethostbyname(iface->address)) == NULL) { 1.67 - logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); 1.68 - return FALSE; 1.69 - } 1.70 - memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); 1.71 - } 1.72 + /* this is how others to it. I follow the crowd... */ 1.73 + if (inet_aton(iface->address, &ia) != 0) { 1.74 + /* IP address */ 1.75 + memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); 1.76 + } else { 1.77 + if ((he = gethostbyname(iface->address)) == NULL) { 1.78 + logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); 1.79 + return FALSE; 1.80 + } 1.81 + memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); 1.82 + } 1.83 #endif 1.84 - name->sin_family = AF_INET; 1.85 - name->sin_port = htons(iface->port); 1.86 + name->sin_family = AF_INET; 1.87 + name->sin_port = htons(iface->port); 1.88 1.89 - return TRUE; 1.90 + return TRUE; 1.91 } 1.92 1.93 -int make_server_socket(interface *iface) 1.94 +int 1.95 +make_server_socket(interface * iface) 1.96 { 1.97 - int sock = -1; 1.98 - struct sockaddr_in server; 1.99 - 1.100 - memset(&server, 0, sizeof(struct sockaddr_in)); 1.101 + int sock = -1; 1.102 + struct sockaddr_in server; 1.103 1.104 - /* Create the socket. */ 1.105 - sock = socket (PF_INET, SOCK_STREAM, 0); 1.106 - if (sock < 0){ 1.107 - logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); 1.108 - return -1; 1.109 - } 1.110 - 1.111 - if(init_sockaddr(&server, iface)){ 1.112 - /* bind the socket */ 1.113 - if (bind (sock, (struct sockaddr *) &server, sizeof (server)) < 0){ 1.114 - logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); 1.115 - return -1; 1.116 - } 1.117 - }else{ 1.118 - close(sock); 1.119 - return -1; 1.120 - } 1.121 - 1.122 - return sock; 1.123 + memset(&server, 0, sizeof(struct sockaddr_in)); 1.124 + 1.125 + /* Create the socket. */ 1.126 + sock = socket(PF_INET, SOCK_STREAM, 0); 1.127 + if (sock < 0) { 1.128 + logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); 1.129 + return -1; 1.130 + } 1.131 + 1.132 + if (init_sockaddr(&server, iface)) { 1.133 + /* bind the socket */ 1.134 + if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) { 1.135 + logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); 1.136 + return -1; 1.137 + } 1.138 + } else { 1.139 + close(sock); 1.140 + return -1; 1.141 + } 1.142 + 1.143 + return sock; 1.144 }