// Wrapper functions for some socket calls. // // These functions assume any error is a fatal error! #include /* standard C i/o facilities */ #include /* needed for atoi() */ #include /* Unix System Calls */ #include /* system data type definitions */ #include /* socket specific definitions */ #include /* INET constants and stuff */ #include /* IP address conversion stuff */ // wrapper for socket system call, assumes it is fatal if a socket // cannot be created. int np_socket( int domain, int type, int protocol) { int sk; if ((sk = socket( PF_INET, SOCK_STREAM, 0 )) < 0) { perror("Problem creating socket\n"); exit(1); } return(sk); } // wrapper for bind, any error is fatal. int np_bind(int sd, const struct sockaddr *addr, int addrlen) { int retval; if ((retval = bind(sd, addr, addrlen))<0) { perror("Problem binding\n"); exit(1); } return(retval); } // wrapper for connect, any error is fatal. int np_connect(int sd, const struct sockaddr *addr, int addrlen) { int retval; if ((retval = connect(sd, addr, addrlen))<0) { perror("Problem calling connect\n"); exit(1); } return(retval); }