MCPcopy Create free account
hub / github.com/deepclause/agentvm / sendDHCPReply

Method sendDHCPReply

src/network.js:744–887  ·  view source on GitHub ↗
(msgType, xid, chaddr, flags)

Source from the content-addressed store, hash-verified

742 }
743
744 sendDHCPReply(msgType, xid, chaddr, flags) {
745 // Build DHCP reply packet
746 const reply = Buffer.alloc(300); // Enough for basic DHCP
747
748 reply[0] = 2; // BOOTREPLY
749 reply[1] = 1; // Ethernet
750 reply[2] = 6; // Hardware address length
751 reply[3] = 0; // Hops
752 reply.writeUInt32BE(xid, 4); // Transaction ID
753 reply.writeUInt16BE(0, 8); // Secs
754 reply.writeUInt16BE(flags, 10); // Flags (broadcast if client requested)
755
756 // CIAddr (0.0.0.0) - offset 12
757 // YIAddr (your/assigned IP) - offset 16
758 const vmIPParts = this.vmIP.split('.').map(Number);
759 reply[16] = vmIPParts[0];
760 reply[17] = vmIPParts[1];
761 reply[18] = vmIPParts[2];
762 reply[19] = vmIPParts[3];
763
764 // SIAddr (server IP) - offset 20
765 const gwIPParts = this.gatewayIP.split('.').map(Number);
766 reply[20] = gwIPParts[0];
767 reply[21] = gwIPParts[1];
768 reply[22] = gwIPParts[2];
769 reply[23] = gwIPParts[3];
770
771 // GIAddr (gateway IP for relay) - offset 24 - leave 0
772
773 // CHAddr (client hardware address) - offset 28
774 chaddr.copy(reply, 28);
775
776 // SName (server name) - offset 44 - leave 0 (64 bytes)
777 // File (boot file) - offset 108 - leave 0 (128 bytes)
778
779 // Magic cookie at offset 236
780 reply.writeUInt32BE(DHCP_MAGIC_COOKIE, 236);
781
782 // Options start at offset 240
783 let optOffset = 240;
784
785 // Option 53: DHCP Message Type
786 reply[optOffset++] = DHCP_OPT_MSG_TYPE;
787 reply[optOffset++] = 1;
788 reply[optOffset++] = msgType;
789
790 // Option 54: Server Identifier
791 reply[optOffset++] = DHCP_OPT_SERVER_ID;
792 reply[optOffset++] = 4;
793 reply[optOffset++] = gwIPParts[0];
794 reply[optOffset++] = gwIPParts[1];
795 reply[optOffset++] = gwIPParts[2];
796 reply[optOffset++] = gwIPParts[3];
797
798 // Option 51: Lease Time (1 day = 86400 seconds)
799 reply[optOffset++] = DHCP_OPT_LEASE_TIME;
800 reply[optOffset++] = 4;
801 reply.writeUInt32BE(86400, optOffset);

Callers 2

sendDHCPOfferMethod · 0.95
sendDHCPAckMethod · 0.95

Calls 1

calculateChecksumMethod · 0.95

Tested by

no test coverage detected