server_socket = connect_to_host(host, port);
}
- if (server_socket == -1) {
+ if (server_socket < 0) {
LOG(WARNING, "failed to connect to server");
send_forwarding_failure(client_fd_write);
goto out;
server_socket = socket(server->ai_family,
server->ai_socktype,
server->ai_protocol);
- if (server_socket == -1) {
+ if (server_socket < 0) {
LOG_PERROR(DEBUG, "connect_to_host(): socket(), trying next");
continue;
}
- if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) {
+ if (connect(server_socket, server->ai_addr, server->ai_addrlen) == 0) {
break;
}
LOG_PERROR(DEBUG, "connect_to_host(): connect(), trying next");
#else
server_socket = socket(PF_INET6, SOCK_STREAM, 0);
#endif
- if (server_socket == -1) {
+ if (server_socket < 0) {
perror("socket()");
return EXIT_FAILURE;
}
server_in.sin6_port = htons((uint16_t)port); /* port to bind to */
#endif
if (bind(server_socket, (struct sockaddr *)&server_in,
- sizeof(server_in)) == -1) {
+ sizeof(server_in)) != 0) {
perror("bind()");
return EXIT_FAILURE;
}
/* And accept connections. */
- if (listen(server_socket, 5) == -1) {
+ if (listen(server_socket, 5) != 0) {
perror("listen()");
return EXIT_FAILURE;
}
while (!done) {
/* Accept new connection. */
client_socket = accept(server_socket, NULL, NULL);
- if (client_socket == -1) {
+ if (client_socket < 0) {
perror("accept()");
break;
}
server_socket = socket(server->ai_family,
server->ai_socktype,
server->ai_protocol);
- if (server_socket == -1) {
+ if (server_socket < 0) {
perror("connect_to_host(): socket(), trying next");
continue;
}
- if (connect(server_socket, server->ai_addr, server->ai_addrlen) != -1) {
+ if (connect(server_socket, server->ai_addr, server->ai_addrlen) == 0) {
break;
}
perror("connect_to_host(): connect(), trying next");