⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 efax-gtk-socket-client.cpp

📁 用于使用moden进行传真的源代码
💻 CPP
字号:
/* Copyright (C) 2003 Chris VineThis program is distributed under the General Public Licence, version 2.For particulars of this and relevant disclaimers see the fileCOPYRIGHT distributed with the source files.*/#include "config.h"// deal with any configuration issues arising from config.h#ifndef HAVE_BOOLtypedef int bool;const bool false = 0;const bool true = 1;#endif#ifndef HAVE_SSIZE_Ttypedef signed int ssize_t;#endif#include <iostream>#include <string>#include <cstdlib>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <unistd.h>#include <syslog.h>#define BUFFER_LENGTH 1024void error_msg(const char*);int main(int argc, char* argv[]) {  if (argc < 3) {    error_msg("Insufficient arguments\n"	      "Usage efax-gtk-socket-client [hostname] [port]\n");    return 1;  }  struct hostent* hostname_info;  if ((hostname_info = gethostbyname(argv[1])) == 0) {    std::string message("Cannot get address for hostname ");    message += argv[1];    message += '\n';    error_msg(message.c_str());    return 1;  }    int sock_fd = socket(AF_INET, SOCK_STREAM, 0);  if (sock_fd < 0) {    error_msg("Cannot create socket for socket server\n");    return 1;  }  sockaddr_in address;  address.sin_family = AF_INET;  address.sin_addr = *(in_addr*)hostname_info->h_addr_list[0];  address.sin_port = htons(std::atoi(argv[2]));  if (connect(sock_fd, (sockaddr*)&address, sizeof(address)) < 0) {    error_msg("Cannot connect to efax-gtk server socket\n");    close(sock_fd);    return 1;  }  char buffer[BUFFER_LENGTH];  ssize_t result;  while ((result = read(0, buffer, BUFFER_LENGTH)) > 0) {    write(sock_fd, buffer, result);  }  close(sock_fd);  return 0;}void error_msg(const char* message) {  std::cerr << "efax-gtk-socket-client: " << message << std::flush;  syslog(LOG_ERR | LOG_USER, message);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -