ftp.nice.ch/pub/next/unix/admin/msend.1.0.N.bs.tar.gz#/msend/establish.c

This is establish.c in view mode; [Download] [Up]

/* establish.c:
 *
 * routine to establish a port for incoming connections
 *
 * this routine was originally written by Barry Shein (bzs@bu-it.bu.edu).
 */

#include "config.h"
#include "msend.h"

int establish(port)
     u_short port;
{ char   myname[MAXHOSTNAME+1];
  int    s;
  struct sockaddr_in sa;
  struct hostent *hp;

  gethostname(myname,MAXHOSTNAME);            /* who are we? */
  bzero(&sa,sizeof(struct sockaddr_in));
  hp= gethostbyname(myname);                  /* get our address info */
  if (hp == NULL)                             /* we don't exist !? */
    return(-1);
  sa.sin_family= hp->h_addrtype;              /* set up info for new socket */
  sa.sin_port= htons(port);
  if ((s= socket(AF_INET,SOCK_STREAM,0)) < 0) /* make new socket */
    return(-1);
  if (bind(s,&sa,sizeof sa) < 0)
    return(-1);                               /* bind socket */
  return(s);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.