Find out if a string is an IP address or host name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xx r3negade
    New Member
    • Apr 2008
    • 39

    #1

    Find out if a string is an IP address or host name

    I'm making a C++ wrapper for the standard C BSD sockets. In my object's "connect" function, I have a "host string" that can be either a host name or an ip address. Is there any C function, or any method, of determining if the string follows IP addressing format. I do *not* want to use any regex library or anything of that sort, as it adds unneeded bloat and complication. However, string parsing is nasty in C / C++ and I'd rather not write my own implementation either.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    You can parse the string to see if it contains only numbers and . then it is an IP address.
    else it should be a host name.
    What i am suggesting is a very crude way of doing this

    Raghu

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Did you look at what libraries have been created to take and manipulate IP addresses?

      Comment

      Working...