ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#include <arpa/inet.h>
-- Function: int inet_pton (int AF, const char *CP, void *BUF)
This function converts an Internet address (either IPv4 or IPv6)
from presentation (textual) to network (binary) format. AF should
be either `AF_INET' or `AF_INET6', as appropriate for the type of
address being converted. CP is a pointer to the input string, and
BUF is a pointer to a buffer for the result. It is the caller's
responsibility to make sure the buffer is large enough.
Just like the docs say, I included a minimal example. When all goes well, 0 is returned, else -1 is returned.
Code:
struct in6_addr output;
char* input;
// READ THE INPUTSTRING INTO INPUT
if(inet_pton(AF_INET6, input, &output)) //Parse input to a binary IPv6 address in output.
{
perror(0);
exit(1);
};
// use your binary IPv6 address called output
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.