Mercurial > masqmail
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:31cc8a89cb74 | 10:26e34ae9a3e3 |
---|---|
19 #include "masqmail.h" | 19 #include "masqmail.h" |
20 | 20 |
21 /* define if you get problems... */ | 21 /* define if you get problems... */ |
22 /*#define SOCKADDR_OLD 1*/ | 22 /*#define SOCKADDR_OLD 1*/ |
23 | 23 |
24 gboolean init_sockaddr(struct sockaddr_in *name, interface *iface) | 24 gboolean |
25 init_sockaddr(struct sockaddr_in * name, interface * iface) | |
25 { | 26 { |
26 struct hostent *he; | 27 struct hostent *he; |
27 struct in_addr ia; | 28 struct in_addr ia; |
28 | 29 |
29 #ifdef SOCKADDR_OLD | 30 #ifdef SOCKADDR_OLD |
30 /* here I tried to be intelligent and failed. */ | 31 /* here I tried to be intelligent and failed. */ |
31 if(isalpha(iface->address[0])){ | 32 if (isalpha(iface->address[0])) { |
32 if ((he = gethostbyname(iface->address)) == NULL) { | 33 if ((he = gethostbyname(iface->address)) == NULL) { |
33 logwrite(LOG_ALERT, | 34 logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); |
34 "local address '%s' unknown. (deleting)\n", | 35 return FALSE; |
35 iface->address); | 36 } |
36 return FALSE; | 37 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); |
37 } | 38 } else if (isdigit(iface->address[0])) { |
38 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); | 39 if (inet_aton(iface->address, &ia)) { |
39 }else if(isdigit(iface->address[0])){ | 40 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); |
40 if(inet_aton(iface->address, &ia)){ | 41 } else { |
41 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); | 42 logwrite(LOG_ALERT, "invalid address '%s': inet_aton() failed (deleting)\n", iface->address); |
42 }else{ | 43 return FALSE; |
43 logwrite(LOG_ALERT, | 44 } |
44 "invalid address '%s': inet_aton() failed (deleting)\n", | 45 } else { |
45 iface->address); | 46 logwrite(LOG_ALERT, "invalid address '%s', should begin with a aphanumeric (deleting)\n", iface->address); |
46 return FALSE; | 47 return FALSE; |
47 } | 48 } |
48 }else{ | |
49 logwrite(LOG_ALERT, | |
50 "invalid address '%s', should begin with a aphanumeric (deleting)\n", | |
51 iface->address); | |
52 return FALSE; | |
53 } | |
54 #else | 49 #else |
55 /* this is how others to it. I follow the crowd... */ | 50 /* this is how others to it. I follow the crowd... */ |
56 if(inet_aton(iface->address, &ia) != 0){ | 51 if (inet_aton(iface->address, &ia) != 0) { |
57 /* IP address */ | 52 /* IP address */ |
58 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); | 53 memcpy(&(name->sin_addr), &ia, sizeof(name->sin_addr)); |
59 }else{ | 54 } else { |
60 if ((he = gethostbyname(iface->address)) == NULL) { | 55 if ((he = gethostbyname(iface->address)) == NULL) { |
61 logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); | 56 logwrite(LOG_ALERT, "local address '%s' unknown. (deleting)\n", iface->address); |
62 return FALSE; | 57 return FALSE; |
63 } | 58 } |
64 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); | 59 memcpy(&(name->sin_addr), he->h_addr, sizeof(name->sin_addr)); |
65 } | 60 } |
66 #endif | 61 #endif |
67 name->sin_family = AF_INET; | 62 name->sin_family = AF_INET; |
68 name->sin_port = htons(iface->port); | 63 name->sin_port = htons(iface->port); |
69 | 64 |
70 return TRUE; | 65 return TRUE; |
71 } | 66 } |
72 | 67 |
73 int make_server_socket(interface *iface) | 68 int |
69 make_server_socket(interface * iface) | |
74 { | 70 { |
75 int sock = -1; | 71 int sock = -1; |
76 struct sockaddr_in server; | 72 struct sockaddr_in server; |
77 | |
78 memset(&server, 0, sizeof(struct sockaddr_in)); | |
79 | 73 |
80 /* Create the socket. */ | 74 memset(&server, 0, sizeof(struct sockaddr_in)); |
81 sock = socket (PF_INET, SOCK_STREAM, 0); | 75 |
82 if (sock < 0){ | 76 /* Create the socket. */ |
83 logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); | 77 sock = socket(PF_INET, SOCK_STREAM, 0); |
84 return -1; | 78 if (sock < 0) { |
85 } | 79 logwrite(LOG_ALERT, "socket: %s\n", strerror(errno)); |
86 | 80 return -1; |
87 if(init_sockaddr(&server, iface)){ | 81 } |
88 /* bind the socket */ | 82 |
89 if (bind (sock, (struct sockaddr *) &server, sizeof (server)) < 0){ | 83 if (init_sockaddr(&server, iface)) { |
90 logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); | 84 /* bind the socket */ |
91 return -1; | 85 if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0) { |
92 } | 86 logwrite(LOG_ALERT, "bind: %s\n", strerror(errno)); |
93 }else{ | 87 return -1; |
94 close(sock); | 88 } |
95 return -1; | 89 } else { |
96 } | 90 close(sock); |
97 | 91 return -1; |
98 return sock; | 92 } |
93 | |
94 return sock; | |
99 } | 95 } |