1 // (C) Copyright 2015 Intel Corporation
\r
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
4 // of this software and associated documentation files (the "Software"), to deal
\r
5 // in the Software without restriction, including without limitation the rights
\r
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
7 // copies of the Software, and to permit persons to whom the Software is
\r
8 // furnished to do so, subject to the following conditions:
\r
10 // The above copyright notice and this permission notice shall be included in
\r
11 // all copies or substantial portions of the Software.
\r
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
21 #include <sys/socket.h>
\r
22 #include <sys/types.h>
\r
24 #include <netinet/in.h>
\r
28 int main(int argc, char* argv[])
\r
34 socklen_t client_length;
\r
35 struct sockaddr_in server_addr, client_addr;
\r
37 char* attr_in = "security.SMACK64IPIN";
\r
40 struct timeval timeout;
\r
41 timeout.tv_sec = 15;
\r
42 timeout.tv_usec = 0;
\r
46 perror("Server: Argument missing please provide port and label for SMACK64IPIN");
\r
50 port = atoi(argv[1]);
\r
55 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
\r
57 perror("Server: Socket failure");
\r
62 if(fsetxattr(sock, attr_in, label_in, strlen(label_in),0) < 0)
\r
64 perror("Server: Unable to set attribute ipin 2");
\r
68 server_addr.sin_family = AF_INET;
\r
69 server_addr.sin_port = htons(port);
\r
70 server_addr.sin_addr.s_addr = INADDR_ANY;
\r
71 bzero(&(server_addr.sin_zero),8);
\r
73 if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
\r
75 perror("Server: Set timeout failed\n");
\r
79 if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0)
\r
81 perror("Server: Bind failure ");
\r
86 client_length = sizeof(client_addr);
\r
88 clientsock = accept(sock,(struct sockaddr*) &client_addr, &client_length);
\r
92 perror("Server: Connection failed");
\r
98 if(fsetxattr(clientsock, "security.SMACK64IPIN", label_in, strlen(label_in),0) < 0)
\r
100 perror(" Server: Unable to set attribute ipin 2");
\r
105 if(read(clientsock, message, 254) < 0)
\r
107 perror("Server: Error when reading from socket");
\r