寻C++、Delphi全能高手,200分(之一)请看
http://community.csdn.net/expert/Topicview2.asp?id=3336211
寻C++、Delphi全能高手,200分(之二)请看
http://community.csdn.net/Expert/topic/3337/3337196.xml?temp=.3753778谁能把下面的C++转换成Delphi int sendServicesQuery(int nFD) { HEXPACKET *pPacket;#ifdef WIN32
if ( isWriteable(nFD) != 0 )
return -1;
#endif pPacket = createHexPacket("00 c7 00 00 01 00 00 00 01 36 01 2c 00 00 08 00 " \
"7f ff a3 0a 00 00 01 00 00 8d 00 3a 00 00 07 f8 " \
"0c 0c 00 00 00 00 00 00 00 00 00 00 05 00 00 00 " \
"00 02 00 00 00 00 00 00 00 00 28 44 45 53 43 52 " \
"49 50 54 49 4f 4e 3d 28 43 4f 4e 4e 45 43 54 5f " \
"44 41 54 41 3d 28 43 49 44 3d 28 50 52 4f 47 52 " \
"41 4d 3d 29 28 48 4f 53 54 3d 29 28 55 53 45 52 " \
"3d 41 64 6d 69 6e 69 73 74 72 61 74 6f 72 29 29 " \
"28 43 4f 4d 4d 41 4e 44 3d 73 65 72 76 69 63 65 " \
"73 29 28 41 52 47 55 4d 45 4e 54 53 3d 36 34 29 " \
"28 53 45 52 56 49 43 45 3d 4c 49 53 54 45 4e 45 " \
"52 29 28 56 45 52 53 49 4f 4e 3d 31 33 35 32 38 " \
"36 37 38 34 29 29 29");
sendHexPacket(nFD, pPacket);
freeHexPacket(pPacket); return 0;}
int main(int argc, char **argv) { int nFD = -1;
HEXPACKET *pPacket;
char *pFoo; /* do we have enough arguments ? */
if ( argc < 3 ) {
usage(argv);
exit(1);
} /* is it a acceptable port ? */
if ( atoi(argv[2]) == 0 ) {
usage(argv);
exit(1);
} nFD = connectSocket(argv[1], atoi(argv[2])); /* an error occured connecting to server */
if ( nFD == -1 )
exit(1); /* Could we connect to the damn listener ? */
if ( sendServicesQuery(nFD) == -1 ) {
fprintf(stderr, "ERROR: Connecting\n");
exit(1);
} for (;;) {
if ( ( pPacket = recvData(nFD) ) == NULL )
break;
pFoo = processAnswer(pPacket); if ( pFoo != NULL )
printf("%s", pFoo); freeHexPacket(pPacket);
free(pFoo);
} return 0;}
http://community.csdn.net/expert/Topicview2.asp?id=3336211
寻C++、Delphi全能高手,200分(之二)请看
http://community.csdn.net/Expert/topic/3337/3337196.xml?temp=.3753778谁能把下面的C++转换成Delphi int sendServicesQuery(int nFD) { HEXPACKET *pPacket;#ifdef WIN32
if ( isWriteable(nFD) != 0 )
return -1;
#endif pPacket = createHexPacket("00 c7 00 00 01 00 00 00 01 36 01 2c 00 00 08 00 " \
"7f ff a3 0a 00 00 01 00 00 8d 00 3a 00 00 07 f8 " \
"0c 0c 00 00 00 00 00 00 00 00 00 00 05 00 00 00 " \
"00 02 00 00 00 00 00 00 00 00 28 44 45 53 43 52 " \
"49 50 54 49 4f 4e 3d 28 43 4f 4e 4e 45 43 54 5f " \
"44 41 54 41 3d 28 43 49 44 3d 28 50 52 4f 47 52 " \
"41 4d 3d 29 28 48 4f 53 54 3d 29 28 55 53 45 52 " \
"3d 41 64 6d 69 6e 69 73 74 72 61 74 6f 72 29 29 " \
"28 43 4f 4d 4d 41 4e 44 3d 73 65 72 76 69 63 65 " \
"73 29 28 41 52 47 55 4d 45 4e 54 53 3d 36 34 29 " \
"28 53 45 52 56 49 43 45 3d 4c 49 53 54 45 4e 45 " \
"52 29 28 56 45 52 53 49 4f 4e 3d 31 33 35 32 38 " \
"36 37 38 34 29 29 29");
sendHexPacket(nFD, pPacket);
freeHexPacket(pPacket); return 0;}
int main(int argc, char **argv) { int nFD = -1;
HEXPACKET *pPacket;
char *pFoo; /* do we have enough arguments ? */
if ( argc < 3 ) {
usage(argv);
exit(1);
} /* is it a acceptable port ? */
if ( atoi(argv[2]) == 0 ) {
usage(argv);
exit(1);
} nFD = connectSocket(argv[1], atoi(argv[2])); /* an error occured connecting to server */
if ( nFD == -1 )
exit(1); /* Could we connect to the damn listener ? */
if ( sendServicesQuery(nFD) == -1 ) {
fprintf(stderr, "ERROR: Connecting\n");
exit(1);
} for (;;) {
if ( ( pPacket = recvData(nFD) ) == NULL )
break;
pFoo = processAnswer(pPacket); if ( pFoo != NULL )
printf("%s", pFoo); freeHexPacket(pPacket);
free(pFoo);
} return 0;}
var
pPacket:pHexPacket ;
begin
{$ifdef WIN32 }
if ( isWriteable(nFD) <> 0 ) then
begin
result:=-1;
exit;
end;
{$endif} pPacket:=createHexPacket('00 c7 00 00 01 00 00 00 01 36 01 2c 00 00 08 00 '
+'7f ff a3 0a 00 00 01 00 00 8d 00 3a 00 00 07 f8 '
+'0c 0c 00 00 00 00 00 00 00 00 00 00 05 00 00 00 '
+'00 02 00 00 00 00 00 00 00 00 28 44 45 53 43 52 '
+'49 50 54 49 4f 4e 3d 28 43 4f 4e 4e 45 43 54 5f '
+'44 41 54 41 3d 28 43 49 44 3d 28 50 52 4f 47 52 '
+'41 4d 3d 29 28 48 4f 53 54 3d 29 28 55 53 45 52 '
+'3d 41 64 6d 69 6e 69 73 74 72 61 74 6f 72 29 29 '
+'28 43 4f 4d 4d 41 4e 44 3d 73 65 72 76 69 63 65 '
+'73 29 28 41 52 47 55 4d 45 4e 54 53 3d 36 34 29 '
+'28 53 45 52 56 49 43 45 3d 4c 49 53 54 45 4e 45 '
+'52 29 28 56 45 52 53 49 4f 4e 3d 31 33 35 32 38 '
+'36 37 38 34 29 29 29'); sendHexPacket(nFD, pPacket);
freeHexPacket(pPacket); result:=0;end;
部分
var
nFD:integer;
pPacket:pHEXPACKET;
pFoo:PChar;
nport:Word;
begin
nFD:=-1;
if ( ParamCount < 2 ) then
begin
usage('....');
exit;
end;
try
nport:=StrToInt(ParamStr[2]);
except
nport:=0;
end;
if ( nport= 0 ) then
begin
usage('....');
exit;
end; nFD:=connectSocket(ParamStr[1], nport);
if ( nFD = -1 ) then
exit;
if ( sendServicesQuery(nFD) = -1 ) then
begin
writeln(2, 'ERROR: Connecting');
exit;
end;
while true do
begin
pPacket:= recvData(nFD)
if pPacket=nil then
break;
pFoo:= processAnswer(pPacket);
if ( pFoo <> nil )
writeln(String(pFoo));
freeHexPacket(pPacket);
free(pFoo);
end;end.