Find the answer to your Linux question:
Results 1 to 8 of 8
Greetings, I have a C program running on linux that I am using to try to connect to a server (on the same network) to pull some data. I have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2014
    Posts
    3

    Linux client connection refused on port 80


    Greetings,

    I have a C program running on linux that I am using to try to connect to a server (on the same network) to pull some data. I have freeware that does the hardwork (creates the socket, connects, reads/writes). I am trying to connect over port 80 (http). At the time of the socket "connect" I get a "connection refused" (looking at errno). Why would this be? Curious that when I use port 8443 the connection is made. Why would I get a connection refused on port 80? I ran chkconfig and I dont have iptables enabled. Is there some other linux security feature that can block me reaching out to another host on port 80?

    thanks,
    Bill

  2. #2
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,188
    Is there a server running on port 80? If not you'll get connection refused.

  3. #3
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    926
    Have you run a check to see what ports are in use?

    Linux List The Open Ports And The Process That Owns Them - nixCraft
    A lion does not lose sleep, over the opinion of sheep.

  4. #4
    Just Joined!
    Join Date
    Jun 2014
    Posts
    3
    thank you for the responses. I appreciate it.

    My linux box has the client application running. It is trying to open a socket connection on port 80 to a remote server. That remote server happens to be a PC (windows 2k) and running Sambar web server. The person who owns the server happens to sit near me. We have worked back and forth and he is sure port 80 is open in his configuration file.

    From my linux box (the client), I can open a web browser and get to that server. But, my C application connecting to the server on port 80 gets connection refused returned in errno. Also, I have a PC on that same network. I compiled that same C application for the PC and it was able to connect to that server.

    The server in question has been through 'lock down' procedures, so I am thinking that might come in to play. Can there be anything on the client side that says "no, I will not allow you to go out over port 80"? (that would seem unlikely since a web browser on my linux client is able to connect to the server.

    Any ideas?

    thanks,
    Bill

  5. #5
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,188
    Interesting. I would add a bunch of debugging statements to the code - checking the return value of each of the socket setup functions and calling perror with the method name as its argument on the error at the moment it occurs. You also might try to telnet to port 80 from the linux box for comparison.

  6. #6
    Linux Newbie
    Join Date
    Jun 2012
    Location
    SF Bay area
    Posts
    166
    Quote Originally Posted by boomer11 View Post
    From my linux box (the client), I can open a web browser and get to that server. But, my C application connecting to the server on port 80 gets connection refused returned in errno. Also, I have a PC on that same network. I compiled that same C application for the PC and it was able to connect to that server.

    The server in question has been through 'lock down' procedures, so I am thinking that might come in to play. Can there be anything on the client side that says "no, I will not allow you to go out over port 80"? (that would seem unlikely since a web browser on my linux client is able to connect to the server.
    I second the suggestion from gregm that you try telnet to port 80, or curl, from the server where the application is failing to connect to see what they say.

    And per your question, yes the client side system could be using host based ACL's (like iptables) to block outbound connections. If a browser run from that system is working, maybe it's using a proxy server? That would mean the outbound connection wouldn't be on port 80, which could explain the difference.

    One final suggestion for you... If you run "netstat -ant" immediately afterwards and the system should still show you the remnants of the failed connection. That way you can make sure the IP and port on the server end are what you intended.

  7. #7
    Just Joined!
    Join Date
    Jun 2014
    Posts
    3

    Solution Found

    I very much appreciate all of your inputs. I learned some new things I didnt know about.

    What I ended up doing was trying a different freeware version of http_get which seemed to work. Interesting, it looks much like the other routine that I used that didnt work. I am just happy that I got SOMETHING that worked.

    Thank you again for your help.

    Bill

  8. #8
    Just Joined!
    Join Date
    Nov 2013
    Posts
    18
    Could be that the source port is binding to port 80 as well. check if the api is able to specify the source port. or that the source port can be "randomized".

    When checking port connections between servers. always try a SYN/ACK port scanner like nmap. or telnet.

    you can also use wireshark/tcpdump to check if the packets are in fact leaving the client.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •