Mercurial > 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 wrap: on
line diff
--- a/src/interface.c Mon Oct 27 16:21:27 2008 +0100 +++ b/src/interface.c Mon Oct 27 16:23:10 2008 +0100 @@ -21,79 +21,75 @@ /* define if you get problems... */ /*#define SOCKADDR_OLD 1*/ -gboolean init_sockaddr(struct sockaddr_in *name, interface *iface) +gboolean +init_sockaddr(struct sockaddr_in * name, interface * iface) { - struct hostent *he; - struct in_addr ia; - + struct hostent *he; + struct in_addr ia; + #ifdef SOCKADDR_OLD - /* here I tried to be intelligent and failed. */ - if(isalpha(iface->address[0])){ - if ((he = gethostbyname(iface->address)) == NULL) { - logwrite(LOG_ALERT, - "local address '%s' unknown. (deleting)\n", - iface->address); - return FALSE; - } - memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); - }else if(isdigit(iface->address[0])){ - if(inet_aton(iface->address, &ia)){ - memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); - }else{ - logwrite(LOG_ALERT, - "invalid address '%s': inet_aton() failed (deleting)\n", - iface->address); - return FALSE; - } - }else{ - logwrite(LOG_ALERT, - "invalid address '%s', should begin with a aphanumeric (deleting)\n", - iface->address); - return FALSE; - } + /* here I tried to be intelligent and failed. */ + if (isalpha(iface->address[0])) { + if ((he = gethostbyname(iface->address)) == NULL) { + logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); + return FALSE; + } + memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); + } else if (isdigit(iface->address[0])) { + if (inet_aton(iface->address, &ia)) { + memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); + } else { + logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed (deleting)\n", iface->address); + return FALSE; + } + } else { + logwrite(LOG_ALERT, "invalid address '%s', should begin with a aphanumeric (deleting)\n", iface->address); + return FALSE; + } #else - /* this is how others to it. I follow the crowd... */ - if(inet_aton(iface->address, &ia) != 0){ - /* IP address */ - memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); - }else{ - if ((he = gethostbyname(iface->address)) == NULL) { - logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); - return FALSE; - } - memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); - } + /* this is how others to it. I follow the crowd... */ + if (inet_aton(iface->address, &ia) != 0) { + /* IP address */ + memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); + } else { + if ((he = gethostbyname(iface->address)) == NULL) { + logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); + return FALSE; + } + memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); + } #endif - name->sin_family = AF_INET; - name->sin_port = htons(iface->port); + name->sin_family = AF_INET; + name->sin_port = htons(iface->port); - return TRUE; + return TRUE; } -int make_server_socket(interface *iface) +int +make_server_socket(interface * iface) { - int sock = -1; - struct sockaddr_in server; - - memset(&server, 0, sizeof(struct sockaddr_in)); + int sock = -1; + struct sockaddr_in server; + + memset(&server, 0, sizeof(struct sockaddr_in)); - /* Create the socket. */ - sock = socket (PF_INET, SOCK_STREAM, 0); - if (sock < 0){ - logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); - return -1; - } - - if(init_sockaddr(&server, iface)){ - /* bind the socket */ - if (bind (sock, (struct sockaddr *) &server, sizeof (server)) < 0){ - logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); - return -1; - } - }else{ - close(sock); - return -1; - } - - return sock; + /* Create the socket. */ + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) { + logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); + return -1; + } + + if (init_sockaddr(&server, iface)) { + /* bind the socket */ + if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) { + logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); + return -1; + } + } else { + close(sock); + return -1; + } + + return sock; }