@lay:4471l1 Listing 1. Establishing an X.25 Connection: Call set up /* Secure socket is created using a standard socket call. */ sock = socket( AF_WANPIPE, SOCK_RAW, 0); if( sock < 0 ) { perror("Socket"); return 1; } /* Fill in the binding information: * - Socket type = AF_WANPIPE (default) * - Socket protocol = X25_PROT (default) * - Connect device = svc_connect (default) * - Card Name = wanpipe# (#=1,2,3...): obtained from command line * arguments. */ sa.sll_family = AF_WANPIPE; sa.sll_protocol = htons(X25_PROT); strcpy(sa.sll_device, "svc_connect"); strcpy(sa.sll_card, i_name); /* Bind a sock to the WANPIPE driver using the above address structure * */ if(bind(sock, (struct sockaddr *)&sa, sizeof(struct wan_sockaddr_ll)) == -1){ perror("bind"); printf("Failed to bind socket to %s interface\n",i_name); close(sock); exit(0); } /* Reset the API command structure: used to pass commands and * protocol specific * information to the socket */ memset(&api_cmd, 0, sizeof(x25api_t)); /* Initialize the command structure with x,25 call data. The call data * will be used to establish an x25 connection with the remote server. * Note: -u data must be have even number of characters. * -f field cannot be set to zero (i.e. -f0) * Refer to x.25.pdf hardware manual. */ sprintf(api_cmd.data,"-d4172625101970 -s41101190 -uC700000054999400"); api_cmd.hdr.length = strlen(api_cmd.data); /* Send the call data to the socket. This must be done before * the connect system call is performed to establish connection */ if ((err=ioctl(sock,SIOC_WANPIPE_SET_CALL_DATA,&api_cmd)) != 0){ printf ("Setting call data Failed\n"); close(sock); exit(1); }else{ printf("Set Call Data OK\n"); } /* We are ready to place a call. The address * structure is optional. The sa structure will contain * a network interface name on which the connection was established */ if (connect(sock, (struct sockaddr *)&sa, len) == 0){ printf("Connection Successful\n"); }else{ printf("Connection Failed\n"); close(sock); return 0; } /* Determine the lcn/ channel, through which we established connection. * Data will be returned in the API command structure */ if ((err=ioctl(sock,SIOC_WANPIPE_GET_CALL_DATA,&api_cmd)) != 0){ printf ("Failed to obtain connection information\n"); exit(1); }else{ printf("Call Established on LCN %i\n",api_cmd.hdr.lcn); }