/* af_x25.c:
*
* X.25 & SOCK_SEQPACKET Socket Address Example C Code:
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/x25.h>
/*
* This function reports the error and
* exits back to the shell:
*/
static void displayError(const char *on_what) {
perror(on_what);
exit(1);
}
int main(int argc, char **argv, char **envp) {
int z; /* Status return code */
int sck_x25; /* Socket */
struct sockaddr_x25 adr_x25;/* AF_X25 */
int len_x25; /* length */
const char x25_host[] /* X.121 addr */
= "79400900";
/*
* Create an AF_X25 socket
*/
sck_x25 = socket(AF_X25, SOCK_SEQPACKET, 0);
if ( sck_x25 == -1 ) {
displayError("socket()");
}
/*
* Form an AF_X25 Address
*/
adr_x25.sx25_family = AF_X25;
strcpy(adr_x25.sx25_addr.x25_addr,x25_host);
len_x25 = sizeof adr_x25;
/*
* Bind the address to the socket
*/
z = bind(sck_x25, (struct sockaddr *)&adr_x25, len_x25);
if ( z == -1 ) {
displayError("bind()");
}
puts("X.25 SOCKETS :");
system("cat /proc/net/x25");
return 0;
}
//output:
*
* X.25 & SOCK_SEQPACKET Socket Address Example C Code:
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/x25.h>
/*
* This function reports the error and
* exits back to the shell:
*/
static void displayError(const char *on_what) {
perror(on_what);
exit(1);
}
int main(int argc, char **argv, char **envp) {
int z; /* Status return code */
int sck_x25; /* Socket */
struct sockaddr_x25 adr_x25;/* AF_X25 */
int len_x25; /* length */
const char x25_host[] /* X.121 addr */
= "79400900";
/*
* Create an AF_X25 socket
*/
sck_x25 = socket(AF_X25, SOCK_SEQPACKET, 0);
if ( sck_x25 == -1 ) {
displayError("socket()");
}
/*
* Form an AF_X25 Address
*/
adr_x25.sx25_family = AF_X25;
strcpy(adr_x25.sx25_addr.x25_addr,x25_host);
len_x25 = sizeof adr_x25;
/*
* Bind the address to the socket
*/
z = bind(sck_x25, (struct sockaddr *)&adr_x25, len_x25);
if ( z == -1 ) {
displayError("bind()");
}
puts("X.25 SOCKETS :");
system("cat /proc/net/x25");
return 0;
}
//output:
$ ./af_x25
X.25 SOCKETS :
dest_addr src_addr dev lci st vs vr va t t2 t21 t22 t23 Snd-Q Rcv-Q inode
* 79400900 ??? 000 0 0 0 0 0 3 200 180 180 0 0 104172
$
NOTE
Normally socket addresses with variable elements like the AF_UNIX address family require a computed length of the address. The Linux implementation of the AF_X25 socket address, however, simply requires the fixed length of sizeof (sockaddr_x25). The host number must be null terminated within the sockaddr_x25 structure.
No comments:
Post a Comment