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
20 #include <sys/socket.h>
\r
22 #include <netinet/in.h>
\r
26 int main(int argc, char* argv[])
\r
29 struct sockaddr_in server_addr, client_addr;
\r
33 char* attr = "security.SMACK64IPIN";
\r
38 perror("Server: Argument missing, please provide port and label for SMACK64IPIN");
\r
42 port = atoi(argv[1]);
\r
45 struct timeval timeout;
\r
46 timeout.tv_sec = 15;
\r
47 timeout.tv_usec = 0;
\r
49 sock = socket(AF_INET,SOCK_DGRAM,0);
\r
52 perror("Server: Socket error");
\r
57 if(fsetxattr(sock, attr, label, strlen(label), 0) < 0)
\r
59 perror("Server: Unable to set attribute ");
\r
63 server_addr.sin_family = AF_INET;
\r
64 server_addr.sin_port = htons(port);
\r
65 server_addr.sin_addr.s_addr = INADDR_ANY;
\r
66 bzero(&(server_addr.sin_zero),8);
\r
69 if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
\r
71 perror("Server: Set timeout failed\n");
\r
75 if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0)
\r
77 perror("Server: Bind failure");
\r
81 len = sizeof(client_addr);
\r
82 ret = recvfrom(sock, message, sizeof(message), 0, (struct sockaddr*)&client_addr,
\r
87 perror("Server: Error receiving");
\r