BRL-CAD
tpkg.c File Reference
#include "common.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include "bio.h"
#include "bu/file.h"
#include "bu/getopt.h"
#include "bu/log.h"
#include "bu/malloc.h"
#include "bu/str.h"
#include "pkg.h"
Include dependency graph for tpkg.c:

Go to the source code of this file.

Data Structures

struct  _my_data_
 

Macros

#define MAGIC_ID   "TPKG"
 
#define MSG_HELO   1
 
#define MSG_DATA   2
 
#define MSG_CIAO   3
 
#define MAX_DIGITS   5
 

Typedefs

typedef struct _my_data_ my_data
 

Functions

void server_helo (struct pkg_conn *connection, char *buf)
 
void server_data (struct pkg_conn *connection, char *buf)
 
void server_ciao (struct pkg_conn *connection, char *buf)
 
void run_server (int port)
 
void run_client (const char *server, int port, const char *file, unsigned int tpkg_bufsize)
 
int main (int argc, char *argv[])
 

Detailed Description

Relatively simple example file transfer program using libpkg, written in a ttcp style.

To compile from an install: gcc -I/usr/brlcad/include -L/usr/brlcad/lib -o tpkg tpkg.c -lpkg -lbu

Definition in file tpkg.c.

Macro Definition Documentation

#define MAGIC_ID   "TPKG"

Definition at line 61 of file tpkg.c.

Referenced by run_client(), and run_server().

#define MSG_HELO   1

Definition at line 62 of file tpkg.c.

Referenced by run_client(), and run_server().

#define MSG_DATA   2

Definition at line 63 of file tpkg.c.

Referenced by run_client(), and run_server().

#define MSG_CIAO   3

Definition at line 64 of file tpkg.c.

Referenced by run_client(), and run_server().

#define MAX_DIGITS   5

Definition at line 67 of file tpkg.c.

Referenced by run_client(), and run_server().

Typedef Documentation

typedef struct _my_data_ my_data

Function Documentation

void server_helo ( struct pkg_conn connection,
char *  buf 
)

callback when a HELO message packet is received.

We should not encounter this packet specifically since we listened for it before beginning processing of packets as part of a simple handshake setup.

Definition at line 107 of file tpkg.c.

References bu_log().

Referenced by run_server().

Here is the call graph for this function:

void server_data ( struct pkg_conn connection,
char *  buf 
)

callback when a DATA message packet is received

Definition at line 118 of file tpkg.c.

References bu_log().

Referenced by run_server().

Here is the call graph for this function:

void server_ciao ( struct pkg_conn connection,
char *  buf 
)

callback when a CIAO message packet is received

Definition at line 129 of file tpkg.c.

References bu_log().

Referenced by run_server().

Here is the call graph for this function:

void run_server ( int  port)

start up a server that listens for a single client.

our server callbacks for each message type

Definition at line 140 of file tpkg.c.

References bu_bomb(), bu_log(), BU_STR_EQUAL, MAGIC_ID, MAX_DIGITS, MSG_CIAO, MSG_DATA, MSG_HELO, PKC_ERROR, PKC_NULL, pkg_bwaitfor(), pkg_close(), pkg_getclient(), pkg_permserver(), pkg_process(), pkg_suckin(), server_ciao(), server_data(), and server_helo().

Referenced by main().

Here is the call graph for this function:

void run_client ( const char *  server,
int  port,
const char *  file,
unsigned int  tpkg_bufsize 
)

start up a client that connects to the given server, and sends serialized file data.

Definition at line 239 of file tpkg.c.

References bu_bomb(), bu_calloc(), bu_free(), bu_log(), _my_data_::connection, MAGIC_ID, MAX_DIGITS, MSG_CIAO, MSG_DATA, MSG_HELO, PKC_ERROR, pkg_close(), pkg_open(), pkg_send(), _my_data_::port, and _my_data_::server.

Referenced by main().

Here is the call graph for this function:

int main ( int  argc,
char *  argv[] 
)

main application for both the client and server

Definition at line 313 of file tpkg.c.

References bu_bomb(), bu_file_exists(), bu_getopt(), bu_log(), bu_optarg, bu_optind, run_client(), and run_server().

Here is the call graph for this function: