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 "ip.h"
  34 #include "protocol.h"
  35 #include "tcp.h"
  36 #include "skbuff.h"
  37 #include "arp.h"
  38 
  39 
  40 /* Display an IP address in readable format. */
  41 char *in_ntoa(unsigned long in)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43   static char buff[18];
  44   register char *p;
  45 
  46   p = (char *) &in;
  47   sprintf(buff, "%d.%d.%d.%d",
  48         (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
  49   return(buff);
  50 }
  51 
  52 
  53 /* Convert an ASCII string to binary IP. */
  54 unsigned long
  55 in_aton(char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57   unsigned long l;
  58   unsigned int val;
  59   int i;
  60 
  61   l = 0;
  62   for (i = 0; i < 4; i++) {
  63         l <<= 8;
  64         if (*str != '\0') {
  65                 val = 0;
  66                 while (*str != '\0' && *str != '.') {
  67                         val *= 10;
  68                         val += *str - '0';
  69                         str++;
  70                 }
  71                 l |= val;
  72                 if (*str != '\0') str++;
  73         }
  74   }
  75   return(htonl(l));
  76 }
  77 
  78 
  79 void
  80 dprintf(int level, char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82   va_list args;
  83   char *buff;
  84   extern int vsprintf(char * buf, const char * fmt, va_list args);
  85 
  86   if (level != inet_debug) return;
  87 
  88   buff = (char *) kmalloc(256, GFP_ATOMIC);
  89   if (buff != NULL) {
  90         va_start(args, fmt);
  91         vsprintf(buff, fmt, args);
  92         va_end(args);
  93         printk(buff);
  94         kfree(buff);
  95   }
  96 }
  97 
  98 
  99 int
 100 dbg_ioctl(void *arg, int level)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102   int val;
 103 
 104   if (!suser()) return(-EPERM);
 105   verify_area(VERIFY_WRITE, (void *)arg, sizeof(int));
 106   val = get_fs_long((int *)arg);
 107   switch(val) {
 108         case 0: /* OFF */
 109                 inet_debug = DBG_OFF;
 110                 break;
 111         case 1: /* ON, INET */
 112                 inet_debug = level;
 113                 break;
 114 
 115         case DBG_RT:            /* modules */
 116         case DBG_DEV:
 117         case DBG_ETH:
 118         case DBG_PROTO:
 119         case DBG_TMR:
 120         case DBG_PKT:
 121         case DBG_RAW:
 122 
 123         case DBG_LOOPB:         /* drivers */
 124         case DBG_SLIP:
 125 
 126         case DBG_ARP:           /* protocols */
 127         case DBG_IP:
 128         case DBG_ICMP:
 129         case DBG_TCP:
 130         case DBG_UDP:
 131 
 132                 inet_debug = val;
 133                 break;
 134 
 135         default:
 136                 return(-EINVAL);
 137   }
 138 
 139   return(0);
 140 }

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