Beispiel #1
0
void ChangeParam(tParam *p, tComplex *c){
	int flag = 1;
	printf("Welchen Parameter moechtest du aendern?\n");
	printf("(1) - Radius\n(2) - Maximale Iterationszahl\n(3) - Fraktaltyp\n(4) - Analysegebiet\n");
	printf("(5) - Linien im Analysegebiet\n(6) - c\n(0) - Ich bin fertig!\n");
	int choice;
	InputInt(&choice);
	while(flag){
	switch (choice){
	case 1:
		printf("Der alte Radius beträgt %lf. Bitte gib einen neuen an.\n", p->radius);
		InputDouble(&p->radius);
		break;
	case 2:
		printf("Der alte imax-Wert beträgt %d. Bitte gib einen neuean an.\n", p->imax);
		InputInt(&p->imax);
		break;
	case 3:
		printf("Der alte Fraktaltyp ist %d. Bitte gib einen neuen ein.\n", p->ftype);
		printf("Tipp: 0 - Apfel, 1- Julia\n");
		if (InputChar() == '0') p->ftype=apfel; else if (InputChar() == '1') p->ftype=julia; else ;
		break;
	case 4:
		printf("Das alte Analysegebiet: %lf<=x<=%lf; %lf<=y<=%lf. Bitte gib ein neues ein.\n", p->xmin, p->xmax, p->ymin, p->ymax);
		printf("x geht von ");
		InputDouble(&p->xmin);
		printf("%lf bis ", p->xmin);
		InputDouble(&p->xmax);
		printf("%lf\ny geht von ", p->xmax);
		InputDouble(&p->ymin);
		printf("%lf bis ", p->ymin);
		InputDouble(&p->ymax);
		printf("%lf.\n", p->ymax);
		break;
	case 5:
		printf("Die alte Linienzahlen sind: x=%d y=%d. Bitte gib neue Werte ein.\n Linien in x-Richtung: ", p->xpoints, p->ypoints);
		InputInt(&p->xpoints);
		printf("%d und in y-Richtung: ", p->xpoints);
		InputInt(&p->ypoints);
		printf("%d.\n", p->ypoints);
		break;
	case 6:
		printf("Der alte Wert für c beträgt: %lf+j(%lf). Bitte gib eien neuen ein.\n", c->x, c->y);
		printf("Realteil ");
		InputDouble(&c->x);
		printf("%lf und Imaginärteil ", c->x);
		InputDouble(&c->y);
		printf("%lf\n", c->y);
		break;
	case 0:
		flag = 0;
		break;
	}
	}
}
Beispiel #2
0
bool WrapperDLL::Tool_InputInt(void* self,const char16_t* label,int* v){
	auto self_ = (Tool*)self;
	auto arg0 = label;
	auto arg1 = v;
	auto ret = self_->InputInt(arg0,arg1);
	return ret;
};
Beispiel #3
0
int main(void)
{
	SRH_IN srh_in ;
	SRH_OUT srh_out ;

	int i, len, wlen, rlen ;
	struct sockaddr_in serv_addr;
	int ret, ret_size = 0 ;

	time_t t ;
	int c_size = 0 ;
	int temp ;
	char *cookies = NULL;

	memset(&srh_in, 0, sizeof(SRH_IN)) ;
	memset(&srh_out, 0, sizeof(SRH_OUT)) ;

	c_size = strlen(COOKIES);
	cookies = (char *)malloc(c_size);

	memset(cookies, 0x00, c_size);

	memcpy(cookies, COOKIES, c_size);

	printf("====[SRH_IN]====\n") ;
	InputInt("srh_in.engVersion", &(srh_in.engVersion), 20060101) ;
	srh_in.engVersion = htonl(srh_in.engVersion) ;
	srh_in.mapVersion = htonl(1) ;
	srh_in.serviceId = htonl(1000) ;
	InputInt("srh_in.resourceVersion", &(srh_in.resourceVersion), 20041029) ;
	srh_in.resourceVersion = htonl(srh_in.resourceVersion) ;
	InputInt("srh_in.mdn", &(srh_in.mdn), 1199981076) ;
	srh_in.mdn = htonl(srh_in.mdn) ;

	memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
	serv_addr.sin_family = AF_INET ;
	serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
	serv_addr.sin_port = htons(SM_SERVER_PORT) ;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("clientsoc: can't open stream socket") ;
		close(sockfd), exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printf("clientsoc: can't connect to server") ;
		close(sockfd), exit(0);
	}

	if((wlen = write(sockfd, &srh_in, sizeof(SRH_IN))) <= 0) {
		printf("ERR: write SRH_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: SRH_IN[wlen:%d]\n", wlen) ;
	printf("[%d] / COOKIE(%s)\n", c_size, cookies);
	c_size = htonl(c_size);
	if((wlen = write(sockfd, &c_size, sizeof(int))) <= 0) {
		printf("ERR: write c_size[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	c_size = ntohl(c_size);
	if((wlen = write(sockfd, cookies, c_size)) <= 0) {
		printf("ERR: write cookies[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: COOKIES(%d)\n", c_size+sizeof(int));

	if ((rlen = read(sockfd, &srh_out, sizeof(SRH_OUT))) <= 0) {
		printf("ERR: read SRH_OUT[rlen:%d]...\n", rlen) ;
		close(sockfd), exit(1) ;
	}
	printf("READ: SRH_OUT[rlen:%d]\n", rlen) ;

	srh_out.engVersion = ntohl(srh_out.engVersion) ;
	srh_out.mapVersion = ntohl(srh_out.mapVersion) ;
	srh_out.serviceId = ntohl(srh_out.serviceId) ;
	srh_out.resourceVersion = ntohl(srh_out.resourceVersion) ;
	srh_out.totalCount = ntohl(srh_out.totalCount) ;
	srh_out.count = ntohl(srh_out.count) ;
	srh_out.errorCode = ntohl(srh_out.errorCode) ;
	srh_out.compFlag = ntohl(srh_out.compFlag) ;
	srh_out.uncompSize = ntohl(srh_out.uncompSize) ;
	srh_out.compSize = ntohl(srh_out.compSize) ;

	printf("SRH_OUT-engVer[%d] mapVer[%d] SerId[%d] ResVer[%d] Total[%d] Cnt[%d] Err[%d] CompFlag[%d] UNCOM[%d] COM[%d]\n",
		srh_out.engVersion, srh_out.mapVersion, srh_out.serviceId, srh_out.resourceVersion, srh_out.totalCount,
		srh_out.count, srh_out.errorCode, srh_out.compFlag, srh_out.uncompSize, srh_out.compSize) ;

	if(srh_out.errorCode == 0) {
		printf("===OK!!! (DONE)===\n");
	}

	exit_handler() ;
}
Beispiel #4
0
///[주유소 리스트 정보 추출]/////: 1060
int main(void)
{
    int len, wlen, rlen ;
    struct sockaddr_in serv_addr;

    OPW_HEADER hd ;
    OPW_RESULT rd ;

    char search_opt[D_SEARCH_OPT_SIZE+1] = {'\0'} ;

    int i ;

    OPW_LIST_REQ in ;
    OPW_LIST_INFO *out = NULL ;

    int search_num = 0 ;
    int start_pos = 0 ;
    int pole = 0 ;
    int sort_opt = 0 ;

    memset(&hd, 0, sizeof(OPW_HEADER)) ;
    memset(&rd, 0, sizeof(OPW_RESULT)) ;
    memset(&in, 0, sizeof(OPW_LIST_REQ)) ;

    printf("====[OPW_HEADER]====\n") ;
    hd.serviceid = htonl(OPW_LIST) ;
    InputInt("hd.mdn", &(hd.mdn), 1031993325) ;
    hd.mdn = htonl(hd.mdn) ;
    InputChar("hd.menu_id", &(hd.menu_id), 'O') ;
    printf("oiltype: G-휘발유 K-경유 L-LPG A-ALL\n") ;
    InputChar("hd.oil_type", &(hd.oil_type), 'A') ;
    printf("search_opt: AL-좌표로 검색 IL-주소로 검색\n") ;
    InputString("hd.search_opt", search_opt, D_SEARCH_OPT_SIZE+1, "AL") ;
    memcpy(hd.search_opt, search_opt, D_SEARCH_OPT_SIZE) ;

    printf("====[OPW_LIST_REQ]====\n") ;
    memset(&in, 0, sizeof(OPW_LIST_REQ)) ;
    InputInt("in.search_num", &(search_num), 10) ;
    InputInt("in.start_pos", &(start_pos), 0) ;

    printf("pole: 3072-LPG 16-SK 32-GS 64-H-OIL 128-S-OIL 512-기타 144-(SK or S-OIL) 0-ALL\n") ;
    InputInt("in.pole", &(pole), 0) ;
    printf("pole: 1-휘발유 가격순 2-경유 가격순 4-LPG 가격순 5-거리순 6-휘발유/경유/LPG 순서\n") ;
    InputInt("in.sort_opt", &(sort_opt), 6) ;

    if(!strcmp(search_opt, "AL")) {			//좌표로 검색
        InputInt("in.x", &(in.x), 320821) ;
        InputInt("in.y", &(in.y), 551729) ;
        InputInt("in.radius", &(in.radius), 5000) ;
    }
    else if(!strcmp(search_opt, "IL")) {	//주소로 검색
        InputString("cido", in.sido, D_SIDO_SIZE, "인천광역시") ;
        InputString("gugun", in.gugun, D_GUGUN_SIZE, "") ;
        InputString("dong", in.dong, D_DONG_SIZE, "") ;
    }
    else {	//잘못된 선택
        return 0 ;
    }
//	sprintf(in.sido, "인천광역시") ;
//	sprintf(in.gugun, "계양구") ;

    in.search_num = htonl(search_num) ;
    in.start_pos = htonl(start_pos) ;
    in.x = htonl(in.x) ;
    in.y = htonl(in.y) ;
    in.radius = htonl(in.radius) ;
    in.nr_num = htonl(in.nr_num) ;

    in.pole = pole ;
    in.sort_opt = sort_opt ;

    in.pole = htons(in.pole) ;
    in.sort_opt = htons(in.sort_opt) ;

    memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
    serv_addr.sin_family = AF_INET ;
    serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
    serv_addr.sin_port = htons(SM_SERVER_PORT) ;

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        printf("clientsoc: can't open stream socket") ;
        close(sockfd), exit(0);
    }

    if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
        printf("clientsoc: can't connect to server") ;
        close(sockfd), exit(0);
    }

    if((wlen = write(sockfd, &hd, sizeof(OPW_HEADER))) <= 0) {
        printf("ERR: write OPW_HEADER[wlen:%d]\n", wlen) ;
        close(sockfd), exit(1) ;
    }
    printf("SEND: OPW_HEADER[wlen:%d]\n", wlen) ;

    if((wlen = write(sockfd, &in, sizeof(OPW_LIST_REQ))) < 0) {
        printf("ERR: write OPW_LIST_REQ\n") ;
        close(sockfd), exit(1) ;
    }
    printf("SEND: OPW_LIST_REQ[wlen:%d]\n", wlen) ;

    if ((rlen = read(sockfd, &rd, sizeof(OPW_RESULT))) <= 0) {
        printf("ERR: read OPW_RESULT[rlen:%d]...\n", rlen) ;
        close(sockfd), exit(1) ;
    }
    printf("READ: OPW_RESULT[rlen:%d]\n", rlen) ;
    rd.res_code = ntohl(rd.res_code) ;
    rd.total_num = ntohl(rd.total_num) ;
    rd.search_num = ntohl(rd.search_num) ;
    printf("OPW_RESULT: res_code[%d] total_num[%d] search_num[%d]\n", rd.res_code, rd.total_num, rd.search_num) ;

    if(rd.res_code == M_TRUE) {
        out = (OPW_LIST_INFO *) malloc (rd.search_num * sizeof(OPW_LIST_INFO)) ;
        memset(out, 0, rd.search_num * sizeof(OPW_LIST_INFO)) ;

        for(i = 0 ; i < rd.search_num; i++) {
            if((rlen = read(sockfd, &(out[i]), sizeof(OPW_LIST_INFO))) <= 0) {
                printf("ERR: [%d] read OPW_LIST_INFO(%d)\n", i, rlen) ;
                if(out != NULL) free(out), out = NULL ;
                close(sockfd), exit(1) ;
            }
            //	printf("READ: OPW_LIST_INFO(%d) Len:[%d]\n", i, rlen) ;
        }
        for(i = 0 ; i < rd.search_num; i ++) {
            out[i].id = ntohl(out[i].id) ;
            out[i].pole = ntohl(out[i].pole) ;
            out[i].g_price = ntohs(out[i].g_price) ;
            out[i].k_price = ntohs(out[i].k_price) ;
            out[i].d_price = ntohs(out[i].d_price) ;
            out[i].l_price = ntohs(out[i].l_price) ;
            out[i].update_date = ntohl(out[i].update_date) ;
            out[i].update_time = ntohl(out[i].update_time) ;
            out[i].x = ntohl(out[i].x) ;
            out[i].y = ntohl(out[i].y) ;
            out[i].distance = ntohl(out[i].distance) ;


            printf("[%d]-ID[%d]NAME[%.52s] POLE[%d]G[%d]K[%d]D[%d]L[%d]DATE[%d]TIME[%d]X[%d]Y[%d]DISTANCE[%d]\n",
                   i, out[i].id, out[i].name, out[i].pole,
                   out[i].g_price, out[i].k_price, out[i].d_price, out[i].l_price,
                   out[i].update_date, out[i].update_time,
                   out[i].x, out[i].y, out[i].distance) ;
        }
        if(out != NULL) free(out) ;
    }

    exit_handler() ;
}
Beispiel #5
0
///[TEXT Á¤º¸ ¾ò±â]/////
int main(void)
{
	SRH_IN srh_in ;
	SRH_OUT srh_out ;

	INFO_OUT info_out ;
	TOTAL_INFO total_info;
	TXT_INFO	txt_info;

	int i, len, wlen, rlen ;
	struct sockaddr_in serv_addr;
	int ret, ret_size = 0 ;

	char *info = NULL ;
	char *data = NULL ;
	char *content = NULL;
	int gpres_ver = 0;

	time_t t ;
	char contents[512+1] = {'\0'};
	char data_fname[256] = {'\0'};
	FILE *fp;

	memset(&srh_in, 0, sizeof(SRH_IN)) ;
	memset(&srh_out, 0, sizeof(SRH_OUT)) ;
	memset(&info_out, 0, sizeof(INFO_OUT)) ;
	memset(&total_info, 0x00, sizeof(total_info));
	memset(&txt_info, 0x00, sizeof(txt_info));

	printf("====[SRH_IN]====\n") ;
	InputInt("srh_in.engVersion", &(srh_in.engVersion), 20060101) ;
	srh_in.engVersion = htonl(srh_in.engVersion) ;
	srh_in.mapVersion = htonl(1) ;
	srh_in.serviceId = htonl(1050) ;
	InputInt("srh_in.resourceVersion", &(srh_in.resourceVersion), 9032100) ;
	srh_in.resourceVersion = htonl(srh_in.resourceVersion) ;
	InputInt("srh_in.mdn", &(srh_in.mdn), 1199981076) ;
	srh_in.mdn = htonl(srh_in.mdn);
	InputInt("GPRES.version", &(gpres_ver), 1) ;
	gpres_ver = htonl(gpres_ver);

	printf("----FILE NAME---\n");
	InputString("oildatafile_name", data_fname, 256, "GP.DAT");

	memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
	serv_addr.sin_family = AF_INET ;
	serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
	serv_addr.sin_port = htons(SM_SERVER_PORT) ;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("clientsoc: can't open stream socket") ;
		close(sockfd), exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printf("clientsoc: can't connect to server") ;
		close(sockfd), exit(0);
	}

	if((wlen = write(sockfd, &srh_in, sizeof(SRH_IN))) <= 0) {
		printf("ERR: write SRH_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: SRH_IN[wlen:%d]\n", wlen) ;
	if((wlen = write(sockfd, &gpres_ver, sizeof(int))) <= 0) {
		printf("ERR: write SRH_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: GPRES_VERSION(%d)[wlen:%d]\n", ntohl(gpres_ver), wlen) ;

	if ((rlen = read(sockfd, &srh_out, sizeof(SRH_OUT))) <= 0) {
		printf("ERR: read SRH_OUT[rlen:%d]...\n", rlen) ;
		close(sockfd), exit(1) ;
	}
	printf("READ: SRH_OUT[rlen:%d]\n", rlen) ;

	srh_out.engVersion = ntohl(srh_out.engVersion) ;
	srh_out.mapVersion = ntohl(srh_out.mapVersion) ;
	srh_out.serviceId = ntohl(srh_out.serviceId) ;
	srh_out.resourceVersion = ntohl(srh_out.resourceVersion) ;
	srh_out.totalCount = ntohl(srh_out.totalCount) ;
	srh_out.count = ntohl(srh_out.count) ;
	srh_out.errorCode = ntohl(srh_out.errorCode) ;
	srh_out.compFlag = ntohl(srh_out.compFlag) ;
	srh_out.uncompSize = ntohl(srh_out.uncompSize) ;
	srh_out.compSize = ntohl(srh_out.compSize) ;

	printf("SRH_OUT-engVer[%d] mapVer[%d] SerId[%d] ResVer[%d] Total[%d] Cnt[%d] Err[%d] CompFlag[%d] UNCOM[%d] COM[%d]\n",
		srh_out.engVersion, srh_out.mapVersion, srh_out.serviceId, srh_out.resourceVersion, srh_out.totalCount,
		srh_out.count, srh_out.errorCode, srh_out.compFlag, srh_out.uncompSize, srh_out.compSize) ;

	if(srh_out.errorCode == 0) {
		if(srh_out.compFlag == 0) ret_size = srh_out.uncompSize ;
		else ret_size = srh_out.compSize ;

		if((info = (char *) malloc (srh_out.uncompSize)) == NULL) {
			printf("ERR: Memory Alloc Fail\n") ;
			close(sockfd), exit(1) ;
		}
		memset(info, 0, srh_out.uncompSize) ;

		if ((rlen = readn(sockfd, info, ret_size)) <= 0) {
			printf("ERR: read info[rlen:%d/%d]...\n", rlen, ret_size) ;
			close(sockfd), exit(1) ;
		}
		printf("READ: DATA[rlen:%d]\n", rlen) ;

		if(srh_out.compFlag == 1) {
			if((data = (char *) malloc (srh_out.uncompSize)) == NULL) {
				printf("ERR: Memory Alloc Fail\n") ;
				close(sockfd), exit(1) ;
			}
			memset(data, 0, srh_out.uncompSize) ;
			memcpy(data, info, srh_out.uncompSize) ;
			memset(info, 0, srh_out.uncompSize) ;

			ret = uncompress(info, &(srh_out.uncompSize), data, srh_out.compSize) ;
			printf("uncompress():ret[%d] uncompSize[%d] compSize[%d]\n", ret, srh_out.uncompSize, srh_out.compSize) ;
		}

		fp = fopen(data_fname, "wb");
		fwrite(info, srh_out.uncompSize, 1, fp);
		fclose(fp);

		printf("---[%s] write complete!\n", data_fname);

		if (info != NULL) free(info);
		info = NULL;
		if (data != NULL) free(data);
		data = NULL;
	}

	exit_handler() ;
}
Beispiel #6
0
///[TEXT 정보 얻기]/////
int main(void)
{
	SRH_IN srh_in ;
	SRH_OUT srh_out ;

	INFO_IN info_in ;
	INFO_OUT info_out ;

	int i, len, wlen, rlen ;
	struct sockaddr_in serv_addr;
	int ret, ret_size = 0 ;
	char svc_flag = 0 ;
	char road_flag = 0 ;
	char highway_flag = 0 ;

	char *info = NULL ;
	char *data = NULL ;

	time_t t ;
	char timeStamp[19+1] = {'\0'} ;
	char roadName[40+1] = {'\0'} ;
	short c_size = 0 ;
	char contents[512+1] = {'\0'} ;
	int temp ;

	memset(&srh_in, 0, sizeof(SRH_IN)) ;
	memset(&srh_out, 0, sizeof(SRH_OUT)) ;
	memset(&info_in, 0, sizeof(INFO_IN)) ;
	memset(&info_out, 0, sizeof(INFO_OUT)) ;

	printf("====[SRH_IN]====\n") ;
	srh_in.engVersion = htonl(1) ;
	srh_in.mapVersion = htonl(1) ;
	srh_in.serviceId = htonl(1030) ;
	InputInt("srh_in.resourceVersion", &(srh_in.resourceVersion), 20041029) ;
	srh_in.resourceVersion = htonl(srh_in.resourceVersion) ;
	InputInt("srh_in.mdn", &(srh_in.mdn), 1022880676) ;
	srh_in.mdn = htonl(srh_in.mdn) ;

	printf("====[INFO_IN]====\n") ;
	printf("areaInfo: 0 - 고속도로 속보 정보, 1 - 대도시 유고정보\n") ;
	InputInt("info_in.areaInfo", &(info_in.areaInfo), 0) ;

	memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
	serv_addr.sin_family = AF_INET ;
	serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
	serv_addr.sin_port = htons(SM_SERVER_PORT) ;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("clientsoc: can't open stream socket") ;
		close(sockfd), exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printf("clientsoc: can't connect to server") ;
		close(sockfd), exit(0);
	}

	if((wlen = write(sockfd, &srh_in, sizeof(SRH_IN))) <= 0) {
		printf("ERR: write SRH_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: SRH_IN[wlen:%d]\n", wlen) ;

	info_in.areaInfo = htonl(info_in.areaInfo) ;

	if((wlen = write(sockfd, &info_in, sizeof(INFO_IN))) <= 0) {
		printf("ERR: write INFO_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: INFO_IN[wlen:%d]-areaInfo[%d]\n", wlen, ntohl(info_in.areaInfo)) ;

	if ((rlen = read(sockfd, &srh_out, sizeof(SRH_OUT))) <= 0) {
		printf("ERR: read SRH_OUT[rlen:%d]...\n", rlen) ;
		close(sockfd), exit(1) ;
	}
	printf("READ: SRH_OUT[rlen:%d]\n", rlen) ;

	srh_out.engVersion = ntohl(srh_out.engVersion) ;
	srh_out.mapVersion = ntohl(srh_out.mapVersion) ;
	srh_out.serviceId = ntohl(srh_out.serviceId) ;
	srh_out.resourceVersion = ntohl(srh_out.resourceVersion) ;
	srh_out.totalCount = ntohl(srh_out.totalCount) ;
	srh_out.count = ntohl(srh_out.count) ;
	srh_out.errorCode = ntohl(srh_out.errorCode) ;
	srh_out.compFlag = ntohl(srh_out.compFlag) ;
	srh_out.uncompSize = ntohl(srh_out.uncompSize) ;
	srh_out.compSize = ntohl(srh_out.compSize) ;

	printf("SRH_OUT-engVer[%d] mapVer[%d] SerId[%d] ResVer[%d] Total[%d] Cnt[%d] Err[%d] CompFlag[%d] UNCOM[%d] COM[%d]\n",
		srh_out.engVersion, srh_out.mapVersion, srh_out.serviceId, srh_out.resourceVersion, srh_out.totalCount,
		srh_out.count, srh_out.errorCode, srh_out.compFlag, srh_out.uncompSize, srh_out.compSize) ;

	if((srh_out.errorCode == 0) && (srh_out.count > 0)) {
		if(srh_out.compFlag == 0) ret_size = srh_out.uncompSize ;
		else ret_size = srh_out.compSize ;

		if((info = (char *) malloc (srh_out.uncompSize)) == NULL) {
			printf("ERR: Memory Alloc Fail\n") ;
			close(sockfd), exit(1) ;
		}
		memset(info, 0, srh_out.uncompSize) ;

		if ((rlen = read(sockfd, info, ret_size)) <= 0) {
			printf("ERR: read info[rlen:%d]...\n", rlen) ;
			close(sockfd), exit(1) ;
		}
		printf("READ: DATA[rlen:%d]\n", rlen) ;

		if(srh_out.compFlag == 1) {
			if((data = (char *) malloc (srh_out.uncompSize)) == NULL) {
				printf("ERR: Memory Alloc Fail\n") ;
				close(sockfd), exit(1) ;
			}
			memset(data, 0, srh_out.uncompSize) ;
			memcpy(data, info, srh_out.uncompSize) ;
			memset(info, 0, srh_out.uncompSize) ;

			ret = uncompress(info, &(srh_out.uncompSize), data, srh_out.compSize) ;
			printf("uncompress():ret[%d] uncompSize[%d] compSize[%d]\n", ret, srh_out.uncompSize, srh_out.compSize) ;
		}
		//INFO 출력
		len = 0 ;
		memcpy(&temp, &(info[len]), 4) ;		//시간
		t = ntohl(temp) ;	
		time2TimeStr(t, timeStamp) ;
		len += 4 ;

		memcpy(&temp, &(info[len]), 4) ;		//SIZE
		ret_size = ntohl(temp) ;
		len += 4 ;

		printf("INFO: time[%.19s] size[%d]\n", timeStamp, ret_size) ;

		
		for(i = 0 ; i < srh_out.count ; i++) {
			memcpy(roadName, &(info[len]), 40) ;
			len += 40 ;
			memcpy(&c_size, &(info[len]), 2) ;
			len += 2 ;
			memcpy(contents, &(info[len]), c_size) ;
			len += c_size ;

			printf("roadName[%.40s] c_size[%d] contents[%.512s]\n", roadName, c_size, contents) ;
			memset(roadName, 0, sizeof(roadName)) ;
			memset(contents, 0, sizeof(contents)) ;
		}

		if(info != NULL) free(info) ; 
		info=NULL ;
		if(data != NULL) free(data) ; 
		data=NULL ;
	}

	exit_handler() ;
}
Beispiel #7
0
int main(void)
{
	REQUEST_HD hd;
	RESPONSE_HD rd;
	REQUEST_CCTV hdc;

	int i, rlen, wlen, len;
	struct sockaddr_in serv_addr;
	int ret, ret_size = 0;

	char *info = NULL;
	char *data = NULL;

	char filename[256];

	FILE *fp;

	char *fdata = NULL;
	short fnum = 0;
	short fclass = 0;
	int fsize = 0;
	long uncompsize = 0;
	char data_time[12+1];
	char f_h;


	memset(&hd, 0x00, sizeof(hd));
	memset(&hdc, 0x00, sizeof(hdc));
	memset(&rd, 0x00, sizeof(rd));

	hd.version = htonl(100);
	hd.serviceid = htonl(1000);
	printf("--------IN------\n");
	InputChar("D or E", &hdc.sourceFlag, 'D');
	InputInt("Camera(CCTV) ID", &hdc.cameraID, 99);
	hdc.cameraID = htonl(hdc.cameraID);
	InputShort("¸îÀå?", &hdc.photoNum, 5);
	hdc.photoNum = htons(hdc.photoNum);

	memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
	serv_addr.sin_family = AF_INET ;
	serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
	serv_addr.sin_port = htons(SM_SERVER_PORT) ;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("clientsoc: can't open stream socket") ;
		close(sockfd), exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printf("clientsoc: can't connect to server") ;
		close(sockfd), exit(0);
	}

	if ((wlen = write(sockfd, &hd, sizeof(hd))) <= 0) {
		printf("ERR: IN(wlen:%d)\n", wlen);
		close(sockfd), exit(1);
	}
	printf("SEND: IN[wlen:%d]\n", wlen);
	if ((wlen = write(sockfd, &hdc, sizeof(hdc))) <= 0) {
		printf("ERR: IN(wlen:%d)\n", wlen);
		close(sockfd), exit(1);
	}
	printf("SEND: IN[wlen:%d]\n", wlen);

	if ((rlen = read(sockfd, &rd, sizeof(rd))) <= 0) {
		printf("ERR: OUT(rlen:%d)\n", rlen);
		close(sockfd), exit(1);
	}
	printf("RECEIVE: OUT[rlen:%d]\n", rlen);

	rd.error_code = ntohl(rd.error_code);
	rd.version = ntohl(rd.version);
	rd.serviceid = ntohl(rd.serviceid);
	rd.file_num = ntohl(rd.file_num);
	rd.comp_flag = ntohl(rd.comp_flag);
	rd.uncomp_size = ntohl(rd.uncomp_size);
	rd.comp_size = ntohl(rd.comp_size);

	printf("ECODE[%d] VER[%d] SID[%d] FNUM[%d] CFLAG[%d] UNC_SIZE[%d] C_SIZE[%d]\n", rd.error_code, rd.version, rd.serviceid, rd.file_num, rd.comp_flag, rd.uncomp_size, rd.comp_size);

	if (rd.error_code == 0) {
		if (rd.comp_flag == 0) ret_size = rd.uncomp_size;
		else ret_size = rd.comp_size;

		if ((info = (char *)malloc(rd.uncomp_size)) == NULL) {
			printf("ERR: Memory Alloc Fail\n");
			close(sockfd), exit(1);
		}
		memset(info, 0, rd.uncomp_size);

		if ((rlen = readn(sockfd, info, ret_size)) <= 0) {
			printf("ERR: read info[rlen:%d/%d]\n", rlen, ret_size);
			close(sockfd), exit(1);
		}
		printf("READ: DATA[rlen:%d]\n", rlen);

		if (rd.comp_flag == 1) {
			if ((data = (char *) malloc(rd.uncomp_size)) == NULL) {
				printf("........Fail\n");
				close(sockfd), exit(1);
			}
			memset(data, 0, rd.uncomp_size);
			memcpy(data, info, rd.uncomp_size);
			memset(info, 0, rd.uncomp_size);
			
			uncompsize = rd.uncomp_size;
			ret = uncompress(info, &(uncompsize), data, rd.comp_size);

			rd.uncomp_size = uncompsize;

			printf("uncompress() ret[%d], un[%d], c[%d]\n", ret, rd.uncomp_size, rd.comp_size);
		}

		memset(data_time, 0x00, sizeof(data_time));
		len = 0;
		memcpy(&fnum, info+len, sizeof(short));
		len += sizeof(short);
		memcpy(&fclass, info+len, sizeof(short));
		len += sizeof(short);
		memcpy(data_time, info+len, 12);
		len += 12;

		fnum = ntohs(fnum);
		fclass = ntohs(fclass);

		printf("---- FILE_COUNT(%d) FCLASS(%d) TIME(%s)\n", fnum, fclass, data_time);

		for (i = 0; i < fnum; i++) {
			memcpy(&f_h, info+len, sizeof(char));
			len += sizeof(char);
			if (f_h != 'T') {
				printf("-------------ERROR!!!(%c)\n", f_h);
				exit(-1);
			}
			memcpy(&f_h, info+len, sizeof(char));
			len += sizeof(char);
			if (f_h != 'W') {
				printf("-------------ERROR!!!(%c)\n", f_h);
				exit(-1);
			}
			
			memset(filename, 0x00, sizeof(filename));
			memcpy(&fsize, info+len, sizeof(int));
			len += sizeof(int);
			fsize = ntohl(fsize);

			fdata = (char *)malloc(fsize);
			memset(fdata, 0x00, fsize);
			memcpy(fdata, info+len, fsize);
			len += fsize;

			sprintf(filename, "cctv%d.jpg", i+1);
			fp = fopen(filename, "wb");
			fwrite(fdata, fsize, 1, fp);
			fclose(fp);
			printf("Write Complete! ---- [%s](%d) (len:%d)\n", filename, fsize, len);
			free(fdata);
		}

		if (info != NULL) free(info);
		info = NULL;
		if (data != NULL) free(data);
		data = NULL;
	}
	exit_handler();
}
Beispiel #8
0
int main(void)
{
	I_REQUEST_H hd ;
	I_RESULT_H rd ;

	I_LOGIN_IN in ;
	I_LOGIN_OUT out ;

	char productid[PRODUCTID_LEN+1] = {'\0'} ;
	char notice[NOTICE_LEN+1] = {'\0'} ;

	memset(&hd, 0, sizeof(I_REQUEST_H)) ;
	memset(&rd, 0, sizeof(I_RESULT_H)) ;
	memset(&in, 0, sizeof(I_LOGIN_IN)) ;
	memset(&out, 0, sizeof(I_LOGIN_OUT)) ;

	hd.serviceid = htonl(MSG_LOGIN) ;
	InputInt("hd.mdn", &(hd.mdn), 1031993325) ;
	hd.mdn = htonl(hd.mdn) ;
	
	InputString("PRODUCTID", productid, PRODUCTID_LEN+1, "ABCD") ;
	memcpy(in.productid, productid, PRODUCTID_LEN) ;

	int wlen, rlen ;
	struct sockaddr_in serv_addr;

	memset((char *) &serv_addr, 0, sizeof(serv_addr)) ;
	serv_addr.sin_family = AF_INET ;
	serv_addr.sin_addr.s_addr = inet_addr(SM_SERVER_IP) ;
	serv_addr.sin_port = htons(SM_SERVER_PORT) ;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		printf("clientsoc: can't open stream socket") ;
		close(sockfd), exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
		printf("clientsoc: can't connect to server") ;
		close(sockfd), exit(0);
	}

	///[SEND]////////////////
	if((wlen = write(sockfd, &hd, sizeof(I_REQUEST_H))) <= 0) {
		printf("ERR: write I_REQUEST_H[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: I_REQUEST_H[wlen:%d]\n", wlen) ;

	if((wlen = write(sockfd, &in, sizeof(I_LOGIN_IN))) <= 0) {
		printf("ERR: write I_LOGIN_IN[wlen:%d]\n", wlen) ;
		close(sockfd), exit(1) ;
	}
	printf("SEND: I_LOGIN_IN[wlen:%d]\n", wlen) ;

	///[READ]////////////////
	if ((rlen = read(sockfd, &rd, sizeof(I_RESULT_H))) <= 0) {
		printf("ERR: read DATA_SD[rlen:%d]...\n", rlen) ;
		close(sockfd), exit(1) ;
	}
	printf("READ: I_RESULT_H[rlen:%d]\n", rlen) ;
	rd.error = ntohl(rd.error) ;
	rd.count = ntohl(rd.count) ;
	rd.total = ntohl(rd.total) ;
	printf("I_RESULT_H: error[%d] count[%d] total[%d]\n", rd.error, rd.count, rd.total) ;

	if ((rlen = read(sockfd, &out, sizeof(I_LOGIN_OUT))) <= 0) {
		printf("ERR: read DATA_SD[rlen:%d]...\n", rlen) ;
		close(sockfd), exit(1) ;
	}
	printf("READ: I_LOGIN_OUT[rlen:%d]\n", rlen) ;
	out.road = ntohl(out.road) ;
	out.highway= ntohl(out.highway) ;
	out.req_date = ntohl(out.req_date) ;
	out.req_time = ntohl(out.req_time) ;
	out.size = ntohl(out.size) ;
	printf("road[%d]highway[%d]-req_date[%d]time[%d]-regnum[%.13s]carrier[%c]sms[%c]service[%d]size[%d]\n",
			out.road, out.highway, out.req_date, out.req_time, out.regnum, out.carrier, out.sms, out.service, out.size) ;

	if(out.size > 0) {
		if ((rlen = read(sockfd, notice, out.size)) <= 0) {
			printf("ERR: read DATA_SD[rlen:%d]...\n", rlen) ;
			close(sockfd), exit(1) ;
		}
		printf("notice[%s]\n", notice) ;
	}

	exit_handler() ;
}