HP-UX IPv6 Porting Guide (September 2004)
Table Of Contents
- About This Document
- 1 Introduction
- 2 IPv6 Addressing
- 3 Data Structure Changes
- 4 Migrating Applications from IPv4 to IPv6
- 5 Overview of IPv4 and IPv6 Call Set-up
- 6 Function Calls Converting Names to Addresses
- 7 Function Calls Converting IP addresses to Names
- 8 Reading Error Messages
- 9 Freeing Memory
- 10 Converting Binary and Text Addresses
- 11 Testing for Scope and Type of IPv6 addresses using Macros
- 12 Identifying Local Interface Names and Indexes
- 13 Configuring or Querying an Interface using IPv6 ioctl() Function Calls
- 14 Verifying IPv6 Installation
- 15 Sample Client/Server Programs
- A IPv4 to IPv6 Quick Reference Guide

Sample Client/Server Programs
IPv6 TCP Client using getipnodebyname()
Chapter 15 63
IPv6 TCP Client using getipnodebyname()
This code fragment is part of an example IPv6 client program that ships in the HP-UX 11i v2
/usr/lib/demos/networking/socket/af_inet6 directory, rewritten using the
getipnodebyname() function call.
struct sockaddr_in6 peeraddr_in6; /* for peer socket address */
memset ((char *)&peeraddr_in6, 0, sizeof(struct sockaddr_in6));
hp = getipnodebyname (argv[1], AF_INET6, AI_DEFAULT, &error);
if (hp == NULL) {
fprintf(stderr, "%s: %s not found in /etc/hosts\n",
argv[0], argv[1]);
exit(1);
}
peeraddr_in6.sin6_family = hp->h_addrtype;
memcpy(&peeraddr_in6.sin6_addr, hp->h_addr, hp->h_length);
/* Find the information for the "example" server
* in order to get the needed port number.
*/
sp = getservbyname ("example", "tcp");
if (sp == NULL) {
fprintf(stderr, "%s: example not found in /etc/services\n",
argv[0]);
exit(1);
}
peeraddr_in6.sin6_port = sp->s_port;
/* Create the socket. */
s = socket (AF_INET6, SOCK_STREAM, 0);
if (s == -1) {
perror(argv[0]);
fprintf(stderr, "%s: unable to create socket\n", argv[0]);
exit(1);
}
/* Try to connect to the remote server at the address
* which was just built into peeraddr.
*/
if (connect(s, &peeraddr_in6, sizeof(peeraddr_in6)) == -1) {
perror(argv[0]);
fprintf(stderr, "%s: unable to connect to remote\n", argv[0]);
exit(1);
}