| 1 |
/* |
| 2 |
* @file netaccess.h |
| 3 |
* @brief ネットワークアクセス |
| 4 |
* @author BananaJinn |
| 5 |
* @version $Id: netaccess.h,v 1.11 2007/10/02 15:10:52 bananajinn Exp $ |
| 6 |
* 円盤複写屋 |
| 7 |
* Copyright (C) 2004-2006 BananaJinn<banana@mxh.mesh.ne.jp>. |
| 8 |
*/ |
| 9 |
#ifndef __NETACCESS_H__ |
| 10 |
#define __NETACCESS_H__ |
| 11 |
|
| 12 |
#if defined(WIN32) |
| 13 |
# include <winsock.h> |
| 14 |
# define SD_RECEIVE 0x00 |
| 15 |
# define SD_SEND 0x01 |
| 16 |
# define SD_BOTH 0x02 |
| 17 |
#else |
| 18 |
# include <sys/socket.h> |
| 19 |
typedef int SOCKET; |
| 20 |
#endif |
| 21 |
#if defined(linux) || defined(__MINGW32__) |
| 22 |
# include <iconv.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#define NETTIMEOUT (60*1000) |
| 26 |
|
| 27 |
typedef struct { |
| 28 |
BOOL server_mode; |
| 29 |
union { |
| 30 |
struct { |
| 31 |
WORD port; |
| 32 |
SOCKET listen_socket; |
| 33 |
SOCKET socket_desc; |
| 34 |
} server; |
| 35 |
struct { |
| 36 |
DWORD remote_address; |
| 37 |
WORD remote_port; |
| 38 |
SOCKET socket_desc; |
| 39 |
} client; |
| 40 |
} u; |
| 41 |
char *remote_host; |
| 42 |
DWORD error_code; |
| 43 |
#if defined(linux) || defined(__MINGW32__) |
| 44 |
iconv_t iconv_desc; |
| 45 |
#endif |
| 46 |
} SOCKCB; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
/* |
| 51 |
* データ転送形式 |
| 52 |
* +-----------------------+ ---- |
| 53 |
* | length[0] MSB| ^ |
| 54 |
* +-----------------------+ | |
| 55 |
* | length[1] | | |
| 56 |
* +-----------------------+ | |
| 57 |
* | length[2] | | 共通部 |
| 58 |
* +-----------------------+ | (8 bytes) |
| 59 |
* | length[3] LSB| | |
| 60 |
* +-----------------------+ | |
| 61 |
* | data type | | |
| 62 |
* +-----------------------+ | |
| 63 |
* | reserved | | |
| 64 |
* +-----------------------+ | |
| 65 |
* | reserved | | |
| 66 |
* +-----------------------+ | |
| 67 |
* | reserved | v |
| 68 |
* +-----------------------+ ---- |
| 69 |
* | ... | ^ |
| 70 |
* | | | 個別部(data typeによる) |
| 71 |
* | | v |
| 72 |
* +-----------------------+ ---- |
| 73 |
* |
| 74 |
* lengthは個別部のデータ長を表す(共通部は含まない) |
| 75 |
*/ |
| 76 |
|
| 77 |
/* |
| 78 |
* ATAPI/ASPIコマンド(Client => Server) |
| 79 |
* 個別データ部は NETCMDHEADER + コマンドデータ(あれば) |
| 80 |
*/ |
| 81 |
#define NETDATATYPE_COMMAND 1 |
| 82 |
/* |
| 83 |
* ATAPI/ASPIコマンドに対する応答(Server => Client) |
| 84 |
* 個別データ部は NETCMDHEADER + コマンドデータ(あれば) |
| 85 |
*/ |
| 86 |
#define NETDATATYPE_RESPONSE 2 |
| 87 |
/* |
| 88 |
* ATAPI/ASPIコマンドの長く続くREAD(Client => Server) |
| 89 |
* READ(12)またはREADCDの形式でServerから連続してデータを返す |
| 90 |
* 個別データ部は NETCMDHEADER + トータルlength(4bytes) |
| 91 |
*/ |
| 92 |
#define NETDATATYPE_LONGREAD 3 |
| 93 |
|
| 94 |
typedef struct { |
| 95 |
BYTE reqflag; |
| 96 |
BYTE reserved[3]; |
| 97 |
BYTE cdb[12]; |
| 98 |
BYTE data_length[4]; |
| 99 |
BYTE sense_data[0x20]; |
| 100 |
} NETCMDHEADER; |
| 101 |
|
| 102 |
/* |
| 103 |
* 表示更新命令(Client => Server) |
| 104 |
* 個別データ部は NETDISPHEADER + メッセージ文字列(\0まで) |
| 105 |
* メッセージ文字列長が 0 の場合はプログレスバーのみ更新したりする |
| 106 |
*/ |
| 107 |
#define NETDATATYPE_DISPLAY 4 |
| 108 |
|
| 109 |
typedef struct { |
| 110 |
BYTE area; /* 0:画面下メッセージ/1:プログレスバー1/2:プログレスバー2 */ |
| 111 |
BYTE percent; /* プログレスバーの進捗(0-100) */ |
| 112 |
} NETDISPHEADER; |
| 113 |
|
| 114 |
/* |
| 115 |
* 処理中断(Client <=> Server) |
| 116 |
* 個別データ部はなし。即座に処理を中断する。 |
| 117 |
*/ |
| 118 |
#define NETDATATYPE_ABORT 5 |
| 119 |
|
| 120 |
/* |
| 121 |
* 処理完了(Client => Server) |
| 122 |
* 個別データ部はなし。 |
| 123 |
*/ |
| 124 |
#define NETDATATYPE_COMPLETE 6 |
| 125 |
|
| 126 |
extern int InitializeSOCKCB(SOCKCB *scb); |
| 127 |
extern int FreeSOCKCB(SOCKCB *scb); |
| 128 |
|
| 129 |
extern int NACreateServer(SOCKCB *scb); |
| 130 |
extern int NAWaitConnect(SOCKCB *scb, DWORD timeout); |
| 131 |
extern int NAConnect(SOCKCB *scb); |
| 132 |
extern int NAClose(SOCKCB *scb); |
| 133 |
extern int NASend(SOCKCB *scb, const void *buffer, int length, DWORD timeout, |
| 134 |
BOOL check_readfd); |
| 135 |
extern int NAReceive(SOCKCB *scb, void *buffer, int length, DWORD timeout); |
| 136 |
|
| 137 |
extern int SendNetCmd(SOCKCB *scb, BYTE *cdb, void *buf, DWORD buflen, |
| 138 |
BYTE *sensedata, DWORD senselen, int reqflag); |
| 139 |
extern int SendNetCmdLongRead(SOCKCB *scb, BYTE *cdb, void *buf, DWORD buflen, |
| 140 |
BYTE *sensedata, DWORD senselen, |
| 141 |
int reqflag, DWORD total_blocks); |
| 142 |
|
| 143 |
extern int NASendDispCmd(SOCKCB *scb, BYTE area, BYTE percent, |
| 144 |
const char *message); |
| 145 |
extern int NASendAbort(SOCKCB *scb); |
| 146 |
extern int NASendComplete(SOCKCB *scb); |
| 147 |
extern int NAUIDispInfo(SOCKCB *scb, const char *message); |
| 148 |
extern int NAUIMeter1Initialize(SOCKCB *scb, const char *message); |
| 149 |
extern int NAUIMeter2Initialize(SOCKCB *scb, const char *message); |
| 150 |
extern int NAUIMeter1Update(SOCKCB *scb, float percentage); |
| 151 |
extern int NAUIMeter2Update(SOCKCB *scb, float percentage); |
| 152 |
extern const char *NAGetErrorMessage(SOCKCB *scb); |
| 153 |
#if defined(linux) || defined(__MINGW32__) |
| 154 |
extern char *ConvertCharcode(iconv_t iconv_desc, const char *in_string); |
| 155 |
#endif |
| 156 |
extern BOOL DispSocketError(SOCKCB *scb, int ret_value); |
| 157 |
|
| 158 |
#endif /* !__NETACCESS_H__ */ |