summaryrefslogtreecommitdiffstats
path: root/recipes-mac/smack/tcp-smack-test/tcp_client.c
diff options
context:
space:
mode:
authorArmin Kuster <akuster808@gmail.com>2021-07-29 16:31:12 -0700
committerArmin Kuster <akuster808@gmail.com>2021-08-01 08:47:08 -0700
commit11a67b861af74d59ccfd609d6d943e966ccff731 (patch)
treece619cf42798050439a4c04ed471ed293f17ede4 /recipes-mac/smack/tcp-smack-test/tcp_client.c
parentd3a484abf81fc196389480df89cf5c82d13e6381 (diff)
downloadmeta-security-11a67b861af74d59ccfd609d6d943e966ccff731.tar.gz
meta-security: Convert to new override syntax
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Diffstat (limited to 'recipes-mac/smack/tcp-smack-test/tcp_client.c')
-rw-r--r--recipes-mac/smack/tcp-smack-test/tcp_client.c222
1 files changed, 111 insertions, 111 deletions
diff --git a/recipes-mac/smack/tcp-smack-test/tcp_client.c b/recipes-mac/smack/tcp-smack-test/tcp_client.c
index 185f973..6c0a474 100644
--- a/recipes-mac/smack/tcp-smack-test/tcp_client.c
+++ b/recipes-mac/smack/tcp-smack-test/tcp_client.c
@@ -1,111 +1,111 @@
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 <netdb.h> 26#include <netdb.h>
27#include <string.h> 27#include <string.h>
28#include <sys/xattr.h> 28#include <sys/xattr.h>
29 29
30int main(int argc, char* argv[]) 30int main(int argc, char* argv[])
31{ 31{
32 32
33 int sock; 33 int sock;
34 char message[255] = "hello"; 34 char message[255] = "hello";
35 struct sockaddr_in server_addr; 35 struct sockaddr_in server_addr;
36 char* label_in; 36 char* label_in;
37 char* label_out; 37 char* label_out;
38 char* attr_out = "security.SMACK64IPOUT"; 38 char* attr_out = "security.SMACK64IPOUT";
39 char* attr_in = "security.SMACK64IPIN"; 39 char* attr_in = "security.SMACK64IPIN";
40 char out[256]; 40 char out[256];
41 int port; 41 int port;
42 42
43 struct timeval timeout; 43 struct timeval timeout;
44 timeout.tv_sec = 15; 44 timeout.tv_sec = 15;
45 timeout.tv_usec = 0; 45 timeout.tv_usec = 0;
46 46
47 struct hostent* host = gethostbyname("localhost"); 47 struct hostent* host = gethostbyname("localhost");
48 48
49 if (argc != 4) 49 if (argc != 4)
50 { 50 {
51 perror("Client: Arguments missing, please provide socket labels"); 51 perror("Client: Arguments missing, please provide socket labels");
52 return 2; 52 return 2;
53 } 53 }
54 54
55 port = atoi(argv[1]); 55 port = atoi(argv[1]);
56 label_in = argv[2]; 56 label_in = argv[2];
57 label_out = argv[3]; 57 label_out = argv[3];
58 58
59 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 59 if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
60 { 60 {
61 perror("Client: Socket failure"); 61 perror("Client: Socket failure");
62 return 2; 62 return 2;
63 } 63 }
64 64
65 65
66 if(fsetxattr(sock, attr_out, label_out, strlen(label_out), 0) < 0) 66 if(fsetxattr(sock, attr_out, label_out, strlen(label_out), 0) < 0)
67 { 67 {
68 perror("Client: Unable to set attribute SMACK64IPOUT"); 68 perror("Client: Unable to set attribute SMACK64IPOUT");
69 return 2; 69 return 2;
70 } 70 }
71 71
72 if(fsetxattr(sock, attr_in, label_in, strlen(label_in), 0) < 0) 72 if(fsetxattr(sock, attr_in, label_in, strlen(label_in), 0) < 0)
73 { 73 {
74 perror("Client: Unable to set attribute SMACK64IPIN"); 74 perror("Client: Unable to set attribute SMACK64IPIN");
75 return 2; 75 return 2;
76 } 76 }
77 77
78 server_addr.sin_family = AF_INET; 78 server_addr.sin_family = AF_INET;
79 server_addr.sin_port = htons(port); 79 server_addr.sin_port = htons(port);
80 bcopy((char*) host->h_addr, (char*) &server_addr.sin_addr.s_addr,host->h_length); 80 bcopy((char*) host->h_addr, (char*) &server_addr.sin_addr.s_addr,host->h_length);
81 bzero(&(server_addr.sin_zero),8); 81 bzero(&(server_addr.sin_zero),8);
82 82
83 if(setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) 83 if(setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0)
84 { 84 {
85 perror("Client: Set timeout failed\n"); 85 perror("Client: Set timeout failed\n");
86 return 2; 86 return 2;
87 } 87 }
88 88
89 if (connect(sock, (struct sockaddr *)&server_addr,sizeof(struct sockaddr)) == -1) 89 if (connect(sock, (struct sockaddr *)&server_addr,sizeof(struct sockaddr)) == -1)
90 { 90 {
91 perror("Client: Connection failure"); 91 perror("Client: Connection failure");
92 close(sock); 92 close(sock);
93 return 1; 93 return 1;
94 } 94 }
95 95
96 96
97 if(write(sock, message, strlen(message)) < 0) 97 if(write(sock, message, strlen(message)) < 0)
98 { 98 {
99 perror("Client: Error sending data\n"); 99 perror("Client: Error sending data\n");
100 close(sock); 100 close(sock);
101 return 1; 101 return 1;
102 } 102 }
103 close(sock); 103 close(sock);
104 return 0; 104 return 0;
105} 105}
106 106
107 107
108 108
109 109
110 110
111 111