Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: Xx r3negade (Newbie) on July 25th, 2008 03:15 AM
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.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
gpraghuram's Avatar
gpraghuram
Expert
1,098 Posts
July 25th, 2008
04:03 AM
#2

Re: Find out if a string is an IP address or host name
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

Reply
sicarie's Avatar
sicarie
Forum Leader
3,779 Posts
July 25th, 2008
02:08 PM
#3

Re: Find out if a string is an IP address or host name
Did you look at what libraries have been created to take and manipulate IP addresses?

Reply
Reply
Not the answer you were looking for? Post your question . . .
183,821 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top C / C++ Forum Contributors