beautypg.com

Zilog EZ80F91AZA User Manual

Page 66

background image

Creating SSL Applications

UM020107-1211

60

ZTP Network Security SSL Plug-In
User Manual

Client Applications

This section presents steps that a ZTP TCP client process uses to create a TCP connection,
and shows the modification required to use the SSL layer.

Observe the following procedure to establish a TCP-SSL connection in client mode:

1. To open a TCP/SSL client, a TCP client application in ZTP uses the

connect()

API

to request a connection to a specific remote server. For example:

INT16 sockfd;

UINT32 dstipaddr;

struct sockaddr_in server;

struct sockaddr_in client;

sockfd = socket(AF_INET, SOCK_STREAM, 0);

dstipaddr = name2ip("172.16.6.204");

server.sin_addr.s_addr = intel(dstipaddr);

server.sin_family = AF_INET;

server.sin_port = intel16(0x1234);

connect(sockfd, (struct sockaddr *)&server, sizeof(struct

sockaddr) );

This API opens the TCP socket and requests a TCP connection to port

0x1234

on the

remote device on which the IP address is 172.16.6.204. If the connection is success-
fully established,

sockfd

will reference the TCP socket dedicated to this connection.

If the connection fails,

connect()

returns a negative value. To create an SSL connec-

tion socket in client mode, the

connect()

call is modified, as shown in the following

code fragment:

INT16 sockfd;

UINT32 dstipaddr;

struct sockaddr_in server;

struct sockaddr_in client;

sockfd = socket(AF_INET, SOCK_SSL, 0);

dstipaddr = name2ip("172.16.6.204");

server.sin_addr.s_addr = intel(dstipaddr);

server.sin_family = AF_INET;

server.sin_port = intel16(0x1234);

connect(sockfd, (struct sockaddr *)&server, sizeof(struct

sockaddr) );

This manual is related to the following products: