An ATM client here opens a connection for PVC over VPI/VCI = 0/64 defining qos using AAL5 UBR Traffic descriptors using ATM
on Linux distribution from sourceforge.net
#define MAX_SDU 20000
#define MAX_OFFSET 8
void usage(char *name)
{
fprintf(stderr,"usage: %s [vpi] [vci]\n",name);
exit(1);
}
int main(int argc, char *argv[])
{
struct sockaddr_atmpvc addr;
struct atm_qos qos;
int fd;
int pid, lst;
static unsigned char buffer[20];
int num;
char * test = "Sending test";
char *quit = "q";
char command[30]="";
int compare = 1;
/*if (argc != 3) {usage(argv[0]);}
*/
printf("Creating a pvc with vpi/vci 0/64... \n");
if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, 0)) < 0)
{
perror("socket error");
return 1;
}
printf("created socket with id: ");
printf("%d",fd);
printf("\n");
memset(&addr,0,sizeof(addr));
addr.sap_family = AF_ATMPVC;
addr.sap_addr.itf = 0;
addr.sap_addr.vpi = 0;
addr.sap_addr.vci = 64;
memset(&qos,0,sizeof(qos));
qos.aal = ATM_AAL5;
qos.txtp.traffic_class = qos.rxtp.traffic_class = ATM_UBR;
qos.txtp.max_sdu = qos.rxtp.max_sdu = MAX_SDU;
if (setsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0)
{
perror("setsockopt SO_ATMQOS");
return 1;
}
printf("Set socket options to AAL5, UBR traffic...\n");
if (bind(fd,(struct sockaddr *) &addr, sizeof(addr)) < 0)
{
perror("bind error");
return 1;
}
srandom(0); /* we want it to be deterministic */
printf("Enter message, q to quit: ");
gets(command);
compare = strcmp(command, quit);
while (compare != 0)
{
printf("\n");
printf("client sending message... \n");
num = write(fd,command, strlen(command));
printf("client: Bytes sent= %d\n",num);
if (num<0)
{
printf("error no ");
printf(" %s", strerror(errno));
return 0;
}
printf("\n");
printf("Enter message, q to quit: ");
gets(command);
compare = strcmp(command, quit);
}
return 0;
}
#define MAX_SDU 20000
#define MAX_OFFSET 8
void usage(char *name)
{
fprintf(stderr,"usage: %s [vpi] [vci]\n",name);
exit(1);
}
int main(int argc, char *argv[])
{
struct sockaddr_atmpvc addr;
struct atm_qos qos;
int fd;
int pid, lst;
static unsigned char buffer[20];
int num;
char * test = "Sending test";
char *quit = "q";
char command[30]="";
int compare = 1;
/*if (argc != 3) {usage(argv[0]);}
*/
printf("Creating a pvc with vpi/vci 0/64... \n");
if ((fd = socket(PF_ATMPVC, SOCK_DGRAM, 0)) < 0)
{
perror("socket error");
return 1;
}
printf("created socket with id: ");
printf("%d",fd);
printf("\n");
memset(&addr,0,sizeof(addr));
addr.sap_family = AF_ATMPVC;
addr.sap_addr.itf = 0;
addr.sap_addr.vpi = 0;
addr.sap_addr.vci = 64;
memset(&qos,0,sizeof(qos));
qos.aal = ATM_AAL5;
qos.txtp.traffic_class = qos.rxtp.traffic_class = ATM_UBR;
qos.txtp.max_sdu = qos.rxtp.max_sdu = MAX_SDU;
if (setsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,sizeof(qos)) < 0)
{
perror("setsockopt SO_ATMQOS");
return 1;
}
printf("Set socket options to AAL5, UBR traffic...\n");
if (bind(fd,(struct sockaddr *) &addr, sizeof(addr)) < 0)
{
perror("bind error");
return 1;
}
srandom(0); /* we want it to be deterministic */
printf("Enter message, q to quit: ");
gets(command);
compare = strcmp(command, quit);
while (compare != 0)
{
printf("\n");
printf("client sending message... \n");
num = write(fd,command, strlen(command));
printf("client: Bytes sent= %d\n",num);
if (num<0)
{
printf("error no ");
printf(" %s", strerror(errno));
return 0;
}
printf("\n");
printf("Enter message, q to quit: ");
gets(command);
compare = strcmp(command, quit);
}
return 0;
}
No comments:
Post a Comment