root/net/inet/utils.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. in_ntoa
  2. in_aton
  3. dprintf
  4. dbg_ioctl

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Various kernel-resident INET utility functions; mainly
   7  *              for format conversion and debugging output.
   8  *
   9  * Version:     @(#)utils.c     1.0.7   05/18/93
  10  *
  11  * Author:      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *
  13  *              This program is free software; you can redistribute it and/or
  14  *              modify it under the terms of the GNU General Public License
  15  *              as published by the Free Software Foundation; either version
  16  *              2 of the License, or (at your option) any later version.
  17  */
  18 #include <asm/segment.h>
  19 #include <asm/system.h>
  20 #include <linux/types.h>
  21 #include <linux/kernel.h>
  22 #include <linux/sched.h>
  23 #include <linux/string.h>
  24 #include <linux/mm.h>
  25 #include <linux/socket.h>
  26 #include <linux/in.h>
  27 #include <linux/errno.h>
  28 #include <linux/stat.h>
  29 #include <stdarg.h>
  30 #include "inet.h"
  31 #include "dev.h"
  32 #include "eth.h"
  33 #include "timer.h"
  34 #include "ip.h"
  35 #include "protocol.h"
  36 #include "tcp.h"
  37 #include "skbuff.h"
  38 #include "sock.h"
  39 #include "arp.h"
  40 
  41 
  42 /* Display an IP address in readable format. */
  43 char *in_ntoa(unsigned long in)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45   static char buff[18];
  46   register char *p;
  47 
  48   p = (char *) &in;
  49   sprintf(buff, "%d.%d.%d.%d",
  50         (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
  51   return(buff);
  52 }
  53 
  54 
  55 /* Convert an ASCII string to binary IP. */
  56 unsigned long
  57 in_aton(char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59   unsigned long l;
  60   unsigned int val;
  61   int i;
  62 
  63   l = 0;
  64   for (i = 0; i < 4; i++) {
  65         l <<= 8;
  66         if (*str != '\0') {
  67                 val = 0;
  68                 while (*str != '\0' && *str != '.') {
  69                         val *= 10;
  70                         val += *str - '0';
  71                         str++;
  72                 }
  73                 l |= val;
  74                 if (*str != '\0') str++;
  75         }
  76   }
  77   return(htonl(l));
  78 }
  79 
  80 
  81 void
  82 dprintf(int level, char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84   va_list args;
  85   char *buff;
  86   extern int vsprintf(char * buf, const char * fmt, va_list args);
  87 
  88   if (level != inet_debug) return;
  89 
  90   buff = kmalloc(256, GFP_ATOMIC);
  91   if (buff != NULL) {
  92         va_start(args, fmt);
  93         vsprintf(buff, fmt, args);
  94         va_end(args);
  95         printk(buff);
  96         kfree(buff);
  97   }
  98 }
  99 
 100 
 101 int
 102 dbg_ioctl(void *arg, int level)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104   int val;
 105 
 106   if (!suser()) return(-EPERM);
 107   verify_area(VERIFY_WRITE, (void *)arg, sizeof(int));
 108   val = get_fs_long((void *)arg);
 109   switch(val) {
 110         case 0: /* OFF */
 111                 inet_debug = DBG_OFF;
 112                 break;
 113         case 1: /* ON, INET */
 114                 inet_debug = level;
 115                 break;
 116 
 117         case DBG_RT:            /* modules */
 118         case DBG_DEV:
 119         case DBG_ETH:
 120         case DBG_PROTO:
 121         case DBG_TMR:
 122         case DBG_PKT:
 123         case DBG_RAW:
 124 
 125         case DBG_LOOPB:         /* drivers */
 126         case DBG_SLIP:
 127 
 128         case DBG_ARP:           /* protocols */
 129         case DBG_IP:
 130         case DBG_ICMP:
 131         case DBG_TCP:
 132         case DBG_UDP:
 133 
 134                 inet_debug = val;
 135                 break;
 136 
 137         default:
 138                 return(-EINVAL);
 139   }
 140 
 141   return(0);
 142 }

/* [previous][next][first][last][top][bottom][index][help] */