Search code examples
chttp-proxy

Get host from IP address C


Given a url-link, I have to send a TCP request. The first thing I did, after parsing the url properly was to get the IP:

...
struct hostnet *host;
...
host = gethostbyname(url);

My question is the following: Is there any possible way to get the port of an IP address, that does not contain : to indicate it's port?


Solution

  • If the port of ann http: URL does not have a port-part, then it is expected that you'll connect at the default port for that schema. If you're on a Unix box, /etc/services/ has a list, but here's an abridged version:

    ftp     21
    ssh     22
    smtp    25
    http    80
    irc    194
    imap3  220
    ldap   389
    https  443