Программное обеспечение ПК
Рефераты >> Кибернетика >> Программное обеспечение ПК

Программа для обмена сообщениями между 2-мя рабочими станциями в сети NetWare.

Программу нужно запускать с ключом т.е. указать свое имя каким оно будет в сети, когда вы будете обмениваться сообщениями.

Например: Message.exe/ sergei

Текст программы:

typedef struct

{

unsigned char netadd[4];

unsigned char nodeadd[6];

unsigned short socket;

} IPXADDRESS;

typedef struct

{

unsigned short checksum;

unsigned short length;

unsigned char tc;

unsigned char type;

IPXADDRESS dest;

IPXADDRESS source;

} IPXHEADER;

typedef struct

{

void far *linkaddress;

void (far *esraddress)();

unsigned char inuse;

unsigned char cc;

unsigned short socket;

unsigned char workspace[16];

unsigned char immedaddr[6];

unsigned short fragcount;

void far *fragaddr1;

unsigned short fragsize1;

void far *fragaddr2;

unsigned short fragsize2;

} IPXECB;

#ifdef cplusplus

extern "C" {

#endif

extern unsigned short reverseword ( unsigned short );

extern unsigned long ipxinit ( void );

extern unsigned long ipxentry;

extern void ipxgetaddress ( void * );

extern unsigned short ipxgetmaxpacketsize ( void );

extern unsigned short ipxgetretrycount ( void );

extern unsigned short ipxverifychecksum( IPXECB * );

extern unsigned char ipxopensocket ( unsigned char, unsigned short * );

extern void ipxclosesocket ( unsigned short );

extern unsigned char ipxlistenforpacket ( IPXECB * );

extern void ipxsendpacket ( IPXECB * );

extern void sendwithchecksum( IPXECB * );

extern void ipxrelenquishcontrol ( void );

#ifdef cplusplus

}

#endif

ассемблер:

.model large

.data

public _ipxentry

_ipxentry dd 0

.code

public _reverseword

_reverseword:

push bp

mov bp,sp

mov ax,[bp+6]

xchg ah,al

pop bp

retf

public _ipxinit

_ipxinit:

push di

push es

mov ax,7A00h

int 2Fh

cmp al,0FFh

jnz _ipxinit0

mov word ptr [_ipxentry+0],di

mov word ptr [_ipxentry+2],es

_ipxinit0:

mov dx,word ptr [_ipxentry+2]

mov ax,word ptr [_ipxentry+0]

pop es

pop di

retf

public _ipxgetaddress

_ipxgetaddress:

push bp

mov bp,sp

mov bx,0009h

mov si,[bp+6]

mov es,[bp+8]

call [_ipxentry]

pop bp

retf

public _ipxgetmaxpacketsize

_ipxgetmaxpacketsize:

mov bx,001Ah ;0d

call [_ipxentry]

retf

public _ipxgetretrycount

_ipxgetretrycount:

mov bx,001Ah

call [_ipxentry]

mov ax,cx

retf

public _ipxopensocket

_ipxopensocket:

push bp

mov bp,sp

push ds

mov al,[bp+6]

mov bx,[bp+8]

mov ds,[bp+10]

mov dx,[bx]

pop ds

mov bx,0000h

call [_ipxentry]

push ds

mov bx,[bp+8]

mov ds,[bp+10]

mov [bx],dx

mov ah,00h

pop ds

pop bp

retf

public _ipxclosesocket

_ipxclosesocket:

push bp

mov bp,sp

mov bx,0001h

mov dx,[bp+6]

call [_ipxentry]

pop bp

retf

public _ipxlistenforpacket

_ipxlistenforpacket:

push bp

mov bp,sp

push ds

push di

push si

push es

mov bx,0004h

mov si,[bp+6]

mov es,[bp+8]

call [_ipxentry]

mov ah,00h

pop es

pop si

pop di

pop ds

pop bp

retf

public _ipxsendpacket

_ipxsendpacket:

push bp

mov bp,sp

push si

push es

mov bx,0003h

mov si,[bp+6]

mov es,[bp+8]

call [_ipxentry]

pop es

pop si

pop bp

retf

public _sendwithchecksum

_sendwithchecksum:

push bp

mov bp,sp

push si

push es

mov bx,0020h

mov si,[bp+6]

mov es,[bp+8]

call [_ipxentry]

pop es

pop si

pop bp

retf

public _ipxrelenquishcontrol

_ipxrelenquishcontrol:

mov bx,000Ah

call [_ipxentry]

retf

public _ipxverifychecksum

_ipxverifychecksum:

push bp

mov bp,sp

push si

push es

mov bx,0022h

mov si,[bp+6]

mov es,[bp+8]

call [_ipxentry]

pop es

pop si

pop bp

retf

end

С++

#include <stdio.h>

#include <bios.h>

#include <fcntl.h>

#include <dos.h>

#include <time.h>

#include <io.h>

#include <stdlib.h>

#include <conio.h>

#include <string.h>

#include <mem.h>

#include "ipx.h"

int getkey(void);

void sent_buf(int msh,char *sbuffer);

unsigned int socket=0x5000;

#define NPACKETS 5 // количество окон приема/прослушивания

#define PACKETSIZE 200 // размер буфера сообщения

IPXECB recb[NPACKETS],secb[NPACKETS];

IPXHEADER rheader[NPACKETS],sheader[NPACKETS];

unsigned char rbuffer[NPACKETS][PACKETSIZE];

unsigned char sbuffer[NPACKETS][PACKETSIZE];

unsigned char M_ADDR[6];

char NAME_USER[30];

//------------------------------------------------------------------------------

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

{

char buf[100],mes[150];

unsigned short ra;

int Flag_exit,key,i;

IPXADDRESS myaddress;

clrscr();

if(argc<2)

{

printf("Ошибка задания параметров !\n\n");

printf("message.exe NAME_USER \n");

exit(1);

}

strcpy(NAME_USER,argv[1]);

if(!ipxinit()) { printf("IPX не найден !\n"); exit(1); }

if (ipxopensocket(0x00,&socket) == 0xff) { printf("Канал уже открыт !\n"); exit(1); }

printf("F1 - ввести сообщение. Esc - выход.\n\n\n");

ipxgetaddress(&myaddress);

for(i=0;i<6;i++) M_ADDR[i]=myaddress.nodeadd[i];

// инициализируем окна прослушивания

for(ra=0;ra<NPACKETS;ra++)

{

recb[ra].socket=socket;

recb[ra].esraddress=NULL;

recb[ra].fragcount=2;

recb[ra].fragaddr1=&rheader[ra];

recb[ra].fragsize1=sizeof(IPXHEADER);

recb[ra].fragaddr2=&rbuffer[ra];

recb[ra].fragsize2=PACKETSIZE;

ipxlistenforpacket(&recb[ra]);

}

Flag_exit=0;

while(!Flag_exit)

{

if( kbhit() ) // нажата клавиша

{

key=getkey();

switch(key)

{

case 27: // Esc

Flag_exit=1;

break;

case 315: // F1

textcolor(7);

printf("-> ");gets(buf); printf("\n");

sprintf(mes,"%s: %s",NAME_USER,buf);

for(ra=0;ra<NPACKETS;ra++)

{

if(!secb[ra].inuse )

{ sent_buf(ra,mes); break; }

}

break;

}

}

for(ra=0;ra<NPACKETS;ra++)

{

if(!recb[ra].inuse) // приемные окна

{

if(memcmp(rheader[ra].source.nodeadd,M_ADDR,6))

{

textcolor(3);

cprintf("%s\n\r",rbuffer[ra]);

}

memset(rbuffer[ra],0,PACKETSIZE);


Страница: