Docsity

Netlib Assignment for Computer Networks I - Fall 2009 - Prof. Philip A. Nelson, Assignments of Computer Systems Networking and Telecommunications

Toggle sidebar
bg1
CSCI 367, Fall 2009 - Computer Networks I
Assignment 3 – 100 points A Network Library
Due: Friday, October 30, 2009
You have been using the following collection of routines for network com-
munications. These are based on the socket interface. These routines con-
solidate tasks that are normally done together when using sockets. The
following listing is the file “netlib.h” as found on the LDC machines in
/home/phil/public/cs367/netlib.
/* netlib.h : prototypes for netlib
*
* 9/29/08 -- Phil Nelson
*
*/
#include <arpa/inet.h>
#include <sys/socket.h>
int tcp4_server (in_addr_t ip, int port, int qsize );
// allocate a socket and prepare it for use by a server.
// ip in network byte order, port in network byte order
// Returns socket fd for use by accept or -1 for an error
// accept(2) is not called.
int tcp4_connect (in_addr_t ip, int port );
// allocate a socket and connect it to a server.
// ip and port number in network byte order
// Returns socket fd for use by send/recv, -1 for an error
in_addr_t dns_lookup ( char *name );
// lookup a name using DNS. name is NUL terminated
// returns ip number in network byte order, 0 if an error.
void dns_rlookup (in_addr_t ip, char* name, int size);
// Given the ip address in network byte order, lookup
// the name of that host. "name" is a pointer to an
// array of characters that has "size" locations in the
1
pf3

Partial preview of the text

Download Netlib Assignment for Computer Networks I - Fall 2009 - Prof. Philip A. Nelson and more Assignments Computer Systems Networking and Telecommunications in PDF only on Docsity!

CSCI 367, Fall 2009 - Computer Networks I

Assignment 3 – 100 points A Network Library

Due: Friday, October 30, 2009 You have been using the following collection of routines for network com- munications. These are based on the socket interface. These routines con- solidate tasks that are normally done together when using sockets. The following listing is the file “netlib.h” as found on the LDC machines in /home/phil/public/cs367/netlib.

/* netlib.h : prototypes for netlib

  • 9/29/08 -- Phil Nelson

*/

#include <arpa/inet.h> #include <sys/socket.h>

int tcp4_server (in_addr_t ip, int port, int qsize ); // allocate a socket and prepare it for use by a server. // ip in network byte order, port in network byte order // Returns socket fd for use by accept or -1 for an error // accept(2) is not called.

int tcp4_connect (in_addr_t ip, int port ); // allocate a socket and connect it to a server. // ip and port number in network byte order // Returns socket fd for use by send/recv, -1 for an error

in_addr_t dns_lookup ( char *name ); // lookup a name using DNS. name is NUL terminated // returns ip number in network byte order, 0 if an error.

void dns_rlookup (in_addr_t ip, char* name, int size); // Given the ip address in network byte order, lookup // the name of that host. "name" is a pointer to an // array of characters that has "size" locations in the

// array. In case of an error, return the empty string.

in_addr_t peer_ip (int sock_fd); // Returns the ip number of the remote machine connected // on the socket. The ip number is in network byte order. // Returns 0 on error.

int recv_line (int sock_fd, char* str, int len); // Receives a line from the sock_fd all the way to the \r\n. // If len or more characters are received, the first "len-1" // characters are put into str. str is zero terminated and // the \r\n at the end of the line are not stored in "str". // Returns the number of characters in the string str. // Returns -1 if a read error was encountered. // Returns -2 if it finds the end-of-file.

int send_line (int sock_fd, char* str ); // Sends the contents of the NUL terminated "str" to the // sock_fd. After all characters in str are sent it also // sends \r\n. On success, it returns the number of // characters in str. On an error, it returns -1.

1 Implementing netlib

On the LDC, you will find the directory /home/phil/public/cs367/netlib. Copy that directory to a working directory in your file space and then com- plete the implementation of netlib.c. To complete netlib.c, you need to use the socket interface calls as discussed in class and as you can find on the internet. There is a “Makefile” provided that will compile your files. Also, there are a simple server and client included that do basic tests on the netlib routines. You may run the tests by giving the command “make test”. When these tests are passed, the client should write the word “pass!” followed by the host name and the IP address. Note: Assignments 4 and 5 will be using this netlib. It is important to get your version working. If you don’t get your netlib working, you may use the reference netlib.o for assignments 4 and 5, but it will cost you 10 percent of the points on each assignment to use the reference netlib.o.