diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-18 20:31:21 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-12-18 20:31:21 +0300 |
commit | 5f0da61541dd368961694b26766b12d051227844 (patch) | |
tree | 98f069f3db91ed38e7044ef022149e6bb6576121 /src/util.c | |
parent | 9e9ced325226942bbfb6c4aa307f388044e29b23 (diff) | |
download | rspamd-5f0da61541dd368961694b26766b12d051227844.tar.gz rspamd-5f0da61541dd368961694b26766b12d051227844.zip |
* Make sample config more complete
* Fix bugs with config file parsing
* Fix bugs with creating sockets and reading commands
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/util.c b/src/util.c index 1399e76c7..6794d7bb7 100644 --- a/src/util.c +++ b/src/util.c @@ -31,33 +31,41 @@ event_make_socket_nonblocking (int fd) return 0; } -static int -make_socket_ai (struct addrinfo *ai) +int +make_socket (struct in_addr *addr, u_short port) { struct linger linger; int fd, on = 1, r; int serrno; + struct sockaddr_in sin; - /* Create listen socket */ - fd = socket(AF_INET, SOCK_STREAM, 0); + /* Create socket */ + fd = socket (AF_INET, SOCK_STREAM, 0); if (fd == -1) { - return (-1); + return -1; } - if (event_make_socket_nonblocking(fd) < 0) + if (event_make_socket_nonblocking(fd) < 0) { goto out; + } if (fcntl(fd, F_SETFD, 1) == -1) { goto out; } - + + /* Socket options */ setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); linger.l_onoff = 1; linger.l_linger = 5; setsockopt(fd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)); + + /* Bind options */ + sin.sin_family = AF_INET; + sin.sin_port = htons (port); + sin.sin_addr.s_addr = addr->s_addr; - r = bind(fd, ai->ai_addr, ai->ai_addrlen); + r = bind(fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in)); if (r == -1) { if (errno != EINPROGRESS) { @@ -75,30 +83,6 @@ make_socket_ai (struct addrinfo *ai) } int -make_socket (const char *address, u_short port) -{ - int fd; - struct addrinfo ai, *aitop = NULL; - char strport[NI_MAXSERV]; - int ai_result; - - memset (&ai, 0, sizeof (ai)); - ai.ai_family = AF_INET; - ai.ai_socktype = SOCK_STREAM; - ai.ai_flags = AI_PASSIVE; - snprintf (strport, sizeof (strport), "%d", port); - if ((ai_result = getaddrinfo (address, strport, &ai, &aitop)) != 0) { - return (-1); - } - - fd = make_socket_ai (aitop); - - freeaddrinfo (aitop); - - return (fd); -} - -int make_unix_socket (const char *path, struct sockaddr_un *addr) { size_t len = strlen (path); |