IPv4 Address

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Mon Nov 28, 2011 5:34 am

IPv4 Address

Postby arunsolo1984 » Tue Nov 29, 2011 2:05 am

:help: How to perform IPv4 (IP Address)format validation? It should accept only unicast Ips. Multicast and broadcast Ips should not be accepted.

New php-forum User
New php-forum User
Posts: 75
Joined: Wed Jun 12, 2013 9:30 pm

Re: IPv4 Address

Postby johnmacd » Mon Apr 11, 2016 5:09 am


Following are steps to check whether a given string is valid IPv4 address or not:
step 1) Parse string with “.” as delimiter using “strtok()” function.
e.g. ptr = strtok(str, DELIM);
Run on IDE
step 2)
……..a) If ptr contains any character which is not digit then return 0
……..b) Convert “ptr” to decimal number say ‘NUM’
……..c) If NUM is not in range of 0-255 return 0
……..d) If NUM is in range of 0-255 and ptr is non-NULL increment “dot_counter” by 1
……..e) if ptr is NULL goto step 3 else goto step 1
step 3) if dot_counter != 3 return 0 else return 1.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 9 guests