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  * Fixes:
  14  *              Alan Cox        :       verify_area check.
  15  *
  16  *
  17  *              This program is free software; you can redistribute it and/or
  18  *              modify it under the terms of the GNU General Public License
  19  *              as published by the Free Software Foundation; either version
  20  *              2 of the License, or (at your option) any later version.
  21  */
  22 
  23 #include <asm/segment.h>
  24 #include <asm/system.h>
  25 #include <linux/types.h>
  26 #include <linux/kernel.h>
  27 #include <linux/sched.h>
  28 #include <linux/string.h>
  29 #include <linux/mm.h>
  30 #include <linux/socket.h>
  31 #include <linux/in.h>
  32 #include <linux/errno.h>
  33 #include <linux/stat.h>
  34 #include <stdarg.h>
  35 #include <linux/inet.h>
  36 #include <linux/netdevice.h>
  37 #include <linux/etherdevice.h>
  38 #include "ip.h"
  39 #include "protocol.h"
  40 #include "tcp.h"
  41 #include <linux/skbuff.h>
  42 
  43 
  44 /*
  45  *      Display an IP address in readable format. 
  46  */
  47  
  48 char *in_ntoa(unsigned long in)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         static char buff[18];
  51         char *p;
  52 
  53         p = (char *) &in;
  54         sprintf(buff, "%d.%d.%d.%d",
  55                 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
  56         return(buff);
  57 }
  58 
  59 
  60 /*
  61  *      Convert an ASCII string to binary IP. 
  62  */
  63  
  64 unsigned long in_aton(char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
  65 {
  66         unsigned long l;
  67         unsigned int val;
  68         int i;
  69 
  70         l = 0;
  71         for (i = 0; i < 4; i++) 
  72         {
  73                 l <<= 8;
  74                 if (*str != '\0') 
  75                 {
  76                         val = 0;
  77                         while (*str != '\0' && *str != '.') 
  78                         {
  79                                 val *= 10;
  80                                 val += *str - '0';
  81                                 str++;
  82                         }
  83                         l |= val;
  84                         if (*str != '\0') 
  85                                 str++;
  86                 }
  87         }
  88         return(htonl(l));
  89 }
  90 
  91 
  92 /*
  93  *      Debugging print out
  94  */
  95  
  96 void dprintf(int level, char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
  97 {
  98         va_list args;
  99         char *buff;
 100         extern int vsprintf(char * buf, const char * fmt, va_list args);
 101 
 102         if (level != inet_debug) 
 103                 return;
 104 
 105         buff = (char *) kmalloc(256, GFP_ATOMIC);
 106         if (buff != NULL) 
 107         {
 108                 va_start(args, fmt);
 109                 vsprintf(buff, fmt, args);
 110                 va_end(args);
 111                 printk(buff);
 112                 kfree(buff);
 113         }
 114         else
 115                 printk("Debugging output lost: No free memory.\n");     
 116 }
 117 
 118 /*
 119  *      Debugging ioctl() requests
 120  */
 121  
 122 int dbg_ioctl(void *arg, int level)
     /* [previous][next][first][last][top][bottom][index][help] */
 123 {
 124         int val;
 125         int err;
 126   
 127         if (!suser()) 
 128                 return(-EPERM);
 129         err=verify_area(VERIFY_READ, (void *)arg, sizeof(int));
 130         if(err)
 131                 return err;
 132         val = get_fs_long((int *)arg);
 133         switch(val) 
 134         {
 135                 case 0: /* OFF */
 136                         inet_debug = DBG_OFF;
 137                         break;
 138                 case 1: /* ON, INET */
 139                         inet_debug = level;
 140                         break;
 141 
 142                 case DBG_RT:            /* modules */
 143                 case DBG_DEV:
 144                 case DBG_ETH:
 145                 case DBG_PROTO:
 146                 case DBG_TMR:
 147                 case DBG_PKT:
 148                 case DBG_RAW:
 149         
 150                 case DBG_LOOPB:         /* drivers */
 151                 case DBG_SLIP:
 152         
 153                 case DBG_ARP:           /* protocols */
 154                 case DBG_IP:
 155                 case DBG_ICMP:
 156                 case DBG_TCP:
 157                 case DBG_UDP:
 158         
 159                         inet_debug = val;
 160                         break;
 161         
 162                 default:
 163                         return(-EINVAL);
 164         }
 165         
 166         return(0);
 167 }

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