LISTENBYNAME(3)                                                LISTENBYNAME(3)



NAME
       listenbyname - listen for IP version agnostic connections

SYNOPSIS
       #include <easyv6.h>

       int listenbyname(const char *service,
                        int socktype, int backlog);

DESCRIPTION
       Open a socket of type socktpye (SOCK_STREAM or SOCK_SEQPACKET) bound to
       the service named service and begin listening for incoming connections.
       The  socket will accept IPv4 and IPv6 connections and may in the future
       accept incoming connections on new protocols.

       Works just like listen(2) but also creates and binds the socket.

       service
              A TCP port number such as "80" or textual representation such as
              "http".

       backlog
              The  backlog  argument  defines  the maximum length to which the
              queue of pending connections for sockfd may grow.  If a  connec-
              tion  request  arrives  when  the  queue is full, the client may
              receive an error with an indication of ECONNREFUSED or,  if  the
              underlying  protocol supports retransmission, the request may be
              ignored so that a later reattempt at connection succeeds.


RETURN VALUE
       On success, a file descriptor for the new listening socket is returned.
       On error, -1 is returned, and errno is set appropriately.

       Note that the returned socket will be in non-blocking mode. If blocking
       mode is desired, use fcntl().

ERRORS
       Refer to socket (2), bind (2), and listen (2) for possible  errno  val-
       ues.

EXAMPLE
       #include <easyv6.h>
       #include <stdio.h>
       #include <errno.h>
       #include <stdlib.h> /* exit */
       #include <sys/socket.h>

       int main (int argc, char **argv) {
         int i, l;
         char s[200], *p;

         l = listenbyname("3000",SOCK_STREAM,10);
         fprintf (stdout,"Listening on port 3000...0);
         i = accept (l,NULL,NULL);
         p=getpeernametext(i,s,200);
         if (p) {
           printf ("Connect from: %s port %s0,p,s);
         } else {
           printf ("getpeernametext failed: socket=%d, errno=%d, error=%s0,
               i,errno,strerror(errno));
         }
         p="You connected to the tester. Bye!0;
         write (i,p,strlen(p));
         shutdown (i,SHUT_RDWR);
         close (i);
         close (l);

         return 0;
       }

SEE ALSO
       addrinfototext(3),        connectbyaddrinfo(3),       connectbyname(3),
       getpeernametext(3), timeoutgetaddrinfo(3),

AUTHOR
       libeasyv6 was written by William Herrin <bill@herrin.us>.



                                March 18, 2012                 LISTENBYNAME(3)
