akaros/kern/src/net/netaux.c
<<
>>
Prefs
   1/* Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
   2 * Portions Copyright © 1997-1999 Vita Nuova Limited
   3 * Portions Copyright © 2000-2007 Vita Nuova Holdings Limited
   4 *                                (www.vitanuova.com)
   5 * Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
   6 *
   7 * Modified for the Akaros operating system:
   8 * Copyright (c) 2013-2014 The Regents of the University of California
   9 * Copyright (c) 2013-2015 Google Inc.
  10 *
  11 * Permission is hereby granted, free of charge, to any person obtaining a copy
  12 * of this software and associated documentation files (the "Software"), to deal
  13 * in the Software without restriction, including without limitation the rights
  14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15 * copies of the Software, and to permit persons to whom the Software is
  16 * furnished to do so, subject to the following conditions:
  17 *
  18 * The above copyright notice and this permission notice shall be included in
  19 * all copies or substantial portions of the Software.
  20 *
  21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27 * SOFTWARE. */
  28
  29#include <slab.h>
  30#include <kmalloc.h>
  31#include <kref.h>
  32#include <string.h>
  33#include <stdio.h>
  34#include <assert.h>
  35#include <error.h>
  36#include <cpio.h>
  37#include <pmap.h>
  38#include <smp.h>
  39#include <net/ip.h>
  40
  41void hnputv(void *p, int64_t v)
  42{
  43        uint8_t *a;
  44
  45        a = p;
  46        hnputl(a, v >> 32);
  47        hnputl(a + 4, v);
  48}
  49
  50void hnputl(void *p, uint32_t v)
  51{
  52        uint8_t *a;
  53
  54        a = p;
  55        a[0] = v >> 24;
  56        a[1] = v >> 16;
  57        a[2] = v >> 8;
  58        a[3] = v;
  59}
  60
  61void hnputs(void *p, uint16_t v)
  62{
  63        uint8_t *a;
  64
  65        a = p;
  66        a[0] = v >> 8;
  67        a[1] = v;
  68}
  69
  70int64_t nhgetv(void *p)
  71{
  72        uint8_t *a;
  73
  74        a = p;
  75        return ((int64_t) nhgetl(a) << 32) | nhgetl(a + 4);
  76}
  77
  78uint32_t nhgetl(void *p)
  79{
  80        uint8_t *a;
  81
  82        a = p;
  83        return (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | (a[3] << 0);
  84}
  85
  86uint16_t nhgets(void *p)
  87{
  88        uint8_t *a;
  89
  90        a = p;
  91        return (a[0] << 8) | (a[1] << 0);
  92}
  93