Documentation ¶
Overview ¶
@@ @ Author : Eacher @ Date : 2023-07-01 15:19:37 @ LastEditTime : 2023-09-04 09:40:23 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/arp.go @@
@@ @ Author : Eacher @ Date : 2023-07-04 08:48:44 @ LastEditTime : 2023-09-04 09:40:22 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/dhcpv4.go @@
@@ @ Author : Eacher @ Date : 2023-07-13 14:02:39 @ LastEditTime : 2023-09-04 09:40:21 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/ethernet.go @@
@@ @ Author : Eacher @ Date : 2023-07-13 15:20:40 @ LastEditTime : 2023-09-04 09:40:25 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/ipv4.go @@
@@ @ Author : Eacher @ Date : 2023-07-01 15:20:41 @ LastEditTime : 2023-09-04 09:40:28 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/netlink.go @@
@@ @ Author : Eacher @ Date : 2023-07-14 08:11:29 @ LastEditTime : 2023-09-04 09:40:14 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/tcp.go @@
@@ @ Author : Eacher @ Date : 2023-07-13 16:56:05 @ LastEditTime : 2023-09-04 09:40:16 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/udp.go @@
Index ¶
- Constants
- Variables
- type ArpPacket
- type DHCP_IPv4_TYPE
- type DHCP_Message_Type
- type DHCP_NetBIOS_Node_Type
- type DHCP_STRING_TYPE
- type DHCP_TIME_TYPE
- type DUPPacket
- type DhcpV4Packet
- type EthernetPacket
- type HardwareAddr
- type IPv4
- type IPv4Packet
- type IfAddrmsg
- type IfInfomsg
- type NlMsgerr
- type NlMsghdr
- type OptionsPacket
- func NewOptionsPacket(b []byte) (list []OptionsPacket)
- func SetDHCPIPv4(t DHCP_IPv4_TYPE, ip ...IPv4) OptionsPacket
- func SetDHCPMaximumMessageSize(size uint16) OptionsPacket
- func SetDHCPMessage(t DHCP_Message_Type) OptionsPacket
- func SetDHCPNetBIOSNodeType(t DHCP_NetBIOS_Node_Type) OptionsPacket
- func SetDHCPOptionsRequestList(codes ...uint8) OptionsPacket
- func SetDHCPString(t DHCP_STRING_TYPE, s string) OptionsPacket
- func SetDHCPTime(t DHCP_TIME_TYPE, d time.Duration) OptionsPacket
- type RtMsg
- type TCPPacket
Constants ¶
const ( ARP_ETHERNETTYPE = 0x01 ARP_REQUEST = 0x01 ARP_REPLY = 0x02 SizeofArpPacket = 0x1c )
Also define the following values (to be discussed later): ares_hrd$Ethernet (= 1), ares_op$REQUEST (= 1, high byte transmitted first) ares_op$REPLY (= 2).
const ( DHCP_ServerPort = 0x43 DHCP_ClientPort = 0x44 DHCP_BOOTREQUEST = 0x01 DHCP_BOOTREPLY = 0x02 DHCP_Ethernet_TYPE = 0x01 DHCP_Ethernet_LEN = 0x06 SizeofDhcpV4Packet = 0xf0 SizeofOptionsPacket = 0x02 )
const ( SizeofNlMsghdr = syscall.SizeofNlMsghdr SizeofRtAttr = syscall.SizeofRtAttr SizeofNlMsgerr = syscall.SizeofNlMsgerr SizeofIfAddrmsg = syscall.SizeofIfAddrmsg SizeofRtMsg = syscall.SizeofRtMsg SizeofIfInfomsg = syscall.SizeofIfInfomsg )
const (
SizeofDUPPacket = 0x08
)
const (
SizeofEthernetPacket = 0x0e
)
const (
SizeofIPv4Packet = 0x14
)
const (
SizeofTCPPacket = 0x14
)
Variables ¶
var Broadcast = HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
var MagicCookie = [4]byte{99, 130, 83, 99}
Functions ¶
This section is empty.
Types ¶
type ArpPacket ¶
type ArpPacket struct { HardwareType uint16 ProtocolType uint16 HardwareLen uint8 IPLen uint8 Operation uint16 SendHardware HardwareAddr SendIP IPv4 TargetHardware HardwareAddr TargetIP IPv4 }
Ethernet transmission layer (not necessarily accessible to the user): // 14.byte EthernetPacket 2.byte 16.bit: (ar$hrd) Hardware address space (e.g., Ethernet, Packet Radio Net.) 2.byte 16.bit: (ar$pro) Protocol address space. For Ethernet hardware, this is from the set of type fields ether_typ$<protocol>. 1.byte 8.bit: (ar$hln) byte length of each hardware address 1.byte 8.bit: (ar$pln) byte length of each protocol address 2.byte 16.bit: (ar$op) opcode (ares_op$REQUEST | ares_op$REPLY) nbytes: (ar$sha) Hardware address of sender of this packet, n from the ar$hln field. mbytes: (ar$spa) Protocol address of sender of this packet, m from the ar$pln field. nbytes: (ar$tha) Hardware address of target of this packet (if known). mbytes: (ar$tpa) Protocol address of target.
func NewArpPacket ¶
func NewArpPacket(b [SizeofArpPacket]byte) (arp ArpPacket)
func (ArpPacket) WireFormat ¶
type DHCP_IPv4_TYPE ¶
type DHCP_IPv4_TYPE uint8
3.3. Subnet Mask
The subnet mask option specifies the client's subnet mask as per RFC 950 [5]. If both the subnet mask and the router option are specified in a DHCP reply, the subnet mask option MUST be first. The code for the subnet mask option is 1, and its length is 4 octets. Code Len Subnet Mask +-----+-----+-----+-----+-----+-----+ | 1 | 4 | m1 | m2 | m3 | m4 | +-----+-----+-----+-----+-----+-----+
3.5. Router Option
The router option specifies a list of IP addresses for routers on the client's subnet. Routers SHOULD be listed in order of preference. The code for the router option is 3. The minimum length for the router option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 3 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.6. Time Server Option
The time server option specifies a list of RFC 868 [6] time servers available to the client. Servers SHOULD be listed in order of preference. The code for the time server option is 4. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 4 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.7. Name Server Option
The name server option specifies a list of IEN 116 [7] name servers available to the client. Servers SHOULD be listed in order of preference. The code for the name server option is 5. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 5 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.8. Domain Name Server Option
The domain name server option specifies a list of Domain Name System (STD 13, RFC 1035 [8]) name servers available to the client. Servers SHOULD be listed in order of preference. The code for the domain name server option is 6. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 6 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.9. Log Server Option
The log server option specifies a list of MIT-LCS UDP log servers available to the client. Servers SHOULD be listed in order of preference. The code for the log server option is 7. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 7 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.10. Cookie Server Option
The cookie server option specifies a list of RFC 865 [9] cookie servers available to the client. Servers SHOULD be listed in order of preference. The code for the log server option is 8. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 8 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.11. LPR Server Option
The LPR server option specifies a list of RFC 1179 [10] line printer servers available to the client. Servers SHOULD be listed in order of preference. The code for the LPR server option is 9. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 9 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.12. Impress Server Option
The Impress server option specifies a list of Imagen Impress servers available to the client. Servers SHOULD be listed in order of preference. The code for the Impress server option is 10. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 10 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
3.13. Resource Location Server Option
This option specifies a list of RFC 887 [11] Resource Location servers available to the client. Servers SHOULD be listed in order of preference. The code for this option is 11. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 11 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.2. Network Information Servers Option
This option specifies a list of IP addresses indicating NIS servers available to the client. Servers SHOULD be listed in order of preference. The code for this option is 41. Its minimum length is 4, and the length MUST be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 41 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.3. Network Time Protocol Servers Option
This option specifies a list of IP addresses indicating NTP [18] servers available to the client. Servers SHOULD be listed in order of preference. The code for this option is 42. Its minimum length is 4, and the length MUST be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 42 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.5. NetBIOS over TCP/IP Name Server Option
The NetBIOS name server (NBNS) option specifies a list of RFC 1001/1002 [19] [20] NBNS name servers listed in order of preference. The code for this option is 44. The minimum length of the option is 4 octets, and the length must always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+---- | 44 | n | a1 | a2 | a3 | a4 | b1 | b2 | b3 | b4 | ... +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
8.6. NetBIOS over TCP/IP Datagram Distribution Server Option
The NetBIOS datagram distribution server (NBDD) option specifies a list of RFC 1001/1002 NBDD servers listed in order of preference. The code for this option is 45. The minimum length of the option is 4 octets, and the length must always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+---- | 45 | n | a1 | a2 | a3 | a4 | b1 | b2 | b3 | b4 | ... +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----
8.9. X Window System Font Server Option
This option specifies a list of X Window System [21] Font servers available to the client. Servers SHOULD be listed in order of preference. The code for this option is 48. The minimum length of this option is 4 octets, and the length MUST be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+--- | 48 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+---
8.10. X Window System Display Manager Option
This option specifies a list of IP addresses of systems that are running the X Window System Display Manager and are available to the client. Addresses SHOULD be listed in order of preference. The code for the this option is 49. The minimum length of this option is 4, and the length MUST be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+--- | 49 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+---
8.12. Network Information Service+ Servers Option
This option specifies a list of IP addresses indicating NIS+ servers available to the client. Servers SHOULD be listed in order of preference. The code for this option is 65. Its minimum length is 4, and the length MUST be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 65 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.13. Mobile IP Home Agent option
This option specifies a list of IP addresses indicating mobile IP home agents available to the client. Agents SHOULD be listed in order of preference. The code for this option is 68. Its minimum length is 0 (indicating no home agents are available) and the length MUST be a multiple of 4. It is expected that the usual length will be four octets, containing a single home agent's address. Code Len Home Agent Addresses (zero or more) +-----+-----+-----+-----+-----+-----+-- | 68 | n | a1 | a2 | a3 | a4 | ... +-----+-----+-----+-----+-----+-----+--
8.14. Simple Mail Transport Protocol (SMTP) Server Option
The SMTP server option specifies a list of SMTP servers available to the client. Servers SHOULD be listed in order of preference. The code for the SMTP server option is 69. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 69 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.15. Post Office Protocol (POP3) Server Option
The POP3 server option specifies a list of POP3 available to the client. Servers SHOULD be listed in order of preference. The code for the POP3 server option is 70. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 70 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.16. Network News Transport Protocol (NNTP) Server Option
The NNTP server option specifies a list of NNTP available to the client. Servers SHOULD be listed in order of preference. The code for the NNTP server option is 71. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 71 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.17. Default World Wide Web (WWW) Server Option
The WWW server option specifies a list of WWW available to the client. Servers SHOULD be listed in order of preference. The code for the WWW server option is 72. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 72 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.18. Default Finger Server Option
The Finger server option specifies a list of Finger available to the client. Servers SHOULD be listed in order of preference. The code for the Finger server option is 73. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 73 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.19. Default Internet Relay Chat (IRC) Server Option
The IRC server option specifies a list of IRC available to the client. Servers SHOULD be listed in order of preference. The code for the IRC server option is 74. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 74 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.20. StreetTalk Server Option
The StreetTalk server option specifies a list of StreetTalk servers available to the client. Servers SHOULD be listed in order of preference. The code for the StreetTalk server option is 75. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 75 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
8.21. StreetTalk Directory Assistance (STDA) Server Option
The StreetTalk Directory Assistance (STDA) server option specifies a list of STDA servers available to the client. Servers SHOULD be listed in order of preference. The code for the StreetTalk Directory Assistance server option is 76. The minimum length for this option is 4 octets, and the length MUST always be a multiple of 4. Code Len Address 1 Address 2 +-----+-----+-----+-----+-----+-----+-----+-----+-- | 76 | n | a1 | a2 | a3 | a4 | a1 | a2 | ... +-----+-----+-----+-----+-----+-----+-----+-----+--
9.1. Requested IP Address
This option is used in a client request (DHCPDISCOVER) to allow the client to request that a particular IP address be assigned. The code for this option is 50, and its length is 4. Code Len Address +-----+-----+-----+-----+-----+-----+ | 50 | 4 | a1 | a2 | a3 | a4 | +-----+-----+-----+-----+-----+-----+
9.7. Server Identifier
This option is used in DHCPOFFER and DHCPREQUEST messages, and may optionally be included in the DHCPACK and DHCPNAK messages. DHCP servers include this option in the DHCPOFFER in order to allow the client to distinguish between lease offers. DHCP clients use the contents of the 'server identifier' field as the destination address for any DHCP messages unicast to the DHCP server. DHCP clients also indicate which of several lease offers is being accepted by including this option in a DHCPREQUEST message. The identifier is the IP address of the selected server. The code for this option is 54, and its length is 4. Code Len Address +-----+-----+-----+-----+-----+-----+ | 54 | 4 | a1 | a2 | a3 | a4 | +-----+-----+-----+-----+-----+-----+
const ( DHCP_Subnet_Mask DHCP_IPv4_TYPE = iota + 1 DHCP_Router DHCP_Time_Server DHCP_Name_Server DHCP_Domain_Name_Server DHCP_Log_Server DHCP_Cookie_Server DHCP_LPR_Server DHCP_Impress_Server DHCP_Resource_Location_Server )
const ( DHCP_Information_Servers DHCP_IPv4_TYPE = iota + 41 DHCP_Protocol_Servers DHCP_NetBIOS_Name_Server DHCP_NetBIOS_Distribution_Server DHCP_Window_System_Server DHCP_Window_System_Display_Manager DHCP_Requested_IP_Address DHCP_Server_Identifier )
const ( DHCP_Network_Information_Service_Servers DHCP_IPv4_TYPE = iota + 65 DHCP_Mobile_IP_Home_Agent DHCP_SMTP_Server DHCP_POP3_Server DHCP_NNTP_Server DHCP_WWW_Server DHCP_Default_Finger_Server DHCP_IRC_Server DHCP_StreetTalk_Server DHCP_STDA_Server )
type DHCP_Message_Type ¶
type DHCP_Message_Type uint8
9.6. DHCP Message Type
This option is used to convey the type of the DHCP message. The code for this option is 53, and its length is 1. Legal values for this option are: Value Message Type ----- ------------ 1 DHCPDISCOVER 2 DHCPOFFER 3 DHCPREQUEST 4 DHCPDECLINE 5 DHCPACK 6 DHCPNAK 7 DHCPRELEASE 8 DHCPINFORM
const ( DHCP_DISCOVER DHCP_Message_Type = iota + 1 DHCP_OFFER DHCP_REQUEST DHCP_DECLINE DHCP_ACK DHCP_NAK DHCP_RELEASE DHCP_INFORM )
type DHCP_NetBIOS_Node_Type ¶
type DHCP_NetBIOS_Node_Type uint8
8.7. NetBIOS over TCP/IP Node Type Option
The NetBIOS node type option allows NetBIOS over TCP/IP clients which are configurable to be configured as described in RFC 1001/1002. The value is specified as a single octet which identifies the client type as follows: Value Node Type ----- --------- 0x1 B-node 0x2 P-node 0x4 M-node 0x8 H-node
const ( DHCP_B_node DHCP_NetBIOS_Node_Type = iota + 1 DHCP_P_node DHCP_M_node DHCP_H_node )
type DHCP_STRING_TYPE ¶
type DHCP_STRING_TYPE uint8
8.1. Network Information Service Domain Option
This option specifies the name of the client's NIS [17] domain. The domain is formatted as a character string consisting of characters from the NVT ASCII character set. The code for this option is 40. Its minimum length is 1. Code Len NIS Domain Name +-----+-----+-----+-----+-----+-----+--- | 40 | n | n1 | n2 | n3 | n4 | ... +-----+-----+-----+-----+-----+-----+---
8.8. NetBIOS over TCP/IP Scope Option
The NetBIOS scope option specifies the NetBIOS over TCP/IP scope parameter for the client as specified in RFC 1001/1002. See [19], [20], and [8] for character-set restrictions. The code for this option is 47. The minimum length of this option is 1. Code Len NetBIOS Scope +-----+-----+-----+-----+-----+-----+---- | 47 | n | s1 | s2 | s3 | s4 | ... +-----+-----+-----+-----+-----+-----+----
8.11. Network Information Service+ Domain Option
This option specifies the name of the client's NIS+ [17] domain. The domain is formatted as a character string consisting of characters from the NVT ASCII character set. The code for this option is 64. Its minimum length is 1. Code Len NIS Client Domain Name +-----+-----+-----+-----+-----+-----+--- | 64 | n | n1 | n2 | n3 | n4 | ... +-----+-----+-----+-----+-----+-----+---
9.4 TFTP server name
This option is used to identify a TFTP server when the 'sname' field in the DHCP header has been used for DHCP options. The code for this option is 66, and its minimum length is 1. Code Len TFTP server +-----+-----+-----+-----+-----+--- | 66 | n | c1 | c2 | c3 | ... +-----+-----+-----+-----+-----+---
9.5 Bootfile name
This option is used to identify a bootfile when the 'file' field in the DHCP header has been used for DHCP options. The code for this option is 67, and its minimum length is 1. Code Len Bootfile name +-----+-----+-----+-----+-----+--- | 67 | n | c1 | c2 | c3 | ... +-----+-----+-----+-----+-----+---
9.9. Message
This option is used by a DHCP server to provide an error message to a DHCP client in a DHCPNAK message in the event of a failure. A client may use this option in a DHCPDECLINE message to indicate the why the client declined the offered parameters. The message consists of n octets of NVT ASCII text, which the client may display on an available output device. The code for this option is 56 and its minimum length is 1. Code Len Text +-----+-----+-----+-----+--- | 56 | n | c1 | c2 | ... +-----+-----+-----+-----+---
9.13. Vendor class identifier
This option is used by DHCP clients to optionally identify the vendor type and configuration of a DHCP client. The information is a string of n octets, interpreted by servers. Vendors may choose to define specific vendor class identifiers to convey particular configuration or other identification information about a client. For example, the identifier may encode the client's hardware configuration. Servers not equipped to interpret the class-specific information sent by a client MUST ignore it (although it may be reported). Servers that respond SHOULD only use option 43 to return the vendor-specific information to the client. The code for this option is 60, and its minimum length is 1. Code Len Vendor class Identifier +-----+-----+-----+-----+--- | 60 | n | i1 | i2 | ... +-----+-----+-----+-----+---
const ( DHCP_Network_Information_Service_Domain DHCP_STRING_TYPE = 40 DHCP_NetBIOS_Scope DHCP_STRING_TYPE = 47 DHCP_Network_Information_ServiceS_Domain DHCP_STRING_TYPE = 64 DHCP_TFTP_Server_Name DHCP_STRING_TYPE = 66 DHCP_Bootfile_Name DHCP_STRING_TYPE = 67 DHCP_Error_Message DHCP_STRING_TYPE = 56 DHCP_Vendor_Class_Identifier DHCP_STRING_TYPE = 60 )
type DHCP_TIME_TYPE ¶
type DHCP_TIME_TYPE uint8
9.2. IP Address Lease Time
This option is used in a client request (DHCPDISCOVER or DHCPREQUEST) to allow the client to request a lease time for the IP address. In a server reply (DHCPOFFER), a DHCP server uses this option to specify the lease time it is willing to offer. The time is in units of seconds, and is specified as a 32-bit unsigned integer. The code for this option is 51, and its length is 4. Code Len Lease Time +-----+-----+-----+-----+-----+-----+ | 51 | 4 | t1 | t2 | t3 | t4 | +-----+-----+-----+-----+-----+-----+
9.11. Renewal (T1) Time Value
This option specifies the time interval from address assignment until the client transitions to the RENEWING state. The value is in units of seconds, and is specified as a 32-bit unsigned integer. The code for this option is 58, and its length is 4. Code Len T1 Interval +-----+-----+-----+-----+-----+-----+ | 58 | 4 | t1 | t2 | t3 | t4 | +-----+-----+-----+-----+-----+-----+
9.12. Rebinding (T2) Time Value
This option specifies the time interval from address assignment until the client transitions to the REBINDING state. The value is in units of seconds, and is specified as a 32-bit unsigned integer. The code for this option is 59, and its length is 4. Code Len T2 Interval +-----+-----+-----+-----+-----+-----+ | 59 | 4 | t1 | t2 | t3 | t4 | +-----+-----+-----+-----+-----+-----+
const ( DHCP_Renewal_Time DHCP_TIME_TYPE = iota + 58 DHCP_Rebinding_Time DHCP_IP_Address_Lease DHCP_TIME_TYPE = 51 )
type DUPPacket ¶ added in v0.1.0
func NewDUPPacket ¶ added in v0.1.0
func NewDUPPacket(b [SizeofDUPPacket]byte) (udp DUPPacket)
14.byte EthernetPacket 20.byte IPv4Packet 或者 IPv6Packet
func (DUPPacket) WireFormat ¶ added in v0.1.0
type DhcpV4Packet ¶
type DhcpV4Packet struct { Op uint8 HardwareType uint8 HardwareLen uint8 Hops uint8 XID uint32 Secs uint16 Flags uint16 CIAddr IPv4 YIAddr IPv4 SIAddr IPv4 GIAddr IPv4 ChHardware [16]byte HostName [64]byte FileName [128]byte Options []OptionsPacket // contains filtered or unexported fields }
// 14.byte EthernetPacket // 20.byte IPv4Packet
FIELD BYTES DESCRIPTION ----- ----- ----------- op 1 packet op code / message type. 1 = BOOTREQUEST, 2 = BOOTREPLY htype 1 hardware address type, see ARP section in "Assigned Numbers" RFC. '1' = 10mb ethernet hlen 1 hardware address length (eg '6' for 10mb ethernet). hops 1 client sets to zero, optionally used by gateways in cross-gateway booting. xid 4 transaction ID, a random number, used to match this boot request with the responses it generates. secs 2 filled in by client, seconds elapsed since client started trying to boot. -- 2 unused ciaddr 4 client IP address; filled in by client in bootrequest if known. yiaddr 4 'your' (client) IP address; filled by server if client doesn't know its own address (ciaddr was 0). siaddr 4 server IP address; returned in bootreply by server. giaddr 4 gateway IP address, used in optional cross-gateway booting. chaddr 16 client hardware address, filled in by client. sname 64 optional server host name, null terminated string. file 128 boot file name, null terminated string; 'generic' name or null in bootrequest, fully qualified directory-path name in bootreply. vend 64 optional vendor-specific area, e.g. could be hardware type/serial on request, or 'capability' / remote file system handle on reply. This info may be set aside for use by a third phase bootstrap or kernel.
func NewDhcpV4Packet ¶
func NewDhcpV4Packet(b []byte) (dhcp DhcpV4Packet)
14.byte EthernetPacket 20.byte IPv4Packet 或者 IPv6Packet
func (DhcpV4Packet) WireFormat ¶
func (dhcp DhcpV4Packet) WireFormat() []byte
type EthernetPacket ¶ added in v0.1.0
type EthernetPacket struct { HeadMAC [2]HardwareAddr FrameType uint16 }
Ethernet transmission layer (not necessarily accessible to the user): 6.byte 48.bit: Ethernet address of destination 6.byte 48.bit: Ethernet address of sender 2.byte 16.bit: Protocol type = ether_type$ADDRESS_RESOLUTION Ethernet packet data: // N.byte packet
func NewEthernetPacket ¶ added in v0.1.0
func NewEthernetPacket(b [SizeofEthernetPacket]byte) (eth EthernetPacket)
func (EthernetPacket) WireFormat ¶ added in v0.1.0
func (eth EthernetPacket) WireFormat() []byte
type HardwareAddr ¶
type HardwareAddr [6]byte
func (HardwareAddr) String ¶
func (h HardwareAddr) String() string
type IPv4Packet ¶ added in v0.1.0
type IPv4Packet struct { Version uint8 TOS uint8 TotalLen uint16 ID uint16 FragOff uint16 TTL uint8 Protocol uint8 Checksum uint16 Src IPv4 Dst IPv4 Flags uint8 IHL uint8 Options []byte }
// 14.byte EthernetPacket
3.1. Internet Header Format
A summary of the contents of the internet header follows: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| IHL |Type of Service| Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identification |Flags| Fragment Offset | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time to Live | Protocol | Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Example Internet Datagram Header Figure 4. Note that each tick mark represents one bit position. Version: 4 bits IHL: 4 bits Type of Service: 8 bits its 0-2: Precedence. Bit 3: 0 = Normal Delay, 1 = Low Delay. Bits 4: 0 = Normal Throughput, 1 = High Throughput. Bits 5: 0 = Normal Relibility, 1 = High Relibility. Bit 6-7: Reserved for Future Use. Total Length: 16 bits Identification: 16 bits Flags: 3 bits Fragment Offset: 13 bits Time to Live: 8 bits Protocol: 8 bits Header Checksum: 16 bits Source Address: 32 bits Destination Address: 32 bits
func NewIPv4Packet ¶ added in v0.1.0
func NewIPv4Packet(b []byte) (ipv4 IPv4Packet, next uint8)
14.byte EthernetPacket 返回负载下标起始位
func (IPv4Packet) String ¶ added in v0.1.0
func (ipv4 IPv4Packet) String() string
func (IPv4Packet) WireFormat ¶ added in v0.1.0
func (ipv4 IPv4Packet) WireFormat() []byte
type IfAddrmsg ¶
func NewIfAddrmsg ¶
func NewIfAddrmsg(b [SizeofIfAddrmsg]byte) (addr *IfAddrmsg)
func (*IfAddrmsg) WireFormat ¶
type IfInfomsg ¶
func NewIfInfomsg ¶
func NewIfInfomsg(b [SizeofIfInfomsg]byte) (info *IfInfomsg)
func (*IfInfomsg) WireFormat ¶
type NlMsgerr ¶
func NewNlMsgerr ¶
func NewNlMsgerr(b [SizeofNlMsgerr]byte) (nlmsg *NlMsgerr)
func (*NlMsgerr) WireFormat ¶
type NlMsghdr ¶
func NewNlMsghdr ¶
func NewNlMsghdr(b [SizeofNlMsghdr]byte) (hdr *NlMsghdr)
func (*NlMsghdr) WireFormat ¶
func (*NlMsghdr) WireFormatToByte ¶
func (hdr *NlMsghdr) WireFormatToByte(b *[SizeofNlMsghdr]byte)
type OptionsPacket ¶
func NewOptionsPacket ¶
func NewOptionsPacket(b []byte) (list []OptionsPacket)
func SetDHCPIPv4 ¶
func SetDHCPIPv4(t DHCP_IPv4_TYPE, ip ...IPv4) OptionsPacket
func SetDHCPMaximumMessageSize ¶
func SetDHCPMaximumMessageSize(size uint16) OptionsPacket
9.10. Maximum DHCP Message Size
This option specifies the maximum length DHCP message that it is willing to accept. The length is specified as an unsigned 16-bit integer. A client may use the maximum DHCP message size option in DHCPDISCOVER or DHCPREQUEST messages, but should not use the option in DHCPDECLINE messages. The code for this option is 57, and its length is 2. The minimum legal value is 576 octets. Code Len Length +-----+-----+-----+-----+ | 57 | 2 | l1 | l2 | +-----+-----+-----+-----+
func SetDHCPMessage ¶
func SetDHCPMessage(t DHCP_Message_Type) OptionsPacket
func SetDHCPNetBIOSNodeType ¶
func SetDHCPNetBIOSNodeType(t DHCP_NetBIOS_Node_Type) OptionsPacket
func SetDHCPOptionsRequestList ¶
func SetDHCPOptionsRequestList(codes ...uint8) OptionsPacket
9.8. Parameter Request List
This option is used by a DHCP client to request values for specified configuration parameters. The list of requested parameters is specified as n octets, where each octet is a valid DHCP option code as defined in this document. The client MAY list the options in order of preference. The DHCP server is not required to return the options in the requested order, but MUST try to insert the requested options in the order requested by the client. The code for this option is 55. Its minimum length is 1. Code Len Option Codes +-----+-----+-----+-----+--- | 55 | n | c1 | c2 | ... +-----+-----+-----+-----+---
func SetDHCPString ¶
func SetDHCPString(t DHCP_STRING_TYPE, s string) OptionsPacket
func SetDHCPTime ¶
func SetDHCPTime(t DHCP_TIME_TYPE, d time.Duration) OptionsPacket
func (OptionsPacket) WireFormat ¶
func (opp OptionsPacket) WireFormat() []byte
type RtMsg ¶
func NewRtMsg ¶
func NewRtMsg(b [SizeofRtMsg]byte) (rtmsg *RtMsg)
func (*RtMsg) WireFormat ¶
type TCPPacket ¶ added in v0.1.0
type TCPPacket struct { SrcPort uint16 DstPort uint16 Sequence uint32 AckNum uint32 Window uint16 CheckSum uint16 UrgentPtr uint16 DataOffset uint8 Reserved uint8 URG bool ACK bool PSH bool RST bool SYN bool FIN bool Options []byte // contains filtered or unexported fields }
// 来源: https://support.huawei.com/enterprise/zh/doc/EDOC1100174722?section=j006
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-------------------------------+-------------------------------+ | Source Port | Destination Port | +-------------------------------+-------------------------------+ | Sequence Number | +---------------------------------------------------------------+ | Acknowledgment Number | +-------+-----------+-+-+-+-+-+-+-------------------------------+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-------+-----------+-+-+-+-+-+-+-------------------------------+ | Checksum | Urgent Pointer | +-------------------------------+---------------+---------------+ | Options | Padding | +-----------------------------------------------+---------------+ | data | +---------------------------------------------------------------+ 字段 长度 含义
Source Port 16比特 源端口,标识哪个应用程序发送。 Destination Port 16比特 目的端口,标识哪个应用程序接收。 Sequence Number 32比特 序号字段。TCP链接中传输的数据流中每个字节都编上一个序号。序号字段的值指的是本报文段所发送的数据的第一个字节的序号。 Acknowledgment Number 32比特 确认号,是期望收到对方的下一个报文段的数据的第1个字节的序号,即上次已成功接收到的数据字节序号加1。只有ACK标识为1,此字段有效。 Data Offset 4比特 数据偏移,即首部长度,指出TCP报文段的数据起始处距离TCP报文段的起始处有多远,以32比特(4字节)为计算单位。最多有60字节的首部,若无选项字段,正常为20字节。 Reserved 6比特 保留,必须填0。 URG 1比特 紧急指针有效标识。它告诉系统此报文段中有紧急数据,应尽快传送(相当于高优先级的数据)。 ACK 1比特 确认序号有效标识。只有当ACK=1时确认号字段才有效。当ACK=0时,确认号无效。 PSH 1比特 标识接收方应该尽快将这个报文段交给应用层。接收到PSH = 1的TCP报文段,应尽快的交付接收应用进程,而不再等待整个缓存都填满了后再向上交付。 RST 1比特 重建连接标识。当RST=1时,表明TCP连接中出现严重错误(如由于主机崩溃或其他原因),必须释放连接,然后再重新建立连接。 SYN 1比特 同步序号标识,用来发起一个连接。SYN=1表示这是一个连接请求或连接接受请求。 FIN 1比特 发端完成发送任务标识。用来释放一个连接。FIN=1表明此报文段的发送端的数据已经发送完毕,并要求释放连接。 Window 16比特 窗口:TCP的流量控制,窗口起始于确认序号字段指明的值,这个值是接收端期望接收的字节数。窗口最大为65535字节。 Checksum 16比特 校验字段,包括TCP首部和TCP数据,是一个强制性的字段,一定是由发端计算和存储,并由收端进行验证。在计算检验和时,要在TCP报文段的前面加上12字节的伪首部。 Urgent Pointer 16比特 紧急指针,只有当URG标志置1时紧急指针才有效。TCP的紧急方式是发送端向另一端发送紧急数据的一种方式。紧急指针指出在本报文段中紧急数据共有多少个字节(紧急数据放在本报文段数据的最前面)。 Options 可变 选项字段。TCP协议最初只规定了一种选项,即最长报文段长度(只包含数据字段,不包括TCP首部),又称为MSS。MSS告诉对方TCP“我的缓存所能接收的报文段的数据字段的最大长度是MSS个字节”。
新的RFC规定有以下几种选型:选项表结束,空操作,最大报文段长度,窗口扩大因子,时间戳。 选项表结束。 空操作:没有特殊含义,一般用于将TCP选项的总长度填充为4字节的整数倍。 最大报文段长度:又称为MSS,只包含数据字段,不包括TCP首部。 窗口扩大因子:3字节,其中一个字节表示偏移值S。新的窗口值等于TCP首部中的窗口位数增大到(16+S),相当于把窗口值向左移动S位后获得实际的窗口大小。 时间戳:10字节,其中最主要的字段是时间戳值(4字节)和时间戳回送应答字段(4字节)。
Padding 可变 填充字段,用来补位,使整个首部长度是4字节的整数倍。
func NewTCPPacket ¶ added in v0.1.0
14.byte EthernetPacket 20.byte IPv4Packet 或者 IPv6Packet 返回负载下标起始位
func (TCPPacket) WireFormat ¶ added in v0.1.0
Directories ¶
Path | Synopsis |
---|---|
@@ @ Author : Eacher @ Date : 2023-09-06 10:48:53 @ LastEditTime : 2023-09-11 08:01:05 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/can/frame.go @@
|
@@ @ Author : Eacher @ Date : 2023-09-06 10:48:53 @ LastEditTime : 2023-09-11 08:01:05 @ LastEditors : Eacher @ --------------------------------------------------------------------------------< @ Description : @ --------------------------------------------------------------------------------< @ FilePath : /20yyq/packet/can/frame.go @@ |