Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | // (C) Copyright 2015 Intel Corporation
|
| 2 | //
|
| 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
|
| 5 | // in the Software without restriction, including without limitation the rights
|
| 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
|
| 8 | // furnished to do so, subject to the following conditions:
|
| 9 | //
|
| 10 | // The above copyright notice and this permission notice shall be included in
|
| 11 | // all copies or substantial portions of the Software.
|
| 12 | //
|
| 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,
|
| 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
|
| 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
|
| 19 | // THE SOFTWARE.
|
| 20 | #include <sys/socket.h>
|
| 21 | #include <stdio.h>
|
| 22 | #include <netinet/in.h>
|
| 23 | #include <netdb.h>
|
| 24 | #include <string.h>
|
| 25 |
|
| 26 | int main(int argc, char* argv[])
|
| 27 | {
|
| 28 | char* message = "hello";
|
| 29 | int sock, ret;
|
| 30 | struct sockaddr_in server_addr;
|
| 31 | struct hostent* host = gethostbyname("localhost");
|
| 32 | char* label;
|
| 33 | char* attr = "security.SMACK64IPOUT";
|
| 34 | int port;
|
| 35 | if (argc != 3)
|
| 36 | {
|
| 37 | perror("Client: Argument missing, please provide port and label for SMACK64IPOUT");
|
| 38 | return 2;
|
| 39 | }
|
| 40 |
|
| 41 | port = atoi(argv[1]);
|
| 42 | label = argv[2];
|
| 43 | sock = socket(AF_INET, SOCK_DGRAM,0);
|
| 44 | if(sock < 0)
|
| 45 | {
|
| 46 | perror("Client: Socket failure");
|
| 47 | return 2;
|
| 48 | }
|
| 49 |
|
| 50 |
|
| 51 | if(fsetxattr(sock, attr, label, strlen(label),0) < 0)
|
| 52 | {
|
| 53 | perror("Client: Unable to set attribute ");
|
| 54 | return 2;
|
| 55 | }
|
| 56 |
|
| 57 |
|
| 58 | server_addr.sin_family = AF_INET;
|
| 59 | server_addr.sin_port = htons(port);
|
| 60 | bcopy((char*) host->h_addr, (char*) &server_addr.sin_addr.s_addr,host->h_length);
|
| 61 | bzero(&(server_addr.sin_zero),8);
|
| 62 |
|
| 63 | ret = sendto(sock, message, strlen(message),0,(const struct sockaddr*)&server_addr,
|
| 64 | sizeof(struct sockaddr_in));
|
| 65 |
|
| 66 | close(sock);
|
| 67 | if(ret < 0)
|
| 68 | {
|
| 69 | perror("Client: Error sending message\n");
|
| 70 | return 1;
|
| 71 | }
|
| 72 |
|
| 73 | return 0;
|
| 74 | }
|
| 75 |
|