LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   IPv6 address ????????? (https://www.linuxquestions.org/questions/programming-9/ipv6-address-456109/)

hegdeshashi 06-19-2006 12:01 AM

IPv6 address ?????????
 
Hi,


To check IPv4 address, we are having inet_addr().
For IPv6 address ?

I want to check IPv6 address ,after entring manually....

any help?????????

elluva 06-19-2006 01:04 AM

This comes from the libc manual,
Code:

#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.


hegdeshashi 06-19-2006 01:38 AM

Hi,


I am entring ipv6 address manually...

I want to check like inet_addr(ipaddr)...


how can I use this one?

elluva 06-19-2006 03:13 AM

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



All times are GMT -5. The time now is 12:23 PM.