Main Prog Common Funcs"
From:     http://what-when-how.com/computer-network-time-synchronization/main-program -and-common-routines-ntp-reference-implementation-computer-network-time -synchronization







Main Program and Common Routines (NTP Reference Implementation) (Computer Network Time Synchronization) The four routines shown in Figure 14.3 stand alone and are not part of any process. The main program main() initializes the program, allocates the persistent associations, and then loops waiting for a received packet. When a packet arrives, the routine captures the receive timestamp and calls the receive() routine. The mobilize() routine allocates and initializes an association and starts the poll timer. The clear() routine resets or demobilizes an association and returns its resources to the system. The md5() routine computes a 128-bit message digest from a given key and message block. For simplicity, the routine shown here is used for both generating and checking. For checking purposes, the routine returns the codes shown in Table 14.4.
Main program and common routines. FIGURE 14.3 Main program and common routines. The md5() routine uses the MD5 algorithm described in Request for Comments (RFC) 1321 [1] but modified to incorporate a symmetric key. The key itself is a 128-bit value held in a special cache where each key is associated with a 32-bit key identifier. The message digest is computed by first prepending the key value to the block and then computing the message digest over the combined key and block. Next post: Peer Process (NTP Reference Implementation) (Computer Network Time Synchronization) Previous post: Control Flow (NTP Reference Implementation) (Computer Network Time Synchronization) Related Links Computer Network Time Synchronization Time Synchronization Time Synchronization Protocols Computer Clocks Processing Time Values Correctness and Accuracy Expectations