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")
41 static char buffer
[5 * 1024];
43 #define PRINTX(x,y) if (y[0]!=0) printf(" # %s %s\n", x, y)
44 #define PRINT_PGP_NAME(X) PRINTX( "NAME:", name)
46 const char str_unknown
[] = "(unknown)";
48 /* Hex encodes the given data.
51 raw_to_string (const unsigned char *raw
, size_t raw_size
)
53 static char buf
[1024];
58 if (raw_size
* 3 + 1 >= sizeof (buf
))
61 for (i
= 0; i
< raw_size
; i
++)
63 sprintf (&(buf
[i
* 3]), "%02X%s", raw
[i
],
64 (i
== raw_size
- 1) ? "" : ":");
66 buf
[sizeof (buf
) - 1] = '\0';
72 my_ctime (const time_t * tv
)
77 if (((tp
= localtime (tv
)) == NULL
) ||
78 (!strftime (buf
, sizeof buf
, "%a %b %e %H:%M:%S %Z %Y\n", tp
)))
79 strcpy (buf
, str_unknown
); /* make sure buf text isn't garbage */
87 print_x509_info (gnutls_session session
, const char *hostname
)
90 const gnutls_datum
*cert_list
;
91 size_t cert_list_size
= 0;
97 size_t digest_size
= sizeof (digest
);
99 size_t serial_size
= sizeof (serial
);
102 unsigned int bits
, algo
;
103 time_t expiret
, activet
;
105 cert_list
= gnutls_certificate_get_peers (session
, &cert_list_size
);
108 if (cert_list_size
== 0)
110 fprintf (stderr
, "No certificates found!\n");
114 printf (" - Got a certificate list of %d certificates.\n\n",
117 for (j
= 0; j
< (unsigned int) cert_list_size
; j
++)
120 gnutls_x509_crt_init (&crt
);
121 ret
= gnutls_x509_crt_import (crt
, &cert_list
[j
], GNUTLS_X509_FMT_DER
);
124 fprintf (stderr
, "Decoding error: %s\n", gnutls_strerror (ret
));
128 printf (" - Certificate[%d] info:\n", j
);
134 size
= sizeof (buffer
);
137 gnutls_x509_crt_export (crt
, GNUTLS_X509_FMT_PEM
, buffer
, &size
);
140 fprintf (stderr
, "Encoding error: %s\n", gnutls_strerror (ret
));
143 fputs ("\n", stdout
);
144 fputs (buffer
, stdout
);
145 fputs ("\n", stdout
);
148 if (j
== 0 && hostname
!= NULL
)
149 { /* Check the hostname of the first certificate
150 * if it matches the name of the host we
153 if (gnutls_x509_crt_check_hostname (crt
, hostname
) == 0)
156 (" # The hostname in the certificate does NOT match '%s'.\n",
162 (" # The hostname in the certificate matches '%s'.\n",
171 gnutls_datum xml_data
;
173 ret
= gnutls_x509_crt_to_xml (crt
, &xml_data
, 0);
176 fprintf (stderr
, "XML encoding error: %s\n",
177 gnutls_strerror (ret
));
181 printf ("%s", xml_data
.data
);
182 gnutls_free (xml_data
.data
);
188 expiret
= gnutls_x509_crt_get_expiration_time (crt
);
189 activet
= gnutls_x509_crt_get_activation_time (crt
);
191 printf (" # valid since: %s", my_ctime (&activet
));
192 printf (" # expires at: %s", my_ctime (&expiret
));
195 /* Print the serial number of the certificate.
198 && gnutls_x509_crt_get_serial (crt
, serial
, &serial_size
) >= 0)
200 print
= raw_to_string (serial
, serial_size
);
202 printf (" # serial number: %s\n", print
);
205 /* Print the fingerprint of the certificate
207 digest_size
= sizeof (digest
);
209 gnutls_x509_crt_get_fingerprint (crt
,
211 digest
, &digest_size
)) < 0)
214 "Error in fingerprint calculation: %s\n",
215 gnutls_strerror (ret
));
219 print
= raw_to_string (digest
, digest_size
);
221 printf (" # fingerprint: %s\n", print
);
224 /* Print the version of the X.509
229 printf (" # version: #%d\n", gnutls_x509_crt_get_version (crt
));
232 algo
= gnutls_x509_crt_get_pk_algorithm (crt
, &bits
);
233 printf (" # public key algorithm: ");
235 cstr
= SU (gnutls_pk_algorithm_get_name (algo
));
236 printf ("%s (%d bits)\n", cstr
, bits
);
239 if (algo
== GNUTLS_PK_RSA
)
243 ret
= gnutls_x509_crt_get_pk_rsa_raw (crt
, &m
, &e
);
246 print
= SU (raw_to_string (e
.data
, e
.size
));
247 printf (" # e [%d bits]: %s\n", e
.size
* 8, print
);
249 print
= SU (raw_to_string (m
.data
, m
.size
));
250 printf (" # m [%d bits]: %s\n", m
.size
* 8, print
);
252 gnutls_free (e
.data
);
253 gnutls_free (m
.data
);
256 else if (algo
== GNUTLS_PK_DSA
)
258 gnutls_datum p
, q
, g
, y
;
260 ret
= gnutls_x509_crt_get_pk_dsa_raw (crt
, &p
, &q
, &g
, &y
);
263 print
= SU (raw_to_string (p
.data
, p
.size
));
264 printf (" # p [%d bits]: %s\n", p
.size
* 8, print
);
266 print
= SU (raw_to_string (q
.data
, q
.size
));
267 printf (" # q [%d bits]: %s\n", q
.size
* 8, print
);
269 print
= SU (raw_to_string (g
.data
, g
.size
));
270 printf (" # g [%d bits]: %s\n", g
.size
* 8, print
);
272 print
= SU (raw_to_string (y
.data
, y
.size
));
273 printf (" # y [%d bits]: %s\n", y
.size
* 8, print
);
275 gnutls_free (p
.data
);
276 gnutls_free (q
.data
);
277 gnutls_free (g
.data
);
278 gnutls_free (y
.data
);
284 dn_size
= sizeof (dn
);
285 ret
= gnutls_x509_crt_get_dn (crt
, dn
, &dn_size
);
287 printf (" # Subject's DN: %s\n", dn
);
289 dn_size
= sizeof (dn
);
290 ret
= gnutls_x509_crt_get_issuer_dn (crt
, dn
, &dn_size
);
292 printf (" # Issuer's DN: %s\n", dn
);
295 gnutls_x509_crt_deinit (crt
);
303 #ifdef ENABLE_OPENPGP
306 print_openpgp_info (gnutls_session session
, const char *hostname
)
310 size_t digest_size
= sizeof (digest
);
315 size_t name_len
= sizeof (name
);
316 gnutls_openpgp_key crt
;
317 const gnutls_datum
*cert_list
;
318 int cert_list_size
= 0;
322 cert_list
= gnutls_certificate_get_peers (session
, &cert_list_size
);
324 if (cert_list_size
> 0)
326 unsigned int algo
, bits
;
328 gnutls_openpgp_key_init (&crt
);
330 gnutls_openpgp_key_import (crt
, &cert_list
[0],
331 GNUTLS_OPENPGP_FMT_RAW
);
334 fprintf (stderr
, "Decoding error: %s\n", gnutls_strerror (ret
));
342 size
= sizeof (buffer
);
345 gnutls_openpgp_key_export (crt
,
346 GNUTLS_OPENPGP_FMT_BASE64
,
350 fprintf (stderr
, "Encoding error: %s\n", gnutls_strerror (ret
));
353 fputs ("\n", stdout
);
354 fputs (buffer
, stdout
);
355 fputs ("\n", stdout
);
358 if (hostname
!= NULL
)
359 { /* Check the hostname of the first certificate
360 * if it matches the name of the host we
363 if (gnutls_openpgp_key_check_hostname (crt
, hostname
) == 0)
366 (" # The hostname in the key does NOT match '%s'.\n",
371 printf (" # The hostname in the key matches '%s'.\n", hostname
);
377 gnutls_datum xml_data
;
379 ret
= gnutls_openpgp_key_to_xml (crt
, &xml_data
, 0);
382 fprintf (stderr
, "XML encoding error: %s\n",
383 gnutls_strerror (ret
));
387 printf ("%s", xml_data
.data
);
388 gnutls_free (xml_data
.data
);
393 activet
= gnutls_openpgp_key_get_creation_time (crt
);
394 expiret
= gnutls_openpgp_key_get_expiration_time (crt
);
396 printf (" # Key was created at: %s", my_ctime (&activet
));
397 printf (" # Key expires: ");
399 printf ("%s", my_ctime (&expiret
));
403 if (gnutls_openpgp_key_get_fingerprint (crt
, digest
, &digest_size
) >= 0)
405 print
= raw_to_string (digest
, digest_size
);
407 printf (" # PGP Key version: %d\n",
408 gnutls_openpgp_key_get_version (crt
));
411 algo
= gnutls_openpgp_key_get_pk_algorithm (crt
, &bits
);
413 printf (" # PGP Key public key algorithm: ");
414 cstr
= SU (gnutls_pk_algorithm_get_name (algo
));
415 printf ("%s (%d bits)\n", cstr
, bits
);
418 printf (" # PGP Key fingerprint: %s\n", print
);
420 name_len
= sizeof (name
);
421 if (gnutls_openpgp_key_get_name (crt
, 0, name
, &name_len
) < 0)
423 fprintf (stderr
, "Could not extract name\n");
427 PRINT_PGP_NAME (name
);
432 gnutls_openpgp_key_deinit (crt
);
440 print_cert_vrfy (gnutls_session session
)
445 rc
= gnutls_certificate_verify_peers2 (session
, &status
);
448 if (rc
== GNUTLS_E_NO_CERTIFICATE_FOUND
)
450 printf ("- Peer did not send any certificate.\n");
456 printf ("- Could not verify certificate (err: %s)\n",
457 gnutls_strerror (rc
));
461 if (gnutls_certificate_type_get (session
) == GNUTLS_CRT_X509
)
463 if (status
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
464 printf ("- Peer's certificate issuer is unknown\n");
465 if (status
& GNUTLS_CERT_INVALID
)
466 printf ("- Peer's certificate is NOT trusted\n");
468 printf ("- Peer's certificate is trusted\n");
472 if (status
& GNUTLS_CERT_INVALID
)
473 printf ("- Peer's key is invalid\n");
475 printf ("- Peer's key is valid\n");
476 if (status
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
477 printf ("- Could not find a signer of the peer's key\n");
482 print_info (gnutls_session session
, const char *hostname
)
485 gnutls_credentials_type cred
;
486 gnutls_kx_algorithm kx
;
489 /* print the key exchange's algorithm name
491 kx
= gnutls_kx_get (session
);
493 cred
= gnutls_auth_get_type (session
);
497 case GNUTLS_CRD_ANON
:
498 printf ("- Anonymous DH using prime of %d bits, secret key "
499 "of %d bits, and peer's public key is %d bits.\n",
500 gnutls_dh_get_prime_bits (session
),
501 gnutls_dh_get_secret_bits (session
),
502 gnutls_dh_get_peers_public_bits (session
));
507 /* This should be only called in server
510 if (gnutls_srp_server_get_username (session
) != NULL
)
511 printf ("- SRP authentication. Connected as '%s'\n",
512 gnutls_srp_server_get_username (session
));
517 /* This should be only called in server
520 if (gnutls_psk_server_get_username (session
) != NULL
)
521 printf ("- PSK authentication. Connected as '%s'\n",
522 gnutls_psk_server_get_username (session
));
523 if (kx
== GNUTLS_KX_DHE_PSK
)
525 printf ("- DH using prime of %d bits, secret key "
526 "of %d bits, and peer's public key is %d bits.\n",
527 gnutls_dh_get_prime_bits (session
),
528 gnutls_dh_get_secret_bits (session
),
529 gnutls_dh_get_peers_public_bits (session
));
533 case GNUTLS_CRD_CERTIFICATE
:
536 size_t dns_size
= sizeof (dns
);
539 /* This fails in client side */
540 if (gnutls_server_name_get (session
, dns
, &dns_size
, &type
, 0) == 0)
542 printf ("- Given server name[%d]: %s\n", type
, dns
);
546 print_cert_info (session
, hostname
);
548 print_cert_vrfy (session
);
552 tmp
= SU (gnutls_protocol_get_name (gnutls_protocol_get_version (session
)));
553 printf ("- Version: %s\n", tmp
);
555 tmp
= SU (gnutls_kx_get_name (kx
));
556 printf ("- Key Exchange: %s\n", tmp
);
558 tmp
= SU (gnutls_cipher_get_name (gnutls_cipher_get (session
)));
559 printf ("- Cipher: %s\n", tmp
);
561 tmp
= SU (gnutls_mac_get_name (gnutls_mac_get (session
)));
562 printf ("- MAC: %s\n", tmp
);
564 tmp
= SU (gnutls_compression_get_name (gnutls_compression_get (session
)));
565 printf ("- Compression: %s\n", tmp
);
573 print_cert_info (gnutls_session session
, const char *hostname
)
576 if (gnutls_certificate_client_get_request_status( session
) != 0)
577 printf("- Server has requested a certificate.\n");
579 printf ("- Certificate type: ");
580 switch (gnutls_certificate_type_get (session
))
582 case GNUTLS_CRT_X509
:
584 print_x509_info (session
, hostname
);
586 #ifdef ENABLE_OPENPGP
587 case GNUTLS_CRT_OPENPGP
:
588 printf ("OpenPGP\n");
589 print_openpgp_info (session
, hostname
);
596 print_list (int verbose
)
602 gnutls_kx_algorithm_t kx
;
603 gnutls_cipher_algorithm_t cipher
;
604 gnutls_mac_algorithm_t mac
;
605 gnutls_protocol_t version
;
607 printf ("Cipher suites:\n");
608 for (i
= 0; (name
= gnutls_cipher_suite_info
609 (i
, id
, &kx
, &cipher
, &mac
, &version
)); i
++)
611 printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
613 (unsigned char) id
[0], (unsigned char) id
[1],
614 gnutls_protocol_get_name (version
));
616 printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
617 gnutls_kx_get_name (kx
),
618 gnutls_cipher_get_name (cipher
),
619 gnutls_mac_get_name (mac
));
624 const gnutls_certificate_type_t
*p
= gnutls_certificate_type_list();
626 printf ("Certificate types: ");
629 printf ("%s", gnutls_certificate_type_get_name (*p
));
638 const gnutls_protocol_t
*p
= gnutls_protocol_list();
640 printf ("Protocols: ");
643 printf ("%s", gnutls_protocol_get_name (*p
));
652 const gnutls_cipher_algorithm_t
*p
= gnutls_cipher_list();
654 printf ("Ciphers: ");
657 printf ("%s", gnutls_cipher_get_name (*p
));
666 const gnutls_mac_algorithm_t
*p
= gnutls_mac_list();
671 printf ("%s", gnutls_mac_get_name (*p
));
680 const gnutls_kx_algorithm_t
*p
= gnutls_kx_list();
682 printf ("Key exchange algorithms: ");
685 printf ("%s", gnutls_kx_get_name (*p
));
694 const gnutls_compression_method_t
*p
= gnutls_compression_list();
696 printf ("Compression: ");
699 printf ("%s", gnutls_compression_get_name (*p
));
711 fputs ("\nCopyright (C) 2004 Free Software Foundation\n"
712 "This program is free software; you can redistribute it and/or modify \n"
713 "it under the terms of the GNU General Public License as published by \n"
714 "the Free Software Foundation; either version 2 of the License, or \n"
715 "(at your option) any later version. \n" "\n"
716 "This program is distributed in the hope that it will be useful, \n"
717 "but WITHOUT ANY WARRANTY; without even the implied warranty of \n"
718 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n"
719 "GNU General Public License for more details. \n" "\n"
720 "You should have received a copy of the GNU General Public License \n"
721 "along with this program; if not, write to the Free Software \n"
722 "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n",
727 parse_protocols (char **protocols
, int protocols_size
, int *protocol_priority
)
731 if (protocols
!= NULL
&& protocols_size
> 0)
733 for (j
= i
= 0; i
< protocols_size
; i
++)
735 if (strncasecmp (protocols
[i
], "SSL", 3) == 0)
736 protocol_priority
[j
++] = GNUTLS_SSL3
;
737 else if (strncasecmp (protocols
[i
], "TLS1.1", 6) == 0)
738 protocol_priority
[j
++] = GNUTLS_TLS1_1
;
739 else if (strncasecmp (protocols
[i
], "TLS1.2", 6) == 0)
740 protocol_priority
[j
++] = GNUTLS_TLS1_2
;
741 else if (strncasecmp (protocols
[i
], "TLS", 3) == 0)
742 protocol_priority
[j
++] = GNUTLS_TLS1_0
;
744 fprintf (stderr
, "Unknown protocol: '%s'\n", protocols
[i
]);
746 protocol_priority
[j
] = 0;
751 parse_ciphers (char **ciphers
, int nciphers
, int *cipher_priority
)
755 if (ciphers
!= NULL
&& nciphers
> 0)
757 for (j
= i
= 0; i
< nciphers
; i
++)
759 if (strncasecmp (ciphers
[i
], "AES-2", 5) == 0)
760 cipher_priority
[j
++] = GNUTLS_CIPHER_AES_256_CBC
;
761 else if (strncasecmp (ciphers
[i
], "AES", 3) == 0)
762 cipher_priority
[j
++] = GNUTLS_CIPHER_AES_128_CBC
;
763 else if (strncasecmp (ciphers
[i
], "3DE", 3) == 0)
764 cipher_priority
[j
++] = GNUTLS_CIPHER_3DES_CBC
;
765 else if (strcasecmp (ciphers
[i
], "ARCFOUR-40") == 0)
766 cipher_priority
[j
++] = GNUTLS_CIPHER_ARCFOUR_40
;
767 else if (strcasecmp (ciphers
[i
], "ARCFOUR") == 0)
768 cipher_priority
[j
++] = GNUTLS_CIPHER_ARCFOUR_128
;
769 else if (strncasecmp (ciphers
[i
], "NUL", 3) == 0)
770 cipher_priority
[j
++] = GNUTLS_CIPHER_NULL
;
772 fprintf (stderr
, "Unknown cipher: '%s'\n", ciphers
[i
]);
774 cipher_priority
[j
] = 0;
779 parse_macs (char **macs
, int nmacs
, int *mac_priority
)
782 if (macs
!= NULL
&& nmacs
> 0)
784 for (j
= i
= 0; i
< nmacs
; i
++)
786 if (strncasecmp (macs
[i
], "MD5", 3) == 0)
787 mac_priority
[j
++] = GNUTLS_MAC_MD5
;
788 else if (strncasecmp (macs
[i
], "RMD", 3) == 0)
789 mac_priority
[j
++] = GNUTLS_MAC_RMD160
;
790 else if (strncasecmp (macs
[i
], "SHA512", 6) == 0)
791 mac_priority
[j
++] = GNUTLS_MAC_SHA512
;
792 else if (strncasecmp (macs
[i
], "SHA384", 6) == 0)
793 mac_priority
[j
++] = GNUTLS_MAC_SHA384
;
794 else if (strncasecmp (macs
[i
], "SHA256", 6) == 0)
795 mac_priority
[j
++] = GNUTLS_MAC_SHA256
;
796 else if (strncasecmp (macs
[i
], "SHA", 3) == 0)
797 mac_priority
[j
++] = GNUTLS_MAC_SHA1
;
799 fprintf (stderr
, "Unknown MAC: '%s'\n", macs
[i
]);
806 parse_ctypes (char **ctype
, int nctype
, int *cert_type_priority
)
809 if (ctype
!= NULL
&& nctype
> 0)
811 for (j
= i
= 0; i
< nctype
; i
++)
813 if (strncasecmp (ctype
[i
], "OPE", 3) == 0)
814 cert_type_priority
[j
++] = GNUTLS_CRT_OPENPGP
;
815 else if (strncasecmp (ctype
[i
], "X", 1) == 0)
816 cert_type_priority
[j
++] = GNUTLS_CRT_X509
;
818 fprintf (stderr
, "Unknown certificate type: '%s'\n", ctype
[i
]);
820 cert_type_priority
[j
] = 0;
825 parse_kx (char **kx
, int nkx
, int *kx_priority
)
828 if (kx
!= NULL
&& nkx
> 0)
830 for (j
= i
= 0; i
< nkx
; i
++)
832 if (strcasecmp (kx
[i
], "SRP") == 0)
833 kx_priority
[j
++] = GNUTLS_KX_SRP
;
834 else if (strcasecmp (kx
[i
], "SRP-RSA") == 0)
835 kx_priority
[j
++] = GNUTLS_KX_SRP_RSA
;
836 else if (strcasecmp (kx
[i
], "SRP-DSS") == 0)
837 kx_priority
[j
++] = GNUTLS_KX_SRP_DSS
;
838 else if (strcasecmp (kx
[i
], "RSA") == 0)
839 kx_priority
[j
++] = GNUTLS_KX_RSA
;
840 else if (strcasecmp (kx
[i
], "PSK") == 0)
841 kx_priority
[j
++] = GNUTLS_KX_PSK
;
842 else if (strcasecmp (kx
[i
], "DHE-PSK") == 0)
843 kx_priority
[j
++] = GNUTLS_KX_DHE_PSK
;
844 else if (strcasecmp (kx
[i
], "RSA-EXPORT") == 0)
845 kx_priority
[j
++] = GNUTLS_KX_RSA_EXPORT
;
846 else if (strncasecmp (kx
[i
], "DHE-RSA", 7) == 0)
847 kx_priority
[j
++] = GNUTLS_KX_DHE_RSA
;
848 else if (strncasecmp (kx
[i
], "DHE-DSS", 7) == 0)
849 kx_priority
[j
++] = GNUTLS_KX_DHE_DSS
;
850 else if (strncasecmp (kx
[i
], "ANON", 4) == 0)
851 kx_priority
[j
++] = GNUTLS_KX_ANON_DH
;
853 fprintf (stderr
, "Unknown key exchange: '%s'\n", kx
[i
]);
860 parse_comp (char **comp
, int ncomp
, int *comp_priority
)
863 if (comp
!= NULL
&& ncomp
> 0)
865 for (j
= i
= 0; i
< ncomp
; i
++)
867 if (strncasecmp (comp
[i
], "NUL", 3) == 0)
868 comp_priority
[j
++] = GNUTLS_COMP_NULL
;
869 else if (strncasecmp (comp
[i
], "ZLI", 3) == 0)
870 comp_priority
[j
++] = GNUTLS_COMP_DEFLATE
;
871 else if (strncasecmp (comp
[i
], "DEF", 3) == 0)
872 comp_priority
[j
++] = GNUTLS_COMP_DEFLATE
;
873 else if (strncasecmp (comp
[i
], "LZO", 3) == 0)
874 comp_priority
[j
++] = GNUTLS_COMP_LZO
;
876 fprintf (stderr
, "Unknown compression: '%s'\n", comp
[i
]);
878 comp_priority
[j
] = 0;
886 WORD wVersionRequested
;
889 wVersionRequested
= MAKEWORD (1, 1);
890 if (WSAStartup (wVersionRequested
, &wsaData
) != 0)
892 perror ("WSA_STARTUP_ERROR");
897 /* converts a service name or a port (in string) to a
898 * port number. The protocol is assumed to be TCP.
900 * returns -1 on error;
903 service_to_port (const char *service
)
906 struct servent
*server_port
;
908 port
= atoi (service
);
912 server_port
= getservbyname (service
, "tcp");
913 if (server_port
== NULL
)
915 perror ("getservbyname()");
919 return ntohs (server_port
->s_port
);