There is a string IP address. How to convert it to byte array?

Closed due to the fact that the essence of the issue is not clear to the participants Vlad from Moscow , Vladimir Martyanov , vp_arth , user194374, Harry 22 Feb '17 at 12:36 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What does "there is a string." Give an example of what is and what you want to get. - Vlad from Moscow
  • 2
    inet_aton() ? - Mike
  • If you have a string in C, then everything is ok, you also have an array of bytes. - vp_arth
  • @Mike you watched the tags? What inet_aton. What are you talking about - Rajab
  • @Radzhab So I put a question mark at the end. I expected you to confirm that you need an analogue of this function (you could indicate this in the question, if so, it would be easier to understand what you want to get). And then you open the source libc, see how this function is made there - Mike

1 answer 1

Most likely, you work with sockets. Then pay attention to such functions as, for example, inet_aton and others, described, for example, here .

If you are interested in a purely abstract question, then you can write something like

 int a[4]; sscanf(addr,"%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]); 

and check that 4 values ​​were read, and all of them fit in the range of 0-255 ...

  • Tags arduino. There is no clean c - Radzhab
  • Then remove the "C" tag :) - Harry
  • You are both confusing C with the standard C library . - 0andriy