1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <netinet/ip.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <time.h>
20 #include <string.h>
21 #include <sys/socket.h>
22 #include "test.h"
23
24 /**
25 * @tc.name : sendmsg_0100
26 * @tc.desc : Test sendmsg to send messages through socket
27 * @tc.level : Level 0
28 */
sendmsg_0100(void)29 void sendmsg_0100(void)
30 {
31 int sockfd;
32 struct sockaddr_in addr;
33 int retval;
34
35 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
36 if (sockfd == -1) {
37 t_error("sendmsg_0100 socket error");
38 exit(EXIT_FAILURE);
39 }
40
41 addr.sin_family = AF_INET;
42 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
43 addr.sin_port = htons(1234);
44 if (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
45 t_error("sendmsg_0100 connect error");
46 exit(EXIT_FAILURE);
47 }
48 struct msghdr msg;
49 bzero(&msg, sizeof(struct msghdr));
50
51 retval = sendmsg(sockfd, &msg, 2);
52 if (retval == -1)
53 t_error("sendmsg_0100 sendmsg error");
54 }
55
main(int argc,char * argv[])56 int main(int argc, char *argv[])
57 {
58 sendmsg_0100();
59 return t_status;
60 }