IPX/SPX Programming Manual

Sample Programs
HP NonStop IPX/SPX Programming Manual528022-001
6-4
Sample SAP Programs
snv.snv_addr.s_host[0] = 0x08;
snv.snv_addr.s_host[1] = 0x00;
snv.snv_addr.s_host[2] = 0x8E;
snv.snv_addr.s_host[3] = 0x00;
snv.snv_addr.s_host[4] = 0x2E;
snv.snv_addr.s_host[5] = 0x18;
snv.snv_addr.s_port = WELL_KNOWN_PORT;
/*
* Connect to remote.
*/
if (connect(sock, (struct sockaddr *)&snv, sizeof(snv)) < 0)
{
perror("SPX Client: connect failure");
exit(1);
}
printf("SPX Client: connected to port 0x%hx\n",
snv.snv_addr.s_port);
/*
* Send data to remote. Note that the number of bytes
* sent could be less than DATA_BUF_SIZE.
*/
bytesSent = send(sock, buf, DATA_BUF_SIZE, 0);
if (bytesSent == -1) {
perror("SPX Client: send failure");
exit(1);
}
printf("SPX Client: sent %d bytes\n", bytesSent);
exit(0);
}
Sample SAP Programs
The following SPXII client/server pair uses the SAP interface.
SPXII Client Using SAP
/*
* Sample SPX client program. This example uses
* SAP to determine the server's address.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <socket.h>
#include <nv.h>
#include <netdb.h>
#include <zspi.c>
#include <zipx.c>
#include <sapapi.h>
#define DATA_BUF_SIZE 512
#define SERVER_TYPE 42
#define SERVER_NAME "TANDEM_EXAMPLE_SERVER"