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

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