Sample Programs

Connection Mode

Connection Mode

/**************************************************************************

(C)COPYRIGHT HEWLETT-PACKARD COMPANY 1992. ALL RIGHTS RESERVED. NO PART OF THIS PROGRAM MAY BE PHOTOCOPIED, REPRODUCED, OR TRANSLATED TO ANOTHER PROGRAM LANGUAGE WITHOUT THE PRIOR WRITTEN CONSENT OF HEWLETT PACKARD COMPANY

**************************************************************************/

/************************************************************************** This program demonstrates data transfer over a connection oriented DLPI stream. It also demonstrates connection handoff.

**************************************************************************/

#include <stdio.h> #include <fcntl.h> #include <memory.h> #include <sys/types.h> #include <sys/stream.h> #include <sys/stropts.h> #include <sys/dlpi.h> #include <sys/dlpi_ext.h>

#define

SEND_SAP

0x80

/*

sending SAP */

#define

RECV_SAP

0x82

/*

receiving SAP */

/************************************************************************** global areas for sending and receiving messages

**************************************************************************/

#define

AREA_SIZE 5000

/* bytes; big enough for largest possible

msg */

#define

LONG_AREA_SIZE

(AREA_SIZE / sizeof(u_long)) /* AREA_SIZE /

4 */

/* these are u_long arrays instead of u_char to insure proper alignment */

u_long

ctrl_area[LONG_AREA_SIZE];

/*

for control messages */

u_long

data_area[LONG_AREA_SIZE];

/*

for data messages */

struct strbuf ctrl_buf = {

 

AREA_SIZE,

/* maxlen = AREA_SIZE */

0,

/* len gets filled in for each message */

ctrl_area

/* buf = control area */

};

 

struct strbuf data_buf = {

 

AREA_SIZE,

/* maxlen = AREA_SIZE */

0,

/* len gets filled in for each message */

data_area

/* buf = data area */

};

 

/************************************************************************ get the next message from a stream; get_msg() returns one of the following defines

************************************************************************/

144

Appendix A