beautypg.com

Zilog EZ80F91AZA User Manual

Page 64

background image

UM020107-1211

Creating SSL Applications

ZTP Network Security SSL Plug-In

User Manual

58

INT16 sockfd;

INT16 confd;

struct sockaddr_in server;

struct sockaddr_in client;

sockfd = socket(AF_INET, SOCK_STREAM, 0);

server.sin_addr.s_addr = INADDR_ANY;

server.sin_family = AF_INET;

server.sin_port = intel16(0x1234);

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

sockaddr_in));

listen(sockfd, 1);

This API opens the TCP socket and requests a server socket to be created on TCP port

0x1234

. To create an SSL server application, the above code is modified, as shown in

the following code fragment:

INT16 sockfd;

INT16 confd;

struct sockaddr_in server;

struct sockaddr_in client;

sockfd = socket(AF_INET, SOCK_SSL, 0);

server.sin_addr.s_addr = INADDR_ANY;

server.sin_family = AF_INET;

server.sin_port = intel16(0x1234);

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

sockaddr_in));

listen(sockfd, 1);

To accept a TCP-SSL connection from a remote client, the code informs the TCP
server to wait for an incoming TCP connection request, as shown in the following
example:

struct sockaddr_in client;

confd = accept(sockfd, (struct sockaddr *)&client, (INT16

*)&addrlen);

The same API is used to wait for an incoming SSL connection request. When a con-
nection is established, the SSL handshake is complete, and the

confd

variable is

released to the application, which transfers the SSL data.

This manual is related to the following products: