From: Sam Hartman Date: Tue, 9 Aug 2011 20:07:39 +0000 (+0000) Subject: Windows fixes for gss-client.c X-Git-Tag: krb5-1.10-alpha1~286 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1342ba2c1a140ed9d68303c5f8d15d3d87a23022;p=krb5.git Windows fixes for gss-client.c close(s) -> closesocket(s) #include "port-sockets.h" (for closesocket()) #include "winsock.h" -> #include "winsock2.h" for consistency with port-sockets.h call WSAStartup() before using sockets functions on Windows Signed-off-by: Kevin Wasserman Signed-off-by: Sam Hartman git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25089 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/appl/gss-sample/gss-client.c b/src/appl/gss-sample/gss-client.c index d439f23fb..c8213edfd 100644 --- a/src/appl/gss-sample/gss-client.c +++ b/src/appl/gss-sample/gss-client.c @@ -49,7 +49,7 @@ #include #ifdef _WIN32 #include -#include +#include #else #include #include @@ -67,6 +67,7 @@ #include #include #include "gss-misc.h" +#include "port-sockets.h" static int verbose = 1; static int spnego = 0; @@ -113,6 +114,15 @@ connect_to_server(char *host, u_short port) struct sockaddr_in saddr; struct hostent *hp; int s; +#ifdef _WIN32 + WSADATA wsadata; + int wsastartuperror = WSAStartup(0x202, &wsadata); + if (wsastartuperror) + { + fprintf(stderr, "WSAStartup error: %x\n", wsastartuperror); + return -1; + } +#endif if ((hp = gethostbyname(host)) == NULL) { fprintf(stderr, "Unknown host: %s\n", host); @@ -129,7 +139,7 @@ connect_to_server(char *host, u_short port) } if (connect(s, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) { perror("connecting to server"); - (void) close(s); + (void) closesocket(s); return -1; } return s; @@ -462,7 +472,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, if (client_establish_context(s, service_name, gss_flags, auth_flag, v1_format, oid, username, password, &context, &ret_flags) < 0) { - (void) close(s); + (void) closesocket(s); return -1; } @@ -560,7 +570,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, &in_buf, &state, &out_buf); if (maj_stat != GSS_S_COMPLETE) { display_status("wrapping message", maj_stat, min_stat); - (void) close(s); + (void) closesocket(s); (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER); return -1; @@ -578,7 +588,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, (encrypt_flag ? TOKEN_ENCRYPTED : 0) | (mic_flag ? TOKEN_SEND_MIC : 0))), &out_buf) < 0) { - (void) close(s); + (void) closesocket(s); (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER); return -1; @@ -588,7 +598,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, /* Read signature block into out_buf */ if (recv_token(s, &token_flags, &out_buf) < 0) { - (void) close(s); + (void) closesocket(s); (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER); return -1; @@ -600,7 +610,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, &out_buf, &qop_state); if (maj_stat != GSS_S_COMPLETE) { display_status("verifying signature", maj_stat, min_stat); - (void) close(s); + (void) closesocket(s); (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER); return -1; @@ -628,7 +638,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, maj_stat = gss_delete_sec_context(&min_stat, &context, &out_buf); if (maj_stat != GSS_S_COMPLETE) { display_status("deleting context", maj_stat, min_stat); - (void) close(s); + (void) closesocket(s); (void) gss_delete_sec_context(&min_stat, &context, GSS_C_NO_BUFFER); return -1; @@ -637,7 +647,7 @@ call_server(host, port, oid, service_name, gss_flags, auth_flag, (void) gss_release_buffer(&min_stat, &out_buf); } - (void) close(s); + (void) closesocket(s); return 0; }