unit IpHdr;
interface
uses Windows,WinSock;
type
TIPHdr=record
ip_verlen:BYTE;
ip_tos:Byte;
ip_totallength:Word;
ip_id:Word;
ip_offset:Word;
ip_ttl:Byte;
ip_protocol:Byte;
ip_checksum:Word;
ip_srcaddr
WORD;
ip_destaddr
WORD;
end;
PIPHdr=^TIPHdr;
TUDPHdr=record
udp_srcport:Word;
udp_destport:Word;
udp_length:Word;
udp_checksum:Word;
end;
PUDPHdr=^TUDPHdr;
function inet_checksum(var buf;buflen:Integer):Word;
function LookupName(const name:string;var addr:TInAddr):Boolean;
implementation
function LookupName(const name: string;var addr:TInAddr):Boolean;
var
HostEnt: PHostEnt;
begin
Result:=False;
addr.S_addr:=inet_addr(PChar(name));
if(addr.S_addr=-1)then
begin
HostEnt := gethostbyname(PChar(Name));
FillChar(Addr, SizeOf(Addr), 0);
if HostEnt <> nil then
begin
with addr, HostEnt^ do
begin
S_un_b.s_b1 := h_addr^[0];
S_un_b.s_b2 := h_addr^[1];
S_un_b.s_b3 := h_addr^[2];
S_un_b.s_b4 := h_addr^[3];
end;
Result:=True;
end;
end
else Result:=True;
end;
function inet_checksum(var buf;buflen:Integer):Word;
var
pBuf
Word;
cksum
WORD;
begin
cksum:=0;
pBuf:=PWord(buf);
while(buflen>1)do
begin
cksum:=cksum+pBuf^;
Inc(pBuf);
Dec(buflen,SizeOf(Word));
end;
if(buflen<>0)then
begin
cksum:=cksum+pBuf^;
end;
cksum:=(cksum shr 16)+(cksum and $ffff);
cksum:=cksum shr 16;
result:=not cksum;
end;