diff options
Diffstat (limited to 'recipes-mac/smack/udp-smack-test/udp_server.c')
-rw-r--r-- | recipes-mac/smack/udp-smack-test/udp_server.c | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/recipes-mac/smack/udp-smack-test/udp_server.c b/recipes-mac/smack/udp-smack-test/udp_server.c index cbab71e..7d2fcf5 100644 --- a/recipes-mac/smack/udp-smack-test/udp_server.c +++ b/recipes-mac/smack/udp-smack-test/udp_server.c | |||
@@ -1,93 +1,93 @@ | |||
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 <sys/socket.h> | 20 | #include <sys/socket.h> |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <netinet/in.h> | 22 | #include <netinet/in.h> |
23 | #include <netdb.h> | 23 | #include <netdb.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | int main(int argc, char* argv[]) | 26 | int main(int argc, char* argv[]) |
27 | { | 27 | { |
28 | int sock,ret; | 28 | int sock,ret; |
29 | struct sockaddr_in server_addr, client_addr; | 29 | struct sockaddr_in server_addr, client_addr; |
30 | socklen_t len; | 30 | socklen_t len; |
31 | char message[5]; | 31 | char message[5]; |
32 | char* label; | 32 | char* label; |
33 | char* attr = "security.SMACK64IPIN"; | 33 | char* attr = "security.SMACK64IPIN"; |
34 | int port; | 34 | int port; |
35 | 35 | ||
36 | if(argc != 3) | 36 | if(argc != 3) |
37 | { | 37 | { |
38 | perror("Server: Argument missing, please provide port and label for SMACK64IPIN"); | 38 | perror("Server: Argument missing, please provide port and label for SMACK64IPIN"); |
39 | return 2; | 39 | return 2; |
40 | } | 40 | } |
41 | 41 | ||
42 | port = atoi(argv[1]); | 42 | port = atoi(argv[1]); |
43 | label = argv[2]; | 43 | label = argv[2]; |
44 | 44 | ||
45 | struct timeval timeout; | 45 | struct timeval timeout; |
46 | timeout.tv_sec = 15; | 46 | timeout.tv_sec = 15; |
47 | timeout.tv_usec = 0; | 47 | timeout.tv_usec = 0; |
48 | 48 | ||
49 | sock = socket(AF_INET,SOCK_DGRAM,0); | 49 | sock = socket(AF_INET,SOCK_DGRAM,0); |
50 | if(sock < 0) | 50 | if(sock < 0) |
51 | { | 51 | { |
52 | perror("Server: Socket error"); | 52 | perror("Server: Socket error"); |
53 | return 2; | 53 | return 2; |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
57 | if(fsetxattr(sock, attr, label, strlen(label), 0) < 0) | 57 | if(fsetxattr(sock, attr, label, strlen(label), 0) < 0) |
58 | { | 58 | { |
59 | perror("Server: Unable to set attribute "); | 59 | perror("Server: Unable to set attribute "); |
60 | return 2; | 60 | return 2; |
61 | } | 61 | } |
62 | 62 | ||
63 | server_addr.sin_family = AF_INET; | 63 | server_addr.sin_family = AF_INET; |
64 | server_addr.sin_port = htons(port); | 64 | server_addr.sin_port = htons(port); |
65 | server_addr.sin_addr.s_addr = INADDR_ANY; | 65 | server_addr.sin_addr.s_addr = INADDR_ANY; |
66 | bzero(&(server_addr.sin_zero),8); | 66 | bzero(&(server_addr.sin_zero),8); |
67 | 67 | ||
68 | 68 | ||
69 | if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) | 69 | if(setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) |
70 | { | 70 | { |
71 | perror("Server: Set timeout failed\n"); | 71 | perror("Server: Set timeout failed\n"); |
72 | return 2; | 72 | return 2; |
73 | } | 73 | } |
74 | 74 | ||
75 | if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0) | 75 | if(bind(sock, (struct sockaddr*) &server_addr, sizeof(server_addr)) < 0) |
76 | { | 76 | { |
77 | perror("Server: Bind failure"); | 77 | perror("Server: Bind failure"); |
78 | return 2; | 78 | return 2; |
79 | } | 79 | } |
80 | 80 | ||
81 | len = sizeof(client_addr); | 81 | len = sizeof(client_addr); |
82 | ret = recvfrom(sock, message, sizeof(message), 0, (struct sockaddr*)&client_addr, | 82 | ret = recvfrom(sock, message, sizeof(message), 0, (struct sockaddr*)&client_addr, |
83 | &len); | 83 | &len); |
84 | close(sock); | 84 | close(sock); |
85 | if(ret < 0) | 85 | if(ret < 0) |
86 | { | 86 | { |
87 | perror("Server: Error receiving"); | 87 | perror("Server: Error receiving"); |
88 | return 1; | 88 | return 1; |
89 | 89 | ||
90 | } | 90 | } |
91 | return 0; | 91 | return 0; |
92 | } | 92 | } |
93 | 93 | ||