summaryrefslogtreecommitdiffstats
path: root/recipes-mac/smack/tcp-smack-test/tcp_server.c
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-mac/smack/tcp-smack-test/tcp_server.c')
-rw-r--r--recipes-mac/smack/tcp-smack-test/tcp_server.c236
1 files changed, 118 insertions, 118 deletions
diff --git a/recipes-mac/smack/tcp-smack-test/tcp_server.c b/recipes-mac/smack/tcp-smack-test/tcp_server.c
index 9285dc6..3c8921f 100644
--- a/recipes-mac/smack/tcp-smack-test/tcp_server.c
+++ b/recipes-mac/smack/tcp-smack-test/tcp_server.c
@@ -1,118 +1,118 @@
1// (C) Copyright 2015 Intel Corporation 1// (C) Copyright 2015 Intel Corporation
2// 2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy 3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal 4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights 5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is 7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions: 8// furnished to do so, subject to the following conditions:
9// 9//
10// The above copyright notice and this permission notice shall be included in 10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software. 11// all copies or substantial portions of the Software.
12// 12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE. 19// THE SOFTWARE.
20#include <stdio.h> 20#include <stdio.h>
21#include <sys/socket.h> 21#include <sys/socket.h>
22#include <sys/types.h> 22#include <sys/types.h>
23#include <errno.h> 23#include <errno.h>
24#include <netinet/in.h> 24#include <netinet/in.h>
25#include <unistd.h> 25#include <unistd.h>
26#include <string.h> 26#include <string.h>
27 27
28int main(int argc, char* argv[]) 28int main(int argc, char* argv[])
29{ 29{
30 30
31 int sock; 31 int sock;
32 int clientsock; 32 int clientsock;
33 char message[255]; 33 char message[255];
34 socklen_t client_length; 34 socklen_t client_length;
35 struct sockaddr_in server_addr, client_addr; 35 struct sockaddr_in server_addr, client_addr;
36 char* label_in; 36 char* label_in;
37 char* attr_in = "security.SMACK64IPIN"; 37 char* attr_in = "security.SMACK64IPIN";
38 int port; 38 int port;
39 39
40 struct timeval timeout; 40 struct timeval timeout;
41 timeout.tv_sec = 15; 41 timeout.tv_sec = 15;
42 timeout.tv_usec = 0; 42 timeout.tv_usec = 0;
43 43
44 if (argc != 3) 44 if (argc != 3)
45 { 45 {
46 perror("Server: Argument missing please provide port and label for SMACK64IPIN"); 46 perror("Server: Argument missing please provide port and label for SMACK64IPIN");
47 return 2; 47 return 2;
48 } 48 }
49 49
50 port = atoi(argv[1]); 50 port = atoi(argv[1]);
51 label_in = argv[2]; 51 label_in = argv[2];
52 bzero(message,255); 52 bzero(message,255);
53 53
54 54
55 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 55 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
56 { 56 {
57 perror("Server: Socket failure"); 57 perror("Server: Socket failure");
58 return 2; 58 return 2;
59 } 59 }
60 60
61 61
62 if(fsetxattr(sock, attr_in, label_in, strlen(label_in),0) < 0) 62 if(fsetxattr(sock, attr_in, label_in, strlen(label_in),0) < 0)
63 { 63 {
64 perror("Server: Unable to set attribute ipin 2"); 64 perror("Server: Unable to set attribute ipin 2");
65 return 2; 65 return 2;
66 } 66 }
67 67
68 server_addr.sin_family = AF_INET; 68 server_addr.sin_family = AF_INET;
69 server_addr.sin_port = htons(port); 69 server_addr.sin_port = htons(port);
70 server_addr.sin_addr.s_addr = INADDR_ANY; 70 server_addr.sin_addr.s_addr = INADDR_ANY;
71 bzero(&(server_addr.sin_zero),8); 71 bzero(&(server_addr.sin_zero),8);
72 72
73 if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) 73 if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
74 { 74 {
75 perror("Server: Set timeout failed\n"); 75 perror("Server: Set timeout failed\n");
76 return 2; 76 return 2;
77 } 77 }
78 78
79 if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0) 79 if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0)
80 { 80 {
81 perror("Server: Bind failure "); 81 perror("Server: Bind failure ");
82 return 2; 82 return 2;
83 } 83 }
84 84
85 listen(sock, 1); 85 listen(sock, 1);
86 client_length = sizeof(client_addr); 86 client_length = sizeof(client_addr);
87 87
88 clientsock = accept(sock,(struct sockaddr*) &client_addr, &client_length); 88 clientsock = accept(sock,(struct sockaddr*) &client_addr, &client_length);
89 89
90 if (clientsock < 0) 90 if (clientsock < 0)
91 { 91 {
92 perror("Server: Connection failed"); 92 perror("Server: Connection failed");
93 close(sock); 93 close(sock);
94 return 1; 94 return 1;
95 } 95 }
96 96
97 97
98 if(fsetxattr(clientsock, "security.SMACK64IPIN", label_in, strlen(label_in),0) < 0) 98 if(fsetxattr(clientsock, "security.SMACK64IPIN", label_in, strlen(label_in),0) < 0)
99 { 99 {
100 perror(" Server: Unable to set attribute ipin 2"); 100 perror(" Server: Unable to set attribute ipin 2");
101 close(sock); 101 close(sock);
102 return 2; 102 return 2;
103 } 103 }
104 104
105 if(read(clientsock, message, 254) < 0) 105 if(read(clientsock, message, 254) < 0)
106 { 106 {
107 perror("Server: Error when reading from socket"); 107 perror("Server: Error when reading from socket");
108 close(clientsock); 108 close(clientsock);
109 close(sock); 109 close(sock);
110 return 1; 110 return 1;
111 } 111 }
112 112
113 113
114 close(clientsock); 114 close(clientsock);
115 close(sock); 115 close(sock);
116 116
117 return 0; 117 return 0;
118} 118}