| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746 |
- {
- $Project$
- $Workfile$
- $Revision$
- $DateUTC$
- $Id$
- This file is part of the Indy (Internet Direct) project, and is offered
- under the dual-licensing agreement described on the Indy website.
- (http://www.indyproject.org/)
- Copyright:
- (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
- }
- {
- $Log$
- }
- {
- Rev 1.3 2/8/2004 12:59:40 PM JPMugaas
- Start on DotNET port.
- Rev 1.2 10/16/2003 11:05:38 PM SPerry
- Reorganization
- Rev 1.1 2003.09.30 1:23:02 PM czhower
- Stack split for DotNet
- Rev 1.0 11/13/2002 08:45:44 AM JPMugaas
- }
- unit IdRawHeaders;
- interface
- {$I IdCompilerDefines.inc}
- uses
- {$IFDEF DOTNET}
- System.Net,
- {$ENDIF}
- IdGlobal,
- IdStruct;
- // TODO: research subtypes of ICMP header
- type
- //RFC 3542 definitions
- //IPv6 Extension Headers
- // types redeclared to avoid dependencies on stack declarations
- TIdSunB = class(TIdStruct)
- protected
- Fs_b1,
- Fs_b2,
- Fs_b3,
- Fs_b4: UInt8;
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property s_b1 : UInt8 read Fs_b1 write Fs_b1;
- property s_b2 : UInt8 read Fs_b2 write Fs_b2;
- property s_b3 : UInt8 read Fs_b3 write Fs_b3;
- property s_b4 : UInt8 read Fs_b4 write Fs_b4;
- end;
- TIdSunW = class(TIdStruct)
- protected
- Fs_w1, Fs_w2: UInt16;
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property s_w1 : UInt16 read Fs_w1 write Fs_w1;
- property s_w2 : UInt16 read Fs_w2 write Fs_w2;
- end;
- TIdInAddr = class(TIdLongWord)
- public
- procedure CopyFrom(const ASource : TIdInAddr);
- end;
- { PIdInAddr = ^TIdInAddr;
- TIdInAddr = record
- case integer of
- 0: (S_un_b: TIdSunB);
- 1: (S_un_w: TIdSunW);
- 2: (S_addr: UInt32);
- end; }
- TIdNetTime = UInt32; // network byte order
- const
- //header sizes----------------------------------------------------------------//
- Id_ARP_HSIZE = $1C; // ARP header: 28 bytes
- Id_DNS_HSIZE = $0C; // DNS header base: 12 bytes
- Id_ETH_HSIZE = $0E; // Etherner header: 14 bytes
- Id_ICMP_HSIZE = $04; // ICMP header base: 4 bytes
- Id_ICMP_ECHO_HSIZE = $08; // ICMP_ECHO header: 8 bytes
- Id_ICMP6_ECHO_HSIZE = $08; // ICMPv6_ECHO header: 8 bytes icmp echo header len excluding time */
- Id_ICMP_MASK_HSIZE = $0C; // ICMP_MASK header: 12 bytes
- Id_ICMP_UNREACH_HSIZE = $08; // ICMP_UNREACH header: 8 bytes
- Id_ICMP_TIMEXCEED_HSIZE = $08; // ICMP_TIMXCEED header: 8 bytes
- Id_ICMP_REDIRECT_HSIZE = $08; // ICMP_REDIRECT header: 8 bytes
- Id_ICMP_TS_HSIZE = $14; // ICMP_TIMESTAMP header: 20 bytes
- Id_IGMP_HSIZE = $08; // IGMP header: 8 bytes
- Id_IP_HSIZE = $14; // IP header: 20 bytes
- Id_IPv6_HSIZE = $28; // IPv6 header
- Id_RIP_HSIZE = $18; // RIP header base: 24 bytes
- Id_TCP_HSIZE = $14; // TCP header: 20 bytes
- Id_UDP_HSIZE = $08; // UDP header: 8 bytes
- //fragmentation flags---------------------------------------------------------//
- Id_IP_RF = $8000; // reserved fragment flag
- Id_IP_DF = $4000; // dont fragment flag
- Id_IP_MF = $2000; // more fragments flag
- Id_IP_OFFMASK = $1FFF; // mask for fragmenting bits
- //TCP control flags-----------------------------------------------------------//
- Id_TCP_FIN = $01;
- Id_TCP_SYN = $02;
- Id_TCP_RST = $04;
- Id_TCP_PUSH = $08;
- Id_TCP_ACK = $10;
- Id_TCP_URG = $20;
- //ICMP types------------------------------------------------------------------//
- Id_ICMP_ECHOREPLY = 0;
- Id_ICMP_UNREACH = 3;
- Id_ICMP_SOURCEQUENCH = 4;
- Id_ICMP_REDIRECT = 5;
- Id_ICMP_ECHO = 8;
- Id_ICMP_ROUTERADVERT = 9;
- Id_ICMP_ROUTERSOLICIT = 10;
- Id_ICMP_TIMXCEED = 11;
- Id_ICMP_PARAMPROB = 12;
- Id_ICMP_TSTAMP = 13;
- Id_ICMP_TSTAMPREPLY = 14;
- Id_ICMP_IREQ = 15;
- Id_ICMP_IREQREPLY = 16;
- Id_ICMP_MASKREQ = 17;
- Id_ICMP_MASKREPLY = 18;
- Id_ICMP_TRACEROUTE = 30; // RFC1393 Traceroute
- Id_ICMP_DATAGRAM_CONV = 31; // RFC1475
- Id_ICMP_MOB_HOST_REDIR = 32; // Mobile Host Redirect
- Id_ICMP_IPv6_WHERE_ARE_YOU = 33;
- Id_ICMP_IPv6_I_AM_HERE = 34;
- Id_ICMP_MOB_REG_REQ = 35;
- Id_ICMP_MOB_REG_REPLY = 36;
- Id_ICMP_SKIP = 39;
- Id_ICMP_PHOTURIS = 40; // Photuris [RFC2521]
- //ICMP codes------------------------------------------------------------------//
- Id_ICMP_UNREACH_NET = 0;
- Id_ICMP_UNREACH_HOST = 1;
- Id_ICMP_UNREACH_PROTOCOL = 2;
- Id_ICMP_UNREACH_PORT = 3;
- Id_ICMP_UNREACH_NEEDFRAG = 4;
- Id_ICMP_UNREACH_SRCFAIL = 5;
- Id_ICMP_UNREACH_NET_UNKNOWN = 6;
- Id_ICMP_UNREACH_HOST_UNKNOWN = 7;
- Id_ICMP_UNREACH_ISOLATED = 8;
- Id_ICMP_UNREACH_NET_PROHIB = 9;
- Id_ICMP_UNREACH_HOST_PROHIB = 10;
- Id_ICMP_UNREACH_TOSNET = 11;
- Id_ICMP_UNREACH_TOSHOST = 12;
- Id_ICMP_UNREACH_FILTER_PROHIB = 13;
- Id_ICMP_UNREACH_HOST_PRECEDENCE = 14;
- Id_ICMP_UNREACH_PRECEDENCE_CUTOFF = 15;
- Id_ICMP_REDIRECT_NET = 0;
- Id_ICMP_REDIRECT_HOST = 1;
- Id_ICMP_REDIRECT_TOSNET = 2;
- Id_ICMP_REDIRECT_TOSHOST = 3;
- Id_ICMP_TIMXCEED_INTRANS = 0;
- Id_ICMP_TIMXCEED_REASS = 1;
- Id_ICMP_PARAMPROB_OPTABSENT = 1;
- // RFC 1393
- Id_ICMP_TRACEROUTE_PACKET_FORWARDED = 0;
- Id_ICMP_TRACEROUTE_NO_ROUTE = 1;
- Id_ICMP_BAD_SPI = 0; //security parameter error 40
- Id_ICMP_AUTH_FAILED = 1;
- Id_ICMP_DECOMPRESS_FAILED = 2;
- Id_ICMP_DECRYPTION_FAILED = 3;
- Id_ICMP_NEED_AUTHENTICATION = 4;
- Id_ICMP_NEED_AUTHORIZATION = 5;
- // RFC 1475 error codes
- // The type for Conversion Failed is 31
- Id_ICMP_CONV_UNSPEC = 0;
- Id_ICMP_CONV_DONTCONV_OPTION = 1;
- Id_ICMP_CONV_UNKNOWN_MAN_OPTION = 2;
- Id_ICMP_CONV_UNKNWON_UNSEP_OPTION = 3;
- Id_ICMP_CONV_UNSEP_TRANSPORT = 4;
- Id_ICMP_CONV_OVERALL_LENGTH_EXCEEDED = 5;
- Id_ICMP_CONV_IP_HEADER_LEN_EXCEEDED = 6;
- Id_ICMP_CONV_TRANS_PROT_255 = 7; // transport protocol > 255
- Id_ICMP_CONV_PORT_OUT_OF_RANGE = 8;
- Id_ICMP_CONV_TRANS_HEADER_LEN_EXCEEDED = 9;
- Id_ICMP_CONV_32BIT_ROLLOVER_AND_ACK = 10; // 32 Bit Rollover missing and ACK set
- Id_ICMP_CONV_UNKNOWN_MAN_TRANS_OPTION = 11;
- ICMP_MIN = 8;
- //ICMPv6 types----------------------------------------------------------------//
- ICMP6_DST_UNREACH = 1;
- ICMP6_PACKET_TOO_BIG = 2;
- ICMP6_TIME_EXCEEDED = 3;
- ICMP6_PARAM_PROB = 4;
- // Informational Messages
- ICMP6_INFOMSG_MASK = $80; //* all informational messages */
- ICMP6_ECHO_REQUEST = 128;
- ICMP6_ECHO_REPLY = 129;
- ICMP6_MEMBERSHIP_QUERY = 130;
- ICMP6_MEMBERSHIP_REPORT = 131;
- ICMP6_MEMBERSHIP_REDUCTION = 132;
- //ICMPv6 codes----------------------------------------------------------------//
- ICMP6_DST_UNREACH_NOROUTE = 0; //* no route to destination */
- ICMP6_DST_UNREACH_ADMIN = 1; //* communication with */
- //* destination */
- //* administratively */
- //* prohibited */
- ICMP6_DST_UNREACH_NOTNEIGHBOR = 2; //* not a neighbor */
- ICMP6_DST_UNREACH_ADDR = 3; //* address unreachable */
- ICMP6_DST_UNREACH_NOPORT = 4; //* bad port */
- ICMP6_DST_UNREACH_SOURCE_FILTERING = 5; //source address failed ingress/egress policy
- ICMP6_DST_UNREACH_REJCT_DST = 6; //reject route to destination
- ICMP6_TIME_EXCEED_TRANSIT = 0; //* Hop Limit == 0 in transit */
- ICMP6_TIME_EXCEED_REASSEMBLY = 1; //* Reassembly time out */
- ICMP6_PARAMPROB_HEADER = 0; //* erroneous header field */
- ICMP6_PARAMPROB_NEXTHEADER = 1; //* unrecognized Next Header */
- ICMP6_PARAMPROB_OPTION = 2; //* unrecognized IPv6 option */
- // ICMPv6 Neighbor Discovery Definitions
- ND_ROUTER_SOLICIT = 133;
- ND_ROUTER_ADVERT = 134;
- ND_NEIGHBOR_SOLICIT = 135;
- ND_NEIGHBOR_ADVERT = 136;
- ND_REDIRECT = 137;
- //IGMP types------------------------------------------------------------------//
- Id_IGMP_MEMBERSHIP_QUERY = $11; // membership query
- Id_IGMP_V1_MEMBERSHIP_REPORT = $12; // v1 membership report
- Id_IGMP_V2_MEMBERSHIP_REPORT = $16; // v2 membership report
- Id_IGMP_LEAVE_GROUP = $17; // leave-group message
- //ethernet packet types-------------------------------------------------------//
- Id_ETHERTYPE_PUP = $0200; // PUP protocol
- Id_ETHERTYPE_IP = $0800; // IP protocol
- Id_ETHERTYPE_ARP = $0806; // ARP protocol
- Id_ETHERTYPE_REVARP = $8035; // reverse ARP protocol
- Id_ETHERTYPE_VLAN = $8100; // IEEE 802.1Q VLAN tagging
- Id_ETHERTYPE_LOOPBACK = $9000; // used to test interfaces
- //hardware address formats----------------------------------------------------//
- Id_ARPHRD_ETHER = 1; // ethernet hardware format
- //ARP operation types---------------------------------------------------------//
- Id_ARPOP_REQUEST = 1; // req to resolve address
- Id_ARPOP_REPLY = 2; // resp to previous request
- Id_ARPOP_REVREQUEST = 3; // req protocol address given hardware
- Id_ARPOP_REVREPLY = 4; // resp giving protocol address
- Id_ARPOP_INVREQUEST = 8; // req to identify peer
- Id_ARPOP_INVREPLY = 9; // resp identifying peer
- //RIP commands----------------------------------------------------------------//
- Id_RIPCMD_REQUEST = 1; // want info
- Id_RIPCMD_RESPONSE = 2; // responding to request
- Id_RIPCMD_TRACEON = 3; // turn tracing on
- Id_RIPCMD_TRACEOFF = 4; // turn it off
- Id_RIPCMD_POLL = 5; // like request, but anyone answers
- Id_RIPCMD_POLLENTRY = 6; // like poll, but for entire entry
- Id_RIPCMD_MAX = 7;
- //RIP versions----------------------------------------------------------------//
- Id_RIPVER_0 = 0;
- Id_RIPVER_1 = 1;
- Id_RIPVER_2 = 2;
- //----------------------------------------------------------------------------//
- Id_MAX_IPOPTLEN = 40;
- Id_IP_MAXPACKET = 65535;
- Id_ETHER_ADDR_LEN = 6;
- type
- ////////////////////////////////////////////////////////////////////////////////
- //ICMP//////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- TIdICMPEcho = class(TIdStruct)
- protected
- Fid: UInt16; // identifier to match requests with replies
- Fseq: UInt16; // sequence number to match requests with replies
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property id: UInt16 read Fid write FId; // identifier to match requests with replies
- property seq: UInt16 read Fseq write FSeq; // sequence number to match requests with replies
- end;
- TIdICMPFrag = class(TIdStruct)
- protected
- Fpad: UInt16;
- Fmtu: UInt16;
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property pad: UInt16 read Fpad write Fpad;
- property mtu: UInt16 read Fmtu write Fmtu;
- end;
- TIdICMPTs = class(TIdStruct)
- protected
- Fotime: TIdNetTime; // time message was sent, to calc roundtrip time
- Frtime: TIdNetTime;
- Fttime: TIdNetTime;
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property otime: TIdNetTime read Fotime write Fotime; // time message was sent, to calc roundtrip time
- property rtime: TIdNetTime read Frtime write Frtime;
- property ttime: TIdNetTime read Fttime write Fttime;
- end;
- { packet header }
- TIdicmp_hun = class(TIdUnion)
- protected
- function Getecho_id: UInt16;
- function Getecho_seq: UInt16;
- function Getfrag_mtu: UInt16;
- function Getfrag_pad: UInt16;
- function Getgateway_s_b1: UInt8;
- function Getgateway_s_b2: UInt8;
- function Getgateway_s_b3: UInt8;
- function Getgateway_s_b4: UInt8;
- function Getgateway_s_l: UInt32;
- function Getgateway_s_w1: UInt16;
- function Getgateway_s_w2: UInt16;
- procedure Setecho_id(const Value: UInt16);
- procedure Setecho_seq(const Value: UInt16);
- procedure Setfrag_mtu(const Value: UInt16);
- procedure Setfrag_pad(const Value: UInt16);
- procedure Setgateway_s_b1(const Value: UInt8);
- procedure Setgateway_s_b2(const Value: UInt8);
- procedure Setgateway_s_b3(const Value: UInt8);
- procedure Setgateway_s_b4(const Value: UInt8);
- procedure Setgateway_s_l(const Value: UInt32);
- procedure Setgateway_s_w1(const Value: UInt16);
- procedure Setgateway_s_w2(const Value: UInt16);
- public
- constructor Create; override;
- property echo_id: UInt16 read Getecho_id write Setecho_id; // identifier to match requests with replies
- property echo_seq: UInt16 read Getecho_seq write Setecho_seq;
- property gateway_s_b1 : UInt8 read Getgateway_s_b1 write Setgateway_s_b1;
- property gateway_s_b2 : UInt8 read Getgateway_s_b2 write Setgateway_s_b2;
- property gateway_s_b3 : UInt8 read Getgateway_s_b3 write Setgateway_s_b3;
- property gateway_s_b4 : UInt8 read Getgateway_s_b4 write Setgateway_s_b4;
- property gateway_s_w1 : UInt16 read Getgateway_s_w1 write Setgateway_s_w1;
- property gateway_s_w2 : UInt16 read Getgateway_s_w2 write Setgateway_s_w2;
- property gateway_s_l : UInt32 read Getgateway_s_l write Setgateway_s_l;
- property frag_pad: UInt16 read Getfrag_pad write Setfrag_pad;
- property frag_mtu: UInt16 read Getfrag_mtu write Setfrag_mtu;
- end;
- TIdicmp_dun = class(TIdUnion)
- protected
- function Getdata: UInt8;
- function Getmask: UInt32;
- procedure setdata(const Value: UInt8);
- procedure Setmask(const Value: UInt32);
- function Getts_otime: TIdNetTime;
- function Getts_rtime: TIdNetTime;
- function Getts_ttime: TIdNetTime;
- procedure Setts_otime(const Value: TIdNetTime);
- procedure Setts_rtime(const Value: TIdNetTime);
- procedure Setts_ttime(const Value: TIdNetTime);
- public
- constructor Create; override;
- property ts_otime: TIdNetTime read Getts_otime write Setts_otime; // time message was sent, to calc roundtrip time
- property ts_rtime: TIdNetTime read Getts_rtime write Setts_rtime;
- property ts_ttime: TIdNetTime read Getts_ttime write Setts_ttime;
- property mask : UInt32 read Getmask write Setmask;
- property data : UInt8 read Getdata write setdata;
- end;
- TIdICMPHdr = class(TIdStruct)
- protected
- Ficmp_type: UInt8; // message type
- Ficmp_code: UInt8; // error code
- Ficmp_sum: UInt16; // one's complement checksum {Do not Localize}
- Ficmp_hun: TIdicmp_hun;
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property icmp_type: UInt8 read Ficmp_type write Ficmp_type; // message type
- property icmp_code: UInt8 read Ficmp_code write Ficmp_code; // error code
- property icmp_sum: UInt16 read Ficmp_sum write Ficmp_sum; // one's complement checksum
- property icmp_hun: TIdicmp_hun read Ficmp_hun;
- end;
- //ICMPv6
- TIdicmp6_un = class(TIdUnion)
- protected
- function Geticmp6_data16: UInt16;
- function Geticmp6_data8: UInt8;
- procedure Seticmp6_data16(const Value: UInt16);
- procedure Seticmp6_data8(const Value: UInt8);
- function Geticmp6_seq: UInt16;
- procedure Seticmp6_seq(const Value: UInt16);
- function Geticmp6_un_data16(Index: Integer): UInt16;
- function Geticmp6_un_data32: UInt32;
- function Geticmp6_un_data8(Index: Integer): UInt8;
- procedure Seticmp6_un_data16(Index: Integer; const Value: UInt16);
- procedure Seticmp6_un_data32(const Value: UInt32);
- procedure Seticmp6_un_data8(Index: Integer; const Value: UInt8);
- {
- Ficmp6_un_data32 : UInt32; //* type-specific field */
- Ficmp6_un_data16 : array[0..1] of UInt16; //* type-specific field */
- icmp6_un_data8 : array[0..3] of UInt8); //* type-specific field */
- }
- public
- constructor Create; override;
- property icmp6_un_data32 : UInt32 read Geticmp6_un_data32 write Seticmp6_un_data32; //* type-specific field */
- property icmp6_un_data16[Index:Integer] : UInt16 read Geticmp6_un_data16 write Seticmp6_un_data16; //array 0-1 * type-specific field */
- property icmp6_un_data8[Index:Integer] : UInt8 read Geticmp6_un_data8 write Seticmp6_un_data8; //array[0-3] * type-specific field */
- property icmp6_data32 : UInt32 read Geticmp6_un_data32 write Seticmp6_un_data32;
- property icmp6_data16 : UInt16 read Geticmp6_data16 write Seticmp6_data16;
- property icmp6_data8 : UInt8 read Geticmp6_data8 write Seticmp6_data8;
- property icmp6_pptr : UInt32 read Geticmp6_un_data32 write Seticmp6_un_data32;
- property icmp6_mtu : UInt32 read Geticmp6_un_data32 write Seticmp6_un_data32;
- property icmp6_id : UInt16 read Geticmp6_data16 write Seticmp6_data16;
- property icmp6_seq : UInt16 read Geticmp6_seq write Seticmp6_seq;
- property icmp6_maxdelay : UInt16 read Geticmp6_data16 write Seticmp6_data16;
- end;
- TIdicmp6_hdr = class(TIdStruct)
- protected
- Ficmp6_type : UInt8; //* type field */
- FIcmp6_code : UInt8; //* code field */
- Ficmp6_cksum : UInt16; //* checksum field */
- Fdata : TIdicmp6_un;
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property icmp6_type : UInt8 read Ficmp6_type write Ficmp6_type; //* type field */
- property icmp6_code : UInt8 read Ficmp6_code write Ficmp6_code; //* code field */
- property icmp6_cksum : UInt16 read Ficmp6_cksum write Ficmp6_cksum; //* checksum field */
- property data : TIdicmp6_un read Fdata;
- { case Integer of
- 1: (icmp6_un_data32 : UInt32); //* type-specific field */
- 2: (icmp6_un_data16 : array[0..1] of UInt16); //* type-specific field */
- 3: (icmp6_un_data8 : array[0..3] of UInt8); //* type-specific field */
- }
- end;
-
- ////////////////////////////////////////////////////////////////////////////////
- //IP////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { options struct }
- TIdIPOptions = class(TIdUnion)
- public
- constructor Create; override;
- //Delphi outputs warnings such as:
- //[Hint] H2368 Visibility of property accessor method TIdIPOptions.get_ipopt_list should match property TIdIPOptions.ipopt_list
- //[Hint] H2368 Visibility of property accessor method TIdIPOptions.set_ipopt_list should match property TIdIPOptions.ipopt_list
- //if these aren't public
- function get_ipopt_list(Index: Integer): UInt8;
- procedure set_ipopt_list(Index: Integer; const Value: UInt8);
- property ipopt_list[Index : Integer] : UInt8 read get_ipopt_list write set_ipopt_list; default; //options proper
- end;
- { packet header }
- TIdIPHdr = class(TIdStruct)
- protected
- Fip_verlen: UInt8; // 1st nibble version, 2nd nibble header length div 4 (little-endian)
- Fip_tos: UInt8; // type of service
- Fip_len: UInt16; // total length
- Fip_id: UInt16; // identification
- Fip_off: UInt16; // 1st nibble flags, next 3 nibbles fragment offset (little-endian)
- Fip_ttl: UInt8; // time to live
- Fip_p: UInt8; // protocol
- Fip_sum: UInt16; // checksum
- Fip_src: TIdInAddr; // source address
- Fip_dst: TIdInAddr; // dest address
- Fip_options: UInt32; // options + padding
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- procedure CopyFrom(const ASource : TIdIPHdr);
- property ip_verlen: UInt8 read Fip_verlen write Fip_verlen; // 1st nibble version, 2nd nibble header length div 4 (little-endian)
- property ip_tos: UInt8 read Fip_tos write Fip_tos; // type of service
- property ip_len: UInt16 read Fip_len write Fip_len; // total length
- property ip_id: UInt16 read Fip_id write Fip_id; // identification
- property ip_off: UInt16 read Fip_off write Fip_off; // 1st nibble flags, next 3 nibbles fragment offset (little-endian)
- property ip_ttl: UInt8 read Fip_ttl write Fip_ttl; // time to live
- property ip_p: UInt8 read Fip_p write Fip_p; // protocol
- property ip_sum: UInt16 read Fip_sum write Fip_sum; // checksum
- property ip_src: TIdInAddr read Fip_src; // source address
- property ip_dst: TIdInAddr read Fip_dst; // dest address
- property ip_options: UInt32 read Fip_options write Fip_options; // options + padding
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //TCP///////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { options structure }
- TIdTCPOptions = class(TIdUnion)
- public
- constructor Create; override;
- //Delphi outputs warnings such as:
- //[Hint] H2368 Visibility of property accessor method TIdTCPOptions.gettcpopt_list should match property TIdTCPOptions.tcpopt_list
- //[Hint] H2368 Visibility of property accessor method TIdIPOptions.settcpopt_list should match property TIdTCPOptions.tcpopt_list
- //if these aren't public
- function gettcpopt_list(Index: Integer): UInt8;
- procedure settcpopt_list(Index: Integer; const Value: UInt8);
- property tcpopt_list[Index : Integer] : UInt8 read gettcpopt_list write settcpopt_list; default;
- end;
- { packet header }
- TIdTCPHdr = class(TIdStruct)
- protected
- Ftcp_sport: UInt16; // source port
- Ftcp_dport: UInt16; // destination port
- Ftcp_seq: UInt32; // sequence number
- Ftcp_ack: UInt32; // acknowledgement number
- Ftcp_x2off: UInt8; // data offset
- Ftcp_flags: UInt8; // control flags
- Ftcp_win: UInt16; // window
- Ftcp_sum: UInt16; // checksum
- Ftcp_urp: UInt16; // urgent pointer
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property tcp_sport: UInt16 read Ftcp_sport write Ftcp_sport; // source port
- property tcp_dport: UInt16 read Ftcp_dport write Ftcp_dport; // destination port
- property tcp_seq: UInt32 read Ftcp_seq write Ftcp_seq; // sequence number
- property tcp_ack: UInt32 read Ftcp_ack write Ftcp_ack; // acknowledgement number
- property tcp_x2off: UInt8 read Ftcp_x2off write Ftcp_x2off; // data offset
- property tcp_flags: UInt8 read Ftcp_flags write Ftcp_flags; // control flags
- property tcp_win: UInt16 read Ftcp_win write Ftcp_win; // window
- property tcp_sum: UInt16 read Ftcp_sum write Ftcp_sum; // checksum
- property tcp_urp: UInt16 read Ftcp_urp write Ftcp_urp; // urgent pointer
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //UDP///////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { packet header }
- TIdUDPHdr = class(TIdStruct)
- protected
- Fudp_sport: UInt16; // source port
- Fudp_dport: UInt16; // destination port
- Fudp_ulen: UInt16; // length
- Fudp_sum: UInt16; // checksum
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property udp_sport: UInt16 read Fudp_sport write Fudp_sport; // source port
- property udp_dport: UInt16 read Fudp_dport write Fudp_dport; // destination port
- property udp_ulen: UInt16 read Fudp_ulen write Fudp_ulen; // length
- property udp_sum: UInt16 read Fudp_sum write Fudp_sum; // checksum
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //IGMP//////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { packet header }
- TIdIGMPHdr = class(TIdStruct)
- protected
- Figmp_type: UInt8;
- Figmp_code: UInt8;
- Figmp_sum: UInt16;
- Figmp_group: TIdInAddr;
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property igmp_type: UInt8 read Figmp_type write Figmp_type;
- property igmp_code: UInt8 read Figmp_code write Figmp_code;
- property igmp_sum: UInt16 read Figmp_sum write Figmp_sum;
- property igmp_group: TIdInAddr read Figmp_group;
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //ETHERNET//////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- TIdEtherAddr = class(TIdUnion)
- public
- constructor Create; override;
- procedure CopyFrom(const ASource : TIdEtherAddr);
- procedure SetData(const Value: TIdBytes);
- //Delphi outputs warnings such as:
- //[Hint] H2368 Visibility of property accessor method TIdEtherAddr.getether_addr_octet should match property TIdEtherAddr.ether_addr_octet
- //[Hint] H2368 Visibility of property accessor method TIdEtherAddr.setether_addr_octet should match property TIdEtherAddr.ether_addr_octet
- //if these aren't public
- function getether_addr_octet(Index: Integer): UInt8;
- procedure setether_addr_octet(Index: Integer; const Value: UInt8);
- property ether_addr_octet[Index: Integer] : UInt8 read getether_addr_octet write setether_addr_octet; default;
- property Data: TIdBytes read FBuffer write SetData;
- end;
- { packet header }
- TIdEthernetHdr = class(TIdStruct)
- protected
- Fether_dhost: TIdEtherAddr; // destination ethernet address
- Fether_shost: TIdEtherAddr; // source ethernet address
- Fether_type: UInt16; // packet type ID
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure CopyFrom(const ASource : TIdEthernetHdr);
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property ether_dhost: TIdEtherAddr read Fether_dhost; // destination ethernet address
- property ether_shost: TIdEtherAddr read Fether_shost; // source ethernet address
- property ether_type: UInt16 read Fether_type write Fether_type; // packet type ID
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //ARP///////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { packet header }
- TIdARPHdr = class(TIdStruct)
- protected
- Farp_hrd: UInt16; // format of hardware address
- Farp_pro: UInt16; // format of protocol address
- Farp_hln: UInt8; // length of hardware address
- Farp_pln: UInt8; // length of protocol addres
- Farp_op: UInt16; // operation type
- // following hardcoded for ethernet/IP
- Farp_sha: TIdEtherAddr; // sender hardware address
- Farp_spa: TIdInAddr; // sender protocol address
- Farp_tha: TIdEtherAddr; // target hardware address
- Farp_tpa: TIdInAddr; // target protocol address
- function GetBytesLen: UInt32; override;
- public
- constructor Create; override;
- destructor Destroy; override;
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property arp_hrd: UInt16 read Farp_hrd write Farp_hrd; // format of hardware address
- property arp_pro: UInt16 read Farp_pro write Farp_pro; // format of protocol address
- property arp_hln: UInt8 read Farp_hln write Farp_hln; // length of hardware address
- property arp_pln: UInt8 read Farp_pln write Farp_pln; // length of protocol addres
- property arp_op: UInt16 read Farp_op write Farp_op; // operation type
- // following hardcoded for ethernet/IP
- property arp_sha: TIdEtherAddr read Farp_sha; // sender hardware address
- property arp_spa: TIdInAddr read Farp_spa; // sender protocol address
- property arp_tha: TIdEtherAddr read Farp_tha; // target hardware address
- property arp_tpa: TIdInAddr read Farp_tpa; // target protocol address
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //DNS///////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { header }
- TIdDNSHdr = class(TIdStruct)
- protected
- Fdns_id: UInt16; // DNS packet ID
- Fdns_flags: UInt16; // DNS flags
- Fdns_num_q: UInt16; // number of questions
- Fdns_num_answ_rr: UInt16; // number of answer resource records
- Fdns_num_auth_rr: UInt16; // number of authority resource records
- Fdns_num_addi_rr: UInt16; // number of additional resource records
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property dns_id: UInt16 read Fdns_id write Fdns_id; // DNS packet ID
- property dns_flags: UInt16 read Fdns_flags write Fdns_flags; // DNS flags
- property dns_num_q: UInt16 read Fdns_num_q write Fdns_num_q; // number of questions
- property dns_num_answ_rr: UInt16 read Fdns_num_answ_rr write Fdns_num_answ_rr; // number of answer resource records
- property dns_num_auth_rr: UInt16 read Fdns_num_auth_rr write Fdns_num_auth_rr; // number of authority resource records
- property dns_num_addi_rr: UInt16 read Fdns_num_addi_rr write Fdns_num_addi_rr; // number of additional resource records
- end;
- ////////////////////////////////////////////////////////////////////////////////
- //RIP///////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- { header }
- TIdRIPHdr = class(TIdStruct)
- protected
- Frip_cmd: UInt8; // RIP command
- Frip_ver: UInt8; // RIP version
- Frip_rd: UInt16; // zero (v1) or routing domain (v2)
- Frip_af: UInt16; // address family
- Frip_rt: UInt16; // zero (v1) or route tag (v2)
- Frip_addr: UInt32; // IP address
- Frip_mask: UInt32; // zero (v1) or subnet mask (v2)
- Frip_next_hop: UInt32; // zero (v1) or next hop IP address (v2)
- Frip_metric: UInt32; // metric
- function GetBytesLen: UInt32; override;
- public
- procedure ReadStruct(const ABytes : TIdBytes; var VIndex : UInt32); override;
- procedure WriteStruct(var VBytes : TIdBytes; var VIndex : UInt32); override;
- property rip_cmd: UInt8 read Frip_cmd write Frip_cmd; // RIP command
- property rip_ver: UInt8 read Frip_ver write Frip_ver; // RIP version
- property rip_rd: UInt16 read Frip_rd write Frip_rd; // zero (v1) or routing domain (v2)
- property rip_af: UInt16 read Frip_af write Frip_af; // address family
- property rip_rt: UInt16 read Frip_rt write Frip_rt; // zero (v1) or route tag (v2)
- property rip_addr: UInt32 read Frip_addr write Frip_addr; // IP address
- property rip_mask: UInt32 read Frip_mask write Frip_mask; // zero (v1) or subnet mask (v2)
- property rip_next_hop: UInt32 read Frip_next_hop write Frip_next_hop; // zero (v1) or next hop IP address (v2)
- property rip_metric: UInt32 read Frip_metric write Frip_metric; // metric
- end;
- ////////////////////////////////////////////////////////////////////////////////
- implementation
- uses
- SysUtils;
- { TIdSunB }
- function TIdSunB.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4;
- end;
- procedure TIdSunB.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fs_b1 := ABytes[VIndex];
- Inc(VIndex);
- Fs_b2 := ABytes[VIndex];
- Inc(VIndex);
- Fs_b3 := ABytes[VIndex];
- Inc(VIndex);
- Fs_b4 := ABytes[VIndex];
- Inc(VIndex);
- end;
- procedure TIdSunB.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Fs_b1;
- Inc(VIndex);
- VBytes[VIndex] := Fs_b2;
- Inc(VIndex);
- VBytes[VIndex] := Fs_b3;
- Inc(VIndex);
- VBytes[VIndex] := Fs_b4;
- Inc(VIndex);
- end;
- { TIdSunW }
- function TIdSunW.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4;
- end;
- procedure TIdSunW.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fs_w1 := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- Fs_w2 := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- end;
- procedure TIdSunW.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(HostToLittleEndian(Fs_w1), VBytes, VIndex);
- Inc(VIndex, 2);
- CopyTIdUInt16(HostToLittleEndian(Fs_w2), VBytes, VIndex);
- Inc(VIndex, 2);
- end;
- { TIdICMPEcho }
- function TIdICMPEcho.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4;
- end;
- procedure TIdICMPEcho.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fid := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- seq := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- end;
- procedure TIdICMPEcho.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(HostToLittleEndian(Fid), VBytes, VIndex);
- Inc(VIndex, 2);
- CopyTIdUInt16(HostToLittleEndian(seq), VBytes, VIndex);
- Inc(VIndex, 2);
- end;
- { TIdICMPFrag }
- function TIdICMPFrag.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4;
- end;
- procedure TIdICMPFrag.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fpad := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- Fmtu := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- end;
- procedure TIdICMPFrag.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(HostToLittleEndian(Fpad), VBytes, VIndex);
- Inc(VIndex, 2);
- CopyTIdUInt16(HostToLittleEndian(Fmtu), VBytes, VIndex);
- Inc(VIndex, 2);
- end;
- { TIdICMPTs }
- function TIdICMPTs.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 12;
- end;
- procedure TIdICMPTs.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fotime := BytesToUInt32(ABytes, VIndex); // time message was sent, to calc roundtrip time
- Inc(VIndex, 4);
- Frtime := BytesToUInt32(ABytes, VIndex);
- Inc(VIndex, 4);
- Fttime := BytesToUInt32(ABytes, VIndex);
- Inc(VIndex, 4);
- end;
- procedure TIdICMPTs.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(HostToLittleEndian(Fotime), VBytes, VIndex); // time message was sent, to calc roundtrip time
- Inc(VIndex, 4);
- CopyTIdUInt16(HostToLittleEndian(Frtime), VBytes, VIndex);
- Inc(VIndex, 4);
- CopyTIdUInt16(HostToLittleEndian(Fttime), VBytes, VIndex);
- Inc(VIndex, 4);
- end;
- { TIdicmp_hun }
- constructor TIdicmp_hun.Create;
- begin
- inherited Create;
- SetBytesLen(4);
- end;
- function TIdicmp_hun.Getecho_id: UInt16;
- begin
- Result := Getgateway_s_w1;
- end;
- procedure TIdicmp_hun.Setecho_id(const Value: UInt16);
- begin
- Setgateway_s_w1(Value);
- end;
- function TIdicmp_hun.Getecho_seq: UInt16;
- begin
- Result := Getgateway_s_w2;
- end;
- procedure TIdicmp_hun.Setecho_seq(const Value: UInt16);
- begin
- Setgateway_s_w2(Value);
- end;
- function TIdicmp_hun.Getgateway_s_w1: UInt16;
- begin
- Result := BytesToUInt32(FBuffer, 0);
- end;
- procedure TIdicmp_hun.Setgateway_s_w1(const Value: UInt16);
- begin
- CopyTIdUInt32(Value, FBuffer, 0);
- end;
- function TIdicmp_hun.Getgateway_s_w2: UInt16;
- begin
- Result := BytesToUInt16(FBuffer, 2);
- end;
- procedure TIdicmp_hun.Setgateway_s_w2(const Value: UInt16);
- begin
- CopyTIdUInt16(HostToLittleEndian(Value), FBuffer, 2);
- end;
- function TIdicmp_hun.Getgateway_s_b1: UInt8;
- begin
- Result := FBuffer[0];
- end;
- procedure TIdicmp_hun.Setgateway_s_b1(const Value: UInt8);
- begin
- FBuffer[0] := Value;
- end;
- function TIdicmp_hun.Getgateway_s_b2: UInt8;
- begin
- Result := FBuffer[1];
- end;
- procedure TIdicmp_hun.Setgateway_s_b2(const Value: UInt8);
- begin
- FBuffer[1] := Value;
- end;
- function TIdicmp_hun.Getgateway_s_b3: UInt8;
- begin
- Result := FBuffer[2];
- end;
- procedure TIdicmp_hun.Setgateway_s_b3(const Value: UInt8);
- begin
- FBuffer[2] := Value;
- end;
- function TIdicmp_hun.Getgateway_s_b4: UInt8;
- begin
- Result := FBuffer[3];
- end;
- procedure TIdicmp_hun.Setgateway_s_b4(const Value: UInt8);
- begin
- FBuffer[3] := Value;
- end;
- function TIdicmp_hun.Getgateway_s_l: UInt32;
- begin
- Result := BytesToUInt32(FBuffer, 0);
- end;
- procedure TIdicmp_hun.Setgateway_s_l(const Value: UInt32);
- begin
- CopyTIdUInt32(Value, FBuffer, 0);
- end;
- function TIdicmp_hun.Getfrag_pad: UInt16;
- begin
- Result := Getgateway_s_w1;
- end;
- procedure TIdicmp_hun.Setfrag_pad(const Value: UInt16);
- begin
- Setgateway_s_w1(Value);
- end;
- function TIdicmp_hun.Getfrag_mtu: UInt16;
- begin
- Result := Getgateway_s_w2;
- end;
- procedure TIdicmp_hun.Setfrag_mtu(const Value: UInt16);
- begin
- Setgateway_s_w2(Value);
- end;
- { TIdicmp_dun }
- constructor TIdicmp_dun.Create;
- begin
- inherited Create;
- SetBytesLen(12);
- end;
- function TIdicmp_dun.Getts_otime: TIdNetTime;
- begin
- Result := BytesToUInt32(FBuffer, 0);
- end;
- procedure TIdicmp_dun.Setts_otime(const Value: TIdNetTime);
- begin
- CopyTIdUInt32(Value, FBuffer, 0);
- end;
- function TIdicmp_dun.Getts_rtime: TIdNetTime;
- begin
- Result := BytesToUInt32(FBuffer, 4);
- end;
- procedure TIdicmp_dun.Setts_rtime(const Value: TIdNetTime);
- begin
- CopyTIdUInt32(Value, FBuffer, 4);
- end;
- function TIdicmp_dun.Getts_ttime: TIdNetTime;
- begin
- Result := BytesToUInt32(FBuffer, 4);
- end;
- procedure TIdicmp_dun.Setts_ttime(const Value: TIdNetTime);
- begin
- CopyTIdUInt32(Value, FBuffer, 8);
- end;
- function TIdicmp_dun.Getmask: UInt32;
- begin
- Result := Getts_otime;
- end;
- procedure TIdicmp_dun.Setmask(const Value: UInt32);
- begin
- Setts_otime(Value);
- end;
- function TIdicmp_dun.Getdata: UInt8;
- begin
- Result := FBuffer[0];
- end;
- procedure TIdicmp_dun.setdata(const Value: UInt8);
- begin
- FBuffer[0] := Value;
- end;
- { TIdICMPHdr }
- constructor TIdICMPHdr.Create;
- begin
- inherited Create;
- Ficmp_hun := TIdicmp_hun.Create;
- end;
- destructor TIdICMPHdr.Destroy;
- begin
- FreeAndNil(Ficmp_hun);
- inherited Destroy;
- end;
- function TIdICMPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4 + Ficmp_hun.BytesLen;
- end;
- procedure TIdICMPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Ficmp_type := ABytes[VIndex];
- Inc(VIndex);
- Ficmp_code := ABytes[Vindex];
- Inc(VIndex);
- Ficmp_sum := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- Ficmp_hun.ReadStruct(ABytes, VIndex);
- end;
- procedure TIdICMPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Ficmp_type;
- Inc(VIndex);
- VBytes[Vindex] := Ficmp_code;
- Inc(VIndex);
- CopyTIdUInt16(Ficmp_sum, VBytes, VIndex);
- Inc(VIndex, 2);
- Ficmp_hun.WriteStruct(VBytes, VIndex);
- end;
- { TIdIPOptions }
- constructor TIdIPOptions.Create;
- begin
- inherited Create;
- SetBytesLen(Id_MAX_IPOPTLEN);
- end;
- function TIdIPOptions.get_ipopt_list(Index: Integer): UInt8;
- begin
- Assert(Index < Id_MAX_IPOPTLEN, 'Out of range'); {do not localize}
- Result := FBuffer[Index];
- end;
- procedure TIdIPOptions.set_ipopt_list(Index: Integer; const Value: UInt8);
- begin
- Assert(Index < Id_MAX_IPOPTLEN, 'Out of range'); {do not localize}
- FBuffer[Index] := Value;
- end;
- { TIdIPHdr }
- constructor TIdIPHdr.Create;
- begin
- inherited Create;
- Fip_src := TIdInAddr.Create;
- Fip_dst := TIdInAddr.Create;
- end;
- destructor TIdIPHdr.Destroy;
- begin
- FreeAndNil(Fip_src);
- FreeAndNil(Fip_dst);
- inherited Destroy;
- end;
- function TIdIPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 12 + Fip_src.BytesLen + Fip_dst.BytesLen + 4;
- end;
- procedure TIdIPHdr.CopyFrom(const ASource: TIdIPHdr);
- begin
- Fip_verlen := ASource.ip_verlen;
- Fip_tos := ASource.ip_tos;
- Fip_len := ASource.ip_len;
- Fip_id := ASource.ip_id;
- Fip_off := ASource.ip_off;
- Fip_ttl := ASource.ip_ttl;
- Fip_p := ASource.ip_p;
- Fip_sum := ASource.ip_sum;
- Fip_src.CopyFrom(ASource.ip_src);
- Fip_dst.CopyFrom(ASource.ip_dst);
- Fip_options := ASource.ip_options;
- end;
- procedure TIdIPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- var LIpHeaderLen : UInt32;
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fip_verlen := ABytes[VIndex]; // 1st nibble version, 2nd nibble header length div 4 (little-endian)
- Inc(VIndex);
- LIpHeaderLen := (Fip_verlen and $0F) * 4;
- Fip_tos := ABytes[VIndex]; // type of service
- Inc(VIndex);
- Fip_len := BytesToUInt16(ABytes, VIndex); // total length
- Inc(VIndex, 2);
- Fip_id := BytesToUInt16(ABytes, VIndex); // identification
- Inc(VIndex, 2);
- Fip_off := BytesToUInt16(ABytes, VIndex); // 1st nibble flags, next 3 nibbles fragment offset (little-endian)
- Inc(VIndex, 2);
- Fip_ttl := ABytes[VIndex]; // time to live
- Inc(VIndex);
- Fip_p := ABytes[VIndex]; // protocol
- Inc(VIndex);
- Fip_sum := BytesToUInt16(ABytes, VIndex); // checksum
- Inc(VIndex, 2);
- Fip_src.ReadStruct(ABytes, VIndex); // source address
- Fip_dst.ReadStruct(ABytes, VIndex); // dest address
- //Fip_options may not be present in the packet
- if VIndex >= LIpHeaderLen then
- begin
- Fip_options := BytesToUInt32(ABytes, VIndex); // options + padding
- end;
- //be sure that we indicate we read the entire packet in case
- //the size varies.
- VIndex := LIpHeaderLen;
- end;
- procedure TIdIPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Fip_verlen; // 1st nibble version, 2nd nibble header length div 4 (little-endian)
- Inc(VIndex);
- VBytes[VIndex] := Fip_tos; // type of service
- Inc(VIndex);
- CopyTIdUInt16(Fip_len, VBytes, VIndex); // total length
- Inc(VIndex, 2);
- CopyTIdUInt16(Fip_id, VBytes, VIndex); // identification
- Inc(VIndex, 2);
- CopyTIdUInt16(Fip_off, VBytes, VIndex); // 1st nibble flags, next 3 nibbles fragment offset (little-endian)
- Inc(VIndex, 2);
- Fip_ttl := VBytes[VIndex]; // time to live
- Inc(VIndex);
- Fip_p := VBytes[VIndex]; // protocol
- Inc(VIndex);
- CopyTIdUInt16(Fip_sum, VBytes, VIndex); // checksum
- Inc(VIndex, 2);
- Fip_src.WriteStruct(VBytes, VIndex); // source address
- Fip_dst.WriteStruct(VBytes, VIndex); // dest address
- CopyTIdUInt32(Fip_options, VBytes, VIndex); // options + padding
- Inc(VIndex, 4);
- end;
- { TIdTCPOptions }
- constructor TIdTCPOptions.Create;
- begin
- inherited Create;
- SetBytesLen(Id_MAX_IPOPTLEN);
- end;
- function TIdTCPOptions.gettcpopt_list(Index: Integer): UInt8;
- begin
- Assert(Index < Id_MAX_IPOPTLEN, 'Out of range');
- Result := FBuffer[Index];
- end;
- procedure TIdTCPOptions.settcpopt_list(Index: Integer; const Value: UInt8);
- begin
- Assert(Index < Id_MAX_IPOPTLEN, 'Out of range');
- FBuffer[Index] := Value;
- end;
- { TIdTCPHdr }
- function TIdTCPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 20;
- end;
- procedure TIdTCPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Ftcp_sport := BytesToUInt16(ABytes, VIndex); // source port
- Inc(VIndex, 2);
- Ftcp_dport := BytesToUInt16(ABytes, VIndex); // destination port
- Inc(VIndex, 2);
- Ftcp_seq := BytesToUInt32(ABytes, VIndex); // sequence number
- Inc(VIndex, 4);
- Ftcp_ack := BytesToUInt32(ABytes, VIndex); // acknowledgement number
- Inc(VIndex, 4);
- Ftcp_x2off := ABytes[VIndex]; // data offset
- Inc(VIndex);
- Ftcp_flags := ABytes[VIndex]; // control flags
- Inc(VIndex);
- Ftcp_win := BytesToUInt16(ABytes, VIndex); // window
- Inc(VIndex, 2);
- Ftcp_sum := BytesToUInt16(ABytes, VIndex); // checksum
- Inc(VIndex, 2);
- Ftcp_urp := BytesToUInt16(ABytes, VIndex); // urgent pointer
- Inc(VIndex, 2);
- end;
- procedure TIdTCPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(Ftcp_sport, VBytes, VIndex); // source port
- Inc(VIndex, 2);
- CopyTIdUInt16(Ftcp_dport, VBytes, VIndex); // destination port
- Inc(VIndex, 2);
- CopyTIdUInt32(Ftcp_seq, VBytes, VIndex); // sequence number
- Inc(VIndex, 4);
- CopyTIdUInt32(Ftcp_ack, VBytes, VIndex); // acknowledgement number
- Inc(VIndex, 4);
- VBytes[VIndex] := Ftcp_x2off; // data offset
- Inc(VIndex);
- VBytes[VIndex] := Ftcp_flags; // control flags
- Inc(VIndex);
- CopyTIdUInt16(Ftcp_win, VBytes, VIndex); // window
- Inc(VIndex, 2);
- CopyTIdUInt16(Ftcp_sum, VBytes, VIndex); // checksum
- Inc(VIndex, 2);
- CopyTIdUInt16(Ftcp_urp, VBytes, VIndex); // urgent pointer
- Inc(VIndex, 2);
- end;
- { TIdUDPHdr }
- function TIdUDPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 8;
- end;
- procedure TIdUDPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fudp_sport := BytesToUInt16(ABytes, VIndex); // source port
- Inc(VIndex, 2);
- Fudp_dport := BytesToUInt16(ABytes, VIndex); // destination port
- Inc(VIndex, 2);
- Fudp_ulen := BytesToUInt16(ABytes, VIndex); // length
- Inc(VIndex, 2);
- Fudp_sum := BytesToUInt16(ABytes, VIndex); // checksum
- Inc(VIndex, 2);
- end;
- procedure TIdUDPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(Fudp_sport, VBytes, VIndex); // source port
- Inc(VIndex, 2);
- CopyTIdUInt16(Fudp_dport, VBytes, VIndex); // destination port
- Inc(VIndex, 2);
- CopyTIdUInt16(Fudp_ulen, VBytes, VIndex); // length
- Inc(VIndex, 2);
- CopyTIdUInt16(Fudp_sum, VBytes, VIndex); // checksum
- Inc(VIndex, 2);
- end;
- { TIdIGMPHdr }
- constructor TIdIGMPHdr.Create;
- begin
- inherited Create;
- Figmp_group := TIdInAddr.Create;
- end;
- destructor TIdIGMPHdr.Destroy;
- begin
- FreeAndNil(Figmp_group);
- inherited Destroy;
- end;
- function TIdIGMPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4 + Figmp_group.BytesLen;
- end;
- procedure TIdIGMPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Figmp_type := ABytes[VIndex];
- Inc(VIndex);
- Figmp_code := ABytes[VIndex];
- Inc(VIndex);
- Figmp_sum := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- Figmp_group.ReadStruct(ABytes, VIndex);
- end;
- procedure TIdIGMPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Figmp_type;
- Inc(VIndex);
- VBytes[VIndex] := Figmp_code;
- Inc(VIndex);
- CopyTIdUInt16(Figmp_sum, VBytes, VIndex);
- Inc(VIndex, 2);
- Figmp_group.WriteStruct(VBytes, VIndex);
- end;
- { TIdEtherAddr }
- constructor TIdEtherAddr.Create;
- begin
- inherited Create;
- SetBytesLen(Id_ETHER_ADDR_LEN);
- end;
- procedure TIdEtherAddr.setether_addr_octet(Index: Integer; const Value: UInt8);
- begin
- Assert(Index < Id_ETHER_ADDR_LEN, 'Out of range');
- FBuffer[Index] := Value;
- end;
- function TIdEtherAddr.getether_addr_octet(Index: Integer): UInt8;
- begin
- Assert(Index < Id_ETHER_ADDR_LEN, 'Out of range');
- Result := FBuffer[Index];
- end;
- procedure TIdEtherAddr.CopyFrom(const ASource: TIdEtherAddr);
- begin
- SetData(ASource.Data);
- end;
- procedure TIdEtherAddr.SetData(const Value: TIdBytes);
- begin
- CopyTIdBytes(Value, 0, FBuffer, 0, Id_ETHER_ADDR_LEN);
- end;
- { TIdEthernetHdr }
- constructor TIdEthernetHdr.Create;
- begin
- inherited Create;
- Fether_dhost := TIdEtherAddr.Create;
- Fether_shost := TIdEtherAddr.Create;
- end;
- destructor TIdEthernetHdr.Destroy;
- begin
- FreeAndNil(Fether_dhost);
- FreeAndNil(Fether_shost);
- inherited Destroy;
- end;
- function TIdEthernetHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + Fether_dhost.BytesLen + Fether_shost.BytesLen + 2;
- end;
- procedure TIdEthernetHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fether_dhost.ReadStruct(ABytes, VIndex); // destination ethernet address
- Fether_shost.ReadStruct(ABytes, VIndex); // source ethernet address
- Fether_type := BytesToUInt16(ABytes, VIndex); // packet type ID
- Inc(VIndex, 2);
- end;
- procedure TIdEthernetHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- Fether_dhost.WriteStruct(VBytes, VIndex); // destination ethernet address
- Fether_shost.WriteStruct(VBytes, VIndex); // source ethernet address
- CopyTIdUInt16(Fether_type, VBytes, VIndex); // packet type ID
- Inc(VIndex, 2);
- end;
- procedure TIdEthernetHdr.CopyFrom(const ASource: TIdEthernetHdr);
- begin
- Fether_dhost.CopyFrom(ASource.Fether_dhost);
- Fether_shost.CopyFrom(ASource.Fether_shost);
- Fether_type := ASource.Fether_type;
- end;
- { TIdARPHdr }
- constructor TIdARPHdr.Create;
- begin
- inherited Create;
- Farp_sha := TIdEtherAddr.Create; // sender hardware address
- Farp_spa := TIdInAddr.Create; // sender protocol address
- Farp_tha := TIdEtherAddr.Create; // target hardware address
- Farp_tpa := TIdInAddr.Create; // target protocol address
- end;
- destructor TIdARPHdr.Destroy;
- begin
- FreeAndNil(Farp_sha);
- FreeAndNil(Farp_spa);
- FreeAndNil(Farp_tha);
- FreeAndNil(Farp_tpa);
- inherited Destroy;
- end;
- function TIdARPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 8 + Farp_sha.BytesLen + Farp_spa.BytesLen + Farp_tha.BytesLen + Farp_tpa.BytesLen;
- end;
- procedure TIdARPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Farp_hrd := BytesToUInt16(ABytes, VIndex); // format of hardware address
- Inc(VIndex, 2);
- Farp_pro := BytesToUInt16(ABytes, VIndex); // format of protocol address
- Inc(VIndex, 2);
- Farp_hln := ABytes[VIndex]; // length of hardware address
- Inc(VIndex);
- Farp_pln := ABytes[VIndex]; // length of protocol addres
- Inc(VIndex);
- Farp_op := BytesToUInt16(ABytes, VIndex); // operation type
- Inc(VIndex, 2);
- // following hardcoded for ethernet/IP
- Farp_sha.ReadStruct(ABytes, VIndex); // sender hardware address
- Farp_spa.ReadStruct(ABytes, VIndex); // sender protocol address
- Farp_tha.ReadStruct(ABytes, VIndex); // target hardware address
- Farp_tpa.ReadStruct(ABytes, VIndex); // target protocol address
- end;
- procedure TIdARPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(Farp_hrd, VBytes, VIndex); // format of hardware address
- Inc(VIndex, 2);
- CopyTIdUInt16(Farp_pro, VBytes, VIndex); // format of protocol address
- Inc(VIndex, 2);
- VBytes[VIndex] := Farp_hln; // length of hardware address
- Inc(VIndex);
- VBytes[VIndex] := Farp_pln; // length of protocol addres
- Inc(VIndex);
- CopyTIdUInt16(Farp_op, VBytes, VIndex); // operation type
- Inc(VIndex, 2);
- // following hardcoded for ethernet/IP
- Farp_sha.WriteStruct(VBytes, VIndex); // sender hardware address
- Farp_spa.WriteStruct(VBytes, VIndex); // sender protocol address
- Farp_tha.WriteStruct(VBytes, VIndex); // target hardware address
- Farp_tpa.WriteStruct(VBytes, VIndex); // target protocol address
- end;
- { TIdDNSHdr }
- function TIdDNSHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 12;
- end;
- procedure TIdDNSHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Fdns_id := BytesToUInt16(ABytes, VIndex); // DNS packet ID
- Inc(VIndex, 2);
- Fdns_flags := BytesToUInt16(ABytes, VIndex); // DNS flags
- Inc(VIndex, 2);
- Fdns_num_q := BytesToUInt16(ABytes, VIndex); // number of questions
- Inc(VIndex, 2);
- Fdns_num_answ_rr := BytesToUInt16(ABytes, VIndex);// number of answer resource records
- Inc(VIndex, 2);
- Fdns_num_auth_rr := BytesToUInt16(ABytes, VIndex); // number of authority resource records
- Inc(VIndex, 2);
- Fdns_num_addi_rr := BytesToUInt16(ABytes, VIndex); // number of additional resource records
- Inc(VIndex, 2);
- end;
- procedure TIdDNSHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- CopyTIdUInt16(Fdns_id, VBytes, VIndex); // DNS packet ID
- Inc(VIndex, 2);
- CopyTIdUInt16(Fdns_flags, VBytes, VIndex); // DNS flags
- Inc(VIndex, 2);
- CopyTIdUInt16(Fdns_num_q, VBytes, VIndex); // number of questions
- Inc(VIndex, 2);
- CopyTIdUInt16(Fdns_num_answ_rr, VBytes, VIndex); // number of answer resource records
- Inc(VIndex, 2);
- CopyTIdUInt16(Fdns_num_auth_rr, VBytes, VIndex); // number of authority resource records
- Inc(VIndex, 2);
- CopyTIdUInt16(Fdns_num_addi_rr, VBytes, VIndex); // number of additional resource records
- Inc(VIndex, 2);
- end;
- { TIdRIPHdr }
- function TIdRIPHdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 24;
- end;
- procedure TIdRIPHdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Frip_cmd := ABytes[VIndex]; // RIP command
- Inc(VIndex);
- Frip_ver := ABytes[VIndex]; // RIP version
- Inc(VIndex);
- Frip_rd := BytesToUInt16(ABytes, VIndex); // zero (v1) or routing domain (v2)
- Inc(VIndex, 2);
- Frip_af := BytesToUInt16(ABytes, VIndex); // address family
- Inc(VIndex, 2);
- Frip_rt := BytesToUInt16(ABytes, VIndex); // zero (v1) or route tag (v2)
- Inc(VIndex, 2);
- Frip_addr := BytesToUInt32(ABytes, VIndex); // IP address
- Inc(VIndex, 4);
- Frip_mask := BytesToUInt32(ABytes, VIndex); // zero (v1) or subnet mask (v2)
- Inc(VIndex, 4);
- Frip_next_hop := BytesToUInt32(ABytes, VIndex); // zero (v1) or next hop IP address (v2)
- Inc(VIndex, 4);
- Frip_metric := BytesToUInt32(ABytes, VIndex); // metric
- Inc(VIndex, 4);
- end;
- procedure TIdRIPHdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Frip_cmd; // RIP command
- Inc(VIndex);
- VBytes[VIndex] := Frip_ver; // RIP version
- Inc(VIndex);
- CopyTIdUInt16(Frip_rd, VBytes, VIndex); // zero (v1) or routing domain (v2)
- Inc(VIndex, 2);
- CopyTIdUInt16(Frip_af, VBytes, VIndex); // address family
- Inc(VIndex, 2);
- CopyTIdUInt16(Frip_rt, VBytes, VIndex); // zero (v1) or route tag (v2)
- Inc(VIndex, 2);
- CopyTIdUInt32(Frip_addr, VBytes, VIndex); // IP address
- Inc(VIndex, 4);
- CopyTIdUInt32(Frip_mask, VBytes, VIndex); // zero (v1) or subnet mask (v2)
- Inc(VIndex, 4);
- CopyTIdUInt32(Frip_next_hop, VBytes, VIndex); // zero (v1) or next hop IP address (v2)
- Inc(VIndex, 4);
- CopyTIdUInt32(Frip_metric, VBytes, VIndex); // metric
- Inc(VIndex, 4);
- end;
- { TIdInAddr }
- procedure TIdInAddr.CopyFrom(const ASource: TIdInAddr);
- begin
- s_l := ASource.s_l;
- end;
- { TIdicmp6_un }
- constructor TIdicmp6_un.Create;
- begin
- inherited Create;
- SetBytesLen(4);
- end;
- function TIdicmp6_un.Geticmp6_un_data16(Index: Integer): UInt16;
- begin
- Result := 0;
- case Index of
- 0 : Result := BytesToUInt16(FBuffer, 0);
- 1 : Result := BytesToUInt16(FBuffer, 2);
- end;
- end;
- procedure TIdicmp6_un.Seticmp6_un_data16(Index: Integer; const Value: UInt16);
- begin
- case Index of
- 0 : CopyTIdUInt16(Value, FBuffer, 0);
- 1 : CopyTIdUInt16(Value, FBuffer, 2);
- end;
- end;
- function TIdicmp6_un.Geticmp6_un_data32: UInt32;
- begin
- Result := BytesToUInt32(FBuffer, 0);
- end;
- procedure TIdicmp6_un.Seticmp6_un_data32(const Value: UInt32);
- begin
- CopyTIdUInt32(Value, FBuffer, 0);
- end;
- function TIdicmp6_un.Geticmp6_un_data8(Index: Integer): UInt8;
- begin
- Assert((Index>-1) and (Index<4), 'Out of range');
- Result := FBuffer[Index];
- end;
- procedure TIdicmp6_un.Seticmp6_un_data8(Index: Integer; const Value: UInt8);
- begin
- Assert((Index>-1) and (Index<4), 'Out of range');
- FBuffer[Index] := Value;
- end;
- function TIdicmp6_un.Geticmp6_data8: UInt8;
- begin
- Result := FBuffer[0];
- end;
- procedure TIdicmp6_un.Seticmp6_data8(const Value: UInt8);
- begin
- FBuffer[0] := Value;
- end;
- function TIdicmp6_un.Geticmp6_data16: UInt16;
- begin
- Result := BytesToUInt16(FBuffer, 0);
- end;
- procedure TIdicmp6_un.Seticmp6_data16(const Value: UInt16);
- begin
- CopyTIdUInt16(Value, FBuffer, 0);
- end;
- function TIdicmp6_un.Geticmp6_seq: UInt16;
- begin
- Result := Geticmp6_un_data16(1);
- end;
- procedure TIdicmp6_un.Seticmp6_seq(const Value: UInt16);
- begin
- Seticmp6_un_data16(1, Value);
- end;
- { TIdicmp6_hdr }
- constructor TIdicmp6_hdr.Create;
- begin
- inherited Create;
- Fdata := TIdicmp6_un.Create;
- end;
- destructor TIdicmp6_hdr.Destroy;
- begin
- FreeAndNil(Fdata);
- inherited Destroy;
- end;
- function TIdicmp6_hdr.GetBytesLen: UInt32;
- begin
- Result := inherited GetBytesLen + 4 + Fdata.BytesLen;
- end;
- procedure TIdicmp6_hdr.ReadStruct(const ABytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited ReadStruct(ABytes, VIndex);
- Ficmp6_type := ABytes[VIndex];
- Inc(VIndex);
- FIcmp6_code := ABytes[VIndex];
- Inc(VIndex);
- Ficmp6_cksum := BytesToUInt16(ABytes, VIndex);
- Inc(VIndex, 2);
- Fdata.ReadStruct(ABytes, VIndex);
- end;
- procedure TIdicmp6_hdr.WriteStruct(var VBytes: TIdBytes; var VIndex: UInt32);
- begin
- inherited WriteStruct(VBytes, VIndex);
- VBytes[VIndex] := Ficmp6_type;
- Inc(VIndex);
- VBytes[VIndex] := FIcmp6_code;
- Inc(VIndex);
- CopyTIdUInt16(Ficmp6_cksum, VBytes, VIndex);
- Inc(VIndex, 2);
- Fdata.WriteStruct(VBytes, VIndex);
- end;
- end.
|