summaryrefslogtreecommitdiffstats
path: root/recipes-mac/smack/udp-smack-test/udp_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-mac/smack/udp-smack-test/udp_client.c')
-rw-r--r--recipes-mac/smack/udp-smack-test/udp_client.c150
1 files changed, 75 insertions, 75 deletions
diff --git a/recipes-mac/smack/udp-smack-test/udp_client.c b/recipes-mac/smack/udp-smack-test/udp_client.c
index 4d3afbe..23f3e00 100644
--- a/recipes-mac/smack/udp-smack-test/udp_client.c
+++ b/recipes-mac/smack/udp-smack-test/udp_client.c
@@ -1,75 +1,75 @@
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
26int main(int argc, char* argv[]) 26int main(int argc, char* argv[])
27{ 27{
28 char* message = "hello"; 28 char* message = "hello";
29 int sock, ret; 29 int sock, ret;
30 struct sockaddr_in server_addr; 30 struct sockaddr_in server_addr;
31 struct hostent* host = gethostbyname("localhost"); 31 struct hostent* host = gethostbyname("localhost");
32 char* label; 32 char* label;
33 char* attr = "security.SMACK64IPOUT"; 33 char* attr = "security.SMACK64IPOUT";
34 int port; 34 int port;
35 if (argc != 3) 35 if (argc != 3)
36 { 36 {
37 perror("Client: Argument missing, please provide port and label for SMACK64IPOUT"); 37 perror("Client: Argument missing, please provide port and label for SMACK64IPOUT");
38 return 2; 38 return 2;
39 } 39 }
40 40
41 port = atoi(argv[1]); 41 port = atoi(argv[1]);
42 label = argv[2]; 42 label = argv[2];
43 sock = socket(AF_INET, SOCK_DGRAM,0); 43 sock = socket(AF_INET, SOCK_DGRAM,0);
44 if(sock < 0) 44 if(sock < 0)
45 { 45 {
46 perror("Client: Socket failure"); 46 perror("Client: Socket failure");
47 return 2; 47 return 2;
48 } 48 }
49 49
50 50
51 if(fsetxattr(sock, attr, label, strlen(label),0) < 0) 51 if(fsetxattr(sock, attr, label, strlen(label),0) < 0)
52 { 52 {
53 perror("Client: Unable to set attribute "); 53 perror("Client: Unable to set attribute ");
54 return 2; 54 return 2;
55 } 55 }
56 56
57 57
58 server_addr.sin_family = AF_INET; 58 server_addr.sin_family = AF_INET;
59 server_addr.sin_port = htons(port); 59 server_addr.sin_port = htons(port);
60 bcopy((char*) host->h_addr, (char*) &server_addr.sin_addr.s_addr,host->h_length); 60 bcopy((char*) host->h_addr, (char*) &server_addr.sin_addr.s_addr,host->h_length);
61 bzero(&(server_addr.sin_zero),8); 61 bzero(&(server_addr.sin_zero),8);
62 62
63 ret = sendto(sock, message, strlen(message),0,(const struct sockaddr*)&server_addr, 63 ret = sendto(sock, message, strlen(message),0,(const struct sockaddr*)&server_addr,
64 sizeof(struct sockaddr_in)); 64 sizeof(struct sockaddr_in));
65 65
66 close(sock); 66 close(sock);
67 if(ret < 0) 67 if(ret < 0)
68 { 68 {
69 perror("Client: Error sending message\n"); 69 perror("Client: Error sending message\n");
70 return 1; 70 return 1;
71 } 71 }
72 72
73 return 0; 73 return 0;
74} 74}
75 75