Try to make indent formatting less horrible
[oweals/busybox.git] / libbb / xconnect.c
index 9e771495d671f9147f4b5de2496e986dae885477..2945d760f76a9d76ddc06fff950ca2af576cb4b2 100644 (file)
@@ -6,7 +6,6 @@
  *
  */
 
-#include "inet_common.h"
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -18,7 +17,7 @@
 
 int xconnect(const char *host, const char *port)
 {
-#if CONFIG_FEATURE_IPV6
+#ifdef CONFIG_FEATURE_IPV6
        struct addrinfo hints;
        struct addrinfo *res;
        struct addrinfo *addr_info;
@@ -31,7 +30,7 @@ int xconnect(const char *host, const char *port)
        hints.ai_socktype = SOCK_STREAM;
        error = getaddrinfo(host, port, &hints, &res);
        if (error||!res)
-               perror_msg_and_die(gai_strerror(error));
+               bb_perror_msg_and_die(gai_strerror(error));
        addr_info=res;
        while (res) {
                s=socket(res->ai_family, res->ai_socktype, res->ai_protocol);
@@ -51,14 +50,14 @@ int xconnect(const char *host, const char *port)
        freeaddrinfo(addr_info);
        if (error < 0)
        {
-               perror_msg_and_die("Unable to connect to remote host (%s)", host);
+               bb_perror_msg_and_die("Unable to connect to remote host (%s)", host);
        }
        return s;
 #else
        struct sockaddr_in s_addr;
        int s = socket(AF_INET, SOCK_STREAM, 0);
        struct servent *tserv;
-       int port_nr=atoi(port);
+       int port_nr=htons(atoi(port));
        struct hostent * he;
 
        if (port_nr==0 && (tserv = getservbyname(port, "tcp")) != NULL)
@@ -66,14 +65,14 @@ int xconnect(const char *host, const char *port)
 
        memset(&s_addr, 0, sizeof(struct sockaddr_in));
        s_addr.sin_family = AF_INET;
-       s_addr.sin_port = htons(port_nr);
+       s_addr.sin_port = port_nr;
 
        he = xgethostbyname(host);
        memcpy(&s_addr.sin_addr, he->h_addr, sizeof s_addr.sin_addr);
 
        if (connect(s, (struct sockaddr *)&s_addr, sizeof s_addr) < 0)
        {
-               perror_msg_and_die("Unable to connect to remote host (%s)", host);
+               bb_perror_msg_and_die("Unable to connect to remote host (%s)", host);
        }
        return s;
 #endif