sbin/atm/atm/atm.c
static void
pvc_add(int argc, char **argv, const struct cmd *cmdp)
{
	struct atmaddreq	apr;
	struct atminfreq	air;
	struct air_int_rsp	*int_info;
	const struct owner	*owp;
	const struct aal	*alp;
	const struct encaps	*enp;
	char	*cp;
	long	v;
	int	buf_len, s;

	/*
	 * Initialize opcode and flags
	 */
	apr.aar_opcode = AIOCS_ADD_PVC;
	apr.aar_pvc_flags = 0;

	/*
	 * Validate interface name and issue an information
	 * request IOCTL for the interface
	 */
	if (strlen(argv[0]) > sizeof(apr.aar_pvc_intf) - 1) {
		fprintf(stderr, "%s: Illegal interface name\n", prog);
		exit(1);
	}
	UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
	strcpy(air.air_int_intf, argv[0]);
	buf_len = sizeof(struct air_int_rsp);
	air.air_opcode = AIOCS_INF_INT;
	buf_len = do_info_ioctl(&air, buf_len);
	if (buf_len < 0) {
		fprintf(stderr, "%s: ", prog);
		switch (errno) {
		case ENOPROTOOPT:
		case EOPNOTSUPP:
			perror("Internal error");
			break;
		case ENXIO:
			fprintf(stderr, "%s is not an ATM device\n",
					argv[0]);
			break;
		default:
			perror("ioctl (AIOCINFO)");
			break;
		}
		exit(1);
	}
	int_info = (struct air_int_rsp *) air.air_buf_addr;
	strcpy(apr.aar_pvc_intf, argv[0]);
	argc--; argv++;

	/*
	 * Validate vpi/vci values
	 */
	v = strtol(argv[0], &cp, 0);
	if ((*cp != '\0') || (v < 0) || (v >= 1 << 8)) {
		fprintf(stderr, "%s: Invalid VPI value\n", prog);
		exit(1);
	}
	apr.aar_pvc_vpi = (u_short) v;
	argc--; argv++;

	v = strtol(argv[0], &cp, 0);
	if ((*cp != '\0') || (v < MIN_VCI) || (v >= 1 << 16)) {
		fprintf(stderr, "%s: Invalid VCI value\n", prog);
		exit(1);
	}
	apr.aar_pvc_vci = (u_short) v;
	argc--; argv++;

	/*
	 * Validate requested PVC AAL
	 */
	for (alp = aals; alp->a_name; alp++) {
		if (strcasecmp(alp->a_name, argv[0]) == 0)
			break;
	}
	if (alp->a_name == NULL) {
		fprintf(stderr, "%s: Invalid PVC AAL\n", prog);
		exit(1);
	}
	apr.aar_pvc_aal = alp->a_id;
	argc--; argv++;

	/*
	 * Validate requested PVC encapsulation
	 */
	for (enp = encaps; enp->e_name; enp++) {
		if (strcasecmp(enp->e_name, argv[0]) == 0)
			break;
	}
	if (enp->e_name == NULL) {
		fprintf(stderr, "%s: Invalid PVC encapsulation\n", prog);
		exit(1);
	}
	apr.aar_pvc_encaps = enp->e_id;
	argc--; argv++;

	/*
	 * Validate requested PVC owner
	 */
	for (owp = owners; owp->o_name; owp++) {
		if (strcasecmp(owp->o_name, argv[0]) == 0)
			break;
	}
	if (owp->o_name == NULL) {
		fprintf(stderr, "%s: Unknown PVC owner\n", prog);
		exit(1);
	}
	apr.aar_pvc_sap = owp->o_sap;
	argc--; argv++;

	/*
	 * Perform service user processing
	 */
	if (owp->o_pvcadd) {
		(*owp->o_pvcadd)(argc, argv, cmdp, &apr, int_info);
	} else {
		fprintf(stderr, "%s: Unsupported PVC owner\n", prog);
		exit(1);
	}

	/*
	 * Tell the kernel to add the PVC
	 */
	s = socket(AF_ATM, SOCK_DGRAM, 0);
	if (s < 0) {
		sock_error(errno);
	}
	if (ioctl(s, AIOCADD, (caddr_t)&apr) < 0) {
		fprintf(stderr, "%s: ", prog);
		switch (errno) {
		case EPROTONOSUPPORT:
		case ENOPROTOOPT:
			perror("Internal error");
			break;
		case EINVAL:
			fprintf(stderr, "Invalid parameter\n");
			break;
		case EEXIST:
			fprintf(stderr, "PVC already exists\n");
			break;
		case ENETDOWN:
			fprintf(stderr, "ATM network is inoperable\n");
			break;
		case ENOMEM:
			fprintf(stderr, "Kernel memory exhausted\n");
			break;
		case EPERM:
			fprintf(stderr, "Must be super user to use add subcommand\n");
			break;
		case ERANGE:
			fprintf(stderr, "Invalid VPI or VCI value\n");
			break;
		default:
			perror("ioctl (AIOCADD) add PVC");
			break;
		}
		exit(1);
	}
	close(s);
}
/*
 * Process PVC add command
 * 
 * Command format: 
 *	atm add PVC <interface_name> <vpi> <vci> <aal> <encaps>
 *		<owner_name>
 *
 * Arguments:
 *	argc	number of arguments to command
 *	argv	pointer to argument strings
 *	cmdp	pointer to command description 
 *
 * Returns:
 *	none
 *
 */
Process PVC add command

Command format:
atm add PVC     


argc    number of arguments to command
argv    pointer to argument strings
cmdp    pointer to command description

none
Process PVC add command Command format : atm add PVC argc number of arguments to command argv pointer to argument strings cmdp pointer to command description none
static void
pvc_add(int argc, char **argv, const struct cmd *cmdp)
{
	struct atmaddreq	apr;
	struct atminfreq	air;
	struct air_int_rsp	*int_info;
	const struct owner	*owp;
	const struct aal	*alp;
	const struct encaps	*enp;
	char	*cp;
	long	v;
	int	buf_len, s;
	apr.aar_opcode = AIOCS_ADD_PVC;
	apr.aar_pvc_flags = 0;
	if (strlen(argv[0]) > sizeof(apr.aar_pvc_intf) - 1) {
		fprintf(stderr, "%s: Illegal interface name\n", prog);
		exit(1);
	}
	UM_ZERO(air.air_int_intf, sizeof(air.air_int_intf));
	strcpy(air.air_int_intf, argv[0]);
	buf_len = sizeof(struct air_int_rsp);
	air.air_opcode = AIOCS_INF_INT;
	buf_len = do_info_ioctl(&air, buf_len);
	if (buf_len < 0) {
		fprintf(stderr, "%s: ", prog);
		switch (errno) {
		case ENOPROTOOPT:
		case EOPNOTSUPP:
			perror("Internal error");
			break;
		case ENXIO:
			fprintf(stderr, "%s is not an ATM device\n",
					argv[0]);
			break;
		default:
			perror("ioctl (AIOCINFO)");
			break;
		}
		exit(1);
	}
	int_info = (struct air_int_rsp *) air.air_buf_addr;
	strcpy(apr.aar_pvc_intf, argv[0]);
	argc--; argv++;
	v = strtol(argv[0], &cp, 0);
	if ((*cp != '\0') || (v < 0) || (v >= 1 << 8)) {
		fprintf(stderr, "%s: Invalid VPI value\n", prog);
		exit(1);
	}
	apr.aar_pvc_vpi = (u_short) v;
	argc--; argv++;
	v = strtol(argv[0], &cp, 0);
	if ((*cp != '\0') || (v < MIN_VCI) || (v >= 1 << 16)) {
		fprintf(stderr, "%s: Invalid VCI value\n", prog);
		exit(1);
	}
	apr.aar_pvc_vci = (u_short) v;
	argc--; argv++;
	for (alp = aals; alp->a_name; alp++) {
		if (strcasecmp(alp->a_name, argv[0]) == 0)
			break;
	}
	if (alp->a_name == NULL) {
		fprintf(stderr, "%s: Invalid PVC AAL\n", prog);
		exit(1);
	}
	apr.aar_pvc_aal = alp->a_id;
	argc--; argv++;
	for (enp = encaps; enp->e_name; enp++) {
		if (strcasecmp(enp->e_name, argv[0]) == 0)
			break;
	}
	if (enp->e_name == NULL) {
		fprintf(stderr, "%s: Invalid PVC encapsulation\n", prog);
		exit(1);
	}
	apr.aar_pvc_encaps = enp->e_id;
	argc--; argv++;
	for (owp = owners; owp->o_name; owp++) {
		if (strcasecmp(owp->o_name, argv[0]) == 0)
			break;
	}
	if (owp->o_name == NULL) {
		fprintf(stderr, "%s: Unknown PVC owner\n", prog);
		exit(1);
	}
	apr.aar_pvc_sap = owp->o_sap;
	argc--; argv++;
	if (owp->o_pvcadd) {
		(*owp->o_pvcadd)(argc, argv, cmdp, &apr, int_info);
	} else {
		fprintf(stderr, "%s: Unsupported PVC owner\n", prog);
		exit(1);
	}
	s = socket(AF_ATM, SOCK_DGRAM, 0);
	if (s < 0) {
		sock_error(errno);
	}
	if (ioctl(s, AIOCADD, (caddr_t)&apr) < 0) {
		fprintf(stderr, "%s: ", prog);
		switch (errno) {
		case EPROTONOSUPPORT:
		case ENOPROTOOPT:
			perror("Internal error");
			break;
		case EINVAL:
			fprintf(stderr, "Invalid parameter\n");
			break;
		case EEXIST:
			fprintf(stderr, "PVC already exists\n");
			break;
		case ENETDOWN:
			fprintf(stderr, "ATM network is inoperable\n");
			break;
		case ENOMEM:
			fprintf(stderr, "Kernel memory exhausted\n");
			break;
		case EPERM:
			fprintf(stderr, "Must be super user to use add subcommand\n");
			break;
		case ERANGE:
			fprintf(stderr, "Invalid VPI or VCI value\n");
			break;
		default:
			perror("ioctl (AIOCADD) add PVC");
			break;
		}
		exit(1);
	}
	close(s);
}
static void pvc_add ( int argc , char * * argv , const struct cmd * cmdp ) { struct atmaddreq apr ; struct atminfreq air ; struct air_int_rsp * int_info ; const struct owner * owp ; const struct aal * alp ; const struct encaps * enp ; char * cp ; long v ; int buf_len , s ; apr . aar_opcode = AIOCS_ADD_PVC ; apr . aar_pvc_flags = 0 ; if ( strlen ( argv [ 0 ] ) > sizeof ( apr . aar_pvc_intf ) - 1 ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } UM_ZERO ( air . air_int_intf , sizeof ( air . air_int_intf ) ) ; strcpy ( air . air_int_intf , argv [ 0 ] ) ; buf_len = sizeof ( struct air_int_rsp ) ; air . air_opcode = AIOCS_INF_INT ; buf_len = do_info_ioctl ( & air , buf_len ) ; if ( buf_len < 0 ) { fprintf ( stderr , " " , prog ) ; switch ( errno ) { case ENOPROTOOPT : case EOPNOTSUPP : perror ( " " ) ; break ; case ENXIO : fprintf ( stderr , " \n " , argv [ 0 ] ) ; break ; default : perror ( " " ) ; break ; } exit ( 1 ) ; } int_info = ( struct air_int_rsp * ) air . air_buf_addr ; strcpy ( apr . aar_pvc_intf , argv [ 0 ] ) ; argc -- ; argv ++ ; v = strtol ( argv [ 0 ] , & cp , 0 ) ; if ( ( * cp != ' \0 ' ) || ( v < 0 ) || ( v >= 1 << 8 ) ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } apr . aar_pvc_vpi = ( u_short ) v ; argc -- ; argv ++ ; v = strtol ( argv [ 0 ] , & cp , 0 ) ; if ( ( * cp != ' \0 ' ) || ( v < MIN_VCI ) || ( v >= 1 << 16 ) ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } apr . aar_pvc_vci = ( u_short ) v ; argc -- ; argv ++ ; for ( alp = aals ; alp -> a_name ; alp ++ ) { if ( strcasecmp ( alp -> a_name , argv [ 0 ] ) == 0 ) break ; } if ( alp -> a_name == NULL ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } apr . aar_pvc_aal = alp -> a_id ; argc -- ; argv ++ ; for ( enp = encaps ; enp -> e_name ; enp ++ ) { if ( strcasecmp ( enp -> e_name , argv [ 0 ] ) == 0 ) break ; } if ( enp -> e_name == NULL ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } apr . aar_pvc_encaps = enp -> e_id ; argc -- ; argv ++ ; for ( owp = owners ; owp -> o_name ; owp ++ ) { if ( strcasecmp ( owp -> o_name , argv [ 0 ] ) == 0 ) break ; } if ( owp -> o_name == NULL ) { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } apr . aar_pvc_sap = owp -> o_sap ; argc -- ; argv ++ ; if ( owp -> o_pvcadd ) { ( * owp -> o_pvcadd ) ( argc , argv , cmdp , & apr , int_info ) ; } else { fprintf ( stderr , " \n " , prog ) ; exit ( 1 ) ; } s = socket ( AF_ATM , SOCK_DGRAM , 0 ) ; if ( s < 0 ) { sock_error ( errno ) ; } if ( ioctl ( s , AIOCADD , ( caddr_t ) & apr ) < 0 ) { fprintf ( stderr , " " , prog ) ; switch ( errno ) { case EPROTONOSUPPORT : case ENOPROTOOPT : perror ( " " ) ; break ; case EINVAL : fprintf ( stderr , " \n " ) ; break ; case EEXIST : fprintf ( stderr , " \n " ) ; break ; case ENETDOWN : fprintf ( stderr , " \n " ) ; break ; case ENOMEM : fprintf ( stderr , " \n " ) ; break ; case EPERM : fprintf ( stderr , " \n " ) ; break ; case ERANGE : fprintf ( stderr , " \n " ) ; break ; default : perror ( " " ) ; break ; } exit ( 1 ) ; } close ( s ) ; }
Process PVC add command
Process PVC add command
/*
	 * Initialize opcode and flags
	 */ /*
	 * Validate interface name and issue an information
	 * request IOCTL for the interface
	 */ /*
	 * Validate vpi/vci values
	 */ /*
	 * Validate requested PVC AAL
	 */ /*
	 * Validate requested PVC encapsulation
	 */ /*
	 * Validate requested PVC owner
	 */ /*
	 * Perform service user processing
	 */ /*
	 * Tell the kernel to add the PVC
	 */