2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
3 * Author: Nikos Mavroyanopoulos
5 * This file is part of GNUTLS.
7 * GNUTLS is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * GNUTLS is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 #include <gnutls/gnutls.h>
27 #include <gnutls/extra.h>
28 #include <gnutls/x509.h>
29 #include <gnutls/openpgp.h>
35 #define SU(x) (x!=NULL?x:"Unknown")
40 static char buffer
[5 * 1024];
42 #define PRINTX(x,y) if (y[0]!=0) printf(" # %s %s\n", x, y)
43 #define PRINT_PGP_NAME(X) PRINTX( "NAME:", name)
45 const char str_unknown
[] = "(unknown)";
47 /* Hex encodes the given data.
50 raw_to_string (const unsigned char *raw
, size_t raw_size
)
52 static char buf
[1024];
57 if (raw_size
* 3 + 1 >= sizeof (buf
))
60 for (i
= 0; i
< raw_size
; i
++)
62 sprintf (&(buf
[i
* 3]), "%02X%s", raw
[i
],
63 (i
== raw_size
- 1) ? "" : ":");
65 buf
[sizeof (buf
) - 1] = '\0';
71 my_ctime (const time_t * tv
)
76 if (((tp
= localtime (tv
)) == NULL
) ||
77 (!strftime (buf
, sizeof buf
, "%a %b %e %H:%M:%S %Z %Y\n", tp
)))
78 strcpy (buf
, str_unknown
); /* make sure buf text isn't garbage */
86 print_x509_info (gnutls_session_t session
, const char *hostname
)
88 gnutls_x509_crt_t crt
;
89 const gnutls_datum_t
*cert_list
;
90 unsigned int cert_list_size
= 0;
96 size_t digest_size
= sizeof (digest
);
98 size_t serial_size
= sizeof (serial
);
101 unsigned int bits
, algo
;
102 time_t expiret
, activet
;
104 cert_list
= gnutls_certificate_get_peers (session
, &cert_list_size
);
107 if (cert_list_size
== 0)
109 fprintf (stderr
, "No certificates found!\n");
113 printf (" - Got a certificate list of %d certificates.\n\n",
116 for (j
= 0; j
< (unsigned int) cert_list_size
; j
++)
119 gnutls_x509_crt_init (&crt
);
120 ret
= gnutls_x509_crt_import (crt
, &cert_list
[j
], GNUTLS_X509_FMT_DER
);
123 fprintf (stderr
, "Decoding error: %s\n", gnutls_strerror (ret
));
127 printf (" - Certificate[%d] info:\n", j
);
133 size
= sizeof (buffer
);
136 gnutls_x509_crt_export (crt
, GNUTLS_X509_FMT_PEM
, buffer
, &size
);
139 fprintf (stderr
, "Encoding error: %s\n", gnutls_strerror (ret
));
142 fputs ("\n", stdout
);
143 fputs (buffer
, stdout
);
144 fputs ("\n", stdout
);
147 if (j
== 0 && hostname
!= NULL
)
148 { /* Check the hostname of the first certificate
149 * if it matches the name of the host we
152 if (gnutls_x509_crt_check_hostname (crt
, hostname
) == 0)
155 (" # The hostname in the certificate does NOT match '%s'.\n",
161 (" # The hostname in the certificate matches '%s'.\n",
167 expiret
= gnutls_x509_crt_get_expiration_time (crt
);
168 activet
= gnutls_x509_crt_get_activation_time (crt
);
170 printf (" # valid since: %s", my_ctime (&activet
));
171 printf (" # expires at: %s", my_ctime (&expiret
));
174 /* Print the serial number of the certificate.
177 && gnutls_x509_crt_get_serial (crt
, serial
, &serial_size
) >= 0)
179 print
= raw_to_string (serial
, serial_size
);
181 printf (" # serial number: %s\n", print
);
184 /* Print the fingerprint of the certificate
186 digest_size
= sizeof (digest
);
188 gnutls_x509_crt_get_fingerprint (crt
,
190 digest
, &digest_size
)) < 0)
193 "Error in fingerprint calculation: %s\n",
194 gnutls_strerror (ret
));
198 print
= raw_to_string (digest
, digest_size
);
200 printf (" # fingerprint: %s\n", print
);
203 /* Print the version of the X.509
208 printf (" # version: #%d\n", gnutls_x509_crt_get_version (crt
));
211 algo
= gnutls_x509_crt_get_pk_algorithm (crt
, &bits
);
212 printf (" # public key algorithm: ");
214 cstr
= SU (gnutls_pk_algorithm_get_name (algo
));
215 printf ("%s (%d bits)\n", cstr
, bits
);
218 if (algo
== GNUTLS_PK_RSA
)
222 ret
= gnutls_x509_crt_get_pk_rsa_raw (crt
, &m
, &e
);
225 print
= SU (raw_to_string (e
.data
, e
.size
));
226 printf (" # e [%d bits]: %s\n", e
.size
* 8, print
);
228 print
= SU (raw_to_string (m
.data
, m
.size
));
229 printf (" # m [%d bits]: %s\n", m
.size
* 8, print
);
231 gnutls_free (e
.data
);
232 gnutls_free (m
.data
);
235 else if (algo
== GNUTLS_PK_DSA
)
237 gnutls_datum_t p
, q
, g
, y
;
239 ret
= gnutls_x509_crt_get_pk_dsa_raw (crt
, &p
, &q
, &g
, &y
);
242 print
= SU (raw_to_string (p
.data
, p
.size
));
243 printf (" # p [%d bits]: %s\n", p
.size
* 8, print
);
245 print
= SU (raw_to_string (q
.data
, q
.size
));
246 printf (" # q [%d bits]: %s\n", q
.size
* 8, print
);
248 print
= SU (raw_to_string (g
.data
, g
.size
));
249 printf (" # g [%d bits]: %s\n", g
.size
* 8, print
);
251 print
= SU (raw_to_string (y
.data
, y
.size
));
252 printf (" # y [%d bits]: %s\n", y
.size
* 8, print
);
254 gnutls_free (p
.data
);
255 gnutls_free (q
.data
);
256 gnutls_free (g
.data
);
257 gnutls_free (y
.data
);
263 dn_size
= sizeof (dn
);
264 ret
= gnutls_x509_crt_get_dn (crt
, dn
, &dn_size
);
266 printf (" # Subject's DN: %s\n", dn
);
268 dn_size
= sizeof (dn
);
269 ret
= gnutls_x509_crt_get_issuer_dn (crt
, dn
, &dn_size
);
271 printf (" # Issuer's DN: %s\n", dn
);
273 gnutls_x509_crt_deinit (crt
);
281 #ifdef ENABLE_OPENPGP
284 print_openpgp_info (gnutls_session_t session
, const char *hostname
)
288 size_t digest_size
= sizeof (digest
);
293 size_t name_len
= sizeof (name
);
294 gnutls_openpgp_key_t crt
;
295 const gnutls_datum_t
*cert_list
;
296 int cert_list_size
= 0;
300 cert_list
= gnutls_certificate_get_peers (session
, &cert_list_size
);
302 if (cert_list_size
> 0)
304 unsigned int algo
, bits
;
306 gnutls_openpgp_key_init (&crt
);
308 gnutls_openpgp_key_import (crt
, &cert_list
[0],
309 GNUTLS_OPENPGP_FMT_RAW
);
312 fprintf (stderr
, "Decoding error: %s\n", gnutls_strerror (ret
));
320 size
= sizeof (buffer
);
323 gnutls_openpgp_key_export (crt
,
324 GNUTLS_OPENPGP_FMT_BASE64
,
328 fprintf (stderr
, "Encoding error: %s\n", gnutls_strerror (ret
));
331 fputs ("\n", stdout
);
332 fputs (buffer
, stdout
);
333 fputs ("\n", stdout
);
336 if (hostname
!= NULL
)
337 { /* Check the hostname of the first certificate
338 * if it matches the name of the host we
341 if (gnutls_openpgp_key_check_hostname (crt
, hostname
) == 0)
344 (" # The hostname in the key does NOT match '%s'.\n",
349 printf (" # The hostname in the key matches '%s'.\n", hostname
);
353 activet
= gnutls_openpgp_key_get_creation_time (crt
);
354 expiret
= gnutls_openpgp_key_get_expiration_time (crt
);
356 printf (" # Key was created at: %s", my_ctime (&activet
));
357 printf (" # Key expires: ");
359 printf ("%s", my_ctime (&expiret
));
363 if (gnutls_openpgp_key_get_fingerprint (crt
, digest
, &digest_size
) >= 0)
365 print
= raw_to_string (digest
, digest_size
);
367 printf (" # PGP Key version: %d\n",
368 gnutls_openpgp_key_get_version (crt
));
371 algo
= gnutls_openpgp_key_get_pk_algorithm (crt
, &bits
);
373 printf (" # PGP Key public key algorithm: ");
374 cstr
= SU (gnutls_pk_algorithm_get_name (algo
));
375 printf ("%s (%d bits)\n", cstr
, bits
);
378 printf (" # PGP Key fingerprint: %s\n", print
);
380 name_len
= sizeof (name
);
381 if (gnutls_openpgp_key_get_name (crt
, 0, name
, &name_len
) < 0)
383 fprintf (stderr
, "Could not extract name\n");
387 PRINT_PGP_NAME (name
);
392 gnutls_openpgp_key_deinit (crt
);
400 print_cert_vrfy (gnutls_session_t session
)
405 rc
= gnutls_certificate_verify_peers2 (session
, &status
);
408 if (rc
== GNUTLS_E_NO_CERTIFICATE_FOUND
)
410 printf ("- Peer did not send any certificate.\n");
416 printf ("- Could not verify certificate (err: %s)\n",
417 gnutls_strerror (rc
));
421 if (gnutls_certificate_type_get (session
) == GNUTLS_CRT_X509
)
423 if (status
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
424 printf ("- Peer's certificate issuer is unknown\n");
425 if (status
& GNUTLS_CERT_INVALID
)
426 printf ("- Peer's certificate is NOT trusted\n");
428 printf ("- Peer's certificate is trusted\n");
432 if (status
& GNUTLS_CERT_INVALID
)
433 printf ("- Peer's key is invalid\n");
435 printf ("- Peer's key is valid\n");
436 if (status
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
437 printf ("- Could not find a signer of the peer's key\n");
442 print_info (gnutls_session_t session
, const char *hostname
)
445 gnutls_credentials_type_t cred
;
446 gnutls_kx_algorithm_t kx
;
449 /* print the key exchange's algorithm name
451 kx
= gnutls_kx_get (session
);
453 cred
= gnutls_auth_get_type (session
);
457 case GNUTLS_CRD_ANON
:
458 printf ("- Anonymous DH using prime of %d bits, secret key "
459 "of %d bits, and peer's public key is %d bits.\n",
460 gnutls_dh_get_prime_bits (session
),
461 gnutls_dh_get_secret_bits (session
),
462 gnutls_dh_get_peers_public_bits (session
));
467 /* This should be only called in server
470 if (gnutls_srp_server_get_username (session
) != NULL
)
471 printf ("- SRP authentication. Connected as '%s'\n",
472 gnutls_srp_server_get_username (session
));
477 /* This should be only called in server
480 if (gnutls_psk_server_get_username (session
) != NULL
)
481 printf ("- PSK authentication. Connected as '%s'\n",
482 gnutls_psk_server_get_username (session
));
483 if (kx
== GNUTLS_KX_DHE_PSK
)
485 printf ("- DH using prime of %d bits, secret key "
486 "of %d bits, and peer's public key is %d bits.\n",
487 gnutls_dh_get_prime_bits (session
),
488 gnutls_dh_get_secret_bits (session
),
489 gnutls_dh_get_peers_public_bits (session
));
494 printf ("- TLS/IA authentication\n");
496 case GNUTLS_CRD_CERTIFICATE
:
499 size_t dns_size
= sizeof (dns
);
502 /* This fails in client side */
503 if (gnutls_server_name_get (session
, dns
, &dns_size
, &type
, 0) == 0)
505 printf ("- Given server name[%d]: %s\n", type
, dns
);
509 print_cert_info (session
, hostname
);
511 print_cert_vrfy (session
);
515 tmp
= SU (gnutls_protocol_get_name (gnutls_protocol_get_version (session
)));
516 printf ("- Version: %s\n", tmp
);
518 tmp
= SU (gnutls_kx_get_name (kx
));
519 printf ("- Key Exchange: %s\n", tmp
);
521 tmp
= SU (gnutls_cipher_get_name (gnutls_cipher_get (session
)));
522 printf ("- Cipher: %s\n", tmp
);
524 tmp
= SU (gnutls_mac_get_name (gnutls_mac_get (session
)));
525 printf ("- MAC: %s\n", tmp
);
527 tmp
= SU (gnutls_compression_get_name (gnutls_compression_get (session
)));
528 printf ("- Compression: %s\n", tmp
);
536 print_cert_info (gnutls_session_t session
, const char *hostname
)
539 if (gnutls_certificate_client_get_request_status (session
) != 0)
540 printf ("- Server has requested a certificate.\n");
542 printf ("- Certificate type: ");
543 switch (gnutls_certificate_type_get (session
))
545 case GNUTLS_CRT_X509
:
547 print_x509_info (session
, hostname
);
549 #ifdef ENABLE_OPENPGP
550 case GNUTLS_CRT_OPENPGP
:
551 printf ("OpenPGP\n");
552 print_openpgp_info (session
, hostname
);
559 print_list (int verbose
)
565 gnutls_kx_algorithm_t kx
;
566 gnutls_cipher_algorithm_t cipher
;
567 gnutls_mac_algorithm_t mac
;
568 gnutls_protocol_t version
;
570 printf ("Cipher suites:\n");
571 for (i
= 0; (name
= gnutls_cipher_suite_info
572 (i
, id
, &kx
, &cipher
, &mac
, &version
)); i
++)
574 printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
576 (unsigned char) id
[0], (unsigned char) id
[1],
577 gnutls_protocol_get_name (version
));
579 printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
580 gnutls_kx_get_name (kx
),
581 gnutls_cipher_get_name (cipher
), gnutls_mac_get_name (mac
));
586 const gnutls_certificate_type_t
*p
= gnutls_certificate_type_list ();
588 printf ("Certificate types: ");
591 printf ("%s", gnutls_certificate_type_get_name (*p
));
600 const gnutls_protocol_t
*p
= gnutls_protocol_list ();
602 printf ("Protocols: ");
605 printf ("%s", gnutls_protocol_get_name (*p
));
614 const gnutls_cipher_algorithm_t
*p
= gnutls_cipher_list ();
616 printf ("Ciphers: ");
619 printf ("%s", gnutls_cipher_get_name (*p
));
628 const gnutls_mac_algorithm_t
*p
= gnutls_mac_list ();
633 printf ("%s", gnutls_mac_get_name (*p
));
642 const gnutls_kx_algorithm_t
*p
= gnutls_kx_list ();
644 printf ("Key exchange algorithms: ");
647 printf ("%s", gnutls_kx_get_name (*p
));
656 const gnutls_compression_method_t
*p
= gnutls_compression_list ();
658 printf ("Compression: ");
661 printf ("%s", gnutls_compression_get_name (*p
));
673 fputs ("\nCopyright (C) 2004 Free Software Foundation\n"
674 "This program is free software; you can redistribute it and/or modify \n"
675 "it under the terms of the GNU General Public License as published by \n"
676 "the Free Software Foundation; either version 2 of the License, or \n"
677 "(at your option) any later version. \n" "\n"
678 "This program is distributed in the hope that it will be useful, \n"
679 "but WITHOUT ANY WARRANTY; without even the implied warranty of \n"
680 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n"
681 "GNU General Public License for more details. \n" "\n"
682 "You should have received a copy of the GNU General Public License \n"
683 "along with this program; if not, write to the Free Software \n"
684 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
689 parse_protocols (char **protocols
, int protocols_size
, int *protocol_priority
)
693 if (protocols
!= NULL
&& protocols_size
> 0)
695 for (j
= i
= 0; i
< protocols_size
; i
++)
697 if (strncasecmp (protocols
[i
], "SSL", 3) == 0)
698 protocol_priority
[j
++] = GNUTLS_SSL3
;
699 else if (strncasecmp (protocols
[i
], "TLS1.1", 6) == 0)
700 protocol_priority
[j
++] = GNUTLS_TLS1_1
;
701 else if (strncasecmp (protocols
[i
], "TLS1.2", 6) == 0)
702 protocol_priority
[j
++] = GNUTLS_TLS1_2
;
703 else if (strncasecmp (protocols
[i
], "TLS", 3) == 0)
704 protocol_priority
[j
++] = GNUTLS_TLS1_0
;
706 fprintf (stderr
, "Unknown protocol: '%s'\n", protocols
[i
]);
708 protocol_priority
[j
] = 0;
713 parse_ciphers (char **ciphers
, int nciphers
, int *cipher_priority
)
717 if (ciphers
!= NULL
&& nciphers
> 0)
719 for (j
= i
= 0; i
< nciphers
; i
++)
721 if (strncasecmp (ciphers
[i
], "AES-2", 5) == 0)
722 cipher_priority
[j
++] = GNUTLS_CIPHER_AES_256_CBC
;
723 else if (strncasecmp (ciphers
[i
], "AES", 3) == 0)
724 cipher_priority
[j
++] = GNUTLS_CIPHER_AES_128_CBC
;
725 else if (strncasecmp (ciphers
[i
], "3DE", 3) == 0)
726 cipher_priority
[j
++] = GNUTLS_CIPHER_3DES_CBC
;
727 else if (strcasecmp (ciphers
[i
], "ARCFOUR-40") == 0)
728 cipher_priority
[j
++] = GNUTLS_CIPHER_ARCFOUR_40
;
729 else if (strcasecmp (ciphers
[i
], "ARCFOUR") == 0)
730 cipher_priority
[j
++] = GNUTLS_CIPHER_ARCFOUR_128
;
731 #ifdef ENABLE_CAMELLIA
732 else if (strncasecmp (ciphers
[i
], "CAMELLIA-2", 10) == 0)
733 cipher_priority
[j
++] = GNUTLS_CIPHER_CAMELLIA_256_CBC
;
734 else if (strncasecmp (ciphers
[i
], "CAM", 3) == 0)
735 cipher_priority
[j
++] = GNUTLS_CIPHER_CAMELLIA_128_CBC
;
737 else if (strncasecmp (ciphers
[i
], "NUL", 3) == 0)
738 cipher_priority
[j
++] = GNUTLS_CIPHER_NULL
;
740 fprintf (stderr
, "Unknown cipher: '%s'\n", ciphers
[i
]);
742 cipher_priority
[j
] = 0;
747 parse_macs (char **macs
, int nmacs
, int *mac_priority
)
750 if (macs
!= NULL
&& nmacs
> 0)
752 for (j
= i
= 0; i
< nmacs
; i
++)
754 if (strncasecmp (macs
[i
], "MD5", 3) == 0)
755 mac_priority
[j
++] = GNUTLS_MAC_MD5
;
756 else if (strncasecmp (macs
[i
], "RMD", 3) == 0)
757 mac_priority
[j
++] = GNUTLS_MAC_RMD160
;
758 else if (strncasecmp (macs
[i
], "SHA512", 6) == 0)
759 mac_priority
[j
++] = GNUTLS_MAC_SHA512
;
760 else if (strncasecmp (macs
[i
], "SHA384", 6) == 0)
761 mac_priority
[j
++] = GNUTLS_MAC_SHA384
;
762 else if (strncasecmp (macs
[i
], "SHA256", 6) == 0)
763 mac_priority
[j
++] = GNUTLS_MAC_SHA256
;
764 else if (strncasecmp (macs
[i
], "SHA", 3) == 0)
765 mac_priority
[j
++] = GNUTLS_MAC_SHA1
;
767 fprintf (stderr
, "Unknown MAC: '%s'\n", macs
[i
]);
774 parse_ctypes (char **ctype
, int nctype
, int *cert_type_priority
)
777 if (ctype
!= NULL
&& nctype
> 0)
779 for (j
= i
= 0; i
< nctype
; i
++)
781 if (strncasecmp (ctype
[i
], "OPE", 3) == 0)
782 cert_type_priority
[j
++] = GNUTLS_CRT_OPENPGP
;
783 else if (strncasecmp (ctype
[i
], "X", 1) == 0)
784 cert_type_priority
[j
++] = GNUTLS_CRT_X509
;
786 fprintf (stderr
, "Unknown certificate type: '%s'\n", ctype
[i
]);
788 cert_type_priority
[j
] = 0;
793 parse_kx (char **kx
, int nkx
, int *kx_priority
)
796 if (kx
!= NULL
&& nkx
> 0)
798 for (j
= i
= 0; i
< nkx
; i
++)
800 if (strcasecmp (kx
[i
], "SRP") == 0)
801 kx_priority
[j
++] = GNUTLS_KX_SRP
;
802 else if (strcasecmp (kx
[i
], "SRP-RSA") == 0)
803 kx_priority
[j
++] = GNUTLS_KX_SRP_RSA
;
804 else if (strcasecmp (kx
[i
], "SRP-DSS") == 0)
805 kx_priority
[j
++] = GNUTLS_KX_SRP_DSS
;
806 else if (strcasecmp (kx
[i
], "RSA") == 0)
807 kx_priority
[j
++] = GNUTLS_KX_RSA
;
808 else if (strcasecmp (kx
[i
], "PSK") == 0)
809 kx_priority
[j
++] = GNUTLS_KX_PSK
;
810 else if (strcasecmp (kx
[i
], "DHE-PSK") == 0)
811 kx_priority
[j
++] = GNUTLS_KX_DHE_PSK
;
812 else if (strcasecmp (kx
[i
], "RSA-EXPORT") == 0)
813 kx_priority
[j
++] = GNUTLS_KX_RSA_EXPORT
;
814 else if (strncasecmp (kx
[i
], "DHE-RSA", 7) == 0)
815 kx_priority
[j
++] = GNUTLS_KX_DHE_RSA
;
816 else if (strncasecmp (kx
[i
], "DHE-DSS", 7) == 0)
817 kx_priority
[j
++] = GNUTLS_KX_DHE_DSS
;
818 else if (strncasecmp (kx
[i
], "ANON", 4) == 0)
819 kx_priority
[j
++] = GNUTLS_KX_ANON_DH
;
821 fprintf (stderr
, "Unknown key exchange: '%s'\n", kx
[i
]);
828 parse_comp (char **comp
, int ncomp
, int *comp_priority
)
831 if (comp
!= NULL
&& ncomp
> 0)
833 for (j
= i
= 0; i
< ncomp
; i
++)
835 if (strncasecmp (comp
[i
], "NUL", 3) == 0)
836 comp_priority
[j
++] = GNUTLS_COMP_NULL
;
837 else if (strncasecmp (comp
[i
], "ZLI", 3) == 0)
838 comp_priority
[j
++] = GNUTLS_COMP_DEFLATE
;
839 else if (strncasecmp (comp
[i
], "DEF", 3) == 0)
840 comp_priority
[j
++] = GNUTLS_COMP_DEFLATE
;
841 else if (strncasecmp (comp
[i
], "LZO", 3) == 0)
842 comp_priority
[j
++] = GNUTLS_COMP_LZO
;
844 fprintf (stderr
, "Unknown compression: '%s'\n", comp
[i
]);
846 comp_priority
[j
] = 0;
854 WORD wVersionRequested
;
857 wVersionRequested
= MAKEWORD (1, 1);
858 if (WSAStartup (wVersionRequested
, &wsaData
) != 0)
860 perror ("WSA_STARTUP_ERROR");
865 /* converts a service name or a port (in string) to a
866 * port number. The protocol is assumed to be TCP.
868 * returns -1 on error;
871 service_to_port (const char *service
)
874 struct servent
*server_port
;
876 port
= atoi (service
);
880 server_port
= getservbyname (service
, "tcp");
881 if (server_port
== NULL
)
883 perror ("getservbyname()");
887 return ntohs (server_port
->s_port
);