shvtr159

면담3 + renew

1 +#include <stdio.h>
2 +#include <sys/types.h>
3 +#include <sys/socket.h>
4 +#include <netinet/in.h>
5 +#include <arpa/inet.h>
6 +#include <signal.h>
7 +#include <stdlib.h>
8 +#include <string.h>
9 +
10 +#define Port 23
11 +
12 +int Sockfd;
13 +
14 +typedef struct {
15 + char filename[256];
16 + char result_filename[256];
17 + char sender[30];
18 + char pwd[256];
19 + int pass;
20 +} Info;
21 +
22 +void Receivedone()
23 +{
24 + close(Sockfd);
25 + printf("\n Program done\n");
26 +
27 + exit(0);
28 +}
29 +
30 +main(int argc, char* argv[])
31 +{
32 + int newSockfd, hostAddrLen, n;
33 + struct sockaddr_in hostAddr, boardAddr;
34 + Info info;
35 +
36 + signal(SIGINT, Receivedone); // 종료 signal
37 +
38 + if((Sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
39 + perror("socket");
40 + exit(1);
41 + }
42 +
43 + bzero((char*)&boardAddr, sizeof(boardAddr));
44 + boardAddr.sin_family = PF_INET;
45 + boardAddr.sin_addr.s_addr = htonl(INADDR_ANY);
46 + boardAddr.sin_port = htons(Port);
47 +
48 + if(bind(Sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
49 + perror("bind");
50 + exit(1);
51 + }
52 +
53 + listen(Sockfd, 5);
54 +
55 + printf("\nReceive waiting\n\n");
56 +
57 + hostAddrLen = sizeof(hostAddr);
58 +
59 + while(1) {
60 + info.pass = 0;
61 + char path[256] = "~/Vitis-AI/vitis_ai_library/samples/yolov3/test_jpeg_yolov3 yolov3_bdd ";
62 + char scp[256] = "scp ";
63 + newSockfd = accept(Sockfd, (struct sockaddr*)&hostAddr, &hostAddrLen);
64 + if(newSockfd < 0) {
65 + perror("accept");
66 + exit(1);
67 + }
68 + if((n = read(newSockfd, (char*)&info, sizeof(info))) < 0) {
69 + perror("read");
70 + exit(1);
71 + }
72 +
73 + printf("Start yolo : %s\n", info.filename);
74 + strcat(path, info.filename);
75 +
76 + if(system(path)) { // yolo 실행
77 + perror("system");
78 + exit(1);
79 + }
80 + // scp 명령어 만들기
81 + strcat(scp, info.result_filename);
82 + strcat(scp, " ");
83 + strcat(scp, info.sender);
84 + strcat(scp, ":");
85 + strcat(scp, info.pwd);
86 + printf("%s\n", scp);
87 +
88 + if(system(scp)) { // scp 명령어 실행
89 + perror("system");
90 + exit(1);
91 + }
92 +
93 + info.pass = 1;
94 +
95 + if(write(newSockfd, (char*)&info, sizeof(info)) < 0) {
96 + perror("write");
97 + exit(1);
98 + }
99 +
100 + printf("\nSuccess\n=========================================================\n\n");
101 + close(newSockfd);
102 + }
103 +}
1 +#include <stdio.h>
2 +#include <sys/types.h>
3 +#include <sys/socket.h>
4 +#include <netinet/in.h>
5 +#include <arpa/inet.h>
6 +#include <stdlib.h>
7 +#include <string.h>
8 +#include <unistd.h>
9 +
10 +#define Port 23
11 +#define Board_addr "192.168.2.99"
12 +
13 +int sockfd;
14 +
15 +typedef struct {
16 + char filename[256];
17 + char result_filename[256];
18 + char sender[30];
19 + char pwd[256];
20 + int pass;
21 +} Info;
22 +
23 +main(int argc, char *argv[])
24 +{
25 + if(argc != 3) {
26 + printf("Usage: %s destination_dir sender_ID@sender_IP\n", argv[0]);
27 + exit(1);
28 + }
29 +
30 + Info info;
31 + info.pass = 0;
32 + int n, len;
33 + struct sockaddr_in boardAddr;
34 + char board_dir[256];
35 + // info 붙여넣기
36 + strcpy(info.sender, argv[2]);
37 + if(getcwd(info.pwd, 256) == NULL) {
38 + perror("getcwd");
39 + exit(1);
40 + }
41 +
42 + while(1) {
43 + if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
44 + perror("socket");
45 + exit(1);
46 + }
47 +
48 + bzero((char *)&boardAddr, sizeof(boardAddr));
49 + boardAddr.sin_family = PF_INET;
50 + boardAddr.sin_addr.s_addr = inet_addr(Board_addr);
51 + boardAddr.sin_port = htons(Port);
52 +
53 + if (connect(sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
54 + perror("connect");
55 + exit(1);
56 + }
57 +
58 + printf("\nsend file name : ");
59 + scanf("%s", &info.filename);
60 +
61 + char scp[256] = "scp ";
62 + char root[30] = " root@";
63 + char fname[256];
64 + //scp 명령어 만들기
65 + strcat(scp, info.filename);
66 + strcat(root, Board_addr);
67 + len = strlen(Board_addr);
68 + root[6+len] = ':';
69 + strcat(scp, root);
70 + strcat(scp, argv[1]);
71 + len = strlen(scp);
72 + scp[len] = '\n';
73 + // 결과 파일 이름 만들기
74 + strcpy(fname, info.filename);
75 + char* ptr = strtok(fname, ".");
76 + char result_name[256];
77 + strcpy(result_name, ptr);
78 + char result[256] = "_result.jpg"; // 출력이 jpg로 고정되어있음
79 + strcat(result_name, result);
80 + strcpy(info.result_filename, result_name);
81 +
82 + printf("Do : %s\n", scp);
83 + if(system(scp)) { // scp 명령어 실행
84 + perror("system");
85 + exit(1);
86 + }
87 +
88 + if(write(sockfd, (char*)&info, sizeof(info)) < 0) { // info 전달
89 + perror("write");
90 + exit(1);
91 + }
92 +
93 + printf("\nwait result\n");
94 +
95 + if((n = read(sockfd, (char*)&info, sizeof(info))) < 0) {
96 + perror("read");
97 + exit(1);
98 + }
99 +
100 + if(info.pass == 1)
101 + printf("Success\n======================================================\n");
102 +
103 + close(sockfd);
104 + }
105 +}
No preview for this file type