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_readdir
  13. sock_ioctl
  14. sock_select
  15. sock_close
  16. sock_fasync
  17. sock_wake_async
  18. sock_awaitconn
  19. sock_socket
  20. sock_socketpair
  21. sock_bind
  22. sock_listen
  23. sock_accept
  24. sock_connect
  25. sock_getsockname
  26. sock_getpeername
  27. sock_send
  28. sock_sendto
  29. sock_recv
  30. sock_recvfrom
  31. sock_setsockopt
  32. sock_getsockopt
  33. sock_shutdown
  34. sock_fcntl
  35. sys_socketcall
  36. sock_register
  37. sock_unregister
  38. proto_init
  39. sock_init
  40. socket_get_info

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

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