/*----------------------------------------------------------------------*/ int get_url(char *url, FILE *outfile){ char *server; int port; char *path; int rc, s; rc = parse_url(url, &server, &port, &path); if(rc<0){ ERROR1("Problem with parsing url %s", url); } #ifdef DEBUG printf("http connection to %s:%d, path: %s\n", server, port, path); #endif s = call_socket(server, port); if(s==-1){ /* error msgs in call_socket */ return -1; } /* we can free memory for server string */ free(server); return get_http(s, path, outfile); }
/* * cmd_connect */ BOOL cmd_connect(BOOL kill_it) { /* Are we trying to stop the server? */ if (kill_it) { /* Make sure the socket was valid */ if (GameSocket != -1) { /* Remove the callback */ fl_remove_io_callback(GameSocket, MyCond, handleServInp); /* Close the socket */ close(GameSocket); GameSocket=-1; fe_puts("*** Connection to server closed\n"); AtMainPrompt=FALSE; } return(TRUE); } fl_addto_browser_chars(fd_ImpFeMain->MainBrowser, "*** Attempting to connect to "); fl_addto_browser_chars(fd_ImpFeMain->MainBrowser, game_host); fl_addto_browser_chars(fd_ImpFeMain->MainBrowser, ", port "); fl_addto_browser_chars(fd_ImpFeMain->MainBrowser, game_port); fl_addto_browser_chars(fd_ImpFeMain->MainBrowser, "\n"); if ((GameSocket=call_socket(game_host, atoi(game_port))) == -1) { fe_puts("**** Connection failed\n"); AtMainPrompt=FALSE; return(FALSE); } /* Add in the callback for the socket */ fl_add_io_callback(GameSocket, MyCond, handleServInp, NULL); DoingLogin=TRUE; return(TRUE); }
char clamdscan (char *file, char *virname) { char buf[BUFM]; char t1[BUFM]; char t3[BUFM]; int s=0; char in[BUFM]; int rlen=0; char *ptr; /* just to be sure there are only zeros in there...*/ memset(in,0,BUFM); snprintf(buf,SBUFM, "SCAN %.255s\n", file); if (cfg.cip[0] == '/') { /* guess at unix socket instead of tcp socket */ s=call_unix_socket(cfg.cip); } else { s=call_socket(cfg.cip,cfg.cp); } if (s < 0) { syslog(LOG_ERR, "Failed to connect to clamd server"); fprintf(stderr,"Failed to connect to clamd server\n"); return 4; } if (sendclam(s, buf,strlen(buf)) < 0 ) { syslog(LOG_ERR, "Failed to hand file over to clamd server"); fprintf(stderr,"Failed to hand file over to clamd\n"); return 4; close(s); } rlen = read_data(s, SECTIME, in, BUFM); close(s); in[rlen] = '\0'; if ((ptr = strchr(in,'\n')) != NULL) { *ptr = '\0'; } if (strcmp(&in[rlen-6],"FOUND") == 0) { memset(virname,0,BUFM); sscanf(in,"%255s %255s %255s\n", t1, virname, t3); if (cfg.debug > 0) { fprintf(stderr, "%s (%i)", virname, rlen); } return 1; } return 0; }
/* int main (void) { fd = open("/dev/lcd", O_RDWR); if (fd < 0){ printf("open /dev/lcd error\n"); return (-1); } LCD_fClearScreen(fd); LCD_fprintf(fd, "running...\n"); ProcessImageFromEthernetToPC(fd, FALSE); globle_flag return (0); } */ int ProcessImageFromEthernetToPC (int* fd_lcd) { cmos_info_t CMOSInfo; // 用來接收server端送過來的command int ret =OK, fd_cmos=-1, fd_socket=-1, WaitImage; int nRead, nWrite, terminate, CMOSRunning, ImgW, ImgH; unsigned long dwImageSize, dwTotalReadSize, count ; unsigned short key; unsigned char *pImageBuffer=NULL, *pMsg, *pRGBBuffer=NULL; //printf("ass hole1\n"); fd_socket = call_socket(PORTNUM); /* if (fd_socket == -1){ LCD_ErrorMessage(fd_lcd, "Socket error\nAny to exit:"); goto out; } */ //printf("ass hole2\n"); // cmos就是camera啦 fd_cmos = open("/dev/cmos", O_RDWR); /* if (fd_cmos < 0) { LCD_ErrorMessage(fd_lcd, "Open ccm error\nAny to exit:"); return (UM); } */ pImageBuffer = malloc(320*240); pRGBBuffer = malloc(320*240*3); /* if (pImageBuffer == NULL || pRGBBuffer == NULL){ LCD_ErrorMessage(fd_lcd, "mem alloc error\nAny to exit:"); goto out; } */ terminate = 1; CMOSRunning = 0; pMsg = "\nImage to PC..."; printf("%s", pMsg); // if (!ImageToLCD) // LCD_printf("%s", pMsg); while (terminate) { if(globle_flag == 1) goto out; /* 等待PC 傳送command */ nRead = recv(fd_socket, &CMOSInfo, sizeof(cmos_info_t), 0); // if (nRead == 0){ // LCD_ErrorMessage(fd_lcd, "socket break\n\n Any to exit:"); // terminate = 0; // } //CMOS_INFO cmosinfo; /*CMOSInfo.command=PC_CMOS_ON; CMOSInfo.ImageSizeMode=CMOS_SIZE_MODE_160_120; CMOSInfo.ImageWidth=160; CMOSInfo.ImageHeight=120; CMOSInfo.HighRef=120; CMOSInfo.Status=0;*/ if (CMOSInfo.command == PC_CMOS_ON) { ret = ioctl(fd_cmos, CMOS_ON, &CMOSInfo); // if (ret < 0){ // LCD_ErrorMessage(fd_lcd, "CCM ON error\n\n Any to exit:"); // goto out; // } ImgW = CMOSInfo.ImageWidth ; ImgH = CMOSInfo.ImageHeight ; dwImageSize = ImgW * ImgH ; continue ; } else if (CMOSInfo.command == PC_CMOS_OFF) { ioctl(fd_cmos, CMOS_OFF, &CMOSInfo); goto out; } ioctl(fd_cmos, CMOS_PARAMETER, &CMOSInfo); WaitImage = 1; while(WaitImage) { if (ioctl(fd_cmos, CMOS_GET_STATUS, &CMOSInfo) >= 0) { if (CMOSInfo.Status == CMOS_IMG_READY) { /* 讀取影像 */ dwTotalReadSize = 0; count = dwImageSize; do { if (count + dwTotalReadSize > dwImageSize) count = dwImageSize - dwTotalReadSize ; nRead = read(fd_cmos, pImageBuffer+dwTotalReadSize, count); if (nRead > 0 ) { dwTotalReadSize += nRead; } else if (nRead == 0) { break; } else { //break; } } while (dwTotalReadSize < dwImageSize); /* 傳送Image raw data to PC */ nWrite = write(fd_socket, pImageBuffer, dwImageSize); /* if (ImageToLCD){ ColorInterpolate(pRGBBuffer, pImageBuffer, ImgW, ImgH); DrawRawDataToLCD(fd_lcd, fd_cmos, pRGBBuffer, &CMOSInfo, ImgW, ImgH); } */ WaitImage = 0; } } // if (KEYPAD_get_key(fd_lcd, &key) == OK){ // goto out; // } else if (CMOSInfo.Status == CMOS_IMG_EMPTY) { /* 等待影像資料*/ //Delay(200); } } } out: nWrite = write(fd_socket, "abc", 3); if (pImageBuffer) free(pImageBuffer); if (pRGBBuffer) free(pRGBBuffer); if (fd_cmos < 0) { ioctl(fd_cmos, CMOS_OFF, &CMOSInfo); close(fd_cmos); } if (fd_socket != -1) { close(fd_socket); printf("socket close\n"); } return (OK); }
int main() { /*---------- Initialized Server Variables ----------*/ char* the_host_name = malloc(MAX_HOST_NAME*sizeof(char)); the_host_name = get_host_name(); unsigned short port_number = get_port_num(); int socket; /*===== End of Initialized Server Vairables ======*/ /*---------- Initial User Input Variables ----------*/ size_t n; size_t max = 40; char *buff; /*===== End of Initial User Input Variables ======*/ int t; /*---------- Program Loop ----------*/ printf("Enter a nickname: "); while (fgets(buff,max,stdin)) { //Gets the length of the buffer n = strlen(buff); //Gets a connection if ((socket = call_socket(the_host_name, port_number)) < 0) { perror("call_socket"); exit(0); } //Checks if the user inputs a blank string if ( n==1 && buff[n-1] == '\n') { //sends an exit command if( write_data(socket, "\0", MAX_BUFFER_SIZE) < 0) { prompt_error("Write Data Failed"); close(socket); exit(0); } //exits break; } else { //If the user doesnt enter a blank string -> Server request routine if (write_data(socket, buff, MAX_BUFFER_SIZE) < 0) { prompt_error("Write Data Failed"); close(socket); exit(0); } else { printf("Write data success!!\n"); } if (read_data(socket, buff, MAX_BUFFER_SIZE) < 0) { prompt_error("Read Data Failed"); close(socket); exit(0); } else { printf("Data read success.............. \n "); } printf("The server responded with: %s\n", buff); close(socket); } printf("Enter a nickname: "); } /*===== End of Program Loop ======*/ /*---------- Ending Program ----------*/ printf("Ending client program......................\n"); free(the_host_name); close(socket); return 0; /*===== End of Ending Programs ======*/ }