Implementation of portscanner for a host I have tried to check whether the ports of a host from port 0 to port 1023 is open or not. Could someone please review this code and provide feedback.

#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
#include&lt;sys/socket.h&gt;
#include&lt;sys/types.h&gt;
#include&lt;netdb.h&gt;
#include&lt;error.h&gt;
#include&lt;errno.h&gt;
char *convert_int_to_string(int num);

char *convert_int_to_string(int num)
{
    int tmp;
    int i = 0;
    int j = 0;
    static char a[5] = {'0'};

    while (num &gt; 0) {
        tmp = num % 10;
        a[i++] = tmp + '0';
        num = num / 10;
    }
    a[i] = '\0';
    for (j = 0; j &lt; i / 2; j++) {
        tmp = a[j];
        a[j] = a[i - j - 1];
        a[i - j - 1] = tmp;
    }
    return a;
}


int main(int argc, char **argv)
{
    int status;
    char *node;
    char *port_no;
    int sock_fd;
    int i = 0;
    struct  addrinfo hints, *serviceinfo;

    if (argc != 2)
        error(1, errno, "Too many or few arguments\n");
    node = argv[1];
    memset(&amp;hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_STREAM;
    for (i = 0; i &lt; 1024; i++) {
        port_no = convert_int_to_string(i);
        status = getaddrinfo(node, port_no, &amp;hints, &amp;serviceinfo);
        if (status != 0) {
            error(1, errno, "error in getaddrinfo() function call\n");
        }
        sock_fd = socket(serviceinfo-&gt;ai_family, serviceinfo-&gt;ai_socktype, serviceinfo-&gt;ai_protocol);
        if (sock_fd == -1)
            error(1, errno, "error in socket() function call\n");
        status = connect(sock_fd, serviceinfo-&gt;ai_addr, serviceinfo-&gt;ai_addrlen);
        if (status != -1)
            printf("Port : %s is open\n", port_no);
        else
            printf("Port : %s is closed\n", port_no);
    }
}
Use getaddrinfo only once, to resolve the host.  Do the port number iteration directly yourself.  While it might be more complicated, it also doesn't call for repeated hostname resolutions.  This also allows you to eliminate convert_int_to_string()
If you don't want IPv4 and IPv6 (which seems to be indicated by specifying AF_INET, you might be better off using the older functions.  This eliminates the complexity noted before.
As the last step in the loop, you MUST close the socket.  Otherwise, you will wind up with 1027 open descriptors.  Since current linux systems have a limit of 1024 open descriptors, your program will terminate early without this.  Other OSes will have similar limits.  Since you only ever need 4 open descriptors (or maybe 5 depending on getaddrinfo()), you should do the cleanup.
I suggest localizing variables where possible.
In convert_int_to_string(), if you start at the end of the buffer and work backwards, you can return the point in the buffer that you have reached instead of reversing the text.  Alternatively, snprintf(a, sizeof(a), "%d", num); works well.
Passing errno to error() is a mistake if errno isn't set.  This includes the wrong number of arguments error (no number) and the call to getaddrinfo() (which returns an error number and has its own function to make it a string).