Home | History | Annotate | Line # | Download | only in common
put.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: put.c,v 1.2 1997/03/25 03:07:33 thorpej Exp $	*/
      2  1.2  thorpej 
      3  1.1      cjs /*
      4  1.1      cjs  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
      5  1.1      cjs  *
      6  1.1      cjs  * Redistribution and use in source and binary forms, with or without
      7  1.1      cjs  * modification, are permitted provided that the following conditions
      8  1.1      cjs  * are met:
      9  1.1      cjs  * 1. Redistributions of source code must retain the above copyright
     10  1.1      cjs  *    notice, this list of conditions and the following disclaimer.
     11  1.1      cjs  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1      cjs  *    notice, this list of conditions and the following disclaimer in the
     13  1.1      cjs  *    documentation and/or other materials provided with the distribution.
     14  1.1      cjs  * 3. All advertising materials mentioning features or use of this software
     15  1.1      cjs  *    must display the following acknowledgement:
     16  1.1      cjs  *	This product includes software developed by Mats O Jansson.
     17  1.1      cjs  * 4. The name of the author may not be used to endorse or promote products
     18  1.1      cjs  *    derived from this software without specific prior written permission.
     19  1.1      cjs  *
     20  1.1      cjs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1      cjs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1      cjs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1      cjs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1      cjs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1      cjs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1      cjs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1      cjs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1      cjs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1      cjs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1      cjs  */
     31  1.1      cjs 
     32  1.1      cjs #ifndef LINT
     33  1.2  thorpej static char rcsid[] = "$NetBSD: put.c,v 1.2 1997/03/25 03:07:33 thorpej Exp $";
     34  1.1      cjs #endif
     35  1.1      cjs 
     36  1.1      cjs #include <stddef.h>
     37  1.1      cjs #include <sys/types.h>
     38  1.1      cjs #include <time.h>
     39  1.1      cjs #include "common/mopdef.h"
     40  1.1      cjs 
     41  1.1      cjs void
     42  1.1      cjs mopPutChar(pkt, index, value)
     43  1.1      cjs 	register u_char *pkt;
     44  1.1      cjs 	register int    *index;
     45  1.1      cjs 	u_char   value;
     46  1.1      cjs {
     47  1.1      cjs 	pkt[*index] = value;
     48  1.1      cjs 	*index = *index + 1;
     49  1.1      cjs }
     50  1.1      cjs 
     51  1.1      cjs void
     52  1.1      cjs mopPutShort(pkt, index, value)
     53  1.1      cjs 	register u_char *pkt;
     54  1.1      cjs 	register int    *index;
     55  1.1      cjs 	u_short  value;
     56  1.1      cjs {
     57  1.1      cjs         int i;
     58  1.1      cjs 	for (i = 0; i < 2; i++) {
     59  1.1      cjs 	  pkt[*index+i] = value % 256;
     60  1.1      cjs 	  value = value / 256;
     61  1.1      cjs 	}
     62  1.1      cjs 	*index = *index + 2;
     63  1.1      cjs }
     64  1.1      cjs 
     65  1.1      cjs void
     66  1.1      cjs mopPutLong(pkt, index, value)
     67  1.1      cjs 	register u_char *pkt;
     68  1.1      cjs 	register int    *index;
     69  1.1      cjs 	u_long   value;
     70  1.1      cjs {
     71  1.1      cjs         int i;
     72  1.1      cjs 	for (i = 0; i < 4; i++) {
     73  1.1      cjs 	  pkt[*index+i] = value % 256;
     74  1.1      cjs 	  value = value / 256;
     75  1.1      cjs 	}
     76  1.1      cjs 	*index = *index + 4;
     77  1.1      cjs }
     78  1.1      cjs 
     79  1.1      cjs void
     80  1.1      cjs mopPutMulti(pkt, index, value, size)
     81  1.1      cjs 	register u_char *pkt,*value;
     82  1.1      cjs 	register int    *index,size;
     83  1.1      cjs {
     84  1.1      cjs 	int i;
     85  1.1      cjs 
     86  1.1      cjs 	for (i = 0; i < size; i++) {
     87  1.1      cjs 	  pkt[*index+i] = value[i];
     88  1.1      cjs 	}
     89  1.1      cjs 	*index = *index + size;
     90  1.1      cjs }
     91  1.1      cjs 
     92  1.1      cjs void
     93  1.1      cjs mopPutTime(pkt, index, value)
     94  1.1      cjs 	register u_char *pkt;
     95  1.1      cjs 	register int    *index;
     96  1.1      cjs 	time_t value;
     97  1.1      cjs {
     98  1.1      cjs 	time_t tnow;
     99  1.1      cjs 	struct tm *timenow;
    100  1.1      cjs 
    101  1.1      cjs 	if ((value == 0)) {
    102  1.1      cjs 	  tnow = time(NULL);
    103  1.1      cjs 	} else {
    104  1.1      cjs 	  tnow = value;
    105  1.1      cjs 	}
    106  1.1      cjs 
    107  1.1      cjs 	timenow = localtime(&tnow);
    108  1.1      cjs 
    109  1.1      cjs 	mopPutChar (pkt,index,10);
    110  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_year / 100) + 19);
    111  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_year % 100));
    112  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_mon + 1));
    113  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_mday));
    114  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_hour));
    115  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_min));
    116  1.1      cjs 	mopPutChar (pkt,index,(timenow->tm_sec));
    117  1.1      cjs 	mopPutChar (pkt,index,0x00);
    118  1.1      cjs 	mopPutChar (pkt,index,0x00);
    119  1.1      cjs 	mopPutChar (pkt,index,0x00);
    120  1.1      cjs }
    121  1.1      cjs 
    122  1.1      cjs void
    123  1.1      cjs mopPutHeader(pkt, index, dst, src, proto, trans)
    124  1.1      cjs 	register u_char *pkt;
    125  1.1      cjs 	register int    *index;
    126  1.1      cjs 	char	 dst[], src[];
    127  1.1      cjs 	u_short	 proto;
    128  1.1      cjs 	int	 trans;
    129  1.1      cjs {
    130  1.1      cjs 
    131  1.1      cjs 	mopPutMulti(pkt, index, dst, 6);
    132  1.1      cjs 	mopPutMulti(pkt, index, src, 6);
    133  1.1      cjs 	if (trans == TRANS_8023) {
    134  1.1      cjs 		mopPutShort(pkt, index, 0);
    135  1.1      cjs 		mopPutChar (pkt, index, MOP_K_PROTO_802_DSAP);
    136  1.1      cjs 		mopPutChar (pkt, index, MOP_K_PROTO_802_SSAP);
    137  1.1      cjs 		mopPutChar (pkt, index, MOP_K_PROTO_802_CNTL);
    138  1.1      cjs 		mopPutChar (pkt, index, 0x08);
    139  1.1      cjs 		mopPutChar (pkt, index, 0x00);
    140  1.1      cjs 		mopPutChar (pkt, index, 0x2b);
    141  1.1      cjs 	}
    142  1.1      cjs #if !defined(__FreeBSD__)
    143  1.1      cjs 	mopPutChar(pkt, index, (proto / 256));
    144  1.1      cjs 	mopPutChar(pkt, index, (proto % 256));
    145  1.1      cjs #else
    146  1.1      cjs 	if (trans == TRANS_8023) {
    147  1.1      cjs 		mopPutChar(pkt, index, (proto / 256));
    148  1.1      cjs 		mopPutChar(pkt, index, (proto % 256));
    149  1.1      cjs 	} else {
    150  1.1      cjs 		mopPutChar(pkt, index, (proto % 256));
    151  1.1      cjs 		mopPutChar(pkt, index, (proto / 256));
    152  1.1      cjs 	}
    153  1.1      cjs #endif
    154  1.1      cjs 	if (trans == TRANS_ETHER)
    155  1.1      cjs 		mopPutShort(pkt, index, 0);
    156  1.1      cjs 
    157  1.1      cjs }
    158  1.1      cjs 
    159  1.1      cjs void
    160  1.1      cjs mopPutLength(pkt, trans, len)
    161  1.1      cjs 	register u_char *pkt;
    162  1.1      cjs 	int	 trans;
    163  1.1      cjs 	u_short	 len;
    164  1.1      cjs {
    165  1.1      cjs 	int	 index = 0;
    166  1.1      cjs 
    167  1.1      cjs 	switch(trans) {
    168  1.1      cjs 	case TRANS_ETHER:
    169  1.1      cjs 		index = 14;
    170  1.1      cjs 		mopPutChar(pkt, &index, ((len - 16) % 256));
    171  1.1      cjs 		mopPutChar(pkt, &index, ((len - 16) / 256));
    172  1.1      cjs 		break;
    173  1.1      cjs 	case TRANS_8023:
    174  1.1      cjs 		index = 12;
    175  1.1      cjs #if !defined(__FreeBSD__)
    176  1.1      cjs 		mopPutChar(pkt, &index, ((len - 14) / 256));
    177  1.1      cjs 		mopPutChar(pkt, &index, ((len - 14) % 256));
    178  1.1      cjs #else
    179  1.1      cjs 		mopPutChar(pkt, &index, ((len - 14) % 256));
    180  1.1      cjs 		mopPutChar(pkt, &index, ((len - 14) / 256));
    181  1.1      cjs #endif
    182  1.1      cjs 		break;
    183  1.1      cjs 	}
    184  1.1      cjs 
    185  1.1      cjs }
    186  1.1      cjs 
    187  1.1      cjs 
    188  1.1      cjs 
    189