//----------------------------------------------------------------- // tcp_lib.h: ソケット通信によるデータ転送用ライブラリ-ヘッダ //----------------------------------------------------------------- #include <stdio.h> #include <string.h> #include <stdlib.h> // TCP/IP 通信用 #include <unistd.h> /* getuid(),read(),write(),close() */ #include <netdb.h> /* gethostbyname() */ #include <sys/types.h> #include <sys/socket.h> /* socket() */ #include <netinet/in.h> /* struct sockaddr_in */ #include <arpa/inet.h> typedef unsigned char BYTE; #define TIMEOUT_SEC 2 #define TIMEOUT_USEC 0 #define TRUE 1 #define FALSE 0 //----------------------------------------------------------------- // 諸関数 //----------------------------------------------------------------- // IPアドレスの取得 char* GetIP(char* hostname); // ホスト名の表示 void Disp_ipinfo(char* msg,int portno); //----------------------------------------------------------------- // サーバ用 //----------------------------------------------------------------- int TCP_accept(int acc,char* conhost); int TCP_acc_port(int portno); //----------------------------------------------------------------- // クライアント用 //----------------------------------------------------------------- // ホスト-ポート先指定のソケット通信開始 int TCP_open(char* hostname,int portno); int TCP_connect(char *hostname,int portno); // ソケット通信終了 void TCP_close(int sock); // ソケットをファイル記述子に割り当て int fdopen_sock(int sock,FILE **inp,FILE **outp); //----------------------------------------------------------------- // ソケットによる送受信 //----------------------------------------------------------------- // 送信(See: UNIX Network Programming, SS.6.6, Utility routines) int TCP_send(int fd,BYTE* buff,int nbytes); // 受信 int TCP_recv(int sock,BYTE* recbuf,int timeout);