Selamlar,
Bilindiği uzre, SLIP (Serial Line IP), TCP/IP iletişiminin seri bağlantı üzerinden yapılabilmesini sağlayan bir arayuzdur (ornegin Ethernet de bir arayuz).
Benim, SLIP'i taban alan bir uygulama örneğine ihtiyacim var. SLIP protokolunu ve onun ustunde de kendi protokulunu gerçekleştiren bir programın kodu lazım. Yardım edebilecek var mı acaba?
Teşekkürler.
Predator
20/10/2002, 12:28
PAKET YOLLAYAN:
// Program: Send.C
// Course : Internet Lab.
// Subject: Serial Line interface programming with SLIP [Sender]
// Note that,sender doesn't need an ISR,only receiver needs
// Name : 9622959 - Ismail OZKAN
// 9622926 - Evren ONDER
/* Referanced from : Craig Peacock <cpeacock@senet.com.au> */
/* See http://www.senet.com.au/~cpeacock/serial.htm */
// Packet Size Max:1024 bytes
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORT1 0x2F8 /* Port Address Goes Here */
/* Defines Serial Ports Base Address */
/* COM1 0x3F8 */
/* COM2 0x2F8 */
/* COM3 0x3E8 */
/* COM4 0x2E8 */
/* SLIP special character codes */
#define END 0300 /* indicates end of packet */
#define ESC 0333 /* indicates byte stuffing */
#define ESC_END 0334 /* ESC ESC_END means END data byte */
#define ESC_ESC 0335 /* ESC ESC_ESC means ESC data byte */
char ch;
char buffer[1025];
void send_char(char ch){
//outputs byte to hardware port1
outportb(PORT1, ch);
}
void send_packet(char *p, int len) {
//send an initial END character to flush out any data that may
//have accumulated in the receiver due to line noise
send_char(END);
//for each byte in the packet, send the appropriate character sequence
while(len--) {
switch(*p) {
// if it's the same code as an END character, we send a
// special two character code so as not to make the
// receiver think we sent an END
case END:
send_char(ESC);
send_char(ESC_END);
break;
// if it's the same code as an ESC character, we send a special two character
// code so as not to make the receiver think we sent an ESC
case ESC:
send_char(ESC);
send_char(ESC_ESC);
break;
// otherwise, we just send the character
default:
send_char(*p);
}
p++;
}
// tell the receiver that we're done sending the packet
send_char(END);
}
void main()
{
int c;
int bufx;
outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */
/* PORT 1 - Communication Settings */
outportb(PORT1 + 3 , 0x80); /* SET DLAB ON */
outportb(PORT1 + 0 , 0x03); /* Set Baud rate - Divisor Latch Low Byte */
/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 56,700 BPS */
/* 0x06 = 19,200 BPS */
/* 0x0C = 9,600 BPS */
/* 0x18 = 4,800 BPS */
/* 0x30 = 2,400 BPS */
outportb(PORT1 + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */
outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 2 , 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */
clrscr();
printf("\nPress a key to start sending packets over serial line!\n");
getch();
do {
bufx=0;
buffer[bufx]=NULL;
printf("\nWrite down your packet end press 'enter' to send!\n");
printf("Packet:");
c = getche();
while(c!=13 && bufx<1024){
buffer[bufx]=c;
bufx++;
c = getche();
}
buffer[bufx]=NULL;
if(bufx==0)
printf("\nPacket failed!No character entered!\n");
else{
send_packet(buffer,bufx);
printf("\nPacket sent successfuly!\n");
}
printf("Send New Packet?(Y/N)\n");
do
ch = getch();
while(ch!='Y' && ch!='y' && ch!='N' && ch!='n');
}while (ch!='n'&& ch!='N');
}
PAKET ALAN
// Program: Receive.C
// Course : Internet Lab.
// Subject: Serial Line interface programming with SLIP [receiver]
// Name : 9622959 - Ismail OZKAN
// 9622926 - Evren ONDER
/* Referanced from : Craig Peacock <cpeacock@senet.com.au> */
/* See http://www.senet.com.au/~cpeacock/serial.htm */
// Packet Size Max:1024 byte
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORT1 0x2F8
/* Defines Serial Ports Base Address */
/* COM1 0x3F8 */
/* COM2 0x2F8 */
/* COM3 0x3E8 */
/* COM4 0x2E8 */
/* SLIP special character codes */
#define END 0300 /* indicates end of packet */
#define ESC 0333 /* indicates byte stuffing */
#define ESC_END 0334 /* ESC ESC_END means END data byte */
#define ESC_ESC 0335 /* ESC ESC_ESC means ESC data byte */
int bufx;
char buffer[1025];
void main(void)
{
int c,cont;
int ch,chlast;
outportb(PORT1 + 1 , 0); /* Turn off interrupts - Port1 */
/* PORT 1 - Communication Settings */
outportb(PORT1 + 3 , 0x80); /* SET DLAB ON */
outportb(PORT1 + 0 , 0x03); /* Set Baud rate - Divisor Latch Low Byte */
/* Default 0x03 = 38,400 BPS */
/* 0x01 = 115,200 BPS */
/* 0x02 = 56,700 BPS */
/* 0x06 = 19,200 BPS */
/* 0x0C = 9,600 BPS */
/* 0x18 = 4,800 BPS */
/* 0x30 = 2,400 BPS */
outportb(PORT1 + 1 , 0x00); /* Set Baud rate - Divisor Latch High Byte */
outportb(PORT1 + 3 , 0x03); /* 8 Bits, No Parity, 1 Stop Bit */
outportb(PORT1 + 2 , 0xC7); /* FIFO Control Register */
outportb(PORT1 + 4 , 0x0B); /* Turn on DTR, RTS, and OUT2 */
bufx=0;
cont=0;
clrscr();
printf("\nWaiting for packets: (ESC to QUIT)\n");
do {
c = inportb(PORT1 + 5); /* Check to see if char has been received. */
if (c & 1) {
ch = inportb(PORT1); /* If so, then get Char */
switch(ch) {
/* if it's an END character then we're done with the packet */
case END:
cont=(cont+1)%2;
buffer[bufx]=NULL;
bufx=0;
if(cont==0)
printf("Packet received:%s\n",buffer);
break;
case ESC:break;
/* if it's the same code as an ESC character, wait
* and get another character and then figure out
* what to store in the packet based on that. */
case ESC_END:
buffer[bufx]=END;
break;
case ESC_ESC:
buffer[bufx]=ESC;
break;
default:
buffer[bufx]=ch;bufx++;
if(bufx>1024) bufx=0;
}
}
if (kbhit())
chlast=getch();
} while (chlast!=27); /* Quit when ESC (ASC 27) is pressed */
printf(" PROGRAM SONA ERD˜\n");
}
Bunu yazan arkadaş hacettepede öğrenci ulaşmak istersen
özel maili: evrenonder@hotmail.com
Allah razı olsun. O arkadaş da benimle aynı amaçta yazmış bu kodları.. :)
Arkadaşla acil bir görüşebilir miyim? Bir kaç noktayı sorup vakit kaybetmeden cevap alabilrisem cok iyi olur, anormal sıkıştı işlerim bu aralar. Sima olarak tanıyorumdur kesin, ama ismen cikaramadim.
Tesekkurler.
MSN: eePPx@hotmail.com
Predator
21/10/2002, 15:43
Verdim ona o adresi ancak internet.lab dersi için ihtiyacın varsa
http://yunus.hacettepe.edu.tr/~bbm739/proje.htm
:D
Site senin mi? Bir aralar gormustum o siteyi de.. Ama simdi bir daha bakayim.. :)
(Adimiz kopyaciya cikacak yahu.. Neyse ben de Polling yerine Interrupt kullanayim da bir gorun.. :) )
Selamlar,
Bir hatirlamada bulunayim:
Yukarida Predator'un verdigi kodlarda hem programlama teknikleri acisindan hem de dogrudan SLIP protokolunun gerceklestirimi acisindan bariz hatalar var, referans almayiniz.
Kolay gelsin.
Predator
30/10/2002, 22:10
Benle bir alakası yok sitenin arkadaşımın :)
Tamam canım, sorun yok :)
(Iki gundur beni ugrastiran, sabahlatan hatayi yeni buldum, bu kadar igrenc olabilirdi.. Uff..)
Forum Yazılımı : vBulletin v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.