11553Srgrimes/*- 21553Srgrimes * Copyright (c) 1985, 1993 31553Srgrimes * The Regents of the University of California. All rights reserved. 41553Srgrimes * 51553Srgrimes * Redistribution and use in source and binary forms, with or without 61553Srgrimes * modification, are permitted provided that the following conditions 71553Srgrimes * are met: 81553Srgrimes * 1. Redistributions of source code must retain the above copyright 91553Srgrimes * notice, this list of conditions and the following disclaimer. 101553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111553Srgrimes * notice, this list of conditions and the following disclaimer in the 121553Srgrimes * documentation and/or other materials provided with the distribution. 131553Srgrimes * 4. Neither the name of the University nor the names of its contributors 141553Srgrimes * may be used to endorse or promote products derived from this software 151553Srgrimes * without specific prior written permission. 161553Srgrimes * 171553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271553Srgrimes * SUCH DAMAGE. 281553Srgrimes */ 291553Srgrimes 301553Srgrimes#ifndef lint 3130642Scharnier#if 0 321553Srgrimesstatic char sccsid[] = "@(#)byteorder.c 8.1 (Berkeley) 6/6/93"; 3330642Scharnier#endif 3430642Scharnierstatic const char rcsid[] = 3550479Speter "$FreeBSD$"; 361553Srgrimes#endif /* not lint */ 371553Srgrimes 381553Srgrimes#include "globals.h" 391553Srgrimes 401553Srgrimes/* 411553Srgrimes * Two routines to do the necessary byte swapping for timed protocol 421553Srgrimes * messages. Protocol is defined in /usr/include/protocols/timed.h 431553Srgrimes */ 441553Srgrimesvoid 451553Srgrimesbytenetorder(ptr) 461553Srgrimes struct tsp *ptr; 471553Srgrimes{ 481553Srgrimes ptr->tsp_seq = htons((u_short)ptr->tsp_seq); 491553Srgrimes switch (ptr->tsp_type) { 501553Srgrimes 511553Srgrimes case TSP_SETTIME: 521553Srgrimes case TSP_ADJTIME: 531553Srgrimes case TSP_SETDATE: 541553Srgrimes case TSP_SETDATEREQ: 551553Srgrimes ptr->tsp_time.tv_sec = htonl((u_long)ptr->tsp_time.tv_sec); 561553Srgrimes ptr->tsp_time.tv_usec = htonl((u_long)ptr->tsp_time.tv_usec); 571553Srgrimes break; 588857Srgrimes 591553Srgrimes default: 601553Srgrimes break; /* nothing more needed */ 611553Srgrimes } 621553Srgrimes} 631553Srgrimes 641553Srgrimesvoid 651553Srgrimesbytehostorder(ptr) 661553Srgrimes struct tsp *ptr; 671553Srgrimes{ 681553Srgrimes ptr->tsp_seq = ntohs((u_short)ptr->tsp_seq); 691553Srgrimes switch (ptr->tsp_type) { 701553Srgrimes 711553Srgrimes case TSP_SETTIME: 721553Srgrimes case TSP_ADJTIME: 731553Srgrimes case TSP_SETDATE: 741553Srgrimes case TSP_SETDATEREQ: 751553Srgrimes ptr->tsp_time.tv_sec = ntohl((u_long)ptr->tsp_time.tv_sec); 761553Srgrimes ptr->tsp_time.tv_usec = ntohl((u_long)ptr->tsp_time.tv_usec); 771553Srgrimes break; 788857Srgrimes 791553Srgrimes default: 801553Srgrimes break; /* nothing more needed */ 811553Srgrimes } 821553Srgrimes} 83