Ask php how to use the self-constructed IP address header PHPcode & lt ;? Php Data $ dns_id & quot; x80xc1 & quot; $ dns_flags & quot; x01x00 & quot; $ dns_count_queries & quot; x00x01 & quot; $ dns_count_answers & quot; x00x ask php how to use self-constructed IP address headers
PHP code
1, 'usec '=> 500000); // socket_set_option ($ socket, IPPROTO_IP, scheme, SO_RCVTIMEO, $ timeout); socket_set_option ($ socket, SOL_SOCKET, SO_RCVTIMEO, $ timeout ); // while (1) socket_sendto ($ socket, $ buf, strlen ($ buf), 0, $ host, $ port);} function udpchecksum ($ ip_src, $ ip_dst, $ ip_proto, $ udp_length, $ udp_srcport, $ udp_dstport, $ dns) {$ data = $ ip_src. $ ip_dst. "\ x00 ". $ ip_proto. $ udp_length. $ udp_srcport. $ udp_ds Tport. $ udp_length. "\ x00 \ x00 ". $ dns; if (strlen ($ data) % 2) $ data. = "\ x00"; $ bit = unpack ('n' * ', $ data); $ sum = array_sum ($ bit); while ($ sum> 16) $ sum = ($ sum> 16) + ($ sum & 0 xffff); return pack ('n *',~ $ Sum);} function ipchecksum ($ ip_version, $ ip_hdr_len, $ ip_dsfield, $ ip_len, $ ip_id, $ ip_flags, $ ip_frag_offset, $ ip_ttl, $ ip_proto, $ ip_src, $ ip_dst) {$ data = $ ip_version. $ ip_hdr_len. $ ip_dsfield. $ ip_len. $ ip_id. $ ip_flags. $ ip_frag_offset. $ ip_ttl. $ ip_proto. "\ x00 \ x00 ". $ ip_src. $ ip_dst; $ bit = unpack ('n' * ', $ data); $ sum = array_sum ($ bit); while ($ sum> 16) $ sum = ($ sum> 16) + ($ sum & 0 xffff); Return pack ('n *',~ $ Sum);} function ipto16 ($ ip) {$ tmp = explode (". ", $ ip); $ ip =" "; foreach ($ tmp as $ a => $ B) {$ tmp = dechex ($ B ); if (strlen ($ tmp) = 1) $ tmp = "0 ". $ tmp; $ ip. = $ tmp;} $ ip = pack ("h *", $ ip); return $ ip;} send ("8.8.4.4", 53, $ buf, $ dns_flags );
This is a program for querying the IP address of a specified domain name from a specified dns server. it can be captured using Wireshark for testing. However, it does not use its network layer, that is, the IP header, I want to use a self-constructed IP header,
Set
$ Buf = $ ip_header. $ udp. $ dns;
// $ Buf = $ udp. $ dns;
Change
$ Buf = $ ip_header. $ udp. $ dns;
// $ Buf = $ udp. $ dns;
The result still does not work. it should be a problem with the send function. how can I modify it?
------ Solution --------------------
I don't know what you are doing? The sock package must be used at the user layer.
Encapsulate the ip address at the next layer.