661 cs130_ryutaro 1.1 server_stop();
662
663 }
664
665 // Translate and dispatch the message
666 TranslateMessage( &msg );
667 DispatchMessage( &msg );
668
669 }
670 }
671
672 /**************** Clients ***************/
673
674 /*
675 * simple_client: A very basic client doing synchronous IO.
676 */
677 static VOID WINAPI simple_client ( client_params *par )
678 {
679 test_params *gen = par->general;
680 client_memory *mem;
681 int n_sent, n_recvd, n_expected = gen->n_chunks * gen->chunk_size, id;
682 cs130_ryutaro 1.1 char *p;
683
684 id = GetCurrentThreadId();
685 trace ( "simple_client (%x): starting\n", id );
686 /* wait here because we want to call set_so_opentype before creating a socket */
687 WaitForSingleObject ( server_ready, INFINITE );
688 trace ( "simple_client (%x): server ready\n", id );
689
690 check_so_opentype ();
691 set_so_opentype ( FALSE ); /* non-overlapped */
692 client_start ( par );
693 mem = TlsGetValue ( tls );
694
695 /* Connect */
696 wsa_ok ( connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) ),
697 0 ==, "simple_client (%lx): connect error: %d\n" );
698 ok ( set_blocking ( mem->s, TRUE ) == 0,
699 "simple_client (%x): failed to set blocking mode\n", id );
700 trace ( "simple_client (%x) connected\n", id );
701
702 /* send data to server */
703 cs130_ryutaro 1.1 n_sent = do_synchronous_send ( mem->s, mem->send_buf, n_expected, par->buflen );
704 ok ( n_sent == n_expected,
705 "simple_client (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
706
707 /* shutdown send direction */
708 wsa_ok ( shutdown ( mem->s, SD_SEND ), 0 ==, "simple_client (%lx): shutdown failed: %d\n" );
709
710 /* Receive data echoed back & check it */
711 n_recvd = do_synchronous_recv ( mem->s, mem->recv_buf, n_expected, par->buflen );
712 ok ( n_recvd == n_expected,
713 "simple_client (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected );
714
715 /* check data */
716 p = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
717 ok ( p == NULL, "simple_client (%x): test pattern error: %d\n", id, p - mem->recv_buf);
718
719 /* cleanup */
720 read_zero_bytes ( mem->s );
721 trace ( "simple_client (%x) exiting\n", id );
722 client_stop ();
723 }
724 cs130_ryutaro 1.1
725 /*
726 * event_client: An event-driven client
727 */
728 static void WINAPI event_client ( client_params *par )
729 {
730 test_params *gen = par->general;
731 client_memory *mem;
732 int id = GetCurrentThreadId(), n_expected = gen->n_chunks * gen->chunk_size,
733 tmp, err, n;
734 HANDLE event;
735 WSANETWORKEVENTS wsa_events;
736 char *send_last, *recv_last, *send_p, *recv_p;
737 long mask = FD_READ | FD_WRITE | FD_CLOSE;
738
739 trace ( "event_client (%x): starting\n", id );
740 client_start ( par );
741 trace ( "event_client (%x): server ready\n", id );
742
743 mem = TlsGetValue ( tls );
744
745 cs130_ryutaro 1.1 /* Prepare event notification for connect, makes socket nonblocking */
746 event = WSACreateEvent ();
747 WSAEventSelect ( mem->s, event, FD_CONNECT );
748 tmp = connect ( mem->s, (struct sockaddr*) &mem->addr, sizeof ( mem->addr ) );
749 if ( tmp != 0 && ( err = WSAGetLastError () ) != WSAEWOULDBLOCK )
750 ok ( 0, "event_client (%x): connect error: %d\n", id, err );
751
752 tmp = WaitForSingleObject ( event, INFINITE );
753 ok ( tmp == WAIT_OBJECT_0, "event_client (%x): wait for connect event failed: %d\n", id, tmp );
754 err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
755 wsa_ok ( err, 0 ==, "event_client (%lx): WSAEnumNetworkEvents error: %d\n" );
756
757 err = wsa_events.iErrorCode[ FD_CONNECT_BIT ];
758 ok ( err == 0, "event_client (%x): connect error: %d\n", id, err );
759 if ( err ) goto out;
760
761 trace ( "event_client (%x) connected\n", id );
762
763 WSAEventSelect ( mem->s, event, mask );
764
765 recv_p = mem->recv_buf;
766 cs130_ryutaro 1.1 recv_last = mem->recv_buf + n_expected;
767 send_p = mem->send_buf;
768 send_last = mem->send_buf + n_expected;
769
770 while ( TRUE )
771 {
772 err = WaitForSingleObject ( event, INFINITE );
773 ok ( err == WAIT_OBJECT_0, "event_client (%x): wait failed\n", id );
774
775 err = WSAEnumNetworkEvents ( mem->s, event, &wsa_events );
776 wsa_ok ( err, 0 ==, "event_client (%lx): WSAEnumNetworkEvents error: %d\n" );
777
778 if ( wsa_events.lNetworkEvents & FD_WRITE )
779 {
780 err = wsa_events.iErrorCode[ FD_WRITE_BIT ];
781 ok ( err == 0, "event_client (%x): FD_WRITE error code: %d\n", id, err );
782
783 if ( err== 0 )
784 do
785 {
786 n = send ( mem->s, send_p, min ( send_last - send_p, par->buflen ), 0 );
787 cs130_ryutaro 1.1 if ( n < 0 )
788 {
789 err = WSAGetLastError ();
790 ok ( err == WSAEWOULDBLOCK, "event_client (%x): send error: %d\n", id, err );
791 }
792 else
793 send_p += n;
794 }
795 while ( n >= 0 && send_p < send_last );
796
797 if ( send_p == send_last )
798 {
799 trace ( "event_client (%x): all data sent - shutdown\n", id );
800 shutdown ( mem->s, SD_SEND );
801 mask &= ~FD_WRITE;
802 WSAEventSelect ( mem->s, event, mask );
803 }
804 }
805 if ( wsa_events.lNetworkEvents & FD_READ )
806 {
807 err = wsa_events.iErrorCode[ FD_READ_BIT ];
808 cs130_ryutaro 1.1 ok ( err == 0, "event_client (%x): FD_READ error code: %d\n", id, err );
809 if ( err != 0 ) break;
810
811 /* First read must succeed */
812 n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
813 wsa_ok ( n, 0 <=, "event_client (%lx): recv error: %d\n" );
814
815 while ( n >= 0 ) {
816 recv_p += n;
817 if ( recv_p == recv_last )
818 {
819 mask &= ~FD_READ;
820 trace ( "event_client (%x): all data received\n", id );
821 WSAEventSelect ( mem->s, event, mask );
822 break;
823 }
824 n = recv ( mem->s, recv_p, min ( recv_last - recv_p, par->buflen ), 0 );
825 if ( n < 0 && ( err = WSAGetLastError()) != WSAEWOULDBLOCK )
826 ok ( 0, "event_client (%x): read error: %d\n", id, err );
827
828 }
829 cs130_ryutaro 1.1 }
830 if ( wsa_events.lNetworkEvents & FD_CLOSE )
831 {
832 trace ( "event_client (%x): close event\n", id );
833 err = wsa_events.iErrorCode[ FD_CLOSE_BIT ];
834 ok ( err == 0, "event_client (%x): FD_CLOSE error code: %d\n", id, err );
835 break;
836 }
837 }
838
839 ok ( send_p == send_last,
840 "simple_client (%x): sent less data than expected: %d of %d\n",
841 id, send_p - mem->send_buf, n_expected );
842 ok ( recv_p == recv_last,
843 "simple_client (%x): received less data than expected: %d of %d\n",
844 id, recv_p - mem->recv_buf, n_expected );
845 recv_p = test_buffer ( mem->recv_buf, gen->chunk_size, gen->n_chunks );
846 ok ( recv_p == NULL, "event_client (%x): test pattern error: %d\n", id, recv_p - mem->recv_buf);
847
848 out:
849 WSACloseEvent ( event );
850 cs130_ryutaro 1.1 trace ( "event_client (%x) exiting\n", id );
851 client_stop ();
852 }
853
854 /**************** Main program utility functions ***************/
855
856 static void Init (void)
857 {
858 WORD ver = MAKEWORD (2, 2);
859 WSADATA data;
860
861 ok ( WSAStartup ( ver, &data ) == 0, "WSAStartup failed\n" );
862 tls = TlsAlloc();
863 }
864
865 static void Exit (void)
866 {
867 TlsFree ( tls );
868 ok ( WSACleanup() == 0, "WSACleanup failed\n" );
869 }
870
871 cs130_ryutaro 1.1 static void StartServer (LPTHREAD_START_ROUTINE routine,
872 test_params *general, server_params *par)
873 {
874 par->general = general;
875 thread[0] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[0] );
876 ok ( thread[0] != NULL, "Failed to create server thread\n" );
877 }
878
879 static void StartClients (LPTHREAD_START_ROUTINE routine,
880 test_params *general, client_params *par)
881 {
882 int i;
883 par->general = general;
884 for ( i = 1; i <= min ( general->n_clients, MAX_CLIENTS ); i++ )
885 {
886 client_id = i - 1;
887 thread[i] = CreateThread ( NULL, 0, routine, par, 0, &thread_id[i] );
888 ok ( thread[i] != NULL, "Failed to create client thread\n" );
889 /* Make sure the client is up and running */
890 WaitForSingleObject ( client_ready[client_id], INFINITE );
891 };
892 cs130_ryutaro 1.1 }
893
894 static void do_test( test_setup *test )
895 {
896 DWORD i, n = min (test->general.n_clients, MAX_CLIENTS);
897 DWORD wait;
898
899 server_ready = CreateEventW ( NULL, TRUE, FALSE, NULL );
900 for (i = 0; i <= n; i++)
901 client_ready[i] = CreateEventW ( NULL, TRUE, FALSE, NULL );
902
903 StartServer ( test->srv, &test->general, &test->srv_params );
904 StartClients ( test->clt, &test->general, &test->clt_params );
905 WaitForSingleObject ( server_ready, INFINITE );
906
907 wait = WaitForMultipleObjects ( 1 + n, thread, TRUE, 1000 * TEST_TIMEOUT );
908 ok ( wait >= WAIT_OBJECT_0 && wait <= WAIT_OBJECT_0 + n ,
909 "some threads have not completed: %lx\n", wait );
910
911 if ( ! ( wait >= WAIT_OBJECT_0 && wait <= WAIT_OBJECT_0 + n ) )
912 {
913 cs130_ryutaro 1.1 for (i = 0; i <= n; i++)
914 {
915 trace ("terminating thread %08lx\n", thread_id[i]);
916 if ( WaitForSingleObject ( thread[i], 0 ) != WAIT_OBJECT_0 )
917 TerminateThread ( thread [i], 0 );
918 }
919 }
920 CloseHandle ( server_ready );
921 for (i = 0; i <= n; i++)
922 CloseHandle ( client_ready[i] );
923 }
924
925 /********* some tests for getsockopt(setsockopt(X)) == X ***********/
926 /* optname = SO_LINGER */
927 LINGER linger_testvals[] = {
928 {0,0},
929 {0,73},
930 {1,0},
931 {5,189}
932 };
933
934 cs130_ryutaro 1.1 /* optname = SO_RCVTIMEO, SOSNDTIMEO */
935 #define SOCKTIMEOUT1 63000 /* 63 seconds. Do not test fractional part because of a
936 bug in the linux kernel (fixed in 2.6.8) */
937 #define SOCKTIMEOUT2 997000 /* 997 seconds */
938
939 static void test_set_getsockopt()
940 {
941 SOCKET s;
942 int i, err;
943 int timeout;
944 LINGER lingval;
945 int size;
946
947 s = socket(AF_INET, SOCK_STREAM, 0);
948 ok(s!=INVALID_SOCKET, "socket() failed error: %d\n", WSAGetLastError());
949 if( s == INVALID_SOCKET) return;
950 /* SO_RCVTIMEO */
951 timeout = SOCKTIMEOUT1;
952 size = sizeof(timeout);
953 err = setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, size);
954 if( !err)
955 cs130_ryutaro 1.1 err = getsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, &size);
956 ok( !err, "get/setsockopt(SO_RCVTIMEO) failed error: %d\n", WSAGetLastError());
957 ok( timeout == SOCKTIMEOUT1, "getsockopt(SO_RCVTIMEO) returned wrong value %d\n", timeout);
958 /* SO_SNDTIMEO */
959 timeout = SOCKTIMEOUT2; /* 54 seconds. See remark above */
960 size = sizeof(timeout);
961 err = setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, size);
962 if( !err)
963 err = getsockopt(s, SOL_SOCKET, SO_SNDTIMEO, (char *) &timeout, &size);
964 ok( !err, "get/setsockopt(SO_SNDTIMEO) failed error: %d\n", WSAGetLastError());
965 ok( timeout == SOCKTIMEOUT2, "getsockopt(SO_SNDTIMEO) returned wrong value %d\n", timeout);
966 /* SO_LINGER */
967 for( i = 0; i < sizeof(linger_testvals)/sizeof(LINGER);i++) {
968 size = sizeof(lingval);
969 lingval = linger_testvals[i];
970 err = setsockopt(s, SOL_SOCKET, SO_LINGER, (char *) &lingval, size);
971 if( !err)
972 err = getsockopt(s, SOL_SOCKET, SO_LINGER, (char *) &lingval, &size);
973 ok( !err, "get/setsockopt(SO_LINGER) failed error: %d\n", WSAGetLastError());
974 ok( !lingval.l_onoff == !linger_testvals[i].l_onoff &&
975 (lingval.l_linger == linger_testvals[i].l_linger ||
976 cs130_ryutaro 1.1 (!lingval.l_linger && !linger_testvals[i].l_onoff))
977 , "getsockopt(SO_LINGER #%d) returned wrong value %d,%d not %d,%d \n", i,
978 lingval.l_onoff, lingval.l_linger,
979 linger_testvals[i].l_onoff, linger_testvals[i].l_linger);
980 }
981 closesocket(s);
982 }
983
984 static void test_so_reuseaddr()
985 {
986 struct sockaddr_in saddr;
987 SOCKET s1,s2;
988 unsigned int rc,reuse,size;
989
990 saddr.sin_family = AF_INET;
991 saddr.sin_port = htons(9375);
992 saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
993
994 s1=socket(AF_INET, SOCK_STREAM, 0);
995 ok(s1!=INVALID_SOCKET, "socket() failed error: %d\n", WSAGetLastError());
996 rc = bind(s1, (struct sockaddr*)&saddr, sizeof(saddr));
997 cs130_ryutaro 1.1 ok(rc!=SOCKET_ERROR, "bind(s1) failed error: %d\n", WSAGetLastError());
998
999 s2=socket(AF_INET, SOCK_STREAM, 0);
1000 ok(s2!=INVALID_SOCKET, "socket() failed error: %d\n", WSAGetLastError());
1001
1002 reuse=0x1234;
1003 size=sizeof(reuse);
1004 rc=getsockopt(s2, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, &size );
1005 ok(rc==0 && reuse==0,"wrong result in getsockopt(SO_REUSEADDR): rc=%d reuse=%d\n",rc,reuse);
1006
1007 rc = bind(s2, (struct sockaddr*)&saddr, sizeof(saddr));
1008 ok(rc==SOCKET_ERROR, "bind() succeeded\n");
1009
1010 reuse = 1;
1011 rc = setsockopt(s2, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse, sizeof(reuse));
1012 ok(rc==0, "setsockopt() failed error: %d\n", WSAGetLastError());
1013
1014 todo_wine {
1015 rc = bind(s2, (struct sockaddr*)&saddr, sizeof(saddr));
1016 ok(rc==0, "bind() failed error: %d\n", WSAGetLastError());
1017 }
1018 cs130_ryutaro 1.1
1019 closesocket(s2);
1020 closesocket(s1);
1021 }
1022
1023 /************* Array containing the tests to run **********/
1024
1025 #define STD_STREAM_SOCKET \
1026 SOCK_STREAM, \
1027 0, \
1028 "127.0.0.1", \
1029 9374
1030
1031 static test_setup tests [NUM_TESTS] =
1032 {
1033 /* Test 0: synchronous client and server */
1034 {
1035 {
1036 STD_STREAM_SOCKET,
1037 2048,
1038 16,
1039 cs130_ryutaro 1.1 2
1040 },
1041 simple_server,
1042 {
1043 NULL,
1044 0,
1045 64
1046 },
1047 simple_client,
1048 {
1049 NULL,
1050 0,
1051 128
1052 }
1053 },
1054 /* Test 1: event-driven client, synchronous server */
1055 {
1056 {
1057 STD_STREAM_SOCKET,
1058 2048,
1059 16,
1060 cs130_ryutaro 1.1 2
1061 },
1062 simple_server,
1063 {
1064 NULL,
1065 0,
1066 64
1067 },
1068 event_client,
1069 {
1070 NULL,
1071 WSA_FLAG_OVERLAPPED,
1072 128
1073 }
1074 },
1075
1076 /* Test 2: synchronous client and asynchronous server */
1077 {
1078 {
1079 STD_STREAM_SOCKET,
1080 2048,
1081 cs130_ryutaro 1.1 16,
1082 2
1083 },
1084 async_server,
1085 {
1086 NULL,
1087 0,
1088 64
1089 },
1090 simple_client,
1091 {
1092 NULL,
1093 0,
1094 128
1095 }
1096 }
1097 };
1098
1099 static void test_WSAAddressToStringA()
1100 {
1101 INT ret;
1102 cs130_ryutaro 1.1 DWORD len;
1103 SOCKADDR_IN sockaddr;
1104 CHAR address[22]; /* 12 digits + 3 dots + ':' + 5 digits + '\0' */
1105
1106 CHAR expect1[] = "0.0.0.0";
1107 CHAR expect2[] = "255.255.255.255";
1108 CHAR expect3[] = "0.0.0.0:65535";
1109 CHAR expect4[] = "255.255.255.255:65535";
1110
1111 len = 0;
1112
1113 sockaddr.sin_family = AF_INET;
1114 sockaddr.sin_port = 0;
1115 sockaddr.sin_addr.s_addr = 0;
1116
1117 ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1118 ok( ret == SOCKET_ERROR, "WSAAddressToStringA() succeeded unexpectedly: %d\n", WSAGetLastError() );
1119
1120 len = sizeof(address);
1121
1122 sockaddr.sin_family = AF_INET;
1123 cs130_ryutaro 1.1 sockaddr.sin_port = 0;
1124 sockaddr.sin_addr.s_addr = 0;
1125
1126 ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1127 ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
1128
1129 ok( !strcmp( address, expect1 ), "Expected: %s, got: %s\n", expect1, address );
1130
1131 len = sizeof(address);
1132
1133 sockaddr.sin_family = AF_INET;
1134 sockaddr.sin_port = 0;
1135 sockaddr.sin_addr.s_addr = 0xffffffff;
1136
1137 ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1138 ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
1139
1140 ok( !strcmp( address, expect2 ), "Expected: %s, got: %s\n", expect2, address );
1141
1142 len = sizeof(address);
1143
1144 cs130_ryutaro 1.1 sockaddr.sin_family = AF_INET;
1145 sockaddr.sin_port = 0xffff;
1146 sockaddr.sin_addr.s_addr = 0;
1147
1148 ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1149 ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
1150
1151 ok( !strcmp( address, expect3 ), "Expected: %s, got: %s\n", expect3, address );
1152
1153 len = sizeof(address);
1154
1155 sockaddr.sin_family = AF_INET;
1156 sockaddr.sin_port = 0xffff;
1157 sockaddr.sin_addr.s_addr = 0xffffffff;
1158
1159 ret = WSAAddressToStringA( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1160 ok( !ret, "WSAAddressToStringA() failed unexpectedly: %d\n", WSAGetLastError() );
1161
1162 ok( !strcmp( address, expect4 ), "Expected: %s, got: %s\n", expect4, address );
1163 }
1164
1165 cs130_ryutaro 1.1 static void test_WSAAddressToStringW()
1166 {
1167 INT ret;
1168 DWORD len;
1169 SOCKADDR_IN sockaddr;
1170 WCHAR address[22]; /* 12 digits + 3 dots + ':' + 5 digits + '\0' */
1171
1172 WCHAR expect1[] = { '0','.','0','.','0','.','0', 0 };
1173 WCHAR expect2[] = { '2','5','5','.','2','5','5','.','2','5','5','.','2','5','5', 0 };
1174 WCHAR expect3[] = { '0','.','0','.','0','.','0', ':', '6', '5', '5', '3', '5', 0 };
1175 WCHAR expect4[] = { '2','5','5','.','2','5','5','.','2','5','5','.','2','5','5', ':',
1176 '6', '5', '5', '3', '5', 0 };
1177
1178 len = 0;
1179
1180 sockaddr.sin_family = AF_INET;
1181 sockaddr.sin_port = 0;
1182 sockaddr.sin_addr.s_addr = 0;
1183
1184 ret = WSAAddressToStringW( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1185 ok( ret == SOCKET_ERROR, "WSAAddressToStringW() succeeded unexpectedly: %x\n", WSAGetLastError() );
1186 cs130_ryutaro 1.1
1187 len = sizeof(address);
1188
1189 sockaddr.sin_family = AF_INET;
1190 sockaddr.sin_port = 0;
1191 sockaddr.sin_addr.s_addr = 0;
1192
1193 ret = WSAAddressToStringW( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1194 ok( !ret, "WSAAddressToStringW() failed unexpectedly: %x\n", WSAGetLastError() );
1195
1196 ok( !lstrcmpW( address, expect1 ), "Expected different address string\n" );
1197
1198 len = sizeof(address);
1199
1200 sockaddr.sin_family = AF_INET;
1201 sockaddr.sin_port = 0;
1202 sockaddr.sin_addr.s_addr = 0xffffffff;
1203
1204 ret = WSAAddressToStringW( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1205 ok( !ret, "WSAAddressToStringW() failed unexpectedly: %x\n", WSAGetLastError() );
1206
1207 cs130_ryutaro 1.1 ok( !lstrcmpW( address, expect2 ), "Expected different address string\n" );
1208
1209 len = sizeof(address);
1210
1211 sockaddr.sin_family = AF_INET;
1212 sockaddr.sin_port = 0xffff;
1213 sockaddr.sin_addr.s_addr = 0;
1214
1215 ret = WSAAddressToStringW( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1216 ok( !ret, "WSAAddressToStringW() failed unexpectedly: %x\n", WSAGetLastError() );
1217
1218 ok( !lstrcmpW( address, expect3 ), "Expected different address string\n" );
1219
1220 len = sizeof(address);
1221
1222 sockaddr.sin_family = AF_INET;
1223 sockaddr.sin_port = 0xffff;
1224 sockaddr.sin_addr.s_addr = 0xffffffff;
1225
1226 ret = WSAAddressToStringW( (SOCKADDR*)&sockaddr, sizeof(sockaddr), NULL, address, &len );
1227 ok( !ret, "WSAAddressToStringW() failed unexpectedly: %x\n", WSAGetLastError() );
1228 cs130_ryutaro 1.1
1229 ok( !lstrcmpW( address, expect4 ), "Expected different address string\n" );
1230 }
1231
1232 static void test_WSAStringToAddressA()
1233 {
1234 INT ret, len;
1235 SOCKADDR_IN sockaddr;
1236
1237 CHAR address1[] = "0.0.0.0";
1238 CHAR address2[] = "127.127.127.127";
1239 CHAR address3[] = "255.255.255.255";
1240 CHAR address4[] = "127.127.127.127:65535";
1241 CHAR address5[] = "255.255.255.255:65535";
1242
1243 len = 0;
1244 sockaddr.sin_family = AF_INET;
1245
1246 ret = WSAStringToAddressA( address1, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1247 ok( ret == SOCKET_ERROR, "WSAStringToAddressA() succeeded unexpectedly: %x\n",
1248 WSAGetLastError() );
1249 cs130_ryutaro 1.1
1250 len = sizeof(sockaddr);
1251 sockaddr.sin_port = 0;
1252 sockaddr.sin_addr.s_addr = 0;
1253
1254 ret = WSAStringToAddressA( address1, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1255 ok( !ret && sockaddr.sin_addr.s_addr == 0,
1256 "WSAStringToAddressA() failed unexpectedly: %d\n", WSAGetLastError() );
1257
1258 len = sizeof(sockaddr);
1259 sockaddr.sin_port = 0;
1260 sockaddr.sin_addr.s_addr = 0;
1261
1262 ret = WSAStringToAddressA( address2, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1263 ok( !ret && sockaddr.sin_addr.s_addr == 0x7f7f7f7f,
1264 "WSAStringToAddressA() failed unexpectedly: %d\n", WSAGetLastError() );
1265
1266 len = sizeof(sockaddr);
1267
1268 ret = WSAStringToAddressA( address3, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1269 ok( ret, "WSAStringToAddressA() succeeded unexpectedly: %d\n", WSAGetLastError() );
1270 cs130_ryutaro 1.1
1271 len = sizeof(sockaddr);
1272 sockaddr.sin_port = 0;
1273 sockaddr.sin_addr.s_addr = 0;
1274
1275 ret = WSAStringToAddressA( address4, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1276 ok( !ret && sockaddr.sin_addr.s_addr == 0x7f7f7f7f && sockaddr.sin_port == 0xffff,
1277 "WSAStringToAddressA() failed unexpectedly: %d\n", WSAGetLastError() );
1278
1279 len = sizeof(sockaddr);
1280
1281 ret = WSAStringToAddressA( address5, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1282 ok( ret, "WSAStringToAddressA() succeeded unexpectedly: %d\n", WSAGetLastError() );
1283 }
1284
1285 static void test_WSAStringToAddressW()
1286 {
1287 INT ret, len;
1288 SOCKADDR_IN sockaddr;
1289
1290 WCHAR address1[] = { '0','.','0','.','0','.','0', 0 };
1291 cs130_ryutaro 1.1 WCHAR address2[] = { '1','2','7','.','1','2','7','.','1','2','7','.','1','2','7', 0 };
1292 WCHAR address3[] = { '2','5','5','.','2','5','5','.','2','5','5','.','2','5','5', 0 };
1293 WCHAR address4[] = { '1','2','7','.','1','2','7','.','1','2','7','.','1','2','7',
1294 ':', '6', '5', '5', '3', '5', 0 };
1295 WCHAR address5[] = { '2','5','5','.','2','5','5','.','2','5','5','.','2','5','5', ':',
1296 '6', '5', '5', '3', '5', 0 };
1297
1298 len = 0;
1299 sockaddr.sin_family = AF_INET;
1300
1301 ret = WSAStringToAddressW( address1, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1302 ok( ret == SOCKET_ERROR, "WSAStringToAddressW() failed unexpectedly: %d\n",
1303 WSAGetLastError() );
1304
1305 len = sizeof(sockaddr);
1306 sockaddr.sin_port = 0;
1307 sockaddr.sin_addr.s_addr = 0;
1308
1309 ret = WSAStringToAddressW( address1, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1310 ok( !ret && sockaddr.sin_addr.s_addr == 0,
1311 "WSAStringToAddressW() failed unexpectedly: %d\n", WSAGetLastError() );
1312 cs130_ryutaro 1.1
1313 len = sizeof(sockaddr);
1314
1315 sockaddr.sin_port = 0;
1316 sockaddr.sin_addr.s_addr = 0;
1317
1318 ret = WSAStringToAddressW( address2, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1319 ok( !ret && sockaddr.sin_addr.s_addr == 0x7f7f7f7f,
1320 "WSAStringToAddressW() failed unexpectedly: %d\n", WSAGetLastError() );
1321
1322 len = sizeof(sockaddr);
1323
1324 ret = WSAStringToAddressW( address3, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1325 ok( ret, "WSAStringToAddressW() failed unexpectedly: %d\n", WSAGetLastError() );
1326
1327 len = sizeof(sockaddr);
1328 sockaddr.sin_port = 0;
1329 sockaddr.sin_addr.s_addr = 0;
1330
1331 ret = WSAStringToAddressW( address4, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1332 ok( !ret && sockaddr.sin_addr.s_addr == 0x7f7f7f7f && sockaddr.sin_port == 0xffff,
1333 cs130_ryutaro 1.1 "WSAStringToAddressW() failed unexpectedly: %d\n", WSAGetLastError() );
1334
1335 len = sizeof(sockaddr);
1336
1337 ret = WSAStringToAddressW( address5, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
1338 ok( ret, "WSAStringToAddressW() succeeded unexpectedly: %d\n", WSAGetLastError() );
1339 }
1340
1341 /**************** Main program ***************/
1342
1343 START_TEST( sock )
1344 {
1345 int i;
1346 Init();
1347
1348 test_set_getsockopt();
1349 test_so_reuseaddr();
1350
1351 for (i = 0; i < NUM_TESTS; i++)
1352 {
1353 trace ( " **** STARTING TEST %d **** \n", i );
1354 cs130_ryutaro 1.1 do_test ( &tests[i] );
1355 trace ( " **** TEST %d COMPLETE **** \n", i );
1356 }
1357
1358 test_WSAAddressToStringA();
1359 test_WSAAddressToStringW();
1360
1361 test_WSAStringToAddressA();
1362 test_WSAStringToAddressW();
1363
1364 Exit();
1365 }
|