Movatterモバイル変換


[0]ホーム

URL:


Go to main content
oracle home

Developer's Guide to Oracle® Solaris 11.4 Security

Exit Print View

 
Search Scope:
  »  ...Documentation Home  »  Oracle Solaris 11.4 Information Library  »  Developer's Guide to Oracle® ...  »  GSS-API Client Example  »  Opening a Connection With the Server
Updated: November 2020
 
 

Opening a Connection With the Server

Thecall_server() function uses the following code to make the connection with the server:

     if ((s = connect_to_server(host, port)) < 0)          return -1;

s is a file descriptor, theint thatis initially returned by a call tosocket().

connect_to_server() is a simple function outsideGSS-API that uses sockets to create a connection. The source code forconnect_to_server() is shown in the following example.

Example 13  GSSAPI Clientconnect_to_server() Function
int connect_to_server(host, port)     char *host;     u_short port;{     struct sockaddr_in saddr;     struct hostent *hp;     int s;         if ((hp = gethostbyname(host)) == NULL) {          fprintf(stderr, "Unknown host: %s\n", host);          return -1;     }     saddr.sin_family = hp->h_addrtype;     memcpy((char *)&saddr.sin_addr, hp->h_addr, sizeof(saddr.sin_addr));     saddr.sin_port = htons(port);     if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {          perror("creating socket");          return -1;     }     if (connect(s, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {          perror("connecting to server");          (void) close(s);          return -1;     }     return s;}
Copyright © 2000, 2020, Oracle and/or its affiliates. 
Previous
Next

[8]ページ先頭

©2009-2025 Movatter.jp