Mercurial > dovecot > core-2.2
comparison src/lib/network.c @ 807:35abd7a5d381 HEAD
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Added str_path() and str_ppath() functions. i_snprintf() now returns only -1
or 0 depending on if buffer got full. dec2str() returns the string allocated
from data stack. Instead of just casting to (long) or (int), we now use
dec2str() with printf-like functions. Added o_stream_send_str(). Added
strocpy() and replaced all strcpy()s and strncpy()s with it.
Pretty much untested, hope it doesn't break too badly :)
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 19 Dec 2002 03:02:34 +0200 |
parents | 5ac361acb316 |
children | fd8888f6f037 |
comparison
equal
deleted
inserted
replaced
806:5e42a1dbcd0c | 807:35abd7a5d381 |
---|---|
179 int net_connect_unix(const char *path) | 179 int net_connect_unix(const char *path) |
180 { | 180 { |
181 struct sockaddr_un sa; | 181 struct sockaddr_un sa; |
182 int fd, ret; | 182 int fd, ret; |
183 | 183 |
184 if (strlen(path) > sizeof(sa.sun_path)-1) { | 184 memset(&sa, 0, sizeof(sa)); |
185 sa.sun_family = AF_UNIX; | |
186 if (strocpy(sa.sun_path, path, sizeof(sa.sun_path)) < 0) { | |
185 /* too long path */ | 187 /* too long path */ |
186 errno = EINVAL; | 188 errno = EINVAL; |
187 return -1; | 189 return -1; |
188 } | 190 } |
189 | 191 |
194 | 196 |
195 /* set socket options */ | 197 /* set socket options */ |
196 net_set_nonblock(fd, TRUE); | 198 net_set_nonblock(fd, TRUE); |
197 | 199 |
198 /* connect */ | 200 /* connect */ |
199 memset(&sa, 0, sizeof(sa)); | |
200 sa.sun_family = AF_UNIX; | |
201 strcpy(sa.sun_path, path); | |
202 | |
203 ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa)); | 201 ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa)); |
204 if (ret < 0 && errno != EINPROGRESS) { | 202 if (ret < 0 && errno != EINPROGRESS) { |
205 close_save_errno(fd); | 203 close_save_errno(fd); |
206 return -1; | 204 return -1; |
207 } | 205 } |
310 int net_listen_unix(const char *path) | 308 int net_listen_unix(const char *path) |
311 { | 309 { |
312 struct sockaddr_un sa; | 310 struct sockaddr_un sa; |
313 int fd; | 311 int fd; |
314 | 312 |
315 if (strlen(path) > sizeof(sa.sun_path)-1) { | 313 memset(&sa, 0, sizeof(sa)); |
314 sa.sun_family = AF_UNIX; | |
315 if (strocpy(sa.sun_path, path, sizeof(sa.sun_path)) < 0) { | |
316 /* too long path */ | 316 /* too long path */ |
317 errno = EINVAL; | 317 errno = EINVAL; |
318 return -1; | 318 return -1; |
319 } | 319 } |
320 | 320 |
325 | 325 |
326 /* set socket options */ | 326 /* set socket options */ |
327 net_set_nonblock(fd, TRUE); | 327 net_set_nonblock(fd, TRUE); |
328 | 328 |
329 /* bind */ | 329 /* bind */ |
330 memset(&sa, 0, sizeof(sa)); | |
331 sa.sun_family = AF_UNIX; | |
332 strcpy(sa.sun_path, path); | |
333 | |
334 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == 0) { | 330 if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == 0) { |
335 /* start listening */ | 331 /* start listening */ |
336 if (listen(fd, LISTEN_BACKLOG) == 0) | 332 if (listen(fd, LISTEN_BACKLOG) == 0) |
337 return fd; | 333 return fd; |
338 } | 334 } |