(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/network.c) |
| |
| 292 | | | int net_listen(const struct ip_addr *my_ip, unsigned int *port, int backlog) |
| 293 | | | { |
| 294 | | | union sockaddr_union so; |
| 295 | | | int ret, fd, opt = 1; |
| 296 | | | socklen_t len; |
| 297 | | | |
| 298 | | | memset(&so, 0, sizeof(so)); |
| 299 | | | sin_set_port(&so, *port); |
| 300 | | | sin_set_ip(&so, my_ip); |
| 301 | | | |
| 302 | | | |
| 303 | | | fd = socket(so.sin.sin_family, SOCK_STREAM, 0);
x /usr/include/bits/socket.h |
| |
44 | #define SOCK_STREAM SOCK_STREAM |
| |
|
| 304 | | | #ifdef HAVE_IPV6 |
| 305 | | | if (fd == -1 && (errno == EINVAL || errno == EAFNOSUPPORT)) {
x /usr/include/asm-generic/errno-base.h |
| |
25 | #define EINVAL 22 /* Invalid argument */ |
| |
x /usr/include/asm-generic/errno.h |
| |
70 | #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ |
| |
|
| 306 | | | |
| 307 | | | so.sin.sin_family = AF_INET;
x /usr/include/bits/socket.h |
| |
78 | #define PF_INET 2 /* IP protocol family. */ |
| |
|
| 308 | | | so.sin.sin_addr.s_addr = INADDR_ANY;
x /usr/include/netinet/in.h |
| |
177 | #define INADDR_ANY ((in_addr_t) 0x00000000) |
| |
|
| 309 | | | |
| 310 | | | fd = socket(AF_INET, SOCK_STREAM, 0);
x /usr/include/bits/socket.h |
| |
78 | #define PF_INET 2 /* IP protocol family. */ |
| |
x /usr/include/bits/socket.h |
| |
44 | #define SOCK_STREAM SOCK_STREAM |
| |
|
| 311 | | | } |
| 312 | | | #endif |
| 313 | | | if (fd == -1) { |
| 314 | | | i_error("socket() failed: %m"); |
| 315 | | | return -1; |
| 316 | | | } |
| 317 | | | |
| 318 | | | |
| 319 | | | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); |
| 320 | | | setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)); |
| 321 | | | |
| 322 | | | |
| 323 | | | |
| 324 | | | #ifdef IPV6_V6ONLY
x /usr/include/bits/in.h |
| |
147 | #define IPV6_V6ONLY 26 |
| |
|
| 325 | | | if (so.sin.sin_family == AF_INET6) {
x /usr/include/bits/socket.h |
| |
86 | #define PF_INET6 10 /* IP version 6. */ |
| |
|
| 326 | | | opt = 1; |
Useless Assignment
This code assigns the variable the same value it already had. |
|
| 327 | | | setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
x /usr/include/netinet/in.h |
| |
59 | #define IPPROTO_IPV6 IPPROTO_IPV6 |
| |
x /usr/include/bits/in.h |
| |
147 | #define IPV6_V6ONLY 26 |
| |
|
| 328 | | | } |
| 329 | | | #endif |
| 330 | | | |
| 331 | | | ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so));
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/network.c |
| |
24 | # define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \ |
25 | sizeof(so.sin6) : sizeof(so.sin)) |
| |
x /usr/include/bits/socket.h |
| |
86 | #define PF_INET6 10 /* IP version 6. */ |
| |
|
| 332 | | | if (ret < 0) { |
| 333 | | | if (errno != EADDRINUSE) {
x /usr/include/asm-generic/errno.h |
| |
71 | #define EADDRINUSE 98 /* Address already in use */ |
| |
|
| 334 | | | i_error("bind(%s, %u) failed: %m", |
| 335 | | | net_ip2addr(my_ip), *port); |
| 336 | | | } |
| 337 | | | } else { |
| 338 | | | |
| 339 | | | len = SIZEOF_SOCKADDR(so);
x /home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/network.c |
| |
24 | # define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \ |
25 | sizeof(so.sin6) : sizeof(so.sin)) |
| |
x /usr/include/bits/socket.h |
| |
86 | #define PF_INET6 10 /* IP version 6. */ |
| |
|
| 340 | | | ret = getsockname(fd, &so.sa, &len); |
| 341 | | | if (ret >= 0) { |
| 342 | | | *port = sin_get_port(&so); |
| 343 | | | |
| 344 | | | |
| 345 | | | if (listen(fd, backlog) >= 0) |
| 346 | | | return fd; |
| 347 | | | |
| 348 | | | if (errno != EADDRINUSE)
x /usr/include/asm-generic/errno.h |
| |
71 | #define EADDRINUSE 98 /* Address already in use */ |
| |
|
| 349 | | | i_error("listen() failed: %m"); |
| 350 | | | } |
| 351 | | | } |
| 352 | | | |
| 353 | | | |
| 354 | | | close_keep_errno(fd); |
| 355 | | | return -1; |
| 356 | | | } |
| |