📄 t_sockopt_error.c
字号:
/* * Copyright (C) 1999-2003 MITSUBISHI ELECTRIC CORPORATION and * RENESAS SOLUTIONS CORPORATION and * RENESAS TECHNOLOGY CORPORATION * All rights reserved. * * TCP/IP Test Application program [API]. */#include <tk/tkernel.h>#include <renesas_tcpip.h>#include <renesas_tcpip_common.h>#include "config.h"voidtest_task(int stacd, void *exinf){ int i, s, s2, ret; int len, flags, option; int num; int testno, testno2, result[10]; num = 1; testno = 0; memset((char *)result, 0, sizeof(result)); /* create TCP socket */ errno = 0; if ((s = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("socket(AF_INET,SOCK_STREAM,0) fail\n"); goto testend; } /* Test 1 */ printf("setsockopt Test %d: \n",num++); errno = 0; flags = 1;testno = 1; if ((ret = unix_setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&flags, sizeof(flags))) < 0) { result[testno] = 1; printf("setsockopt fail\n"); unix_close(s); goto testend; } else { result[testno] = 0; } /* Test 2 */ printf("getsockopt Test %d: \n",num++); errno = 0; flags = 0; len = sizeof(flags);testno = 2; if ((ret = unix_getsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&flags, &len)) < 0) { result[testno] = 1; printf("getsockopt fail\n"); unix_close(s); goto testend; } else { result[testno] = 0; } /* Test 3 */ printf("setsockopt Test %d: \n",num++); errno = 0; flags = 1;testno = 3; if ((ret = unix_setsockopt(-1, SOL_SOCKET, SO_DEBUG, (char *)&flags, sizeof(flags))) < 0) { if (errno == EBADF) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("setsockopt fail\n"); unix_close(s); goto testend; } /* Test 4 */ printf("getsockopt Test %d: \n",num++); errno = 0; flags = 1; len = sizeof(flags);testno = 4; if ((ret = unix_getsockopt(-1, SOL_SOCKET, SO_DEBUG, (char *)&flags, &len)) < 0) { if (errno == EBADF) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("getsockopt fail\n"); unix_close(s); goto testend; } /* Test 5 */ printf("setsockopt Test %d: \n",num++); errno = 0; flags = 1; option = 0x00001010;testno = 5; if ((ret = unix_setsockopt(s, SOL_SOCKET, option, (char *)&flags, sizeof(flags))) < 0) { if (errno == ENOPROTOOPT) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("setsockopt fail\n"); unix_close(s); goto testend; } /* Test 6 */ printf("getsockopt Test %d: \n",num++); errno = 0; flags = 1; option = 0x00001010; len = sizeof(flags);testno = 6; if ((ret = unix_getsockopt(s, SOL_SOCKET, option, (char *)&flags, &len)) < 0) { if (errno == ENOPROTOOPT) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("getsockopt fail\n"); unix_close(s); goto testend; } /* Test 7 */ printf("setsockopt Test %d: \n",num++); errno = 0; flags = 1;testno = 7; if ((ret = unix_setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)-1, sizeof(flags))) < 0) { if (errno == EFAULT) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("setsockopt fail\n"); unix_close(s); goto testend; } /* Test 8 */ printf("getsockopt Test %d: \n",num++); errno = 0; flags = 1; len = sizeof(flags);testno = 8; if ((ret = unix_getsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)-1, &len)) < 0) { if (errno == EFAULT) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("getsockopt fail\n"); unix_close(s); goto testend; } /* Test 9 */ printf("getsockopt Test %d: \n",num++); errno = 0; flags = 1; len = sizeof(flags);testno = 9; if ((ret = unix_getsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&flags, (int *)-1)) < 0) { if (errno == EFAULT) result[testno] = 0; else result[testno] = 1; } else { result[testno] = 1; printf("getsockopt fail\n"); unix_close(s); goto testend; } unix_close(s);#if defined(T_KERNEL) tk_slp_tsk(2000);#endiftestend: /* check the results */ testno2 = 9; for (i=1; i <= testno; i++) { if (result[i] == 1) break; } if (i > testno2) printf("Pass.\n"); else printf("Error.\n");#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -