shvtr159

면담3 + renew

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#define Port 23
int Sockfd;
typedef struct {
char filename[256];
char result_filename[256];
char sender[30];
char pwd[256];
int pass;
} Info;
void Receivedone()
{
close(Sockfd);
printf("\n Program done\n");
exit(0);
}
main(int argc, char* argv[])
{
int newSockfd, hostAddrLen, n;
struct sockaddr_in hostAddr, boardAddr;
Info info;
signal(SIGINT, Receivedone); // 종료 signal
if((Sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
exit(1);
}
bzero((char*)&boardAddr, sizeof(boardAddr));
boardAddr.sin_family = PF_INET;
boardAddr.sin_addr.s_addr = htonl(INADDR_ANY);
boardAddr.sin_port = htons(Port);
if(bind(Sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
perror("bind");
exit(1);
}
listen(Sockfd, 5);
printf("\nReceive waiting\n\n");
hostAddrLen = sizeof(hostAddr);
while(1) {
info.pass = 0;
char path[256] = "~/Vitis-AI/vitis_ai_library/samples/yolov3/test_jpeg_yolov3 yolov3_bdd ";
char scp[256] = "scp ";
newSockfd = accept(Sockfd, (struct sockaddr*)&hostAddr, &hostAddrLen);
if(newSockfd < 0) {
perror("accept");
exit(1);
}
if((n = read(newSockfd, (char*)&info, sizeof(info))) < 0) {
perror("read");
exit(1);
}
printf("Start yolo : %s\n", info.filename);
strcat(path, info.filename);
if(system(path)) { // yolo 실행
perror("system");
exit(1);
}
// scp 명령어 만들기
strcat(scp, info.result_filename);
strcat(scp, " ");
strcat(scp, info.sender);
strcat(scp, ":");
strcat(scp, info.pwd);
printf("%s\n", scp);
if(system(scp)) { // scp 명령어 실행
perror("system");
exit(1);
}
info.pass = 1;
if(write(newSockfd, (char*)&info, sizeof(info)) < 0) {
perror("write");
exit(1);
}
printf("\nSuccess\n=========================================================\n\n");
close(newSockfd);
}
}
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define Port 23
#define Board_addr "192.168.2.99"
int sockfd;
typedef struct {
char filename[256];
char result_filename[256];
char sender[30];
char pwd[256];
int pass;
} Info;
main(int argc, char *argv[])
{
if(argc != 3) {
printf("Usage: %s destination_dir sender_ID@sender_IP\n", argv[0]);
exit(1);
}
Info info;
info.pass = 0;
int n, len;
struct sockaddr_in boardAddr;
char board_dir[256];
// info 붙여넣기
strcpy(info.sender, argv[2]);
if(getcwd(info.pwd, 256) == NULL) {
perror("getcwd");
exit(1);
}
while(1) {
if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
exit(1);
}
bzero((char *)&boardAddr, sizeof(boardAddr));
boardAddr.sin_family = PF_INET;
boardAddr.sin_addr.s_addr = inet_addr(Board_addr);
boardAddr.sin_port = htons(Port);
if (connect(sockfd, (struct sockaddr*)&boardAddr, sizeof(boardAddr)) < 0) {
perror("connect");
exit(1);
}
printf("\nsend file name : ");
scanf("%s", &info.filename);
char scp[256] = "scp ";
char root[30] = " root@";
char fname[256];
//scp 명령어 만들기
strcat(scp, info.filename);
strcat(root, Board_addr);
len = strlen(Board_addr);
root[6+len] = ':';
strcat(scp, root);
strcat(scp, argv[1]);
len = strlen(scp);
scp[len] = '\n';
// 결과 파일 이름 만들기
strcpy(fname, info.filename);
char* ptr = strtok(fname, ".");
char result_name[256];
strcpy(result_name, ptr);
char result[256] = "_result.jpg"; // 출력이 jpg로 고정되어있음
strcat(result_name, result);
strcpy(info.result_filename, result_name);
printf("Do : %s\n", scp);
if(system(scp)) { // scp 명령어 실행
perror("system");
exit(1);
}
if(write(sockfd, (char*)&info, sizeof(info)) < 0) { // info 전달
perror("write");
exit(1);
}
printf("\nwait result\n");
if((n = read(sockfd, (char*)&info, sizeof(info))) < 0) {
perror("read");
exit(1);
}
if(info.pass == 1)
printf("Success\n======================================================\n");
close(sockfd);
}
}
No preview for this file type