Text   |  XML   |  ReML   |   Visible Warnings:

Useless Assignment  at network.c:326

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

net_listen

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/network.c)expand/collapse
Show more  
 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          /* create the socket */
 303          fd = socket(so.sin.sin_family, SOCK_STREAM, 0);
 304  #ifdef HAVE_IPV6 
 305          if (fd == -1 && (errno == EINVAL || errno == EAFNOSUPPORT)) {
 306                  /* IPv6 is not supported by OS */
 307                  so.sin.sin_family = AF_INET;
 308                  so.sin.sin_addr.s_addr = INADDR_ANY;
 309   
 310                  fd = socket(AF_INET, SOCK_STREAM, 0);
 311          }
 312  #endif
 313          if (fd == -1) {
 314                  i_error("socket() failed: %m");
 315                  return -1;
 316          }
 317   
 318          /* set socket options */
 319          setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
 320          setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
 321   
 322          /* If using IPv6, bind only to IPv6 if possible. This avoids
 323             ambiguities with IPv4-mapped IPv6 addresses. */
 324  #ifdef IPV6_V6ONLY 
 325          if (so.sin.sin_family == AF_INET6) {
 326                  opt = 1;
 327                  setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
 328          }
 329  #endif
 330          /* specify the address/port we want to listen in */
 331          ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so));
 332          if (ret < 0) {
 333                  if (errno != EADDRINUSE) {
 334                          i_error("bind(%s, %u) failed: %m",
 335                                  net_ip2addr(my_ip), *port);
 336                  }
 337          } else {
 338                  /* get the actual port we started listen */
 339                  len = SIZEOF_SOCKADDR(so);
 340                  ret = getsockname(fd, &so.sa, &len);
 341                  if (ret >= 0) {
 342                          *port = sin_get_port(&so);
 343   
 344                          /* start listening */
 345                          if (listen(fd, backlog) >= 0)
 346                                  return fd;
 347   
 348                          if (errno != EADDRINUSE)
 349                                  i_error("listen() failed: %m");
 350                  }
 351          }
 352   
 353          /* error */
 354          close_keep_errno(fd);
 355          return -1;
 356  }
Show more  




Change Warning 7116.24495 : Useless Assignment

Priority:
State:
Finding:
Owner:
Note: