root/net/socket.c

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

DEFINITIONS

This source file includes following definitions.
  1. move_addr_to_kernel
  2. move_addr_to_user
  3. get_fd
  4. socki_lookup
  5. sockfd_lookup
  6. sock_alloc
  7. sock_release_peer
  8. sock_release
  9. sock_lseek
  10. sock_read
  11. sock_write
  12. sock_ioctl
  13. sock_select
  14. sock_close
  15. sock_fasync
  16. sock_wake_async
  17. sock_awaitconn
  18. sys_socket
  19. sys_socketpair
  20. sys_bind
  21. sys_listen
  22. sys_accept
  23. sys_connect
  24. sys_getsockname
  25. sys_getpeername
  26. sys_send
  27. sys_sendto
  28. sys_recv
  29. sys_recvfrom
  30. sys_setsockopt
  31. sys_getsockopt
  32. sys_shutdown
  33. sys_sendmsg
  34. sys_recvmsg
  35. sock_fcntl
  36. sys_socketcall
  37. sock_register
  38. sock_unregister
  39. proto_init
  40. sock_init
  41. socket_get_info

   1 /*
   2  * NET          An implementation of the SOCKET network access protocol.
   3  *
   4  * Version:     @(#)socket.c    1.1.93  18/02/95
   5  *
   6  * Authors:     Orest Zborowski, <obz@Kodak.COM>
   7  *              Ross Biro, <bir7@leland.Stanford.Edu>
   8  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
   9  *
  10  * Fixes:
  11  *              Anonymous       :       NOTSOCK/BADF cleanup. Error fix in
  12  *                                      shutdown()
  13  *              Alan Cox        :       verify_area() fixes
  14  *              Alan Cox        :       Removed DDI
  15  *              Jonathan Kamens :       SOCK_DGRAM reconnect bug
  16  *              Alan Cox        :       Moved a load of checks to the very
  17  *                                      top level.
  18  *              Alan Cox        :       Move address structures to/from user
  19  *                                      mode above the protocol layers.
  20  *              Rob Janssen     :       Allow 0 length sends.
  21  *              Alan Cox        :       Asynchronous I/O support (cribbed from the
  22  *                                      tty drivers).
  23  *              Niibe Yutaka    :       Asynchronous I/O for writes (4.4BSD style)
  24  *              Jeff Uphoff     :       Made max number of sockets command-line
  25  *                                      configurable.
  26  *              Matti Aarnio    :       Made the number of sockets dynamic,
  27  *                                      to be allocated when needed, and mr.
  28  *                                      Uphoff's max is used as max to be
  29  *                                      allowed to allocate.
  30  *              Linus           :       Argh. removed all the socket allocation
  31  *                                      altogether: it's in the inode now.
  32  *              Alan Cox        :       Made sock_alloc()/sock_release() public
  33  *                                      for NetROM and future kernel nfsd type
  34  *                                      stuff.
  35  *              Alan Cox        :       sendmsg/recvmsg basics.
  36  *
  37  *
  38  *              This program is free software; you can redistribute it and/or
  39  *              modify it under the terms of the GNU General Public License
  40  *              as published by the Free Software Foundation; either version
  41  *              2 of the License, or (at your option) any later version.
  42  *
  43  *
  44  *      This module is effectively the top level interface to the BSD socket
  45  *      paradigm. Because it is very simple it works well for Unix domain sockets,
  46  *      but requires a whole layer of substructure for the other protocols.
  47  *
  48  *      In addition it lacks an effective kernel -> kernel interface to go with
  49  *      the user one.
  50  */
  51 
  52 #include <linux/config.h>
  53 #include <linux/signal.h>
  54 #include <linux/errno.h>
  55 #include <linux/sched.h>
  56 #include <linux/mm.h>
  57 #include <linux/kernel.h>
  58 #include <linux/major.h>
  59 #include <linux/stat.h>
  60 #include <linux/socket.h>
  61 #include <linux/fcntl.h>
  62 #include <linux/net.h>
  63 #include <linux/interrupt.h>
  64 #include <linux/netdevice.h>
  65 #include <linux/proc_fs.h>
  66 
  67 #include <asm/system.h>
  68 #include <asm/segment.h>
  69 
  70 static int sock_lseek(struct inode *inode, struct file *file, off_t offset,
  71                       int whence);
  72 static int sock_read(struct inode *inode, struct file *file, char *buf,
  73                      int size);
  74 static int sock_write(struct inode *inode, struct file *file, const char *buf,
  75                       int size);
  76 
  77 static void sock_close(struct inode *inode, struct file *file);
  78 static int sock_select(struct inode *inode, struct file *file, int which, select_table *seltable);
  79 static int sock_ioctl(struct inode *inode, struct file *file,
  80                       unsigned int cmd, unsigned long arg);
  81 static int sock_fasync(struct inode *inode, struct file *filp, int on);
  82 
  83 
  84 /*
  85  *      Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
  86  *      in the operation structures but are done directly via the socketcall() multiplexor.
  87  */
  88 
  89 static struct file_operations socket_file_ops = {
  90         sock_lseek,
  91         sock_read,
  92         sock_write,
  93         NULL,                   /* readdir */
  94         sock_select,
  95         sock_ioctl,
  96         NULL,                   /* mmap */
  97         NULL,                   /* no special open code... */
  98         sock_close,
  99         NULL,                   /* no fsync */
 100         sock_fasync
 101 };
 102 
 103 /*
 104  *      The protocol list. Each protocol is registered in here.
 105  */
 106 static struct proto_ops *pops[NPROTO];
 107 /*
 108  *      Statistics counters of the socket lists
 109  */
 110 static int sockets_in_use  = 0;
 111 
 112 /*
 113  *      Support routines. Move socket addresses back and forth across the kernel/user
 114  *      divide and look after the messy bits.
 115  */
 116 
 117 #define MAX_SOCK_ADDR   128             /* 108 for Unix domain - 16 for IP, 16 for IPX, about 80 for AX.25 */
 118  
 119 int move_addr_to_kernel(void *uaddr, int ulen, void *kaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         int err;
 122         if(ulen<0||ulen>MAX_SOCK_ADDR)
 123                 return -EINVAL;
 124         if(ulen==0)
 125                 return 0;
 126         if((err=verify_area(VERIFY_READ,uaddr,ulen))<0)
 127                 return err;
 128         memcpy_fromfs(kaddr,uaddr,ulen);
 129         return 0;
 130 }
 131 
 132 int move_addr_to_user(void *kaddr, int klen, void *uaddr, int *ulen)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134         int err;
 135         int len;
 136 
 137                 
 138         if((err=verify_area(VERIFY_WRITE,ulen,sizeof(*ulen)))<0)
 139                 return err;
 140         len=get_user(ulen);
 141         if(len>klen)
 142                 len=klen;
 143         if(len<0 || len> MAX_SOCK_ADDR)
 144                 return -EINVAL;
 145         if(len)
 146         {
 147                 if((err=verify_area(VERIFY_WRITE,uaddr,len))<0)
 148                         return err;
 149                 memcpy_tofs(uaddr,kaddr,len);
 150         }
 151         put_user(len,ulen);
 152         return 0;
 153 }
 154 
 155 /*
 156  *      Obtains the first available file descriptor and sets it up for use. 
 157  */
 158 
 159 static int get_fd(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         int fd;
 162         struct file *file;
 163 
 164         /*
 165          *      Find a file descriptor suitable for return to the user. 
 166          */
 167 
 168         file = get_empty_filp();
 169         if (!file) 
 170                 return(-1);
 171 
 172         for (fd = 0; fd < NR_OPEN; ++fd)
 173                 if (!current->files->fd[fd]) 
 174                         break;
 175         if (fd == NR_OPEN) 
 176         {
 177                 file->f_count = 0;
 178                 return(-1);
 179         }
 180 
 181         FD_CLR(fd, &current->files->close_on_exec);
 182                 current->files->fd[fd] = file;
 183         file->f_op = &socket_file_ops;
 184         file->f_mode = 3;
 185         file->f_flags = O_RDWR;
 186         file->f_count = 1;
 187         file->f_inode = inode;
 188         if (inode) 
 189                 inode->i_count++;
 190         file->f_pos = 0;
 191         return(fd);
 192 }
 193 
 194 
 195 /*
 196  *      Go from an inode to its socket slot.
 197  *
 198  * The original socket implementation wasn't very clever, which is
 199  * why this exists at all..
 200  */
 201 inline struct socket *socki_lookup(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 202 {
 203         return &inode->u.socket_i;
 204 }
 205 
 206 /*
 207  *      Go from a file number to its socket slot.
 208  */
 209 
 210 static inline struct socket *sockfd_lookup(int fd, struct file **pfile)
     /* [previous][next][first][last][top][bottom][index][help] */
 211 {
 212         struct file *file;
 213         struct inode *inode;
 214 
 215         if (fd < 0 || fd >= NR_OPEN || !(file = current->files->fd[fd])) 
 216                 return NULL;
 217 
 218         inode = file->f_inode;
 219         if (!inode || !inode->i_sock)
 220                 return NULL;
 221 
 222         if (pfile) 
 223                 *pfile = file;
 224 
 225         return socki_lookup(inode);
 226 }
 227 
 228 /*
 229  *      Allocate a socket.
 230  */
 231 
 232 struct socket *sock_alloc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 233 {
 234         struct inode * inode;
 235         struct socket * sock;
 236 
 237         inode = get_empty_inode();
 238         if (!inode)
 239                 return NULL;
 240 
 241         inode->i_mode = S_IFSOCK;
 242         inode->i_sock = 1;
 243         inode->i_uid = current->uid;
 244         inode->i_gid = current->gid;
 245 
 246         sock = &inode->u.socket_i;
 247         sock->state = SS_UNCONNECTED;
 248         sock->flags = 0;
 249         sock->ops = NULL;
 250         sock->data = NULL;
 251         sock->conn = NULL;
 252         sock->iconn = NULL;
 253         sock->next = NULL;
 254         sock->wait = &inode->i_wait;
 255         sock->inode = inode;            /* "backlink": we could use pointer arithmetic instead */
 256         sock->fasync_list = NULL;
 257         sockets_in_use++;
 258         return sock;
 259 }
 260 
 261 /*
 262  *      Release a socket.
 263  */
 264 
 265 static inline void sock_release_peer(struct socket *peer)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267         peer->state = SS_DISCONNECTING;
 268         wake_up_interruptible(peer->wait);
 269         sock_wake_async(peer, 1);
 270 }
 271 
 272 void sock_release(struct socket *sock)
     /* [previous][next][first][last][top][bottom][index][help] */
 273 {
 274         int oldstate;
 275         struct socket *peersock, *nextsock;
 276 
 277         if ((oldstate = sock->state) != SS_UNCONNECTED)
 278                 sock->state = SS_DISCONNECTING;
 279 
 280         /*
 281          *      Wake up anyone waiting for connections. 
 282          */
 283 
 284         for (peersock = sock->iconn; peersock; peersock = nextsock) 
 285         {
 286                 nextsock = peersock->next;
 287                 sock_release_peer(peersock);
 288         }
 289 
 290         /*
 291          * Wake up anyone we're connected to. First, we release the
 292          * protocol, to give it a chance to flush data, etc.
 293          */
 294 
 295         peersock = (oldstate == SS_CONNECTED) ? sock->conn : NULL;
 296         if (sock->ops) 
 297                 sock->ops->release(sock, peersock);
 298         if (peersock)
 299                 sock_release_peer(peersock);
 300         --sockets_in_use;       /* Bookkeeping.. */
 301         iput(SOCK_INODE(sock));
 302 }
 303 
 304 /*
 305  *      Sockets are not seekable.
 306  */
 307 
 308 static int sock_lseek(struct inode *inode, struct file *file, off_t offset, int whence)
     /* [previous][next][first][last][top][bottom][index][help] */
 309 {
 310         return(-ESPIPE);
 311 }
 312 
 313 /*
 314  *      Read data from a socket. ubuf is a user mode pointer. We make sure the user
 315  *      area ubuf...ubuf+size-1 is writable before asking the protocol.
 316  */
 317 
 318 static int sock_read(struct inode *inode, struct file *file, char *ubuf, int size)
     /* [previous][next][first][last][top][bottom][index][help] */
 319 {
 320         struct socket *sock;
 321         int err;
 322   
 323         sock = socki_lookup(inode); 
 324         if (sock->flags & SO_ACCEPTCON) 
 325                 return(-EINVAL);
 326 
 327         if(size<0)
 328                 return -EINVAL;
 329         if(size==0)             /* Match SYS5 behaviour */
 330                 return 0;
 331         if ((err=verify_area(VERIFY_WRITE,ubuf,size))<0)
 332                 return err;
 333         return(sock->ops->read(sock, ubuf, size, (file->f_flags & O_NONBLOCK)));
 334 }
 335 
 336 /*
 337  *      Write data to a socket. We verify that the user area ubuf..ubuf+size-1 is
 338  *      readable by the user process.
 339  */
 340 
 341 static int sock_write(struct inode *inode, struct file *file, const char *ubuf, int size)
     /* [previous][next][first][last][top][bottom][index][help] */
 342 {
 343         struct socket *sock;
 344         int err;
 345         
 346         sock = socki_lookup(inode); 
 347 
 348         if (sock->flags & SO_ACCEPTCON) 
 349                 return(-EINVAL);
 350         
 351         if(size<0)
 352                 return -EINVAL;
 353         if(size==0)             /* Match SYS5 behaviour */
 354                 return 0;
 355                 
 356         if ((err=verify_area(VERIFY_READ,ubuf,size))<0)
 357                 return err;
 358         return(sock->ops->write(sock, ubuf, size,(file->f_flags & O_NONBLOCK)));
 359 }
 360 
 361 /*
 362  *      With an ioctl arg may well be a user mode pointer, but we don't know what to do
 363  *      with it - thats up to the protocol still.
 364  */
 365 
 366 int sock_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
     /* [previous][next][first][last][top][bottom][index][help] */
 367            unsigned long arg)
 368 {
 369         struct socket *sock;
 370         sock = socki_lookup(inode); 
 371         return(sock->ops->ioctl(sock, cmd, arg));
 372 }
 373 
 374 
 375 static int sock_select(struct inode *inode, struct file *file, int sel_type, select_table * wait)
     /* [previous][next][first][last][top][bottom][index][help] */
 376 {
 377         struct socket *sock;
 378 
 379         sock = socki_lookup(inode);
 380 
 381         /*
 382          *      We can't return errors to select, so it's either yes or no. 
 383          */
 384 
 385         if (sock->ops->select)
 386                 return(sock->ops->select(sock, sel_type, wait));
 387         return(0);
 388 }
 389 
 390 
 391 void sock_close(struct inode *inode, struct file *filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 392 {
 393         /*
 394          *      It's possible the inode is NULL if we're closing an unfinished socket. 
 395          */
 396 
 397         if (!inode) 
 398                 return;
 399         sock_fasync(inode, filp, 0);
 400         sock_release(socki_lookup(inode));
 401 }
 402 
 403 /*
 404  *      Update the socket async list
 405  */
 406  
 407 static int sock_fasync(struct inode *inode, struct file *filp, int on)
     /* [previous][next][first][last][top][bottom][index][help] */
 408 {
 409         struct fasync_struct *fa, *fna=NULL, **prev;
 410         struct socket *sock;
 411         unsigned long flags;
 412         
 413         if (on)
 414         {
 415                 fna=(struct fasync_struct *)kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
 416                 if(fna==NULL)
 417                         return -ENOMEM;
 418         }
 419 
 420         sock = socki_lookup(inode);
 421         
 422         prev=&(sock->fasync_list);
 423         
 424         save_flags(flags);
 425         cli();
 426         
 427         for(fa=*prev; fa!=NULL; prev=&fa->fa_next,fa=*prev)
 428                 if(fa->fa_file==filp)
 429                         break;
 430         
 431         if(on)
 432         {
 433                 if(fa!=NULL)
 434                 {
 435                         kfree_s(fna,sizeof(struct fasync_struct));
 436                         restore_flags(flags);
 437                         return 0;
 438                 }
 439                 fna->fa_file=filp;
 440                 fna->magic=FASYNC_MAGIC;
 441                 fna->fa_next=sock->fasync_list;
 442                 sock->fasync_list=fna;
 443         }
 444         else
 445         {
 446                 if(fa!=NULL)
 447                 {
 448                         *prev=fa->fa_next;
 449                         kfree_s(fa,sizeof(struct fasync_struct));
 450                 }
 451         }
 452         restore_flags(flags);
 453         return 0;
 454 }
 455 
 456 int sock_wake_async(struct socket *sock, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
 457 {
 458         if (!sock || !sock->fasync_list)
 459                 return -1;
 460         switch (how)
 461         {
 462                 case 0:
 463                         kill_fasync(sock->fasync_list, SIGIO);
 464                         break;
 465                 case 1:
 466                         if (!(sock->flags & SO_WAITDATA))
 467                                 kill_fasync(sock->fasync_list, SIGIO);
 468                         break;
 469                 case 2:
 470                         if (sock->flags & SO_NOSPACE)
 471                         {
 472                                 kill_fasync(sock->fasync_list, SIGIO);
 473                                 sock->flags &= ~SO_NOSPACE;
 474                         }
 475                         break;
 476         }
 477         return 0;
 478 }
 479 
 480         
 481 /*
 482  *      Wait for a connection.
 483  */
 484 
 485 int sock_awaitconn(struct socket *mysock, struct socket *servsock, int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 486 {
 487         struct socket *last;
 488 
 489         /*
 490          *      We must be listening
 491          */
 492         if (!(servsock->flags & SO_ACCEPTCON)) 
 493         {
 494                 return(-EINVAL);
 495         }
 496 
 497         /*
 498          *      Put ourselves on the server's incomplete connection queue. 
 499          */
 500          
 501         mysock->next = NULL;
 502         cli();
 503         if (!(last = servsock->iconn)) 
 504                 servsock->iconn = mysock;
 505         else 
 506         {
 507                 while (last->next) 
 508                         last = last->next;
 509                 last->next = mysock;
 510         }
 511         mysock->state = SS_CONNECTING;
 512         mysock->conn = servsock;
 513         sti();
 514 
 515         /*
 516          * Wake up server, then await connection. server will set state to
 517          * SS_CONNECTED if we're connected.
 518          */
 519         wake_up_interruptible(servsock->wait);
 520         sock_wake_async(servsock, 0);
 521 
 522         if (mysock->state != SS_CONNECTED) 
 523         {
 524                 if (flags & O_NONBLOCK)
 525                         return -EINPROGRESS;
 526 
 527                 interruptible_sleep_on(mysock->wait);
 528                 if (mysock->state != SS_CONNECTED &&
 529                     mysock->state != SS_DISCONNECTING) 
 530                 {
 531                 /*
 532                  * if we're not connected we could have been
 533                  * 1) interrupted, so we need to remove ourselves
 534                  *    from the server list
 535                  * 2) rejected (mysock->conn == NULL), and have
 536                  *    already been removed from the list
 537                  */
 538                         if (mysock->conn == servsock) 
 539                         {
 540                                 cli();
 541                                 if ((last = servsock->iconn) == mysock)
 542                                         servsock->iconn = mysock->next;
 543                                 else 
 544                                 {
 545                                         while (last->next != mysock) 
 546                                                 last = last->next;
 547                                         last->next = mysock->next;
 548                                 }
 549                                 sti();
 550                         }
 551                         return(mysock->conn ? -EINTR : -EACCES);
 552                 }
 553         }
 554         return(0);
 555 }
 556 
 557 
 558 /*
 559  *      Perform the socket system call. we locate the appropriate
 560  *      family, then create a fresh socket.
 561  */
 562 
 563 asmlinkage int sys_socket(int family, int type, int protocol)
     /* [previous][next][first][last][top][bottom][index][help] */
 564 {
 565         int i, fd;
 566         struct socket *sock;
 567         struct proto_ops *ops;
 568 
 569         /* Locate the correct protocol family. */
 570         for (i = 0; i < NPROTO; ++i) 
 571         {
 572                 if (pops[i] == NULL) continue;
 573                 if (pops[i]->family == family) 
 574                         break;
 575         }
 576 
 577         if (i == NPROTO) 
 578         {
 579                 return -EINVAL;
 580         }
 581 
 582         ops = pops[i];
 583 
 584 /*
 585  *      Check that this is a type that we know how to manipulate and
 586  *      the protocol makes sense here. The family can still reject the
 587  *      protocol later.
 588  */
 589   
 590         if ((type != SOCK_STREAM && type != SOCK_DGRAM &&
 591                 type != SOCK_SEQPACKET && type != SOCK_RAW &&
 592                 type != SOCK_PACKET) || protocol < 0)
 593                         return(-EINVAL);
 594 
 595 /*
 596  *      Allocate the socket and allow the family to set things up. if
 597  *      the protocol is 0, the family is instructed to select an appropriate
 598  *      default.
 599  */
 600 
 601         if (!(sock = sock_alloc())) 
 602         {
 603                 printk("NET: sys_socket: no more sockets\n");
 604                 return(-ENOSR); /* Was: EAGAIN, but we are out of
 605                                    system resources! */
 606         }
 607 
 608         sock->type = type;
 609         sock->ops = ops;
 610         if ((i = sock->ops->create(sock, protocol)) < 0) 
 611         {
 612                 sock_release(sock);
 613                 return(i);
 614         }
 615 
 616         if ((fd = get_fd(SOCK_INODE(sock))) < 0) 
 617         {
 618                 sock_release(sock);
 619                 return(-EINVAL);
 620         }
 621 
 622         return(fd);
 623 }
 624 
 625 /*
 626  *      Create a pair of connected sockets.
 627  */
 628 
 629 asmlinkage int sys_socketpair(int family, int type, int protocol, int usockvec[2])
     /* [previous][next][first][last][top][bottom][index][help] */
 630 {
 631         int fd1, fd2, i;
 632         struct socket *sock1, *sock2;
 633         int er;
 634 
 635         /*
 636          * Obtain the first socket and check if the underlying protocol
 637          * supports the socketpair call.
 638          */
 639 
 640         if ((fd1 = sys_socket(family, type, protocol)) < 0) 
 641                 return(fd1);
 642         sock1 = sockfd_lookup(fd1, NULL);
 643         if (!sock1->ops->socketpair) 
 644         {
 645                 sys_close(fd1);
 646                 return(-EINVAL);
 647         }
 648 
 649         /*
 650          *      Now grab another socket and try to connect the two together. 
 651          */
 652 
 653         if ((fd2 = sys_socket(family, type, protocol)) < 0) 
 654         {
 655                 sys_close(fd1);
 656                 return(-EINVAL);
 657         }
 658 
 659         sock2 = sockfd_lookup(fd2, NULL);
 660         if ((i = sock1->ops->socketpair(sock1, sock2)) < 0) 
 661         {
 662                 sys_close(fd1);
 663                 sys_close(fd2);
 664                 return(i);
 665         }
 666 
 667         sock1->conn = sock2;
 668         sock2->conn = sock1;
 669         sock1->state = SS_CONNECTED;
 670         sock2->state = SS_CONNECTED;
 671 
 672         er=verify_area(VERIFY_WRITE, usockvec, sizeof(usockvec));
 673         if(er)
 674         {
 675                 sys_close(fd1);
 676                 sys_close(fd2);
 677                 return er;
 678         }
 679         put_user(fd1, &usockvec[0]);
 680         put_user(fd2, &usockvec[1]);
 681 
 682         return(0);
 683 }
 684 
 685 
 686 /*
 687  *      Bind a name to a socket. Nothing much to do here since it's
 688  *      the protocol's responsibility to handle the local address.
 689  *
 690  *      We move the socket address to kernel space before we call
 691  *      the protocol layer (having also checked the address is ok).
 692  */
 693  
 694 asmlinkage int sys_bind(int fd, struct sockaddr *umyaddr, int addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 695 {
 696         struct socket *sock;
 697         int i;
 698         char address[MAX_SOCK_ADDR];
 699         int err;
 700 
 701         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 702                 return(-EBADF);
 703         
 704         if (!(sock = sockfd_lookup(fd, NULL))) 
 705                 return(-ENOTSOCK);
 706   
 707         if((err=move_addr_to_kernel(umyaddr,addrlen,address))<0)
 708                 return err;
 709   
 710         if ((i = sock->ops->bind(sock, (struct sockaddr *)address, addrlen)) < 0) 
 711         {
 712                 return(i);
 713         }
 714         return(0);
 715 }
 716 
 717 
 718 /*
 719  *      Perform a listen. Basically, we allow the protocol to do anything
 720  *      necessary for a listen, and if that works, we mark the socket as
 721  *      ready for listening.
 722  */
 723 
 724 asmlinkage int sys_listen(int fd, int backlog)
     /* [previous][next][first][last][top][bottom][index][help] */
 725 {
 726         struct socket *sock;
 727 
 728         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 729                 return(-EBADF);
 730         if (!(sock = sockfd_lookup(fd, NULL))) 
 731                 return(-ENOTSOCK);
 732 
 733         if (sock->state != SS_UNCONNECTED) 
 734         {
 735                 return(-EINVAL);
 736         }
 737 
 738         if (sock->ops && sock->ops->listen)
 739                 sock->ops->listen(sock, backlog);
 740         sock->flags |= SO_ACCEPTCON;
 741         return(0);
 742 }
 743 
 744 
 745 /*
 746  *      For accept, we attempt to create a new socket, set up the link
 747  *      with the client, wake up the client, then return the new
 748  *      connected fd. We collect the address of the connector in kernel
 749  *      space and move it to user at the very end. This is buggy because
 750  *      we open the socket then return an error.
 751  */
 752 
 753 asmlinkage int sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 754 {
 755         struct file *file;
 756         struct socket *sock, *newsock;
 757         int i;
 758         char address[MAX_SOCK_ADDR];
 759         int len;
 760 
 761         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 762                 return(-EBADF);
 763         if (!(sock = sockfd_lookup(fd, &file))) 
 764                 return(-ENOTSOCK);
 765         if (sock->state != SS_UNCONNECTED) 
 766         {
 767                 return(-EINVAL);
 768         }
 769         if (!(sock->flags & SO_ACCEPTCON)) 
 770         {
 771                 return(-EINVAL);
 772         }
 773 
 774         if (!(newsock = sock_alloc())) 
 775         {
 776                 printk("NET: sock_accept: no more sockets\n");
 777                 return(-ENOSR); /* Was: EAGAIN, but we are out of system
 778                                    resources! */
 779         }
 780         newsock->type = sock->type;
 781         newsock->ops = sock->ops;
 782         if ((i = sock->ops->dup(newsock, sock)) < 0) 
 783         {
 784                 sock_release(newsock);
 785                 return(i);
 786         }
 787 
 788         i = newsock->ops->accept(sock, newsock, file->f_flags);
 789         if ( i < 0) 
 790         {
 791                 sock_release(newsock);
 792                 return(i);
 793         }
 794 
 795         if ((fd = get_fd(SOCK_INODE(newsock))) < 0) 
 796         {
 797                 sock_release(newsock);
 798                 return(-EINVAL);
 799         }
 800 
 801         if (upeer_sockaddr)
 802         {
 803                 newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 1);
 804                 move_addr_to_user(address,len, upeer_sockaddr, upeer_addrlen);
 805         }
 806         return(fd);
 807 }
 808 
 809 
 810 /*
 811  *      Attempt to connect to a socket with the server address.  The address
 812  *      is in user space so we verify it is OK and move it to kernel space.
 813  */
 814  
 815 asmlinkage int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 816 {
 817         struct socket *sock;
 818         struct file *file;
 819         int i;
 820         char address[MAX_SOCK_ADDR];
 821         int err;
 822 
 823         if (fd < 0 || fd >= NR_OPEN || (file=current->files->fd[fd]) == NULL)
 824                 return(-EBADF);
 825         if (!(sock = sockfd_lookup(fd, &file)))
 826                 return(-ENOTSOCK);
 827 
 828         if((err=move_addr_to_kernel(uservaddr,addrlen,address))<0)
 829                 return err;
 830   
 831         switch(sock->state) 
 832         {
 833                 case SS_UNCONNECTED:
 834                         /* This is ok... continue with connect */
 835                         break;
 836                 case SS_CONNECTED:
 837                         /* Socket is already connected */
 838                         if(sock->type == SOCK_DGRAM) /* Hack for now - move this all into the protocol */
 839                                 break;
 840                         return -EISCONN;
 841                 case SS_CONNECTING:
 842                         /* Not yet connected... we will check this. */
 843                 
 844                         /*
 845                          *      FIXME:  for all protocols what happens if you start
 846                          *      an async connect fork and both children connect. Clean
 847                          *      this up in the protocols!
 848                          */
 849                         break;
 850                 default:
 851                         return(-EINVAL);
 852         }
 853         i = sock->ops->connect(sock, (struct sockaddr *)address, addrlen, file->f_flags);
 854         if (i < 0) 
 855         {
 856                 return(i);
 857         }
 858         return(0);
 859 }
 860 
 861 /*
 862  *      Get the local address ('name') of a socket object. Move the obtained
 863  *      name to user space.
 864  */
 865 
 866 asmlinkage int sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 867 {
 868         struct socket *sock;
 869         char address[MAX_SOCK_ADDR];
 870         int len;
 871         int err;
 872         
 873         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 874                 return(-EBADF);
 875         if (!(sock = sockfd_lookup(fd, NULL)))
 876                 return(-ENOTSOCK);
 877 
 878         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
 879         if(err)
 880                 return err;
 881         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 882                 return err;
 883         return 0;
 884 }
 885 
 886 /*
 887  *      Get the remote address ('name') of a socket object. Move the obtained
 888  *      name to user space.
 889  */
 890  
 891 asmlinkage int sys_getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
     /* [previous][next][first][last][top][bottom][index][help] */
 892 {
 893         struct socket *sock;
 894         char address[MAX_SOCK_ADDR];
 895         int len;
 896         int err;
 897 
 898         if (fd < 0 || fd >= NR_OPEN || current->files->fd[fd] == NULL)
 899                 return(-EBADF);
 900         if (!(sock = sockfd_lookup(fd, NULL)))
 901                 return(-ENOTSOCK);
 902 
 903         err=sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
 904         if(err)
 905                 return err;
 906         if((err=move_addr_to_user(address,len, usockaddr, usockaddr_len))<0)
 907                 return err;
 908         return 0;
 909 }
 910 
 911 /*
 912  *      Send a datagram down a socket. The datagram as with write() is
 913  *      in user space. We check it can be read.
 914  */
 915 
 916 asmlinkage int sys_send(int fd, void * buff, int len, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 917 {
 918         struct socket *sock;
 919         struct file *file;
 920         int err;
 921 
 922         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 923                 return(-EBADF);
 924         if (!(sock = sockfd_lookup(fd, NULL))) 
 925                 return(-ENOTSOCK);
 926 
 927         if(len<0)
 928                 return -EINVAL;
 929         err=verify_area(VERIFY_READ, buff, len);
 930         if(err)
 931                 return err;
 932         return(sock->ops->send(sock, buff, len, (file->f_flags & O_NONBLOCK), flags));
 933 }
 934 
 935 /*
 936  *      Send a datagram to a given address. We move the address into kernel
 937  *      space and check the user space data area is readable before invoking
 938  *      the protocol.
 939  */
 940 
 941 asmlinkage int sys_sendto(int fd, void * buff, int len, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
 942            struct sockaddr *addr, int addr_len)
 943 {
 944         struct socket *sock;
 945         struct file *file;
 946         char address[MAX_SOCK_ADDR];
 947         int err;
 948         
 949         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 950                 return(-EBADF);
 951         if (!(sock = sockfd_lookup(fd, NULL)))
 952                 return(-ENOTSOCK);
 953 
 954         if(len<0)
 955                 return -EINVAL;
 956         err=verify_area(VERIFY_READ,buff,len);
 957         if(err)
 958                 return err;
 959         
 960         if((err=move_addr_to_kernel(addr,addr_len,address))<0)
 961                 return err;
 962 
 963         return(sock->ops->sendto(sock, buff, len, (file->f_flags & O_NONBLOCK),
 964                 flags, (struct sockaddr *)address, addr_len));
 965 }
 966 
 967 
 968 /*
 969  *      Receive a datagram from a socket. This isn't really right. The BSD manual
 970  *      pages explicitly state that recv is recvfrom with a NULL to argument. The
 971  *      Linux stack gets the right results for the wrong reason and this need to
 972  *      be tidied in the inet layer and removed from here.
 973  *      We check the buffer is writable and valid.
 974  */
 975 
 976 asmlinkage int sys_recv(int fd, void * buff, int len, unsigned flags)
     /* [previous][next][first][last][top][bottom][index][help] */
 977 {
 978         struct socket *sock;
 979         struct file *file;
 980         int err;
 981 
 982         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
 983                 return(-EBADF);
 984 
 985         if (!(sock = sockfd_lookup(fd, NULL))) 
 986                 return(-ENOTSOCK);
 987                 
 988         if(len<0)
 989                 return -EINVAL;
 990         if(len==0)
 991                 return 0;
 992         err=verify_area(VERIFY_WRITE, buff, len);
 993         if(err)
 994                 return err;
 995 
 996         return(sock->ops->recv(sock, buff, len,(file->f_flags & O_NONBLOCK), flags));
 997 }
 998 
 999 /*
1000  *      Receive a frame from the socket and optionally record the address of the 
1001  *      sender. We verify the buffers are writable and if needed move the
1002  *      sender address from kernel to user space.
1003  */
1004 
1005 asmlinkage int sys_recvfrom(int fd, void * buff, int len, unsigned flags,
     /* [previous][next][first][last][top][bottom][index][help] */
1006              struct sockaddr *addr, int *addr_len)
1007 {
1008         struct socket *sock;
1009         struct file *file;
1010         char address[MAX_SOCK_ADDR];
1011         int err;
1012         int alen;
1013         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1014                 return(-EBADF);
1015         if (!(sock = sockfd_lookup(fd, NULL))) 
1016                 return(-ENOTSOCK);
1017         if(len<0)
1018                 return -EINVAL;
1019         if(len==0)
1020                 return 0;
1021 
1022         err=verify_area(VERIFY_WRITE,buff,len);
1023         if(err)
1024                 return err;
1025   
1026         len=sock->ops->recvfrom(sock, buff, len, (file->f_flags & O_NONBLOCK),
1027                      flags, (struct sockaddr *)address, &alen);
1028 
1029         if(len<0)
1030                 return len;
1031         if(addr!=NULL && (err=move_addr_to_user(address,alen, addr, addr_len))<0)
1032                 return err;
1033 
1034         return len;
1035 }
1036 
1037 /*
1038  *      Set a socket option. Because we don't know the option lengths we have
1039  *      to pass the user mode parameter for the protocols to sort out.
1040  */
1041  
1042 asmlinkage int sys_setsockopt(int fd, int level, int optname, char *optval, int optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1043 {
1044         struct socket *sock;
1045         struct file *file;
1046         
1047         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1048                 return(-EBADF);
1049         if (!(sock = sockfd_lookup(fd, NULL))) 
1050                 return(-ENOTSOCK);
1051 
1052         return(sock->ops->setsockopt(sock, level, optname, optval, optlen));
1053 }
1054 
1055 /*
1056  *      Get a socket option. Because we don't know the option lengths we have
1057  *      to pass a user mode parameter for the protocols to sort out.
1058  */
1059 
1060 asmlinkage int sys_getsockopt(int fd, int level, int optname, char *optval, int *optlen)
     /* [previous][next][first][last][top][bottom][index][help] */
1061 {
1062         struct socket *sock;
1063         struct file *file;
1064 
1065         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1066                 return(-EBADF);
1067         if (!(sock = sockfd_lookup(fd, NULL)))
1068                 return(-ENOTSOCK);
1069             
1070         if (!sock->ops->getsockopt) 
1071                 return(0);
1072         return(sock->ops->getsockopt(sock, level, optname, optval, optlen));
1073 }
1074 
1075 
1076 /*
1077  *      Shutdown a socket.
1078  */
1079  
1080 asmlinkage int sys_shutdown(int fd, int how)
     /* [previous][next][first][last][top][bottom][index][help] */
1081 {
1082         struct socket *sock;
1083         struct file *file;
1084 
1085         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1086                 return(-EBADF);
1087         if (!(sock = sockfd_lookup(fd, NULL))) 
1088                 return(-ENOTSOCK);
1089 
1090         return(sock->ops->shutdown(sock, how));
1091 }
1092 
1093 /*
1094  *      BSD sendmsg interface
1095  */
1096  
1097 asmlinkage int sys_sendmsg(int fd, struct msghdr *msg, unsigned int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1098 {
1099         struct socket *sock;
1100         struct file *file;
1101         char address[MAX_SOCK_ADDR];
1102         struct iovec iov[MAX_IOVEC];
1103         struct msghdr msg_sys;
1104         int err;
1105         int total_len;
1106         
1107         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1108                 return(-EBADF);
1109         if (!(sock = sockfd_lookup(fd, NULL)))
1110                 return(-ENOTSOCK);
1111         
1112         err=verify_area(VERIFY_READ, msg,sizeof(struct msghdr));
1113         if(err)
1114                 return err;
1115         memcpy_fromfs(&msg_sys,msg,sizeof(struct msghdr));
1116         if(msg_sys.msg_iovlen>MAX_IOVEC)
1117                 return -EINVAL;
1118         err=verify_iovec(&msg_sys,iov,address, VERIFY_READ);
1119         if(err<0)
1120                 return err;
1121         total_len=err;
1122         
1123         if(sock->ops->sendmsg==NULL)
1124                 return -EOPNOTSUPP;
1125         return sock->ops->sendmsg(sock, &msg_sys, total_len, (file->f_flags&O_NONBLOCK), flags);
1126 }
1127 
1128 /*
1129  *      BSD recvmsg interface
1130  */
1131  
1132 asmlinkage int sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)
     /* [previous][next][first][last][top][bottom][index][help] */
1133 {
1134         struct socket *sock;
1135         struct file *file;
1136         char address[MAX_SOCK_ADDR];
1137         struct iovec iov[MAX_IOVEC];
1138         struct msghdr msg_sys;
1139         int err;
1140         int total_len;
1141         int addr_len;
1142         int len;
1143         
1144         if (fd < 0 || fd >= NR_OPEN || ((file = current->files->fd[fd]) == NULL))
1145                 return(-EBADF);
1146         if (!(sock = sockfd_lookup(fd, NULL)))
1147                 return(-ENOTSOCK);
1148         
1149         err=verify_area(VERIFY_READ, msg,sizeof(struct msghdr));
1150         if(err)
1151                 return err;
1152         memcpy_fromfs(&msg_sys,msg,sizeof(struct msghdr));
1153         if(msg_sys.msg_iovlen>MAX_IOVEC)
1154                 return -EINVAL;
1155         err=verify_iovec(&msg_sys,iov,address, VERIFY_WRITE);
1156         if(err<0)
1157                 return err;
1158         total_len=err;
1159         
1160         if(sock->ops->recvmsg==NULL)
1161                 return -EOPNOTSUPP;
1162         len=sock->ops->recvmsg(sock, &msg_sys, total_len, (file->f_flags&O_NONBLOCK), flags, &addr_len);
1163         if(len<0)
1164                 return len;
1165         /*
1166          *      Fixme: writing actual length into original msghdr.
1167          */
1168         if(msg_sys.msg_name!=NULL && (err=move_addr_to_user(address,addr_len, msg_sys.msg_name, &msg_sys.msg_namelen))<0)
1169                 return err;
1170         return len;
1171 }
1172 
1173 
1174 /*
1175  *      Perform a file control on a socket file descriptor.
1176  */
1177 
1178 int sock_fcntl(struct file *filp, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
1179 {
1180         struct socket *sock;
1181 
1182         sock = socki_lookup (filp->f_inode);
1183         if (sock != NULL && sock->ops != NULL && sock->ops->fcntl != NULL)
1184                 return(sock->ops->fcntl(sock, cmd, arg));
1185         return(-EINVAL);
1186 }
1187 
1188 
1189 /*
1190  *      System call vectors. Since I (RIB) want to rewrite sockets as streams,
1191  *      we have this level of indirection. Not a lot of overhead, since more of
1192  *      the work is done via read/write/select directly.
1193  *
1194  *      I'm now expanding this up to a higher level to separate the assorted
1195  *      kernel/user space manipulations and global assumptions from the protocol
1196  *      layers proper - AC.
1197  *
1198  *      Argument checking cleaned up. Saved 20% in size.
1199  */
1200 
1201 asmlinkage int sys_socketcall(int call, unsigned long *args)
     /* [previous][next][first][last][top][bottom][index][help] */
1202 {
1203         int er;
1204         unsigned char nargs[18]={0,3,3,3,2,3,3,3,
1205                                  4,4,4,6,6,2,5,5,3,3};
1206 
1207         unsigned long a0,a1;
1208                                  
1209         if(call<1||call>SYS_RECVMSG)
1210                 return -EINVAL;
1211                 
1212         er=verify_area(VERIFY_READ, args, nargs[call] * sizeof(unsigned long));
1213         if(er)
1214                 return er;
1215                 
1216         a0=get_user(args);
1217         a1=get_user(args+1);
1218         
1219                 
1220         switch(call) 
1221         {
1222                 case SYS_SOCKET:
1223                         return(sys_socket(a0,a1,get_user(args+2)));
1224                 case SYS_BIND:
1225                         return(sys_bind(a0,(struct sockaddr *)a1,
1226                                         get_user(args+2)));
1227                 case SYS_CONNECT:
1228                         return(sys_connect(a0, (struct sockaddr *)a1,
1229                                            get_user(args+2)));
1230                 case SYS_LISTEN:
1231                         return(sys_listen(a0,a1));
1232                 case SYS_ACCEPT:
1233                         return(sys_accept(a0,(struct sockaddr *)a1,
1234                                           (int *)get_user(args+2)));
1235                 case SYS_GETSOCKNAME:
1236                         return(sys_getsockname(a0,(struct sockaddr *)a1,
1237                                                (int *)get_user(args+2)));
1238                 case SYS_GETPEERNAME:
1239                         return(sys_getpeername(a0, (struct sockaddr *)a1,
1240                                                (int *)get_user(args+2)));
1241                 case SYS_SOCKETPAIR:
1242                         return(sys_socketpair(a0,a1,
1243                                               get_user(args+2),
1244                                               (int *)get_user(args+3)));
1245                 case SYS_SEND:
1246                         return(sys_send(a0,
1247                                 (void *)a1,
1248                                 get_user(args+2),
1249                                 get_user(args+3)));
1250                 case SYS_SENDTO:
1251                         return(sys_sendto(a0,(void *)a1,
1252                                 get_user(args+2),
1253                                 get_user(args+3),
1254                                 (struct sockaddr *)get_user(args+4),
1255                                 get_user(args+5)));
1256                 case SYS_RECV:
1257                         return(sys_recv(a0,
1258                                 (void *)a1,
1259                                 get_user(args+2),
1260                                 get_user(args+3)));
1261                 case SYS_RECVFROM:
1262                         return(sys_recvfrom(a0,
1263                                 (void *)a1,
1264                                 get_user(args+2),
1265                                 get_user(args+3),
1266                                 (struct sockaddr *)get_user(args+4),
1267                                 (int *)get_user(args+5)));
1268                 case SYS_SHUTDOWN:
1269                         return(sys_shutdown(a0,a1));
1270                 case SYS_SETSOCKOPT:
1271                         return(sys_setsockopt(a0,
1272                                 a1,
1273                                 get_user(args+2),
1274                                 (char *)get_user(args+3),
1275                                 get_user(args+4)));
1276                 case SYS_GETSOCKOPT:
1277                         return(sys_getsockopt(a0,
1278                                 a1,
1279                                 get_user(args+2),
1280                                 (char *)get_user(args+3),
1281                                 (int *)get_user(args+4)));
1282                 case SYS_SENDMSG:
1283                                 return sys_sendmsg(a0,
1284                                         (struct msghdr *) a1,
1285                                         get_user(args+2));
1286                 case SYS_RECVMSG:
1287                                 return sys_recvmsg(a0,
1288                                         (struct msghdr *) a1,
1289                                         get_user(args+2));
1290         }
1291         return -EINVAL; /* to keep gcc happy */
1292 }
1293 
1294 /*
1295  *      This function is called by a protocol handler that wants to
1296  *      advertise its address family, and have it linked into the
1297  *      SOCKET module.
1298  */
1299  
1300 int sock_register(int family, struct proto_ops *ops)
     /* [previous][next][first][last][top][bottom][index][help] */
1301 {
1302         int i;
1303 
1304         cli();
1305         for(i = 0; i < NPROTO; i++) 
1306         {
1307                 if (pops[i] != NULL) 
1308                         continue;
1309                 pops[i] = ops;
1310                 pops[i]->family = family;
1311                 sti();
1312                 return(i);
1313         }
1314         sti();
1315         return(-ENOMEM);
1316 }
1317 
1318 /*
1319  *      This function is called by a protocol handler that wants to
1320  *      remove its address family, and have it unlinked from the
1321  *      SOCKET module.
1322  */
1323  
1324 int sock_unregister(int family)
     /* [previous][next][first][last][top][bottom][index][help] */
1325 {
1326         int i;
1327 
1328         cli();
1329         for(i = 0; i < NPROTO; i++) 
1330         {
1331                 if (pops[i] == NULL) 
1332                         continue;
1333                 if (pops[i]->family == family)
1334                 {
1335                         pops[i]=NULL;
1336                         sti();
1337                         return(i);
1338                 }
1339         }
1340         sti();
1341         return(-ENOENT);
1342 }
1343 
1344 void proto_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1345 {
1346         extern struct net_proto protocols[];    /* Network protocols */
1347         struct net_proto *pro;
1348 
1349         /* Kick all configured protocols. */
1350         pro = protocols;
1351         while (pro->name != NULL) 
1352         {
1353                 (*pro->init_func)(pro);
1354                 pro++;
1355         }
1356         /* We're all done... */
1357 }
1358 
1359 
1360 void sock_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1361 {
1362         int i;
1363 
1364         printk("Swansea University Computer Society NET3.030 Snap #1 for Linux 1.3.4\n");
1365 
1366         /*
1367          *      Initialize all address (protocol) families. 
1368          */
1369          
1370         for (i = 0; i < NPROTO; ++i) pops[i] = NULL;
1371 
1372         /*
1373          *      Initialize the protocols module. 
1374          */
1375 
1376         proto_init();
1377 
1378 #ifdef CONFIG_NET
1379         /* 
1380          *      Initialize the DEV module. 
1381          */
1382 
1383         dev_init();
1384   
1385         /*
1386          *      And the bottom half handler 
1387          */
1388 
1389         bh_base[NET_BH].routine= net_bh;
1390         enable_bh(NET_BH);
1391 #endif  
1392 }
1393 
1394 int socket_get_info(char *buffer, char **start, off_t offset, int length)
     /* [previous][next][first][last][top][bottom][index][help] */
1395 {
1396         int len = sprintf(buffer, "sockets: used %d\n", sockets_in_use);
1397         if (offset >= len)
1398         {
1399                 *start = buffer;
1400                 return 0;
1401         }
1402         *start = buffer + offset;
1403         len -= offset;
1404         if (len > length)
1405                 len = length;
1406         return len;
1407 }

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