1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)byteorder.c 2.6 (Berkeley) 06/18/88"; 20 #endif /* not lint */ 21 22 #include "globals.h" 23 #include <protocols/timed.h> 24 25 /* 26 * Two routines to do the necessary byte swapping for timed protocol 27 * messages. Protocol is defined in /usr/include/protocols/timed.h 28 */ 29 30 bytenetorder(ptr) 31 struct tsp *ptr; 32 { 33 ptr->tsp_seq = htons((u_short)ptr->tsp_seq); 34 switch (ptr->tsp_type) { 35 36 case TSP_SETTIME: 37 case TSP_ADJTIME: 38 case TSP_SETDATE: 39 case TSP_SETDATEREQ: 40 ptr->tsp_time.tv_sec = htonl((u_long)ptr->tsp_time.tv_sec); 41 ptr->tsp_time.tv_usec = htonl((u_long)ptr->tsp_time.tv_usec); 42 break; 43 44 default: 45 break; /* nothing more needed */ 46 } 47 } 48 49 bytehostorder(ptr) 50 struct tsp *ptr; 51 { 52 ptr->tsp_seq = ntohs((u_short)ptr->tsp_seq); 53 switch (ptr->tsp_type) { 54 55 case TSP_SETTIME: 56 case TSP_ADJTIME: 57 case TSP_SETDATE: 58 case TSP_SETDATEREQ: 59 ptr->tsp_time.tv_sec = ntohl((u_long)ptr->tsp_time.tv_sec); 60 ptr->tsp_time.tv_usec = ntohl((u_long)ptr->tsp_time.tv_usec); 61 break; 62 63 default: 64 break; /* nothing more needed */ 65 } 66 } 67