Thread: inet_pton IPv6 question

  1. #1
    Registered User
    Join Date
    Jul 2017
    Posts
    28

    inet_pton IPv6 question

    My code works for the local loopback address "::1". I want to change it so it works for any IPv6 address.

    If I set my server IPv6 computer's address as "fd00::1" and I don't set up any IPv6 address for my client can I set up the address structure for my server, like:

    Code:
    int portNum = 3344;
    char *addrIn = "fd00::1";
    char *addrOut;
    
    int success = inet_pton(AF_INET6, addrIn, addrOut);
    sAddr->sin6_flowinfo = 0;
    sAddr->sin6_family = AF_INET6;
    sAdr->sin6_addr = addrOut; // Instead of in6addr_any
    sAddr->sin6_port = htons(portNum);

    And, I can set up my client like:

    Code:
    struct hostent *server;
    char *phostAddr ="fd00::1";
    
    server = gethostbyname2(phostAddr, AF_INET6);
    
    cAddr->sin6_flowinfo = 0;
    cAddr->sin6_family = AF_INET6;
    memmove((char *) &cAddr>sin6_addr.s6_addr, (char *) server->h_addr, server->h_length)
    cAddr->sin6_port = htons(portNum);
    I'm mostly interested in whether my client code makes sense and whether or not I need to set up an IPv6 address for my client because my client does not have a GUI for IPv6, but works for the IPv6 loopback address. Also, whether the IPv6 address that I chose for my server would work for Ethernet connection?
    Last edited by JHugh; 08-17-2017 at 07:19 AM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I stopped reading on the line 5
    From the manual for inet_pton
    The address is converted to a struct in6_addr and
    copied to dst, which must be sizeof(struct in6_addr) (16)
    bytes (128 bits) long.
    since your addrOut is uninitialized - this call should crash.

    Do you really have some working code you are trying to modify?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-27-2015, 03:27 PM
  2. Expanding IPv6 address using inet_pton
    By roxynatal in forum Linux Programming
    Replies: 3
    Last Post: 12-07-2011, 04:54 AM
  3. Expanding IPv6 address using inet_pton
    By roxynatal in forum C Programming
    Replies: 3
    Last Post: 12-07-2011, 03:23 AM
  4. error C2065: 'inet_pton' : undeclared identifier - ipv6
    By WeberGer in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-14-2010, 11:38 AM
  5. Replies: 1
    Last Post: 04-05-2003, 08:39 AM

Tags for this Thread